From 5759cb3be2dad3bac9d10caaabe8b47a070eb08b Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Wed, 28 Oct 2020 19:19:32 +0800 Subject: [PATCH] 1 --- server/analyseapi/riskmgr.go | 44 +++++++++++++++++++++++++++++++++++- third_party/q5 | 2 +- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/server/analyseapi/riskmgr.go b/server/analyseapi/riskmgr.go index 926865f..e5f20f8 100644 --- a/server/analyseapi/riskmgr.go +++ b/server/analyseapi/riskmgr.go @@ -3,6 +3,7 @@ package main import ( "net/http" "sync" + //"github.com/aliyun/alibaba-cloud-sdk-go/services/geoip" "q5" "f5" ) @@ -19,6 +20,9 @@ type RiskMgr struct { launchBlackList map[string]int32 launchBlackListMutex sync.RWMutex + + blockProvinceCityHash map[string]int32 + blockProvinceCityHashMutex sync.RWMutex } func (this* RiskMgr) Init() *RiskMgr { @@ -26,15 +30,18 @@ func (this* RiskMgr) Init() *RiskMgr { this.ipBlackListMutex.Lock() this.launchWhiteListMutex.Lock() this.launchBlackListMutex.Lock() + this.blockProvinceCityHashMutex.Lock() defer this.ipWhiteListMutex.Unlock() defer this.ipBlackListMutex.Unlock() defer this.launchWhiteListMutex.Unlock() defer this.launchBlackListMutex.Unlock() + defer this.blockProvinceCityHashMutex.Unlock() this.ipWhiteList = make(map[string]int32) this.ipBlackList = make(map[string]int32) this.launchWhiteList = make(map[string]int32) this.launchBlackList = make(map[string]int32) + this.blockProvinceCityHash = make(map[string]int32) for _, val := range G.MetaMgr.GetIpWhiteList().GetList() { this.ipWhiteList[val] = 1 @@ -84,10 +91,45 @@ func (this* RiskMgr) InLaunchBlackList(gameId int32, channel int32, launchInfo s return ok } -func (this* RiskMgr) IsSafeZone(gameId int32, channel int32, ip string) bool { +func (this* RiskMgr) IsBlockZone(gameId int32, channel int32, + country string, province string, city string) bool { + if country == "" || province == "" || city == "" { + return true + } + if country != "中国" { + return true + } + + this.blockProvinceCityHashMutex.Lock() + defer this.blockProvinceCityHashMutex.Unlock() + if _, ok := this.blockProvinceCityHash[province]; ok { + return true + } + if _, ok := this.blockProvinceCityHash[city]; ok { + return true + } + if _, ok := this.blockProvinceCityHash[province + "/" + city]; ok { + return true + } return false } +func (this* RiskMgr) IsSafeZone(gameId int32, channel int32, ip string) bool { + //_, _ := geoip.NewClientWithAccessKey("cn-hangzhou", "", "") + response := "" + xobj := q5.NewXoFromJsonStr(response) + if xobj == nil { + return false + } + if !xobj.IsObject() { + return false + } + country := xobj.GetSimpleStr("Country", "") + province := xobj.GetSimpleStr("Province", "") + city := xobj.GetSimpleStr("City", "") + return !this.IsBlockZone(gameId, channel, country, province, city) +} + func (this *RiskMgr) __analyseIsOpen(w http.ResponseWriter, r *http.Request) { if r.Method != "POST" { q5.ResponseInt32Ok(w, "is_open", 0) diff --git a/third_party/q5 b/third_party/q5 index f9776eb..e21d2e3 160000 --- a/third_party/q5 +++ b/third_party/q5 @@ -1 +1 @@ -Subproject commit f9776ebd7cdd0b60b64c762b7d3325b691714745 +Subproject commit e21d2e3b5d4f2c80ade87837c1f80ccc1e474fe6