1
This commit is contained in:
parent
7c88a9a814
commit
6e48eaf266
@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"net/http"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"github.com/aliyun/alibaba-cloud-sdk-go/services/geoip"
|
||||
"q5"
|
||||
"f5"
|
||||
@ -30,6 +31,29 @@ type RiskMgr struct {
|
||||
accessKeyId string
|
||||
accessSecret string
|
||||
sdkInfoMutex sync.RWMutex
|
||||
|
||||
totalPassTimes int64
|
||||
totalBlockTimes int64
|
||||
passTimes int64
|
||||
blockTimes int64
|
||||
|
||||
totalIpWhiteListPassTimes int64
|
||||
ipWhiteListPassTimes int64
|
||||
totalLaunchWhiteListPassTimes int64
|
||||
launchWhiteListPassTimes int64
|
||||
totalSafeZonePassTimes int64
|
||||
safeZonePassTimes int64
|
||||
|
||||
totalHttpMethodBlockTimes int64
|
||||
httpMethodBlockTimes int64
|
||||
totalSessionErrBlockTimes int64
|
||||
sessionErrBlockTimes int64
|
||||
totalIpBlackListBlockTimes int64
|
||||
ipBlackListBlockTimes int64
|
||||
totalLaunchBlackListBlockTimes int64
|
||||
launchBlackListBlockTimes int64
|
||||
totalUnSafeZoneBlockTimes int64
|
||||
unSafeZoneBlockTimes int64
|
||||
}
|
||||
|
||||
func (this* RiskMgr) Init() *RiskMgr {
|
||||
@ -161,43 +185,62 @@ func (this* RiskMgr) IsSafeZone(gameId int32, channel int32, ip string) bool {
|
||||
}
|
||||
|
||||
func (this *RiskMgr) __analyseIsOpen(w* http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != "POST" {
|
||||
q5.ResponseInt32Ok(w, "is_open", 0)
|
||||
return
|
||||
}
|
||||
accountId := q5.Request(r, "account_id").GetString()
|
||||
sessionId := q5.Request(r, "session_id").GetString()
|
||||
if !f5.IsValidSessionId(accountId, sessionId, SESSION_KEY) {
|
||||
q5.ResponseInt32Ok(w, "is_open", 0)
|
||||
return
|
||||
}
|
||||
gameId := f5.ExtractGameIdFromAccountId(accountId)
|
||||
channel := f5.ExtractChannelFromAccountId(accountId)
|
||||
isPass := func () bool {
|
||||
if r.Method != "POST" {
|
||||
atomic.AddInt64(&this.totalHttpMethodBlockTimes, 1)
|
||||
atomic.AddInt64(&this.httpMethodBlockTimes, 1)
|
||||
return false
|
||||
}
|
||||
accountId := q5.Request(r, "account_id").GetString()
|
||||
sessionId := q5.Request(r, "session_id").GetString()
|
||||
if !f5.IsValidSessionId(accountId, sessionId, SESSION_KEY) {
|
||||
atomic.AddInt64(&this.totalSessionErrBlockTimes, 1)
|
||||
atomic.AddInt64(&this.sessionErrBlockTimes, 1)
|
||||
return false
|
||||
}
|
||||
gameId := f5.ExtractGameIdFromAccountId(accountId)
|
||||
channel := f5.ExtractChannelFromAccountId(accountId)
|
||||
|
||||
remoteAddr := q5.GetRequestRemoteAddr(r)
|
||||
if G.RiskMgr.InIpWhiteList(remoteAddr) {
|
||||
remoteAddr := q5.GetRequestRemoteAddr(r)
|
||||
if G.RiskMgr.InIpWhiteList(remoteAddr) {
|
||||
atomic.AddInt64(&this.totalIpWhiteListPassTimes, 1)
|
||||
atomic.AddInt64(&this.ipWhiteListPassTimes, 1)
|
||||
return true
|
||||
}
|
||||
if G.RiskMgr.InIpBlackList(remoteAddr) {
|
||||
atomic.AddInt64(&this.totalIpBlackListBlockTimes, 1)
|
||||
atomic.AddInt64(&this.ipBlackListBlockTimes, 1)
|
||||
return false
|
||||
}
|
||||
launchInfo := q5.GetPostBody(r).GetString()
|
||||
if G.RiskMgr.InLaunchWhiteList(gameId, channel, launchInfo) {
|
||||
atomic.AddInt64(&this.totalLaunchWhiteListPassTimes, 1)
|
||||
atomic.AddInt64(&this.launchWhiteListPassTimes, 1)
|
||||
return true
|
||||
}
|
||||
if G.RiskMgr.InLaunchBlackList(gameId, channel, launchInfo) {
|
||||
atomic.AddInt64(&this.totalLaunchBlackListBlockTimes, 1)
|
||||
atomic.AddInt64(&this.launchBlackListBlockTimes, 1)
|
||||
return false
|
||||
}
|
||||
if G.RiskMgr.IsSafeZone(gameId, channel, remoteAddr) {
|
||||
atomic.AddInt64(&this.totalSafeZonePassTimes, 1)
|
||||
atomic.AddInt64(&this.safeZonePassTimes, 1)
|
||||
return true
|
||||
} else {
|
||||
atomic.AddInt64(&this.totalUnSafeZoneBlockTimes, 1)
|
||||
atomic.AddInt64(&this.unSafeZoneBlockTimes, 1)
|
||||
return false
|
||||
}
|
||||
}
|
||||
if isPass() {
|
||||
atomic.AddInt64(&this.totalPassTimes, 1)
|
||||
atomic.AddInt64(&this.passTimes, 1)
|
||||
q5.ResponseInt32Ok(w, "is_open", 1)
|
||||
return
|
||||
}
|
||||
if G.RiskMgr.InIpBlackList(remoteAddr) {
|
||||
q5.ResponseInt32Ok(w, "is_open", 0)
|
||||
return
|
||||
}
|
||||
launchInfo := q5.GetPostBody(r).GetString()
|
||||
if G.RiskMgr.InLaunchWhiteList(gameId, channel, launchInfo) {
|
||||
q5.ResponseInt32Ok(w, "is_open", 1)
|
||||
return
|
||||
}
|
||||
if G.RiskMgr.InLaunchBlackList(gameId, channel, launchInfo) {
|
||||
q5.ResponseInt32Ok(w, "is_open", 0)
|
||||
return
|
||||
}
|
||||
if G.RiskMgr.IsSafeZone(gameId, channel, remoteAddr) {
|
||||
q5.ResponseInt32Ok(w, "is_open", 1)
|
||||
return
|
||||
} else {
|
||||
atomic.AddInt64(&this.totalBlockTimes, 1)
|
||||
atomic.AddInt64(&this.blockTimes, 1)
|
||||
q5.ResponseInt32Ok(w, "is_open", 0)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
@ -236,4 +279,5 @@ func (this *RiskMgr) __opsDump(w* http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func (this *RiskMgr) __opsSyncConf(w* http.ResponseWriter, r *http.Request) {
|
||||
q5.ResponseOk(w)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user