add analyseapi
This commit is contained in:
parent
efcfe08c97
commit
0aeeca5e49
31
server/analyseapi/app.go
Normal file
31
server/analyseapi/app.go
Normal file
@ -0,0 +1,31 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"f5"
|
||||
)
|
||||
|
||||
type App_ struct {
|
||||
f5.App_
|
||||
}
|
||||
|
||||
var App = new (App_)
|
||||
|
||||
func (this *App_) Init() {
|
||||
f5.App = &this.App_
|
||||
f5.App.SetPkgName("analyseapi")
|
||||
this.App_.Init()
|
||||
G.MetaMgr = new(MetaMgr).Init()
|
||||
G.GameLog = new(GameLog).Init()
|
||||
G.HttpServer = new(f5.HttpServer).Init("httpserver", 1000 * 60)
|
||||
G.RiskMgr = new(RiskMgr).Init()
|
||||
|
||||
G.HttpServer.Start(G.MetaMgr.GetCurrServer().GetListenPort());
|
||||
}
|
||||
|
||||
func (this *App_) UnInit() {
|
||||
G.RiskMgr.UnInit()
|
||||
G.HttpServer.UnInit()
|
||||
G.GameLog.UnInit()
|
||||
G.MetaMgr.UnInit()
|
||||
this.App_.UnInit()
|
||||
}
|
7
server/analyseapi/constant.go
Normal file
7
server/analyseapi/constant.go
Normal file
@ -0,0 +1,7 @@
|
||||
package main
|
||||
|
||||
const (
|
||||
IM_GAMECONF_CREATE = 100
|
||||
)
|
||||
|
||||
const SESSION_KEY = "f3a6a9a5-217a-4079-ab99-b5d69b8212be"
|
14
server/analyseapi/g.go
Normal file
14
server/analyseapi/g.go
Normal file
@ -0,0 +1,14 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"f5"
|
||||
)
|
||||
|
||||
type GlobalVar struct {
|
||||
MetaMgr *MetaMgr
|
||||
HttpServer *f5.HttpServer
|
||||
GameLog *GameLog
|
||||
RiskMgr *RiskMgr
|
||||
}
|
||||
|
||||
var G *GlobalVar = &GlobalVar{}
|
17
server/analyseapi/gamelog.go
Normal file
17
server/analyseapi/gamelog.go
Normal file
@ -0,0 +1,17 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"f5"
|
||||
)
|
||||
|
||||
type GameLog struct {
|
||||
|
||||
}
|
||||
|
||||
func (this *GameLog) Init() *GameLog {
|
||||
f5.TgLog().SetPolyLog(true)
|
||||
return this
|
||||
}
|
||||
|
||||
func (this *GameLog) UnInit() {
|
||||
}
|
24
server/analyseapi/go.mod
Normal file
24
server/analyseapi/go.mod
Normal file
@ -0,0 +1,24 @@
|
||||
module analyseapi
|
||||
|
||||
go 1.11
|
||||
|
||||
require q5 v1.0.0
|
||||
|
||||
require f5 v1.0.0
|
||||
|
||||
require mt v1.0.0
|
||||
|
||||
require (
|
||||
github.com/aliyun/alibaba-cloud-sdk-go v1.61.614
|
||||
github.com/golang/protobuf v1.4.2
|
||||
google.golang.org/protobuf v1.23.0
|
||||
im v1.0.0
|
||||
)
|
||||
|
||||
replace q5 => ../../third_party/q5
|
||||
|
||||
replace f5 => ../../third_party/f5
|
||||
|
||||
replace im => ../../third_party/f5/im
|
||||
|
||||
replace mt => ./mt
|
53
server/analyseapi/go.sum
Normal file
53
server/analyseapi/go.sum
Normal file
@ -0,0 +1,53 @@
|
||||
github.com/aliyun/alibaba-cloud-sdk-go v1.61.614 h1:FHWBfCJLqPmXTe/rdx1D0Dp0uQkNDcadDTmXEO5YcEE=
|
||||
github.com/aliyun/alibaba-cloud-sdk-go v1.61.614/go.mod h1:pUKYbK5JQ+1Dfxk80P0qxGqe5dkxDoabbZS7zOcouyA=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/garyburd/redigo v1.6.2/go.mod h1:NR3MbYisc3/PwhQ00EMzDiPmrwpPxAn5GI05/YaO1SY=
|
||||
github.com/go-sql-driver/mysql v1.5.0 h1:ozyZYNQW3x3HtqT1jira07DN2PArx2v7/mN66gGcHOs=
|
||||
github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
|
||||
github.com/goji/httpauth v0.0.0-20160601135302-2da839ab0f4d/go.mod h1:nnjvkQ9ptGaCkuDUx6wNykzzlUixGxvkme+H/lnzb+A=
|
||||
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
|
||||
github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
|
||||
github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
|
||||
github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
|
||||
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
|
||||
github.com/golang/protobuf v1.4.2 h1:+Z5KGCizgyZCbGh1KZqA0fcLLkwbsjIzS4aV2v7wJX0=
|
||||
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
|
||||
github.com/gomodule/redigo v1.8.3 h1:HR0kYDX2RJZvAup8CsiJwxB4dTCSC0AaUq6S4SiLwUc=
|
||||
github.com/gomodule/redigo v1.8.3/go.mod h1:P9dn9mFrCBvWhGE1wpxx6fgq7BAeLBk+UUUzlpkBYO0=
|
||||
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
|
||||
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af h1:pmfjZENx5imkbgOkpRUYLnmbU7UEFbjtDA2hxJ1ichM=
|
||||
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
|
||||
github.com/json-iterator/go v1.1.5 h1:gL2yXlmiIo4+t+y32d4WGwOjKGYcGOuyrg46vadswDE=
|
||||
github.com/json-iterator/go v1.1.5/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
|
||||
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 h1:Esafd1046DLDQ0W1YjYsBW+p8U2u7vzgW2SQVmlNazg=
|
||||
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
|
||||
github.com/smartystreets/goconvey v0.0.0-20190330032615-68dc04aab96a/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
|
||||
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
|
||||
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
|
||||
google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
|
||||
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
|
||||
google.golang.org/protobuf v1.23.0 h1:4MY060fB1DLGMB/7MBTLnwQUY6+F09GEiz6SsrNqyzM=
|
||||
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/ini.v1 v1.42.0 h1:7N3gPTt50s8GuLortA00n8AqRTk75qOP98+mTPpgzRk=
|
||||
gopkg.in/ini.v1 v1.42.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
7
server/analyseapi/main.go
Normal file
7
server/analyseapi/main.go
Normal file
@ -0,0 +1,7 @@
|
||||
package main
|
||||
|
||||
func main() {
|
||||
App.Init()
|
||||
App.Run()
|
||||
App.UnInit()
|
||||
}
|
19
server/analyseapi/makefile
Normal file
19
server/analyseapi/makefile
Normal file
@ -0,0 +1,19 @@
|
||||
compile:
|
||||
@. /etc/profile
|
||||
|
||||
protoc --proto_path=proto --go_out=./mt proto/mt.proto
|
||||
@export GOPROXY=https://goproxy.io
|
||||
@go build -gcflags=all="-N -l" -o ../bin/analyseapi
|
||||
@echo "compile done"
|
||||
|
||||
debug:
|
||||
@. /etc/profile
|
||||
|
||||
protoc --proto_path=proto --go_out=./mt proto/mt.proto
|
||||
@export GOPROXY=https://goproxy.io
|
||||
@go build -gcflags=all="-N -l" -ldflags "-X q5.optDebug=1" -o ../bin/analyseapi
|
||||
@echo "compile done"
|
||||
|
||||
clean:
|
||||
@rm -f ../bin/analyseapi
|
||||
@echo "clean done"
|
141
server/analyseapi/metamgr.go
Normal file
141
server/analyseapi/metamgr.go
Normal file
@ -0,0 +1,141 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"f5"
|
||||
"mt"
|
||||
)
|
||||
|
||||
const (
|
||||
MT_SERVER_INFO = 0
|
||||
MT_ALI_KEY = iota
|
||||
MT_IP_WHITE_LIST
|
||||
MT_IP_BLACK_LIST
|
||||
MT_LAUNCH_WHITE_LIST
|
||||
MT_LAUNCH_BLACK_LIST
|
||||
MT_BLOCK_PROVINCE_CITY
|
||||
MT_MAX
|
||||
)
|
||||
|
||||
type MetaMgr struct {
|
||||
f5.MetaMgr
|
||||
}
|
||||
|
||||
func (this *MetaMgr) Init() *MetaMgr {
|
||||
this.MetaMgr.Init()
|
||||
configDir := "../config/"
|
||||
if !f5.IsOnlineEnv() {
|
||||
configDir = "/var/data/conf_test/analyseapi/"
|
||||
}
|
||||
metaClasses := &[]f5.MetaClass{
|
||||
f5.MetaClass{
|
||||
PrimKey: "InstanceId",
|
||||
FileName: configDir + "analyseapi.cluster.json",
|
||||
Idx: MT_SERVER_INFO,
|
||||
RawMeta: (*mt.ServerInfoMetas)(nil),
|
||||
WrapMeta: (*MtwServerInfo)(nil)},
|
||||
f5.MetaClass{
|
||||
FileName: configDir + "ali_key.json",
|
||||
Idx: MT_ALI_KEY,
|
||||
RawMeta: (*mt.AliKeyInfoMetas)(nil),
|
||||
WrapMeta: (*MtwAliKeyConf)(nil)},
|
||||
f5.MetaClass{
|
||||
FileName: configDir + "ip_whitelist.json",
|
||||
Idx: MT_IP_WHITE_LIST,
|
||||
RawMeta: (*mt.IpWhiteListMetas)(nil),
|
||||
WrapMeta: (*MtwIpWhiteList)(nil)},
|
||||
f5.MetaClass{
|
||||
FileName: configDir + "ip_blacklist.json",
|
||||
Idx: MT_IP_BLACK_LIST,
|
||||
RawMeta: (*mt.IpBlackListMetas)(nil),
|
||||
WrapMeta: (*MtwIpBlackList)(nil)},
|
||||
f5.MetaClass{
|
||||
FileName: configDir + "launch_whitelist.json",
|
||||
Idx: MT_LAUNCH_WHITE_LIST,
|
||||
RawMeta: (*mt.LaunchWhiteListMetas)(nil),
|
||||
WrapMeta: (*MtwLaunchWhiteList)(nil)},
|
||||
f5.MetaClass{
|
||||
FileName: configDir + "launch_blacklist.json",
|
||||
Idx: MT_LAUNCH_BLACK_LIST,
|
||||
RawMeta: (*mt.LaunchBlackListMetas)(nil),
|
||||
WrapMeta: (*MtwLaunchBlackList)(nil)},
|
||||
f5.MetaClass{
|
||||
FileName: configDir + "block_province_city.json",
|
||||
Idx: MT_BLOCK_PROVINCE_CITY,
|
||||
RawMeta: (*mt.BlockProvinceCityMetas)(nil),
|
||||
WrapMeta: (*MtwBlockProvinceCity)(nil)},
|
||||
}
|
||||
this.MetaMgr.RegisterMetaClasses(metaClasses)
|
||||
this.Load()
|
||||
return this
|
||||
}
|
||||
|
||||
func (this *MetaMgr) UnInit() {
|
||||
this.MetaMgr.UnInit()
|
||||
}
|
||||
|
||||
func (this *MetaMgr) GetServer(instance_id int32) *MtwServerInfo {
|
||||
v, ok := this.MetaMgr.GetMetaById(MT_SERVER_INFO, instance_id).(*MtwServerInfo)
|
||||
if ok {
|
||||
return v
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func (this *MetaMgr) GetCurrServer() *MtwServerInfo {
|
||||
return this.GetServer(int32(f5.App.GetInstanceId()))
|
||||
}
|
||||
|
||||
func (this *MetaMgr) GetAliKey() *MtwAliKeyConf {
|
||||
v, ok := this.MetaMgr.GetMetaById(MT_ALI_KEY, 1).(*MtwAliKeyConf)
|
||||
if ok {
|
||||
return v
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func (this *MetaMgr) GetIpWhiteList() *MtwIpWhiteList {
|
||||
v, ok := this.MetaMgr.GetMetaById(MT_IP_WHITE_LIST, 1).(*MtwIpWhiteList)
|
||||
if ok {
|
||||
return v
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func (this *MetaMgr) GetIpBlackList() *MtwIpBlackList {
|
||||
v, ok := this.MetaMgr.GetMetaById(MT_IP_BLACK_LIST, 1).(*MtwIpBlackList)
|
||||
if ok {
|
||||
return v
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func (this *MetaMgr) GetLaunchWhiteList() *MtwLaunchWhiteList {
|
||||
v, ok := this.MetaMgr.GetMetaById(MT_LAUNCH_WHITE_LIST, 1).(*MtwLaunchWhiteList)
|
||||
if ok {
|
||||
return v
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func (this *MetaMgr) GetLaunchBlackList() *MtwLaunchBlackList {
|
||||
v, ok := this.MetaMgr.GetMetaById(MT_LAUNCH_BLACK_LIST, 1).(*MtwLaunchBlackList)
|
||||
if ok {
|
||||
return v
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func (this *MetaMgr) GetFixedBlockProvinceCity() *MtwBlockProvinceCity {
|
||||
v, ok := this.MetaMgr.GetMetaById(MT_BLOCK_PROVINCE_CITY, 1).(*MtwBlockProvinceCity)
|
||||
if ok {
|
||||
return v
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
31
server/analyseapi/metawrap.go
Normal file
31
server/analyseapi/metawrap.go
Normal file
@ -0,0 +1,31 @@
|
||||
package main
|
||||
|
||||
import "mt"
|
||||
|
||||
type MtwServerInfo struct {
|
||||
*mt.ServerInfo
|
||||
}
|
||||
|
||||
type MtwAliKeyConf struct {
|
||||
*mt.AliKeyConf
|
||||
}
|
||||
|
||||
type MtwIpWhiteList struct {
|
||||
*mt.IpWhiteList
|
||||
}
|
||||
|
||||
type MtwIpBlackList struct {
|
||||
*mt.IpBlackList
|
||||
}
|
||||
|
||||
type MtwLaunchWhiteList struct {
|
||||
*mt.LaunchWhiteList
|
||||
}
|
||||
|
||||
type MtwLaunchBlackList struct {
|
||||
*mt.LaunchBlackList
|
||||
}
|
||||
|
||||
type MtwBlockProvinceCity struct {
|
||||
*mt.BlockProvinceCity
|
||||
}
|
8
server/analyseapi/mt/go.mod
Normal file
8
server/analyseapi/mt/go.mod
Normal file
@ -0,0 +1,8 @@
|
||||
module metatable
|
||||
|
||||
go 1.15
|
||||
|
||||
require (
|
||||
github.com/golang/protobuf v1.4.2
|
||||
google.golang.org/protobuf v1.23.0
|
||||
)
|
19
server/analyseapi/mt/go.sum
Normal file
19
server/analyseapi/mt/go.sum
Normal file
@ -0,0 +1,19 @@
|
||||
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
|
||||
github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
|
||||
github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
|
||||
github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
|
||||
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
|
||||
github.com/golang/protobuf v1.4.2 h1:+Z5KGCizgyZCbGh1KZqA0fcLLkwbsjIzS4aV2v7wJX0=
|
||||
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
|
||||
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||
github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4=
|
||||
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
|
||||
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
|
||||
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
|
||||
google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
|
||||
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
|
||||
google.golang.org/protobuf v1.23.0 h1:4MY060fB1DLGMB/7MBTLnwQUY6+F09GEiz6SsrNqyzM=
|
||||
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
1006
server/analyseapi/mt/mt.pb.go
Normal file
1006
server/analyseapi/mt/mt.pb.go
Normal file
File diff suppressed because it is too large
Load Diff
77
server/analyseapi/proto/mt.proto
Normal file
77
server/analyseapi/proto/mt.proto
Normal file
@ -0,0 +1,77 @@
|
||||
package mt;
|
||||
|
||||
option go_package = ".;mt";
|
||||
|
||||
message AliKeyConf
|
||||
{
|
||||
optional string access_keyid = 1;
|
||||
optional string access_secret = 2;
|
||||
}
|
||||
|
||||
message AliKeyInfoMetas
|
||||
{
|
||||
repeated AliKeyConf values = 1;
|
||||
}
|
||||
|
||||
message ServerInfo
|
||||
{
|
||||
optional int32 instance_id = 1;
|
||||
optional string listen_ip = 2;
|
||||
optional int32 listen_port = 3;
|
||||
optional int32 testing = 4;
|
||||
}
|
||||
|
||||
message ServerInfoMetas
|
||||
{
|
||||
repeated ServerInfo values = 1;
|
||||
}
|
||||
|
||||
message IpWhiteList
|
||||
{
|
||||
repeated string list = 1;
|
||||
}
|
||||
|
||||
message IpWhiteListMetas
|
||||
{
|
||||
repeated IpWhiteList values = 1;
|
||||
}
|
||||
|
||||
message IpBlackList
|
||||
{
|
||||
repeated string list = 1;
|
||||
}
|
||||
|
||||
message IpBlackListMetas
|
||||
{
|
||||
repeated IpBlackList values = 1;
|
||||
}
|
||||
|
||||
message LaunchWhiteList
|
||||
{
|
||||
repeated string list = 1;
|
||||
}
|
||||
|
||||
message LaunchWhiteListMetas
|
||||
{
|
||||
repeated LaunchWhiteList values = 1;
|
||||
}
|
||||
|
||||
message LaunchBlackList
|
||||
{
|
||||
repeated string list = 1;
|
||||
}
|
||||
|
||||
message LaunchBlackListMetas
|
||||
{
|
||||
repeated LaunchBlackList values = 1;
|
||||
}
|
||||
|
||||
message BlockProvinceCity
|
||||
{
|
||||
repeated string list = 1;
|
||||
}
|
||||
|
||||
message BlockProvinceCityMetas
|
||||
{
|
||||
repeated BlockProvinceCity values = 1;
|
||||
}
|
267
server/analyseapi/riskmgr.go
Normal file
267
server/analyseapi/riskmgr.go
Normal file
@ -0,0 +1,267 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"fmt"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"q5"
|
||||
"f5"
|
||||
)
|
||||
|
||||
type RiskMgr struct {
|
||||
fixedBlockProvinceCityHash map[string]int32
|
||||
fixedBlockProvinceCityHashMutex sync.RWMutex
|
||||
|
||||
accessKeyId string
|
||||
accessSecret string
|
||||
sdkInfoMutex sync.RWMutex
|
||||
|
||||
totalPassTimes int64
|
||||
totalBlockTimes int64
|
||||
passTimes int64
|
||||
blockTimes int64
|
||||
|
||||
totalHttpMethodBlockTimes int64
|
||||
httpMethodBlockTimes int64
|
||||
totalSessionErrBlockTimes int64
|
||||
sessionErrBlockTimes int64
|
||||
|
||||
gameHash map[int64]*GameConf
|
||||
gameHashMutex sync.RWMutex
|
||||
|
||||
clusterConf *MtwServerInfo
|
||||
}
|
||||
|
||||
func (this* RiskMgr) Init() *RiskMgr {
|
||||
this.fixedBlockProvinceCityHashMutex.Lock()
|
||||
this.gameHashMutex.Lock()
|
||||
defer this.fixedBlockProvinceCityHashMutex.Unlock()
|
||||
defer this.gameHashMutex.Unlock()
|
||||
|
||||
this.fixedBlockProvinceCityHash = make(map[string]int32)
|
||||
this.gameHash = make(map[int64]*GameConf)
|
||||
for _, val := range G.MetaMgr.GetFixedBlockProvinceCity().GetList() {
|
||||
this.fixedBlockProvinceCityHash[val] = 1
|
||||
}
|
||||
|
||||
this.accessKeyId = G.MetaMgr.GetAliKey().GetAccessKeyid()
|
||||
this.accessSecret = G.MetaMgr.GetAliKey().GetAccessSecret()
|
||||
this.clusterConf = G.MetaMgr.GetCurrServer()
|
||||
|
||||
G.HttpServer.RegisterHandle("Analyse", "isOpen", this.__analyseIsOpen)
|
||||
G.HttpServer.RegisterHandle("Ops", "dump", this.__opsDump)
|
||||
G.HttpServer.RegisterHandle("Ops", "syncConf", this.__opsSyncConf)
|
||||
G.HttpServer.RegisterHandle("Ops", "info", this.__opsInfo)
|
||||
f5.Timer().AddRepeatTimer(1000 * 60,
|
||||
func (params* q5.XParams) {
|
||||
},
|
||||
func (params* q5.XParams) {
|
||||
this.OutputLog()
|
||||
})
|
||||
f5.App.RegisterIMMsgHandle(IM_GAMECONF_CREATE, func (msgId int16, params *q5.XParams) {
|
||||
G.RiskMgr.OnGameConfCreate(
|
||||
params.Sender.GetInt32(),
|
||||
params.Param1.GetInt32())
|
||||
})
|
||||
return this
|
||||
}
|
||||
|
||||
func (this* RiskMgr) UnInit() {
|
||||
}
|
||||
|
||||
func (this* RiskMgr) fetchGameConfList() []*GameConf {
|
||||
this.gameHashMutex.Lock()
|
||||
defer this.gameHashMutex.Unlock()
|
||||
|
||||
gameConfList := make([]*GameConf, 0)
|
||||
for _, val := range this.gameHash {
|
||||
gameConfList = append(gameConfList, val)
|
||||
}
|
||||
return gameConfList
|
||||
}
|
||||
|
||||
func (this* RiskMgr) OutputLog() {
|
||||
for _, val := range this.fetchGameConfList() {
|
||||
f5.SysLog().Info("gameid:%d channel:%d passobj %s",
|
||||
val.gameId,
|
||||
val.channel,
|
||||
val.GetPassObj().ToJsonStr())
|
||||
f5.SysLog().Info("gameid:%d channel:%d blockobj %s",
|
||||
val.gameId,
|
||||
val.channel,
|
||||
val.GetBlockObj().ToJsonStr())
|
||||
}
|
||||
f5.SysLog().Info("global passobj %s", this.GetGlobalPassObj().ToJsonStr())
|
||||
f5.SysLog().Info("global blockobj %s", this.GetGlobalBlockObj().ToJsonStr())
|
||||
atomic.StoreInt64(&this.passTimes, 0)
|
||||
atomic.StoreInt64(&this.blockTimes, 0)
|
||||
atomic.StoreInt64(&this.passTimes, 0)
|
||||
atomic.StoreInt64(&this.httpMethodBlockTimes, 0)
|
||||
atomic.StoreInt64(&this.sessionErrBlockTimes, 0)
|
||||
}
|
||||
|
||||
func (this* RiskMgr) GetGlobalPassObj() *q5.XObject {
|
||||
passObj := q5.NewMxoObject()
|
||||
passObj.SetXValue("total", q5.NewXInt64(this.totalPassTimes))
|
||||
passObj.SetXValue("curr", q5.NewXInt64(this.passTimes))
|
||||
return passObj.AsXObject()
|
||||
}
|
||||
|
||||
func (this* RiskMgr) GetGlobalBlockObj() *q5.XObject {
|
||||
blockObj := q5.NewMxoObject()
|
||||
blockObj.SetXValue("total", q5.NewXInt64(this.totalBlockTimes))
|
||||
blockObj.SetXValue("curr", q5.NewXInt64(this.blockTimes))
|
||||
blockObj.SetXValue("total_methoderr", q5.NewXInt64(this.totalHttpMethodBlockTimes))
|
||||
blockObj.SetXValue("curr_methoderr", q5.NewXInt64(this.httpMethodBlockTimes))
|
||||
blockObj.SetXValue("total_sessonerr", q5.NewXInt64(this.totalSessionErrBlockTimes))
|
||||
blockObj.SetXValue("curr_sessionerr", q5.NewXInt64(this.sessionErrBlockTimes))
|
||||
return blockObj.AsXObject()
|
||||
}
|
||||
|
||||
func (this* RiskMgr) GetSdkInfo(accessKeyId* string, accessSecret* string) {
|
||||
this.sdkInfoMutex.Lock()
|
||||
defer this.sdkInfoMutex.Unlock()
|
||||
*accessKeyId = "" + this.accessKeyId
|
||||
*accessSecret = "" + this.accessSecret
|
||||
}
|
||||
|
||||
func (this *RiskMgr) ForceGameConf(gameId int32, channel int32) *GameConf {
|
||||
this.gameHashMutex.Lock()
|
||||
defer this.gameHashMutex.Unlock()
|
||||
if val, ok := this.gameHash[q5.MkInt64(gameId, channel)]; ok {
|
||||
val.Active()
|
||||
return val
|
||||
} else {
|
||||
gameConf := new(GameConf)
|
||||
gameConf.gameId = gameId
|
||||
gameConf.channel = channel
|
||||
gameConf.Init()
|
||||
this.gameHash[q5.MkInt64(gameId, channel)] = gameConf
|
||||
gameConf.Active()
|
||||
return gameConf
|
||||
}
|
||||
}
|
||||
|
||||
func (this *RiskMgr) GetGameConf(gameId int32, channel int32) *GameConf {
|
||||
this.gameHashMutex.Lock()
|
||||
defer this.gameHashMutex.Unlock()
|
||||
val, _ := this.gameHash[q5.MkInt64(gameId, channel)]
|
||||
return val
|
||||
}
|
||||
|
||||
func (this *RiskMgr) __analyseIsOpen(w* http.ResponseWriter, r *http.Request) {
|
||||
var gameConf *GameConf
|
||||
responseStr := ""
|
||||
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)
|
||||
|
||||
gameConf = this.ForceGameConf(gameId, channel)
|
||||
if gameConf == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
remoteAddr := q5.GetRequestRemoteAddr(r)
|
||||
if this.clusterConf.GetTesting() == 1 && q5.Request(r, "ip").GetString() != "" {
|
||||
remoteAddr = q5.Request(r, "ip").GetString()
|
||||
}
|
||||
launchInfo := q5.GetPostBody(r).GetString()
|
||||
return gameConf.IsPass(remoteAddr, launchInfo)
|
||||
}
|
||||
if isPass() {
|
||||
atomic.AddInt64(&this.totalPassTimes, 1)
|
||||
atomic.AddInt64(&this.passTimes, 1)
|
||||
if this.clusterConf.GetTesting() == 1 {
|
||||
if responseStr == "" {
|
||||
responseStr = `""`
|
||||
}
|
||||
data := fmt.Sprintf(`{"errcode":0, "errmsg":"", "is_open":%d, "data":%s}`,
|
||||
1,
|
||||
responseStr)
|
||||
q5.Response(w, data)
|
||||
} else {
|
||||
q5.ResponseInt32Ok(w, "is_open", 1)
|
||||
}
|
||||
} else {
|
||||
atomic.AddInt64(&this.totalBlockTimes, 1)
|
||||
atomic.AddInt64(&this.blockTimes, 1)
|
||||
if this.clusterConf.GetTesting() == 1 {
|
||||
if responseStr == "" {
|
||||
responseStr = `""`
|
||||
}
|
||||
data := fmt.Sprintf(`{"errcode":0, "errmsg":"", "is_open":%d, "data":%s}`,
|
||||
0,
|
||||
responseStr)
|
||||
q5.Response(w, data)
|
||||
} else {
|
||||
q5.ResponseInt32Ok(w, "is_open", 0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (this *RiskMgr) __opsDump(w* http.ResponseWriter, r *http.Request) {
|
||||
gameId := q5.Request(r, "gameid").GetInt32()
|
||||
channel := q5.Request(r, "channel").GetInt32()
|
||||
gameConf := this.GetGameConf(gameId, channel)
|
||||
if gameConf == nil {
|
||||
q5.ResponseErr(w, 1, "数据不存在")
|
||||
return
|
||||
}
|
||||
q5.Response(w, gameConf.Dump().ToJsonStr())
|
||||
}
|
||||
|
||||
func (this *RiskMgr) __opsSyncConf(w* http.ResponseWriter, r *http.Request) {
|
||||
gameId := q5.Request(r, "gameid").GetInt32()
|
||||
channel := q5.Request(r, "channel").GetInt32()
|
||||
gameConf := this.GetGameConf(gameId, channel)
|
||||
if gameConf == nil {
|
||||
q5.ResponseErr(w, 1, "数据不存在")
|
||||
return
|
||||
}
|
||||
gameConf.SyncConf()
|
||||
q5.ResponseOk(w)
|
||||
}
|
||||
|
||||
func (this *RiskMgr) __opsInfo(w* http.ResponseWriter, r *http.Request) {
|
||||
gameId := q5.Request(r, "gameid").GetInt32()
|
||||
channel := q5.Request(r, "channel").GetInt32()
|
||||
gameConf := this.GetGameConf(gameId, channel)
|
||||
if gameConf == nil {
|
||||
q5.ResponseErr(w, 1, "数据不存在")
|
||||
return
|
||||
}
|
||||
respObj := q5.NewMxoObject()
|
||||
respObj.SetXValue("errcode", q5.NewXInt32(0))
|
||||
respObj.SetXValue("errmsg", q5.NewXString(""))
|
||||
respObj.SetXObject("pass", gameConf.GetPassObj())
|
||||
respObj.SetXObject("block", gameConf.GetBlockObj())
|
||||
q5.Response(w, respObj.ToJsonStr())
|
||||
}
|
||||
|
||||
/*
|
||||
安装定时器定时更新逻辑
|
||||
*/
|
||||
func (this *RiskMgr) OnGameConfCreate(gameId int32, channel int32) {
|
||||
f5.Timer().AddRepeatTimer(1000 * 30,
|
||||
func (params* q5.XParams) {
|
||||
},
|
||||
func (params* q5.XParams) {
|
||||
gameConf := this.GetGameConf(gameId, channel)
|
||||
if gameConf != nil {
|
||||
gameConf.SyncConf()
|
||||
}
|
||||
})
|
||||
}
|
274
server/analyseapi/types.go
Normal file
274
server/analyseapi/types.go
Normal file
@ -0,0 +1,274 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"sync"
|
||||
"github.com/aliyun/alibaba-cloud-sdk-go/services/geoip"
|
||||
"f5"
|
||||
"q5"
|
||||
)
|
||||
|
||||
type GameConf struct {
|
||||
gameId int32
|
||||
channel int32
|
||||
syncTimes int64
|
||||
lastSyncTime int64
|
||||
lastActiveTime int64
|
||||
|
||||
ipWhiteList map[string]int32
|
||||
ipWhiteListMutex sync.RWMutex
|
||||
|
||||
ipBlackList map[string]int32
|
||||
ipBlackListMutex sync.RWMutex
|
||||
|
||||
launchWhiteList map[string]int32
|
||||
launchWhiteListMutex sync.RWMutex
|
||||
|
||||
launchBlackList map[string]int32
|
||||
launchBlackListMutex sync.RWMutex
|
||||
|
||||
blockProvinceCityHash map[string]int32
|
||||
blockProvinceCityHashMutex 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 *GameConf) IsPass(remoteAddr string, launchInfo string) bool {
|
||||
/*
|
||||
remoteAddr := q5.GetRequestRemoteAddr(r)
|
||||
if this.clusterConf.GetTesting() == 1 && q5.Request(r, "ip").GetString() != "" {
|
||||
remoteAddr = q5.Request(r, "ip").GetString()
|
||||
}
|
||||
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, &responseStr) {
|
||||
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
|
||||
}
|
||||
*/
|
||||
return false
|
||||
}
|
||||
|
||||
func (this* GameConf) InIpWhiteList(ip string) bool {
|
||||
this.ipWhiteListMutex.Lock()
|
||||
defer this.ipWhiteListMutex.Unlock()
|
||||
_, ok := this.ipWhiteList[ip]
|
||||
return ok
|
||||
}
|
||||
|
||||
func (this* GameConf) InIpBlackList(ip string) bool {
|
||||
this.ipBlackListMutex.Lock()
|
||||
defer this.ipBlackListMutex.Unlock()
|
||||
_, ok := this.ipBlackList[ip]
|
||||
return ok
|
||||
}
|
||||
|
||||
func (this* GameConf) InLaunchWhiteList(gameId int32, channel int32, launchInfo string) bool {
|
||||
this.launchWhiteListMutex.Lock()
|
||||
defer this.launchWhiteListMutex.Unlock()
|
||||
_, ok := this.launchWhiteList[launchInfo]
|
||||
return ok
|
||||
}
|
||||
|
||||
func (this* GameConf) InLaunchBlackList(gameId int32, channel int32, launchInfo string) bool {
|
||||
this.launchBlackListMutex.Lock()
|
||||
defer this.launchBlackListMutex.Unlock()
|
||||
_, ok := this.launchBlackList[launchInfo]
|
||||
return ok
|
||||
}
|
||||
|
||||
func (this* GameConf) Init() {
|
||||
this.ipWhiteListMutex.Lock()
|
||||
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
|
||||
}
|
||||
for _, val := range G.MetaMgr.GetIpBlackList().GetList() {
|
||||
this.ipBlackList[val] = 1
|
||||
}
|
||||
for _, val := range G.MetaMgr.GetLaunchWhiteList().GetList() {
|
||||
this.launchWhiteList[val] = 1
|
||||
}
|
||||
for _, val := range G.MetaMgr.GetLaunchBlackList().GetList() {
|
||||
this.launchBlackList[val] = 1
|
||||
}
|
||||
for _, val := range G.MetaMgr.GetFixedBlockProvinceCity().GetList() {
|
||||
this.blockProvinceCityHash[val] = 1
|
||||
}
|
||||
this.lastActiveTime = f5.App.NowUnix()
|
||||
f5.App.AddIMMsg(IM_GAMECONF_CREATE, new(q5.XParams).Init(func (params* q5.XParams) {
|
||||
params.Sender.SetInt32(this.gameId)
|
||||
params.Param1.SetInt32(this.channel)
|
||||
}))
|
||||
}
|
||||
|
||||
func (this* GameConf) IsBlockZone(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* GameConf) IsSafeZone(ip string, response_str* string) bool {
|
||||
accessKeyId := ""
|
||||
accessSecret := ""
|
||||
G.RiskMgr.GetSdkInfo(&accessKeyId, &accessSecret)
|
||||
client, err := geoip.NewClientWithAccessKey("cn-hangzhou", accessKeyId, accessSecret)
|
||||
if err != nil {
|
||||
f5.SysLog().Warning("NewClientWithAccessKey error %s", err.Error())
|
||||
return false
|
||||
}
|
||||
|
||||
request := geoip.CreateDescribeIpv4LocationRequest()
|
||||
request.Scheme = "https"
|
||||
request.Ip = ip
|
||||
|
||||
response, err := client.DescribeIpv4Location(request)
|
||||
if err != nil {
|
||||
f5.SysLog().Warning("Ipv4Location error %s", err.Error())
|
||||
return false
|
||||
}
|
||||
*response_str = q5.EncodeJson(response)
|
||||
return !this.IsBlockZone(response.Country, response.Province, response.City)
|
||||
}
|
||||
|
||||
func (this* GameConf) Dump() *q5.MutableXObject {
|
||||
this.ipWhiteListMutex.Lock()
|
||||
this.ipBlackListMutex.Lock()
|
||||
this.launchWhiteListMutex.Lock()
|
||||
this.launchBlackListMutex.Lock()
|
||||
this.blockProvinceCityHashMutex.Lock()
|
||||
//this.fixedBlockProvinceCityHashMutex.Lock()
|
||||
defer this.ipWhiteListMutex.Unlock()
|
||||
defer this.ipBlackListMutex.Unlock()
|
||||
defer this.launchWhiteListMutex.Unlock()
|
||||
defer this.launchBlackListMutex.Unlock()
|
||||
defer this.blockProvinceCityHashMutex.Unlock()
|
||||
//defer this.fixedBlockProvinceCityHashMutex.Unlock()
|
||||
|
||||
fillRespObj := func(respObj* q5.MutableXObject, attrName string, mapObj* map[string]int32) {
|
||||
list := q5.NewMxoArray()
|
||||
for key, _ := range *mapObj {
|
||||
list.PushXValue(q5.NewXString(key))
|
||||
}
|
||||
respObj.SetXObject(attrName, list.AsXObject())
|
||||
}
|
||||
|
||||
respObj := q5.NewMxoObject()
|
||||
respObj.SetXValue("errcode", q5.NewXInt32(0))
|
||||
respObj.SetXValue("errmsg", q5.NewXString(""))
|
||||
fillRespObj(respObj, "ip_white_list", &this.ipWhiteList)
|
||||
fillRespObj(respObj, "ip_black_list", &this.ipBlackList)
|
||||
fillRespObj(respObj, "launch_white_list", &this.launchWhiteList)
|
||||
fillRespObj(respObj, "launch_black_list", &this.launchBlackList)
|
||||
fillRespObj(respObj, "block_province_city_list", &this.blockProvinceCityHash)
|
||||
//fillRespObj(respObj, "fixed_block_province_city_list", &this.fixedBlockProvinceCityHash)
|
||||
return respObj
|
||||
}
|
||||
|
||||
func (this* GameConf) GetPassObj() *q5.XObject {
|
||||
passObj := q5.NewMxoObject()
|
||||
/*passObj.SetXValue("total_white_ip_times", q5.NewXInt64(this.totalIpWhiteListPassTimes))
|
||||
passObj.SetXValue("curr_white_ip_times", q5.NewXInt64(this.ipWhiteListPassTimes))
|
||||
passObj.SetXValue("total_white_launch_times", q5.NewXInt64(this.totalLaunchWhiteListPassTimes))
|
||||
passObj.SetXValue("curr_white_launch_times", q5.NewXInt64(this.launchWhiteListPassTimes))
|
||||
passObj.SetXValue("total_safezone_times", q5.NewXInt64(this.totalSafeZonePassTimes))
|
||||
passObj.SetXValue("curr_safezone_times", q5.NewXInt64(this.safeZonePassTimes))*/
|
||||
return passObj.AsXObject()
|
||||
}
|
||||
|
||||
func (this* GameConf) GetBlockObj() *q5.XObject {
|
||||
blockObj := q5.NewMxoObject()
|
||||
/*blockObj.SetXValue("total_method_err_times", q5.NewXInt64(this.totalHttpMethodBlockTimes))
|
||||
blockObj.SetXValue("curr_method_err_times", q5.NewXInt64(this.httpMethodBlockTimes))
|
||||
blockObj.SetXValue("total_session_err_times", q5.NewXInt64(this.totalSessionErrBlockTimes))
|
||||
blockObj.SetXValue("curr_session_err_times", q5.NewXInt64(this.sessionErrBlockTimes))
|
||||
blockObj.SetXValue("total_black_ip_times", q5.NewXInt64(this.totalIpBlackListBlockTimes))
|
||||
blockObj.SetXValue("curr_black_ip_times", q5.NewXInt64(this.ipBlackListBlockTimes))
|
||||
blockObj.SetXValue("total_black_launch_times", q5.NewXInt64(this.totalLaunchBlackListBlockTimes))
|
||||
blockObj.SetXValue("curr_black_launch_times", q5.NewXInt64(this.launchBlackListBlockTimes))
|
||||
blockObj.SetXValue("total_unsafezone_times", q5.NewXInt64(this.totalUnSafeZoneBlockTimes))
|
||||
blockObj.SetXValue("curr_unsafezone_times", q5.NewXInt64(this.unSafeZoneBlockTimes))*/
|
||||
return blockObj.AsXObject()
|
||||
}
|
||||
|
||||
func (this* GameConf) Active() {
|
||||
this.lastActiveTime = f5.App.NowUnix()
|
||||
}
|
||||
|
||||
func (this* GameConf) SyncConf() {
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user