1
This commit is contained in:
parent
7c88a9a814
commit
6e48eaf266
@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"sync"
|
"sync"
|
||||||
|
"sync/atomic"
|
||||||
"github.com/aliyun/alibaba-cloud-sdk-go/services/geoip"
|
"github.com/aliyun/alibaba-cloud-sdk-go/services/geoip"
|
||||||
"q5"
|
"q5"
|
||||||
"f5"
|
"f5"
|
||||||
@ -30,6 +31,29 @@ type RiskMgr struct {
|
|||||||
accessKeyId string
|
accessKeyId string
|
||||||
accessSecret string
|
accessSecret string
|
||||||
sdkInfoMutex sync.RWMutex
|
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 {
|
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) {
|
func (this *RiskMgr) __analyseIsOpen(w* http.ResponseWriter, r *http.Request) {
|
||||||
if r.Method != "POST" {
|
isPass := func () bool {
|
||||||
q5.ResponseInt32Ok(w, "is_open", 0)
|
if r.Method != "POST" {
|
||||||
return
|
atomic.AddInt64(&this.totalHttpMethodBlockTimes, 1)
|
||||||
}
|
atomic.AddInt64(&this.httpMethodBlockTimes, 1)
|
||||||
accountId := q5.Request(r, "account_id").GetString()
|
return false
|
||||||
sessionId := q5.Request(r, "session_id").GetString()
|
}
|
||||||
if !f5.IsValidSessionId(accountId, sessionId, SESSION_KEY) {
|
accountId := q5.Request(r, "account_id").GetString()
|
||||||
q5.ResponseInt32Ok(w, "is_open", 0)
|
sessionId := q5.Request(r, "session_id").GetString()
|
||||||
return
|
if !f5.IsValidSessionId(accountId, sessionId, SESSION_KEY) {
|
||||||
}
|
atomic.AddInt64(&this.totalSessionErrBlockTimes, 1)
|
||||||
gameId := f5.ExtractGameIdFromAccountId(accountId)
|
atomic.AddInt64(&this.sessionErrBlockTimes, 1)
|
||||||
channel := f5.ExtractChannelFromAccountId(accountId)
|
return false
|
||||||
|
}
|
||||||
|
gameId := f5.ExtractGameIdFromAccountId(accountId)
|
||||||
|
channel := f5.ExtractChannelFromAccountId(accountId)
|
||||||
|
|
||||||
remoteAddr := q5.GetRequestRemoteAddr(r)
|
remoteAddr := q5.GetRequestRemoteAddr(r)
|
||||||
if G.RiskMgr.InIpWhiteList(remoteAddr) {
|
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)
|
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 {
|
} else {
|
||||||
|
atomic.AddInt64(&this.totalBlockTimes, 1)
|
||||||
|
atomic.AddInt64(&this.blockTimes, 1)
|
||||||
q5.ResponseInt32Ok(w, "is_open", 0)
|
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) {
|
func (this *RiskMgr) __opsSyncConf(w* http.ResponseWriter, r *http.Request) {
|
||||||
|
q5.ResponseOk(w)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user