From 7fbe9edc4d680c09d0e9955d3384c6278716856b Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Thu, 7 Jan 2021 14:03:59 +0800 Subject: [PATCH] 1 --- server/analyseapi/gameconf.go | 40 +++++------------------------------ server/analyseapi/riskmgr.go | 26 ++++++++++++++++++++++- 2 files changed, 30 insertions(+), 36 deletions(-) diff --git a/server/analyseapi/gameconf.go b/server/analyseapi/gameconf.go index eb13cb1..279321f 100644 --- a/server/analyseapi/gameconf.go +++ b/server/analyseapi/gameconf.go @@ -3,7 +3,6 @@ package main import ( "sync" "sync/atomic" - "github.com/aliyun/alibaba-cloud-sdk-go/services/geoip" "f5" "q5" ) @@ -33,10 +32,6 @@ type GameConf struct { totalSafeZonePassTimes int64 safeZonePassTimes int64 - totalHttpMethodBlockTimes int64 - httpMethodBlockTimes int64 - totalSessionErrBlockTimes int64 - sessionErrBlockTimes int64 totalIpBlackListBlockTimes int64 ipBlackListBlockTimes int64 totalLaunchBlackListBlockTimes int64 @@ -45,7 +40,7 @@ type GameConf struct { unSafeZoneBlockTimes int64 } -func (this *GameConf) IsPass(remoteAddr string, launchInfo string) bool { +func (this *GameConf) IsPass(remoteAddr string, launchInfo string, responseStr* string) bool { if G.MetaMgr.InIpWhiteList(remoteAddr) { atomic.AddInt64(&this.totalIpWhiteListPassTimes, 1) atomic.AddInt64(&this.ipWhiteListPassTimes, 1) @@ -66,7 +61,8 @@ func (this *GameConf) IsPass(remoteAddr string, launchInfo string) bool { atomic.AddInt64(&this.launchBlackListBlockTimes, 1) return false }*/ - /*if G.RiskMgr.IsSafeZone(gameId, channel, remoteAddr, &responseStr) { + + if G.RiskMgr.IsSafeZone(remoteAddr, responseStr) { atomic.AddInt64(&this.totalSafeZonePassTimes, 1) atomic.AddInt64(&this.safeZonePassTimes, 1) return true @@ -74,7 +70,7 @@ func (this *GameConf) IsPass(remoteAddr string, launchInfo string) bool { atomic.AddInt64(&this.totalUnSafeZoneBlockTimes, 1) atomic.AddInt64(&this.unSafeZoneBlockTimes, 1) return false - }*/ + } return false } @@ -114,29 +110,6 @@ func (this* GameConf) Init() { })) } -func (this* GameConf) IsSafeZone(ip string, responseStr* string) bool { - 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()) - return false - } - - request := geoip.CreateDescribeIpv4LocationRequest() - request.Scheme = "https" - request.Ip = ip - - response, err := client.DescribeIpv4Location(request) - if err != nil { - f5.SysLog().Warning("Ipv4Location error %s", err.Error()) - return false - } - *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() @@ -175,10 +148,7 @@ func (this* GameConf) GetPassObj() *q5.XObject { func (this* GameConf) GetBlockObj() *q5.XObject { blockObj := q5.NewMxoObject() - /*blockObj.SetXValue("total_method_err_times", q5.NewXInt64(this.totalHttpMethodBlockTimes)) - blockObj.SetXValue("curr_method_err_times", q5.NewXInt64(this.httpMethodBlockTimes)) - blockObj.SetXValue("total_session_err_times", q5.NewXInt64(this.totalSessionErrBlockTimes)) - blockObj.SetXValue("curr_session_err_times", q5.NewXInt64(this.sessionErrBlockTimes)) + /* blockObj.SetXValue("total_black_ip_times", q5.NewXInt64(this.totalIpBlackListBlockTimes)) blockObj.SetXValue("curr_black_ip_times", q5.NewXInt64(this.ipBlackListBlockTimes)) blockObj.SetXValue("total_black_launch_times", q5.NewXInt64(this.totalLaunchBlackListBlockTimes)) diff --git a/server/analyseapi/riskmgr.go b/server/analyseapi/riskmgr.go index 7b39ca3..da1785f 100644 --- a/server/analyseapi/riskmgr.go +++ b/server/analyseapi/riskmgr.go @@ -4,6 +4,7 @@ import ( "fmt" "sync" "sync/atomic" + "github.com/aliyun/alibaba-cloud-sdk-go/services/geoip" "q5" "f5" ) @@ -155,7 +156,7 @@ func (this *RiskMgr) _analyseIsOpen(c *f5.Context) { remoteAddr = c.Request("ip").GetString() } launchInfo := c.GetBody().GetString() - return gameConf.IsPass(remoteAddr, launchInfo) + return gameConf.IsPass(remoteAddr, launchInfo, &responseStr) } if isPass() { atomic.AddInt64(&this.totalPassTimes, 1) @@ -241,3 +242,26 @@ func (this *RiskMgr) OnGameConfCreate(gameId int32, channel int32) { } }) } + +func (this* RiskMgr) IsSafeZone(ip string, responseStr* string) bool { + 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()) + return false + } + + request := geoip.CreateDescribeIpv4LocationRequest() + request.Scheme = "https" + request.Ip = ip + + response, err := client.DescribeIpv4Location(request) + if err != nil { + f5.SysLog().Warning("Ipv4Location error %s", err.Error()) + return false + } + *responseStr = q5.EncodeJson(response) + return !G.MetaMgr.IsBlockZone(response.Country, response.Province, response.City) +}