From 6c4a9292f4ae31d6fae26e0d97932b6ed4a265f2 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Thu, 7 Jan 2021 13:50:05 +0800 Subject: [PATCH] 1 --- server/analyseapi/gameconf.go | 44 ++++------------------------------- server/analyseapi/metamgr.go | 39 ++++++++++++++++++++++++++++++- server/analyseapi/riskmgr.go | 13 ----------- 3 files changed, 42 insertions(+), 54 deletions(-) diff --git a/server/analyseapi/gameconf.go b/server/analyseapi/gameconf.go index e37c6bc..eb13cb1 100644 --- a/server/analyseapi/gameconf.go +++ b/server/analyseapi/gameconf.go @@ -21,9 +21,6 @@ type GameConf struct { launchBlackList map[string]int32 launchBlackListMutex sync.RWMutex - blockRegionHash map[string]int32 - blockRegionHashMutex sync.RWMutex - totalPassTimes int64 totalBlockTimes int64 passTimes int64 @@ -98,14 +95,11 @@ func (this* GameConf) InLaunchBlackList(gameId int32, channel int32, launchInfo func (this* GameConf) Init() { this.launchWhiteListMutex.Lock() this.launchBlackListMutex.Lock() - this.blockRegionHashMutex.Lock() defer this.launchWhiteListMutex.Unlock() defer this.launchBlackListMutex.Unlock() - defer this.blockRegionHashMutex.Unlock() this.launchWhiteList = make(map[string]int32) this.launchBlackList = make(map[string]int32) - this.blockRegionHash = make(map[string]int32) for _, val := range G.MetaMgr.GetLaunchWhiteList().GetList() { this.launchWhiteList[val] = 1 @@ -113,9 +107,6 @@ func (this* GameConf) Init() { for _, val := range G.MetaMgr.GetLaunchBlackList().GetList() { this.launchBlackList[val] = 1 } - for _, val := range G.MetaMgr.GetFixedBlockRegion().GetList() { - this.blockRegionHash[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) @@ -123,32 +114,10 @@ func (this* GameConf) Init() { })) } -func (this* GameConf) IsBlockZone(country string, province string, city string) bool { - if country == "" || province == "" || city == "" { - return true - } - if country != "中国" { - return true - } - - /*this.blockRegionHashMutex.Lock() - defer this.blockRegionHashMutex.Unlock() - if _, ok := this.blockRegionHash[province]; ok { - return true - } - if _, ok := this.blockRegionHash[city]; ok { - return true - } - if _, ok := this.blockRegionHash[province + "/" + city]; ok { - return true - }*/ - return false -} - -func (this* GameConf) IsSafeZone(ip string, response_str* string) bool { +func (this* GameConf) IsSafeZone(ip string, responseStr* string) bool { accessKeyId := "" accessSecret := "" - G.RiskMgr.GetSdkInfo(&accessKeyId, &accessSecret) + G.MetaMgr.GetSdkInfo(&accessKeyId, &accessSecret) client, err := geoip.NewClientWithAccessKey("cn-hangzhou", accessKeyId, accessSecret) if err != nil { f5.SysLog().Warning("NewClientWithAccessKey error %s", err.Error()) @@ -164,19 +133,15 @@ func (this* GameConf) IsSafeZone(ip string, response_str* string) bool { f5.SysLog().Warning("Ipv4Location error %s", err.Error()) return false } - *response_str = q5.EncodeJson(response) - return !this.IsBlockZone(response.Country, response.Province, response.City) + *responseStr = q5.EncodeJson(response) + return !G.MetaMgr.IsBlockZone(response.Country, response.Province, response.City) } func (this* GameConf) Dump() *q5.MutableXObject { this.launchWhiteListMutex.Lock() this.launchBlackListMutex.Lock() - this.blockRegionHashMutex.Lock() - //this.fixedBlockProvinceCityHashMutex.Lock() defer this.launchWhiteListMutex.Unlock() defer this.launchBlackListMutex.Unlock() - defer this.blockRegionHashMutex.Unlock() - //defer this.fixedBlockProvinceCityHashMutex.Unlock() fillRespObj := func(respObj* q5.MutableXObject, attrName string, mapObj* map[string]int32) { list := q5.NewMxoArray() @@ -193,7 +158,6 @@ func (this* GameConf) Dump() *q5.MutableXObject { //fillRespObj(respObj, "ip_black_list", &this.ipBlackList) fillRespObj(respObj, "launch_white_list", &this.launchWhiteList) fillRespObj(respObj, "launch_black_list", &this.launchBlackList) - fillRespObj(respObj, "block_province_city_list", &this.blockRegionHash) //fillRespObj(respObj, "fixed_block_province_city_list", &this.fixedBlockProvinceCityHash) return respObj } diff --git a/server/analyseapi/metamgr.go b/server/analyseapi/metamgr.go index 67cf84a..7718d08 100644 --- a/server/analyseapi/metamgr.go +++ b/server/analyseapi/metamgr.go @@ -20,6 +20,10 @@ const ( type MetaMgr struct { f5.MetaMgr + accessKeyId string + accessSecret string + sdkInfoMutex sync.RWMutex + ipWhiteList map[string]int32 ipWhiteListMutex sync.RWMutex @@ -28,7 +32,6 @@ type MetaMgr struct { fixedBlockRegionHash map[string]int32 fixedBlockRegionHashMutex sync.RWMutex - } func (this *MetaMgr) Init() *MetaMgr { @@ -86,13 +89,18 @@ func (this *MetaMgr) UnInit() { } func (this *MetaMgr) secondInit() { + this.sdkInfoMutex.Lock() this.ipWhiteListMutex.Lock() this.ipBlackListMutex.Lock() this.fixedBlockRegionHashMutex.Lock() + defer this.sdkInfoMutex.Unlock() defer this.ipWhiteListMutex.Unlock() defer this.ipBlackListMutex.Unlock() defer this.fixedBlockRegionHashMutex.Unlock() + this.accessKeyId = G.MetaMgr.GetAliKey().GetAccessKeyid() + this.accessSecret = G.MetaMgr.GetAliKey().GetAccessSecret() + this.ipWhiteList = make(map[string]int32) this.ipBlackList = make(map[string]int32) this.fixedBlockRegionHash = make(map[string]int32) @@ -190,3 +198,32 @@ func (this* MetaMgr) InIpBlackList(ip string) bool { _, ok := this.ipBlackList[ip] return ok } + +func (this* MetaMgr) GetSdkInfo(accessKeyId* string, accessSecret* string) { + this.sdkInfoMutex.Lock() + defer this.sdkInfoMutex.Unlock() + *accessKeyId = "" + this.accessKeyId + *accessSecret = "" + this.accessSecret +} + +func (this* MetaMgr) IsBlockZone(country string, province string, city string) bool { + if country == "" || province == "" || city == "" { + return true + } + if country != "中国" { + return true + } + + /*this.blockRegionHashMutex.Lock() + defer this.blockRegionHashMutex.Unlock() + if _, ok := this.blockRegionHash[province]; ok { + return true + } + if _, ok := this.blockRegionHash[city]; ok { + return true + } + if _, ok := this.blockRegionHash[province + "/" + city]; ok { + return true + }*/ + return false +} diff --git a/server/analyseapi/riskmgr.go b/server/analyseapi/riskmgr.go index 91921f5..7b39ca3 100644 --- a/server/analyseapi/riskmgr.go +++ b/server/analyseapi/riskmgr.go @@ -9,10 +9,6 @@ import ( ) type RiskMgr struct { - accessKeyId string - accessSecret string - sdkInfoMutex sync.RWMutex - totalPassTimes int64 totalBlockTimes int64 passTimes int64 @@ -34,8 +30,6 @@ func (this* RiskMgr) Init() *RiskMgr { defer this.gameHashMutex.Unlock() this.gameHash = make(map[int64]*GameConf) - this.accessKeyId = G.MetaMgr.GetAliKey().GetAccessKeyid() - this.accessSecret = G.MetaMgr.GetAliKey().GetAccessSecret() this.clusterConf = G.MetaMgr.GetCurrServer() G.HttpServer.RegisterHandle("Analyse", "isOpen", this._analyseIsOpen) @@ -108,13 +102,6 @@ func (this* RiskMgr) GetGlobalBlockObj() *q5.XObject { return blockObj.AsXObject() } -func (this* RiskMgr) GetSdkInfo(accessKeyId* string, accessSecret* string) { - this.sdkInfoMutex.Lock() - defer this.sdkInfoMutex.Unlock() - *accessKeyId = "" + this.accessKeyId - *accessSecret = "" + this.accessSecret -} - func (this *RiskMgr) ForceGameConf(gameId int32, channel int32) *GameConf { this.gameHashMutex.Lock() defer this.gameHashMutex.Unlock()