This commit is contained in:
aozhiwei 2021-01-07 13:50:05 +08:00
parent 910ba5968f
commit 6c4a9292f4
3 changed files with 42 additions and 54 deletions

View File

@ -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
}

View File

@ -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
}

View File

@ -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()