From b49eac493487f7e26b4be688f4ebdf65a65db986 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Wed, 28 Oct 2020 17:00:44 +0800 Subject: [PATCH] 1 --- server/analyseapi/riskmgr.go | 40 +++++++++++++++++++++++++++--------- third_party/q5 | 2 +- 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/server/analyseapi/riskmgr.go b/server/analyseapi/riskmgr.go index 28c46b6..926865f 100644 --- a/server/analyseapi/riskmgr.go +++ b/server/analyseapi/riskmgr.go @@ -3,8 +3,8 @@ package main import ( "net/http" "sync" - "fmt" "q5" + "f5" ) type RiskMgr struct { @@ -70,41 +70,61 @@ func (this* RiskMgr) InIpBlackList(ip string) bool { return ok } -func (this* RiskMgr) InLaunchWhiteList(launchInfo string) bool { +func (this* RiskMgr) InLaunchWhiteList(gameId int32, channel int32, launchInfo string) bool { this.launchWhiteListMutex.Lock() defer this.launchWhiteListMutex.Unlock() _, ok := this.launchWhiteList[launchInfo] return ok } -func (this* RiskMgr) InLaunchBlackList(launchInfo string) bool { +func (this* RiskMgr) InLaunchBlackList(gameId int32, channel int32, launchInfo string) bool { this.launchBlackListMutex.Lock() defer this.launchBlackListMutex.Unlock() _, ok := this.launchBlackList[launchInfo] 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) { if r.Method != "POST" { - w.Write([]byte(fmt.Sprintf(`{"errcode":0, "errmsg":"", "is_open":%d}`, 1))) + 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) + remoteAddr := q5.GetRequestRemoteAddr(r) if G.RiskMgr.InIpWhiteList(remoteAddr) { - w.Write([]byte(fmt.Sprintf(`{"errcode":0, "errmsg":"", "is_open":%d}`, 1))) + q5.ResponseInt32Ok(w, "is_open", 1) return } if G.RiskMgr.InIpBlackList(remoteAddr) { - w.Write([]byte(fmt.Sprintf(`{"errcode":0, "errmsg":"", "is_open":%d}`, 0))) + q5.ResponseInt32Ok(w, "is_open", 0) return } launchInfo := q5.GetPostBody(r).GetString() - if G.RiskMgr.InLaunchWhiteList(launchInfo) { - w.Write([]byte(fmt.Sprintf(`{"errcode":0, "errmsg":"", "is_open":%d}`, 1))) + if G.RiskMgr.InLaunchWhiteList(gameId, channel, launchInfo) { + q5.ResponseInt32Ok(w, "is_open", 1) return } - if G.RiskMgr.InLaunchBlackList(launchInfo) { - w.Write([]byte(fmt.Sprintf(`{"errcode":0, "errmsg":"", "is_open":%d}`, 0))) + 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 { + q5.ResponseInt32Ok(w, "is_open", 0) return } } diff --git a/third_party/q5 b/third_party/q5 index 933ed5c..f9776eb 160000 --- a/third_party/q5 +++ b/third_party/q5 @@ -1 +1 @@ -Subproject commit 933ed5c972526defdfc035714f769ac10e0ce8c5 +Subproject commit f9776ebd7cdd0b60b64c762b7d3325b691714745