This commit is contained in:
aozhiwei 2021-01-07 14:03:59 +08:00
parent 6c4a9292f4
commit 7fbe9edc4d
2 changed files with 30 additions and 36 deletions

View File

@ -3,7 +3,6 @@ package main
import ( import (
"sync" "sync"
"sync/atomic" "sync/atomic"
"github.com/aliyun/alibaba-cloud-sdk-go/services/geoip"
"f5" "f5"
"q5" "q5"
) )
@ -33,10 +32,6 @@ type GameConf struct {
totalSafeZonePassTimes int64 totalSafeZonePassTimes int64
safeZonePassTimes int64 safeZonePassTimes int64
totalHttpMethodBlockTimes int64
httpMethodBlockTimes int64
totalSessionErrBlockTimes int64
sessionErrBlockTimes int64
totalIpBlackListBlockTimes int64 totalIpBlackListBlockTimes int64
ipBlackListBlockTimes int64 ipBlackListBlockTimes int64
totalLaunchBlackListBlockTimes int64 totalLaunchBlackListBlockTimes int64
@ -45,7 +40,7 @@ type GameConf struct {
unSafeZoneBlockTimes int64 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) { if G.MetaMgr.InIpWhiteList(remoteAddr) {
atomic.AddInt64(&this.totalIpWhiteListPassTimes, 1) atomic.AddInt64(&this.totalIpWhiteListPassTimes, 1)
atomic.AddInt64(&this.ipWhiteListPassTimes, 1) atomic.AddInt64(&this.ipWhiteListPassTimes, 1)
@ -66,7 +61,8 @@ func (this *GameConf) IsPass(remoteAddr string, launchInfo string) bool {
atomic.AddInt64(&this.launchBlackListBlockTimes, 1) atomic.AddInt64(&this.launchBlackListBlockTimes, 1)
return false return false
}*/ }*/
/*if G.RiskMgr.IsSafeZone(gameId, channel, remoteAddr, &responseStr) {
if G.RiskMgr.IsSafeZone(remoteAddr, responseStr) {
atomic.AddInt64(&this.totalSafeZonePassTimes, 1) atomic.AddInt64(&this.totalSafeZonePassTimes, 1)
atomic.AddInt64(&this.safeZonePassTimes, 1) atomic.AddInt64(&this.safeZonePassTimes, 1)
return true return true
@ -74,7 +70,7 @@ func (this *GameConf) IsPass(remoteAddr string, launchInfo string) bool {
atomic.AddInt64(&this.totalUnSafeZoneBlockTimes, 1) atomic.AddInt64(&this.totalUnSafeZoneBlockTimes, 1)
atomic.AddInt64(&this.unSafeZoneBlockTimes, 1) atomic.AddInt64(&this.unSafeZoneBlockTimes, 1)
return false return false
}*/ }
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 { func (this* GameConf) Dump() *q5.MutableXObject {
this.launchWhiteListMutex.Lock() this.launchWhiteListMutex.Lock()
this.launchBlackListMutex.Lock() this.launchBlackListMutex.Lock()
@ -175,10 +148,7 @@ func (this* GameConf) GetPassObj() *q5.XObject {
func (this* GameConf) GetBlockObj() *q5.XObject { func (this* GameConf) GetBlockObj() *q5.XObject {
blockObj := q5.NewMxoObject() 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("total_black_ip_times", q5.NewXInt64(this.totalIpBlackListBlockTimes))
blockObj.SetXValue("curr_black_ip_times", q5.NewXInt64(this.ipBlackListBlockTimes)) blockObj.SetXValue("curr_black_ip_times", q5.NewXInt64(this.ipBlackListBlockTimes))
blockObj.SetXValue("total_black_launch_times", q5.NewXInt64(this.totalLaunchBlackListBlockTimes)) blockObj.SetXValue("total_black_launch_times", q5.NewXInt64(this.totalLaunchBlackListBlockTimes))

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
"sync" "sync"
"sync/atomic" "sync/atomic"
"github.com/aliyun/alibaba-cloud-sdk-go/services/geoip"
"q5" "q5"
"f5" "f5"
) )
@ -155,7 +156,7 @@ func (this *RiskMgr) _analyseIsOpen(c *f5.Context) {
remoteAddr = c.Request("ip").GetString() remoteAddr = c.Request("ip").GetString()
} }
launchInfo := c.GetBody().GetString() launchInfo := c.GetBody().GetString()
return gameConf.IsPass(remoteAddr, launchInfo) return gameConf.IsPass(remoteAddr, launchInfo, &responseStr)
} }
if isPass() { if isPass() {
atomic.AddInt64(&this.totalPassTimes, 1) 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)
}