1
This commit is contained in:
parent
6c4a9292f4
commit
7fbe9edc4d
@ -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))
|
||||
|
@ -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)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user