1
This commit is contained in:
parent
b49eac4934
commit
5759cb3be2
@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"net/http"
|
||||
"sync"
|
||||
//"github.com/aliyun/alibaba-cloud-sdk-go/services/geoip"
|
||||
"q5"
|
||||
"f5"
|
||||
)
|
||||
@ -19,6 +20,9 @@ type RiskMgr struct {
|
||||
|
||||
launchBlackList map[string]int32
|
||||
launchBlackListMutex sync.RWMutex
|
||||
|
||||
blockProvinceCityHash map[string]int32
|
||||
blockProvinceCityHashMutex sync.RWMutex
|
||||
}
|
||||
|
||||
func (this* RiskMgr) Init() *RiskMgr {
|
||||
@ -26,15 +30,18 @@ func (this* RiskMgr) Init() *RiskMgr {
|
||||
this.ipBlackListMutex.Lock()
|
||||
this.launchWhiteListMutex.Lock()
|
||||
this.launchBlackListMutex.Lock()
|
||||
this.blockProvinceCityHashMutex.Lock()
|
||||
defer this.ipWhiteListMutex.Unlock()
|
||||
defer this.ipBlackListMutex.Unlock()
|
||||
defer this.launchWhiteListMutex.Unlock()
|
||||
defer this.launchBlackListMutex.Unlock()
|
||||
defer this.blockProvinceCityHashMutex.Unlock()
|
||||
|
||||
this.ipWhiteList = make(map[string]int32)
|
||||
this.ipBlackList = make(map[string]int32)
|
||||
this.launchWhiteList = make(map[string]int32)
|
||||
this.launchBlackList = make(map[string]int32)
|
||||
this.blockProvinceCityHash = make(map[string]int32)
|
||||
|
||||
for _, val := range G.MetaMgr.GetIpWhiteList().GetList() {
|
||||
this.ipWhiteList[val] = 1
|
||||
@ -84,10 +91,45 @@ func (this* RiskMgr) InLaunchBlackList(gameId int32, channel int32, launchInfo s
|
||||
return ok
|
||||
}
|
||||
|
||||
func (this* RiskMgr) IsSafeZone(gameId int32, channel int32, ip string) bool {
|
||||
func (this* RiskMgr) IsBlockZone(gameId int32, channel int32,
|
||||
country string, province string, city string) bool {
|
||||
if country == "" || province == "" || city == "" {
|
||||
return true
|
||||
}
|
||||
if country != "中国" {
|
||||
return true
|
||||
}
|
||||
|
||||
this.blockProvinceCityHashMutex.Lock()
|
||||
defer this.blockProvinceCityHashMutex.Unlock()
|
||||
if _, ok := this.blockProvinceCityHash[province]; ok {
|
||||
return true
|
||||
}
|
||||
if _, ok := this.blockProvinceCityHash[city]; ok {
|
||||
return true
|
||||
}
|
||||
if _, ok := this.blockProvinceCityHash[province + "/" + city]; ok {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (this* RiskMgr) IsSafeZone(gameId int32, channel int32, ip string) bool {
|
||||
//_, _ := geoip.NewClientWithAccessKey("cn-hangzhou", "<accessKeyId>", "<accessSecret>")
|
||||
response := ""
|
||||
xobj := q5.NewXoFromJsonStr(response)
|
||||
if xobj == nil {
|
||||
return false
|
||||
}
|
||||
if !xobj.IsObject() {
|
||||
return false
|
||||
}
|
||||
country := xobj.GetSimpleStr("Country", "")
|
||||
province := xobj.GetSimpleStr("Province", "")
|
||||
city := xobj.GetSimpleStr("City", "")
|
||||
return !this.IsBlockZone(gameId, channel, country, province, city)
|
||||
}
|
||||
|
||||
func (this *RiskMgr) __analyseIsOpen(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != "POST" {
|
||||
q5.ResponseInt32Ok(w, "is_open", 0)
|
||||
|
2
third_party/q5
vendored
2
third_party/q5
vendored
@ -1 +1 @@
|
||||
Subproject commit f9776ebd7cdd0b60b64c762b7d3325b691714745
|
||||
Subproject commit e21d2e3b5d4f2c80ade87837c1f80ccc1e474fe6
|
Loading…
x
Reference in New Issue
Block a user