This commit is contained in:
aozhiwei 2020-10-28 17:00:44 +08:00
parent 156634c3e8
commit b49eac4934
2 changed files with 31 additions and 11 deletions

View File

@ -3,8 +3,8 @@ package main
import ( import (
"net/http" "net/http"
"sync" "sync"
"fmt"
"q5" "q5"
"f5"
) )
type RiskMgr struct { type RiskMgr struct {
@ -70,41 +70,61 @@ func (this* RiskMgr) InIpBlackList(ip string) bool {
return ok return ok
} }
func (this* RiskMgr) InLaunchWhiteList(launchInfo string) bool { func (this* RiskMgr) InLaunchWhiteList(gameId int32, channel int32, launchInfo string) bool {
this.launchWhiteListMutex.Lock() this.launchWhiteListMutex.Lock()
defer this.launchWhiteListMutex.Unlock() defer this.launchWhiteListMutex.Unlock()
_, ok := this.launchWhiteList[launchInfo] _, ok := this.launchWhiteList[launchInfo]
return ok return ok
} }
func (this* RiskMgr) InLaunchBlackList(launchInfo string) bool { func (this* RiskMgr) InLaunchBlackList(gameId int32, channel int32, launchInfo string) bool {
this.launchBlackListMutex.Lock() this.launchBlackListMutex.Lock()
defer this.launchBlackListMutex.Unlock() defer this.launchBlackListMutex.Unlock()
_, ok := this.launchBlackList[launchInfo] _, ok := this.launchBlackList[launchInfo]
return ok return ok
} }
func (this* RiskMgr) IsSafeZone(gameId int32, channel int32, ip string) bool {
return false
}
func (this *RiskMgr) __analyseIsOpen(w http.ResponseWriter, r *http.Request) { func (this *RiskMgr) __analyseIsOpen(w http.ResponseWriter, r *http.Request) {
if r.Method != "POST" { if r.Method != "POST" {
w.Write([]byte(fmt.Sprintf(`{"errcode":0, "errmsg":"", "is_open":%d}`, 1))) q5.ResponseInt32Ok(w, "is_open", 0)
return 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)
remoteAddr := q5.GetRequestRemoteAddr(r) remoteAddr := q5.GetRequestRemoteAddr(r)
if G.RiskMgr.InIpWhiteList(remoteAddr) { if G.RiskMgr.InIpWhiteList(remoteAddr) {
w.Write([]byte(fmt.Sprintf(`{"errcode":0, "errmsg":"", "is_open":%d}`, 1))) q5.ResponseInt32Ok(w, "is_open", 1)
return return
} }
if G.RiskMgr.InIpBlackList(remoteAddr) { if G.RiskMgr.InIpBlackList(remoteAddr) {
w.Write([]byte(fmt.Sprintf(`{"errcode":0, "errmsg":"", "is_open":%d}`, 0))) q5.ResponseInt32Ok(w, "is_open", 0)
return return
} }
launchInfo := q5.GetPostBody(r).GetString() launchInfo := q5.GetPostBody(r).GetString()
if G.RiskMgr.InLaunchWhiteList(launchInfo) { if G.RiskMgr.InLaunchWhiteList(gameId, channel, launchInfo) {
w.Write([]byte(fmt.Sprintf(`{"errcode":0, "errmsg":"", "is_open":%d}`, 1))) q5.ResponseInt32Ok(w, "is_open", 1)
return return
} }
if G.RiskMgr.InLaunchBlackList(launchInfo) { if G.RiskMgr.InLaunchBlackList(gameId, channel, launchInfo) {
w.Write([]byte(fmt.Sprintf(`{"errcode":0, "errmsg":"", "is_open":%d}`, 0))) q5.ResponseInt32Ok(w, "is_open", 0)
return
}
if G.RiskMgr.IsSafeZone(gameId, channel, remoteAddr) {
q5.ResponseInt32Ok(w, "is_open", 1)
return
} else {
q5.ResponseInt32Ok(w, "is_open", 0)
return return
} }
} }

2
third_party/q5 vendored

@ -1 +1 @@
Subproject commit 933ed5c972526defdfc035714f769ac10e0ce8c5 Subproject commit f9776ebd7cdd0b60b64c762b7d3325b691714745