186 lines
5.5 KiB
Go
186 lines
5.5 KiB
Go
package main
|
|
|
|
import (
|
|
"sync"
|
|
"sync/atomic"
|
|
"f5"
|
|
"q5"
|
|
)
|
|
|
|
type GameConf struct {
|
|
gameId int32
|
|
channel int32
|
|
syncTimes int64
|
|
lastSyncTime int64
|
|
lastActiveTime int64
|
|
|
|
sceneWhiteList map[string]int32
|
|
sceneWhiteListMutex sync.RWMutex
|
|
|
|
launchWhiteList map[string]int32
|
|
launchWhiteListMutex sync.RWMutex
|
|
|
|
totalPassTimes int64
|
|
totalBlockTimes int64
|
|
passTimes int64
|
|
blockTimes int64
|
|
|
|
totalLaunchWhiteListPassTimes int64
|
|
launchWhiteListPassTimes int64
|
|
totalSafeZonePassTimes int64
|
|
safeZonePassTimes int64
|
|
|
|
totalDataBlockTimes int64
|
|
sceneWhiteListBlockTimes int64
|
|
totalUnSafeZoneBlockTimes int64
|
|
unSafeZoneBlockTimes int64
|
|
}
|
|
|
|
func (this *GameConf) IsPass(remoteAddr string, launchInfo string, responseStr* string) bool {
|
|
launchObj := q5.NewXoFromJsonStr(launchInfo)
|
|
if launchObj == nil {
|
|
atomic.AddInt64(&this.totalDataBlockTimes, 1)
|
|
return false
|
|
}
|
|
if !this.InSceneWhiteList(launchObj) {
|
|
atomic.AddInt64(&this.sceneWhiteListBlockTimes, 1)
|
|
return false
|
|
}
|
|
if G.RiskMgr.IsSafeZone(remoteAddr, responseStr) {
|
|
atomic.AddInt64(&this.totalSafeZonePassTimes, 1)
|
|
atomic.AddInt64(&this.safeZonePassTimes, 1)
|
|
return true
|
|
} else {
|
|
if this.InLaunchWhiteList(launchObj) {
|
|
atomic.AddInt64(&this.totalLaunchWhiteListPassTimes, 1)
|
|
atomic.AddInt64(&this.launchWhiteListPassTimes, 1)
|
|
return true
|
|
} else {
|
|
atomic.AddInt64(&this.totalUnSafeZoneBlockTimes, 1)
|
|
atomic.AddInt64(&this.unSafeZoneBlockTimes, 1)
|
|
return false
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
func (this* GameConf) InSceneWhiteList(launchObj *q5.XObject) bool {
|
|
this.sceneWhiteListMutex.Lock()
|
|
defer this.sceneWhiteListMutex.Unlock()
|
|
if !launchObj.IsObject() ||
|
|
!launchObj.HasKey("scene") ||
|
|
!launchObj.At("scene").IsSimple() {
|
|
return false;
|
|
}
|
|
sceneId := launchObj.At("scene").AsXValue().GetInt32()
|
|
_, ok := this.sceneWhiteList[q5.NewXInt32(sceneId).GetString()]
|
|
return ok
|
|
}
|
|
|
|
func (this* GameConf) InLaunchWhiteList(launchObj *q5.XObject) bool {
|
|
this.launchWhiteListMutex.Lock()
|
|
defer this.launchWhiteListMutex.Unlock()
|
|
if launchObj.IsObject() &&
|
|
launchObj.HasKey("query") &&
|
|
launchObj.At("query").IsSimple() {
|
|
return launchObj.At("query").AsXValue().GetString() != "";
|
|
}
|
|
if launchObj.IsObject() &&
|
|
launchObj.HasKey("query") &&
|
|
launchObj.At("query").IsArray() {
|
|
return launchObj.At("query").Size() > 0;
|
|
}
|
|
if !launchObj.IsObject() ||
|
|
!launchObj.HasKey("query") ||
|
|
!launchObj.At("query").IsObject() {
|
|
return false;
|
|
}
|
|
return launchObj.At("query").Size() > 0;
|
|
/*queryObj := launchObj.At("query")
|
|
for key, _ := range(this.launchWhiteList) {
|
|
if queryObj.HasKey(key) {
|
|
return true;
|
|
}
|
|
}
|
|
return false*/
|
|
}
|
|
|
|
func (this* GameConf) Init() {
|
|
this.sceneWhiteListMutex.Lock()
|
|
this.launchWhiteListMutex.Lock()
|
|
defer this.sceneWhiteListMutex.Unlock()
|
|
defer this.launchWhiteListMutex.Unlock()
|
|
|
|
this.sceneWhiteList = make(map[string]int32)
|
|
this.launchWhiteList = make(map[string]int32)
|
|
|
|
for _, val := range G.MetaMgr.GetSceneWhiteList().GetList() {
|
|
this.sceneWhiteList[val] = 1
|
|
}
|
|
for _, val := range G.MetaMgr.GetLaunchWhiteList().GetList() {
|
|
this.launchWhiteList[val] = 1
|
|
}
|
|
this.lastActiveTime = f5.App.NowUnix()
|
|
f5.App.AddIMMsg(IM_GAMECONF_CREATE, new(q5.XParams).Init(func (params* q5.XParams) {
|
|
params.Sender.SetInt32(this.gameId)
|
|
params.Param1.SetInt32(this.channel)
|
|
}))
|
|
}
|
|
|
|
func (this* GameConf) GetConfObj() *q5.XObject {
|
|
this.sceneWhiteListMutex.Lock()
|
|
this.launchWhiteListMutex.Lock()
|
|
defer this.sceneWhiteListMutex.Unlock()
|
|
defer this.launchWhiteListMutex.Unlock()
|
|
|
|
fillRespObj := func(respObj* q5.MutableXObject, attrName string, mapObj* map[string]int32) {
|
|
list := q5.NewMxoArray()
|
|
for key, _ := range *mapObj {
|
|
list.PushXValue(q5.NewXString(key))
|
|
}
|
|
respObj.SetXObject(attrName, list.AsXObject())
|
|
}
|
|
|
|
respObj := q5.NewMxoObject()
|
|
fillRespObj(respObj, "scene_white_list", &this.sceneWhiteList)
|
|
fillRespObj(respObj, "launch_white_list", &this.launchWhiteList)
|
|
return respObj.AsXObject()
|
|
}
|
|
|
|
func (this* GameConf) GetPassObj() *q5.XObject {
|
|
passObj := q5.NewMxoObject()
|
|
passObj.SetXValue("total", q5.NewXInt64(this.totalPassTimes))
|
|
passObj.SetXValue("curr", q5.NewXInt64(this.passTimes))
|
|
passObj.SetXValue("total_white_launch_times", q5.NewXInt64(this.totalLaunchWhiteListPassTimes))
|
|
passObj.SetXValue("curr_white_launch_times", q5.NewXInt64(this.launchWhiteListPassTimes))
|
|
passObj.SetXValue("total_safezone_times", q5.NewXInt64(this.totalSafeZonePassTimes))
|
|
passObj.SetXValue("curr_safezone_times", q5.NewXInt64(this.safeZonePassTimes))
|
|
return passObj.AsXObject()
|
|
}
|
|
|
|
func (this* GameConf) GetBlockObj() *q5.XObject {
|
|
blockObj := q5.NewMxoObject()
|
|
blockObj.SetXValue("total", q5.NewXInt64(this.totalBlockTimes))
|
|
blockObj.SetXValue("curr", q5.NewXInt64(this.blockTimes))
|
|
blockObj.SetXValue("total_data_times", q5.NewXInt64(this.totalDataBlockTimes))
|
|
blockObj.SetXValue("curr_white_scene_times", q5.NewXInt64(this.sceneWhiteListBlockTimes))
|
|
blockObj.SetXValue("total_unsafezone_times", q5.NewXInt64(this.totalUnSafeZoneBlockTimes))
|
|
blockObj.SetXValue("curr_unsafezone_times", q5.NewXInt64(this.unSafeZoneBlockTimes))
|
|
return blockObj.AsXObject()
|
|
}
|
|
|
|
func (this* GameConf) Active() {
|
|
if f5.App.NowUnix() - this.lastActiveTime > 1000 * 30 {
|
|
atomic.StoreInt64(&this.passTimes, 0)
|
|
atomic.StoreInt64(&this.blockTimes, 0)
|
|
atomic.StoreInt64(&this.sceneWhiteListBlockTimes, 0)
|
|
atomic.StoreInt64(&this.safeZonePassTimes, 0)
|
|
atomic.StoreInt64(&this.launchWhiteListPassTimes, 0)
|
|
atomic.StoreInt64(&this.unSafeZoneBlockTimes, 0)
|
|
}
|
|
this.lastActiveTime = f5.App.NowUnix()
|
|
}
|
|
|
|
func (this* GameConf) SyncConf() {
|
|
}
|