解决冲突

This commit is contained in:
sk 2024-05-24 10:48:22 +08:00
commit eddad2e788
24 changed files with 321 additions and 1368 deletions

View File

@ -47,6 +47,12 @@
"data":{
"RootPath":"../data"
},
"etcd": {
"Url": ["127.0.0.1:2379"],
"UserName": "",
"Password": "",
"DialTimeout": 60
},
"costum": {
"MgoRpcCliNet": "tcp",
"MgoRpcCliAddr": "127.0.0.1:8999",
@ -54,11 +60,6 @@
"RMQExchange": "win88",
"RMQQosPrefetchCount": 2,
"RMQQosPrefetchSize": 0,
"RMQQosGlobal": true,
"etcdurl": [
"127.0.0.1:2379"
],
"etcduser": "",
"etcdpwd": ""
"RMQQosGlobal": true
}
}

View File

@ -5,15 +5,14 @@ import (
"net"
"net/http"
"net/rpc"
"time"
"mongo.games.com/goserver/core"
"mongo.games.com/goserver/core/etcd"
"mongo.games.com/goserver/core/module"
_ "mongo.games.com/game"
"mongo.games.com/game/common"
"mongo.games.com/game/dbproxy/svc"
"mongo.games.com/game/etcd"
"mongo.games.com/game/model"
"mongo.games.com/game/mq"
_ "mongo.games.com/game/srvdata"
@ -27,7 +26,7 @@ func main() {
core.LoadPackages("config.json")
// core hook
core.RegisteHook(core.HOOK_BEFORE_START, func() error {
etcd.Start(common.CustomConfig.GetStrings("etcdurl"), common.CustomConfig.GetString("etcduser"), common.CustomConfig.GetString("etcdpwd"), time.Minute)
etcd.Start()
mq.StartConsumer(common.CustomConfig.GetString("RabbitMQURL"), common.CustomConfig.GetString("RMQExchange"), true)
mq.StartPublisher(common.CustomConfig.GetString("RabbitMQURL"), common.CustomConfig.GetString("RMQExchange"), true, common.CustomConfig.GetInt("RMQPublishBacklog"))
// 尝试初始化玩家id
@ -42,7 +41,6 @@ func main() {
return nil
})
core.RegisteHook(core.HOOK_AFTER_STOP, func() error {
etcd.Close()
mq.StopConsumer()
mq.StopPublisher()
return nil

View File

@ -1,247 +0,0 @@
package etcd
import (
"context"
"time"
"go.etcd.io/etcd/client/v3"
"mongo.games.com/goserver/core/logger"
)
/*
etcd常用操作和数据监听
*/
type (
InitFunc func() int64
WatchFunc func(context.Context, int64)
FuncPair struct {
initFunc InitFunc
watchFunc WatchFunc
}
)
type Client struct {
cli *clientv3.Client
functions []FuncPair
closed bool
}
func (c *Client) IsClosed() bool {
return c.closed
}
func (c *Client) Ctx() context.Context {
if c.cli != nil {
return c.cli.Ctx()
}
return context.TODO()
}
func (c *Client) Open(etcdUrl []string, userName, passWord string, dialTimeout time.Duration) error {
var err error
c.cli, err = clientv3.New(clientv3.Config{
Endpoints: etcdUrl,
Username: userName,
Password: passWord,
DialTimeout: dialTimeout,
DialKeepAliveTime: 5 * time.Second,
DialKeepAliveTimeout: 30 * time.Second,
})
if err != nil {
logger.Logger.Errorf("EtcdClient.open(%v) err:%v", etcdUrl, err)
return err
}
c.closed = false
return err
}
func (c *Client) Close() error {
logger.Logger.Warn("EtcdClient.close")
c.closed = true
if c.cli != nil {
return c.cli.Close()
}
return nil
}
// PutValue 添加键值对
func (c *Client) PutValue(key, value string) (*clientv3.PutResponse, error) {
resp, err := c.cli.Put(context.TODO(), key, value)
if err != nil {
logger.Logger.Warnf("EtcdClient.PutValue(%v,%v) error:%v", key, value, err)
}
return resp, err
}
// GetValue 查询
func (c *Client) GetValue(key string) (*clientv3.GetResponse, error) {
resp, err := c.cli.Get(context.TODO(), key)
if err != nil {
logger.Logger.Warnf("EtcdClient.GetValue(%v) error:%v", key, err)
}
return resp, err
}
// DelValue 返回删除了几条数据
func (c *Client) DelValue(key string) (*clientv3.DeleteResponse, error) {
res, err := c.cli.Delete(context.TODO(), key)
if err != nil {
logger.Logger.Warnf("EtcdClient.DelValue(%v) error:%v", key, err)
}
return res, err
}
// DelValueWithPrefix 按照前缀删除
func (c *Client) DelValueWithPrefix(prefix string) (*clientv3.DeleteResponse, error) {
res, err := c.cli.Delete(context.TODO(), prefix, clientv3.WithPrefix())
if err != nil {
logger.Logger.Warnf("EtcdClient.DelValueWithPrefix(%v) error:%v", prefix, err)
}
return res, err
}
// GetValueWithPrefix 获取前缀
func (c *Client) GetValueWithPrefix(prefix string) (*clientv3.GetResponse, error) {
resp, err := c.cli.Get(context.TODO(), prefix, clientv3.WithPrefix())
if err != nil {
logger.Logger.Warnf("EtcdClient.GetValueWIthPrefix(%v) error:%v", prefix, err)
}
return resp, err
}
// WatchWithPrefix 监测前缀创建事件
func (c *Client) WatchWithPrefix(prefix string, revision int64) clientv3.WatchChan {
if c.cli != nil {
opts := []clientv3.OpOption{clientv3.WithPrefix(), clientv3.WithCreatedNotify()}
if revision > 0 {
opts = append(opts, clientv3.WithRev(revision))
}
return c.cli.Watch(clientv3.WithRequireLeader(context.Background()), prefix, opts...)
}
return nil
}
// Compact 压缩数据
//func (this *Client) Compact() {
// if this.closed {
// return
// }
//
// resp, err := this.GetValue("@@@GET_LASTEST_REVISION@@@")
// if err == nil {
// ctx, _ := context.WithCancel(this.cli.Ctx())
// start := time.Now()
// compactResponse, err := this.cli.Compact(ctx, resp.Header.Revision, clientv3.WithCompactPhysical())
// if err == nil {
// logger.Logger.Infof("EtcdClient.Compact From %v CompactResponse %v take %v", resp.Header.Revision, compactResponse.Header, time.Now().Sub(start))
// } else {
// logger.Logger.Errorf("EtcdClient.Compact From %v CompactResponse:%v take:%v err:%v", resp.Header.Revision, compactResponse, time.Now().Sub(start), err)
// }
// endpoints := this.cli.Endpoints()
// for _, endpoint := range endpoints {
// ctx1, _ := context.WithCancel(this.cli.Ctx())
// start := time.Now()
// defragmentResponse, err := this.cli.Defragment(ctx1, endpoint)
// if err == nil {
// logger.Logger.Infof("EtcdClient.Defragment %v,%v take %v", endpoint, defragmentResponse.Header, time.Now().Sub(start))
// } else {
// logger.Logger.Errorf("EtcdClient.Defragment DefragmentResponse:%v take:%v err:%v", defragmentResponse, time.Now().Sub(start), err)
// }
// }
// }
//}
// AddFunc 添加监听函数
func (c *Client) AddFunc(initFunc InitFunc, watchFunc WatchFunc) {
funcPair := FuncPair{
initFunc: initFunc,
watchFunc: watchFunc,
}
c.functions = append(c.functions, funcPair)
}
// ReInitAndWatchAll 重新监听
func (c *Client) ReInitAndWatchAll() {
if c.closed {
return
}
oldFunc := c.functions
c.functions = nil
for i := 0; i < len(oldFunc); i++ {
c.InitAndWatch(oldFunc[i].initFunc, oldFunc[i].watchFunc)
}
}
// InitAndWatch 开始监听
func (c *Client) InitAndWatch(initFunc InitFunc, watchFunc WatchFunc) {
funcPair := FuncPair{
initFunc: initFunc,
watchFunc: watchFunc,
}
c.functions = append(c.functions, funcPair)
lastRevision := initFunc()
ctx, _ := context.WithCancel(c.cli.Ctx())
watchFunc(ctx, lastRevision+1)
}
// GoWatch 异步监听
func (c *Client) GoWatch(ctx context.Context, revision int64, prefix string, f func(res clientv3.WatchResponse) error) {
go func() {
defer func() {
if err := recover(); err != nil {
logger.Logger.Errorf("etcd watch WithPrefix(%v) panic:%v", prefix, err)
}
logger.Logger.Warnf("etcd watch WithPrefix(%v) quit!!!", prefix)
}()
var times int64
for !c.closed {
times++
logger.Logger.Warnf("etcd watch WithPrefix(%v) base revision %v start[%v]!!!", prefix, revision, times)
rch := c.WatchWithPrefix(prefix, revision)
for {
skip := false
select {
case _, ok := <-ctx.Done():
if !ok {
return
}
case resp, ok := <-rch:
if !ok {
logger.Logger.Warnf("etcd watch WithPrefix(%v) be closed", prefix)
skip = true
break
}
if resp.Header.Revision > revision {
revision = resp.Header.Revision
}
if resp.Canceled {
logger.Logger.Warnf("etcd watch WithPrefix(%v) be closed, reason:%v", prefix, resp.Err())
skip = true
break
}
if err := resp.Err(); err != nil {
logger.Logger.Warnf("etcd watch WithPrefix(%v) err:%v", prefix, resp.Err())
continue
}
if len(resp.Events) == 0 {
continue
}
logger.Logger.Tracef("@goWatch %v changed, header:%#v", prefix, resp.Header)
f(resp)
}
if skip {
break
}
}
time.Sleep(time.Second)
}
}()
}

View File

@ -1,133 +0,0 @@
package etcd
import (
"context"
"reflect"
"time"
"go.etcd.io/etcd/client/v3"
"mongo.games.com/goserver/core"
"mongo.games.com/goserver/core/basic"
"mongo.games.com/goserver/core/logger"
"mongo.games.com/game/proto"
)
/*
ETCD Manager
*/
var (
defaultUrl = []string{"localhost:2379"}
defaultUser = ""
defaultPasswd = ""
defaultDialTimeout = time.Minute
)
var globalClient = new(Client)
// Register 注册etcd监听方法
// key:监听的key
// msgType:数据类型
// f:数据变更回调方法, completeKey:完整键, isInit:第一次主动拉取数据,event:事件类型, data:已经反序列化的数据类型为msgType,是指针类型
func Register(key string, msgType interface{}, f func(ctx context.Context, completeKey string, isInit bool, event *clientv3.Event, data interface{})) {
createFunc := func() interface{} {
tp := reflect.TypeOf(msgType)
if tp.Kind() == reflect.Ptr {
tp = tp.Elem()
}
return reflect.New(tp).Interface()
}
initFunc := func() int64 {
logger.Logger.Info("ETCD 拉取数据:", key)
res, err := globalClient.GetValueWithPrefix(key)
if err == nil {
for i := int64(0); i < res.Count; i++ {
data := createFunc()
v, ok := data.(proto.Message)
if !ok {
logger.Logger.Errorf("ETCD %v error: not proto message", key)
continue
}
err := proto.Unmarshal(res.Kvs[i].Value, v)
if err != nil {
logger.Logger.Errorf("ETCD %v unmarshal error:%v", key, err)
continue
}
logger.Logger.Tracef("ETCD 拉取成功 %v ==> %v", string(res.Kvs[i].Key), v)
event := &clientv3.Event{
Type: 0,
}
f(context.TODO(), string(res.Kvs[i].Key), true, event, v)
}
if res.Header != nil {
return res.Header.Revision
}
} else {
logger.Logger.Errorf("ETCD get WithPrefix(%v) panic:%v", key, err)
}
return -1
}
// 监控数据变动
watchFunc := func(ctx context.Context, revision int64) {
globalClient.GoWatch(ctx, revision, key, func(res clientv3.WatchResponse) error {
obj := core.CoreObject()
if obj != nil {
obj.SendCommand(basic.CommandWrapper(func(*basic.Object) error {
for _, ev := range res.Events {
switch ev.Type {
case clientv3.EventTypePut:
data := createFunc()
v, ok := data.(proto.Message)
if !ok {
logger.Logger.Errorf("ETCD %v error: not proto message", string(ev.Kv.Key))
continue
}
err := proto.Unmarshal(ev.Kv.Value, v)
if err != nil {
logger.Logger.Errorf("etcd unmarshal(%v) error:%v", string(ev.Kv.Key), err)
continue
}
logger.Logger.Tracef("ETCD 更新事件 %v ==> %v", string(ev.Kv.Key), v)
f(ctx, string(ev.Kv.Key), false, ev, v)
case clientv3.EventTypeDelete:
logger.Logger.Tracef("ETCD 删除事件 %v", string(ev.Kv.Key))
f(ctx, string(ev.Kv.Key), false, ev, nil)
}
}
return nil
}), true)
}
return nil
})
}
globalClient.AddFunc(initFunc, watchFunc)
}
func Reset() {
globalClient.Close()
Start(defaultUrl, defaultUser, defaultPasswd, defaultDialTimeout)
}
func Close() {
globalClient.Close()
}
func Start(url []string, user, passwd string, dialTimeout time.Duration) {
defaultUrl = url
defaultUser = user
defaultPasswd = passwd
if dialTimeout > 0 {
defaultDialTimeout = dialTimeout
}
err := globalClient.Open(defaultUrl, defaultUser, defaultPasswd, defaultDialTimeout)
if err != nil {
logger.Logger.Errorf("etcd.Open err:%v", err)
}
globalClient.ReInitAndWatchAll()
}

120
etcd/register.go Normal file
View File

@ -0,0 +1,120 @@
package etcd
import (
"context"
"encoding/json"
"reflect"
"go.etcd.io/etcd/client/v3"
"mongo.games.com/goserver/core"
"mongo.games.com/goserver/core/basic"
"mongo.games.com/goserver/core/etcd"
"mongo.games.com/goserver/core/logger"
"mongo.games.com/game/proto"
)
// Register 注册etcd监听方法
// key:监听的key
// msgType:数据类型
// f:数据变更回调方法, completeKey:完整键, isInit:第一次主动拉取数据,event:事件类型, data:已经反序列化的数据类型为msgType,是指针类型
func Register(key string, msgType interface{}, f func(ctx context.Context, completeKey string, isInit bool, event *clientv3.Event, data interface{})) {
createFunc := func() interface{} {
tp := reflect.TypeOf(msgType)
if tp.Kind() == reflect.Ptr {
tp = tp.Elem()
}
return reflect.New(tp).Interface()
}
initFunc := func(ctx context.Context, res *clientv3.GetResponse) {
if res == nil {
return
}
f := func() {
for i := int64(0); i < res.Count; i++ {
data := createFunc()
switch d := data.(type) {
case proto.Message:
err := proto.Unmarshal(res.Kvs[i].Value, d)
if err != nil {
logger.Logger.Errorf("ETCD %v proto.Unmarshal error:%v", key, err)
continue
}
logger.Logger.Tracef("ETCD 拉取成功 %v ==> %v", string(res.Kvs[i].Key), d)
event := &clientv3.Event{
Type: 0,
}
f(context.TODO(), string(res.Kvs[i].Key), true, event, d)
default:
err := json.Unmarshal(res.Kvs[i].Value, d)
if err != nil {
logger.Logger.Errorf("ETCD %v josn.Unmarshal error:%v", key, err)
continue
}
logger.Logger.Tracef("ETCD 拉取成功 %v ==> %v", string(res.Kvs[i].Key), d)
event := &clientv3.Event{
Type: 0,
}
f(context.TODO(), string(res.Kvs[i].Key), true, event, d)
}
}
}
obj := core.CoreObject()
if obj == nil {
f()
return
}
obj.SendCommand(basic.CommandWrapper(func(*basic.Object) error {
f()
return nil
}), true)
}
// 监控数据变动
watchFunc := func(ctx context.Context, res *clientv3.WatchResponse) {
if res == nil {
return
}
f := func() {
for _, ev := range res.Events {
switch ev.Type {
case clientv3.EventTypePut:
data := createFunc()
switch d := data.(type) {
case proto.Message:
err := proto.Unmarshal(ev.Kv.Value, d)
if err != nil {
logger.Logger.Errorf("ETCD %v proto.Unmarshal error:%v", key, err)
continue
}
logger.Logger.Tracef("ETCD 更新事件 %v ==> %v", string(ev.Kv.Key), d)
f(ctx, string(ev.Kv.Key), false, ev, d)
default:
err := json.Unmarshal(ev.Kv.Value, d)
if err != nil {
logger.Logger.Errorf("ETCD %v josn.Unmarshal error:%v", key, err)
continue
}
logger.Logger.Tracef("ETCD 更新事件 %v ==> %v", string(ev.Kv.Key), d)
f(ctx, string(ev.Kv.Key), false, ev, d)
}
case clientv3.EventTypeDelete:
logger.Logger.Tracef("ETCD 删除事件 %v", string(ev.Kv.Key))
f(ctx, string(ev.Kv.Key), false, ev, nil)
}
}
}
obj := core.CoreObject()
if obj == nil {
f()
return
}
obj.SendCommand(basic.CommandWrapper(func(*basic.Object) error {
f()
return nil
}), true)
}
etcd.AddFunc(key, initFunc, watchFunc)
}

View File

@ -148,18 +148,19 @@
"profile": {
"SlowMS": 500
},
"etcd": {
"Url": ["127.0.0.1:2379"],
"UserName": "",
"Password": "",
"DialTimeout": 60
},
"costum": {
"MgoRpcCliNet": "tcp",
"MgoRpcCliAddr": "127.0.0.1:8999",
"MgoRpcCliReconnInterV": 3,
"RabbitMQURL": "amqp://win88:123456@127.0.0.1:5672/win88",
"RMQExchange": "win88",
"RMQPublishBacklog": 1024,
"etcdurl": [
"127.0.0.1:2379"
],
"etcduser": "",
"etcdpwd": ""
"RMQPublishBacklog": 1024
},
"webapi": {
"GameApiURL": "http://127.0.0.1:8000/api/game_srv"

View File

@ -4,12 +4,12 @@ import (
"time"
"mongo.games.com/goserver/core"
"mongo.games.com/goserver/core/etcd"
_ "mongo.games.com/goserver/core/i18n"
"mongo.games.com/goserver/core/module"
_ "mongo.games.com/game"
"mongo.games.com/game/common"
"mongo.games.com/game/etcd"
_ "mongo.games.com/game/gamesrv/action"
_ "mongo.games.com/game/gamesrv/base"
_ "mongo.games.com/game/gamesrv/transact"
@ -45,14 +45,13 @@ func main() {
core.LoadPackages("config.json")
// core hook
core.RegisteHook(core.HOOK_BEFORE_START, func() error {
etcd.Start()
model.StartupRPClient(common.CustomConfig.GetString("MgoRpcCliNet"), common.CustomConfig.GetString("MgoRpcCliAddr"), time.Duration(common.CustomConfig.GetInt("MgoRpcCliReconnInterV"))*time.Second)
etcd.Start(common.CustomConfig.GetStrings("etcdurl"), common.CustomConfig.GetString("etcduser"), common.CustomConfig.GetString("etcdpwd"), time.Minute)
mq.StartPublisher(common.CustomConfig.GetString("RabbitMQURL"), common.CustomConfig.GetString("RMQExchange"), true, common.CustomConfig.GetInt("RMQPublishBacklog"))
model.InitGameKVData()
return nil
})
core.RegisteHook(core.HOOK_AFTER_STOP, func() error {
etcd.Close()
mq.StopPublisher()
return nil
})

View File

@ -1,12 +1,13 @@
package main
import (
"mongo.games.com/goserver/core"
"mongo.games.com/goserver/core/module"
_ "mongo.games.com/game"
"mongo.games.com/game/common"
"mongo.games.com/game/model"
"mongo.games.com/game/mq"
"mongo.games.com/goserver/core"
"mongo.games.com/goserver/core/module"
)
func main() {

View File

@ -83,6 +83,12 @@
"SupportAdmin": true,
"AdminHttpPort": 9899
},
"etcd": {
"Url": ["127.0.0.1:2379"],
"UserName": "",
"Password": "",
"DialTimeout": 60
},
"costum": {
"MgoRpcCliNet": "tcp",
"MgoRpcCliAddr": "127.0.0.1:8999",

View File

@ -97,7 +97,12 @@
}
}
},
"etcd": {
"Url": ["127.0.0.1:2379"],
"UserName": "",
"Password": "",
"DialTimeout": 60
},
"costum": {
"MgoRpcCliNet": "tcp",
"MgoRpcCliAddr": "127.0.0.1:8999",
@ -106,13 +111,6 @@
"RabbitMQURL": "amqp://win88:123456@127.0.0.1:5672/win88",
"RMQExchange": "win88",
"RMQPublishBacklog": 1024,
"etcdurl":[
"127.0.0.1:2379"
],
"etcduser": "root",
"etcdpwd": "win88",
"GameIdFilter": []
},

View File

@ -4,11 +4,11 @@ import (
"time"
"mongo.games.com/goserver/core"
"mongo.games.com/goserver/core/etcd"
"mongo.games.com/goserver/core/module"
_ "mongo.games.com/game"
"mongo.games.com/game/common"
"mongo.games.com/game/etcd"
"mongo.games.com/game/model"
"mongo.games.com/game/mq"
)
@ -21,13 +21,12 @@ func main() {
defer core.ClosePackages()
// core hook
core.RegisteHook(core.HOOK_BEFORE_START, func() error {
etcd.Start()
model.StartupRPClient(common.CustomConfig.GetString("MgoRpcCliNet"), common.CustomConfig.GetString("MgoRpcCliAddr"), time.Duration(common.CustomConfig.GetInt("MgoRpcCliReconnInterV"))*time.Second)
etcd.Start(common.CustomConfig.GetStrings("etcdurl"), common.CustomConfig.GetString("etcduser"), common.CustomConfig.GetString("etcdpwd"), time.Minute)
mq.StartConsumer(common.CustomConfig.GetString("RabbitMQURL"), common.CustomConfig.GetString("RMQExchange"), true)
return nil
})
core.RegisteHook(core.HOOK_AFTER_STOP, func() error {
etcd.Close()
mq.StopConsumer()
model.ShutdownRPClient()
return nil

View File

@ -154,7 +154,9 @@ func (this *Configuration) Init() error {
}
func (this *Configuration) Close() error {
this.watcher.Close()
if this.watcher != nil {
this.watcher.Close()
}
return nil
}

View File

@ -1,14 +1,8 @@
package main
import (
"mongo.games.com/game/common"
"mongo.games.com/game/webapi"
"encoding/json"
"time"
"mongo.games.com/game/model"
"mongo.games.com/goserver/core/logger"
"mongo.games.com/goserver/core/module"
)
@ -104,33 +98,6 @@ func (this *ActMgr) Init() {
if this.ConfigByPlateform == nil {
this.ConfigByPlateform = make(map[string]*ActGivePlateformConfig)
}
type ApiResult struct {
Tag int
Msg []ActGivePlateformConfig
}
//不使用etcd的情况下走api获取
if !model.GameParamData.UseEtcd {
buff, err := webapi.API_GetActConfig(common.GetAppId())
if err == nil {
ar := ApiResult{}
err = json.Unmarshal(buff, &ar)
if err == nil {
for _, plateformConfig := range ar.Msg {
t := plateformConfig
this.AddGiveConfig(&t, plateformConfig.Platform)
}
} else {
logger.Logger.Error("Unmarshal ActMgr data error:", err, " buff:", string(buff))
}
} else {
logger.Logger.Error("Init ActMgr list failed.")
}
} else {
EtcdMgrSington.InitPlatformAct()
}
}
func (this *ActMgr) Update() {

View File

@ -16,34 +16,7 @@ const (
BlackState_Max
)
var BlackListMgrSington = &BlackListMgr{
BlackList: make(map[int32]*BlackInfo),
}
type BlackListMgr struct {
BlackList map[int32]*BlackInfo
BlackListByPlatform [BlackState_Max]map[string]map[int32]*BlackInfo
AlipayAccByPlatform [BlackState_Max]map[string]map[string]*BlackInfo
AlipayNameByPlatform [BlackState_Max]map[string]map[string]*BlackInfo
BankcardByPlatform [BlackState_Max]map[string]map[string]*BlackInfo
IpByPlatform [BlackState_Max]map[string]map[string]*BlackInfo
IpNetByPlatform [BlackState_Max]map[string][]*BlackInfo
PackageTagByPlatform [BlackState_Max]map[string]*BlackInfo
DeviceByPlatform [BlackState_Max]map[string]map[string]*BlackInfo
}
type BlackInfo struct {
Id int32
BlackType int //1.游戏2.兑换3.充值4.比赛
Alipay_account string
Alipay_name string
Bankcard string
Ip string //support like "192.0.2.0/24" or "2001:db8::/32", as defined in RFC 4632 and RFC 4291.
Platform string
PackageTag string
DeviceId string //设备ID
ipNet *net.IPNet
}
var BlackListMgrSington = NewBlackListMgr()
type BlackInfoApi struct {
Id int32
@ -62,26 +35,46 @@ type BlackInfoApi struct {
DeviceId string //设备ID
}
func (this *BlackListMgr) Init() {
if this.BlackList == nil {
this.BlackList = make(map[int32]*BlackInfo)
type BlackInfo struct {
Id int32
BlackType int //1.游戏2.兑换3.充值4.比赛
Alipay_account string
Alipay_name string
Bankcard string
Ip string //support like "192.0.2.0/24" or "2001:db8::/32", as defined in RFC 4632 and RFC 4291.
Platform string
PackageTag string
DeviceId string //设备ID
ipNet *net.IPNet
}
type BlackListMgr struct {
BlackList map[int32]*BlackInfo
BlackListByPlatform [BlackState_Max]map[string]map[int32]*BlackInfo
AlipayAccByPlatform [BlackState_Max]map[string]map[string]*BlackInfo
AlipayNameByPlatform [BlackState_Max]map[string]map[string]*BlackInfo
BankcardByPlatform [BlackState_Max]map[string]map[string]*BlackInfo
IpByPlatform [BlackState_Max]map[string]map[string]*BlackInfo
IpNetByPlatform [BlackState_Max]map[string][]*BlackInfo
PackageTagByPlatform [BlackState_Max]map[string]*BlackInfo
DeviceByPlatform [BlackState_Max]map[string]map[string]*BlackInfo
}
func NewBlackListMgr() *BlackListMgr {
ret := &BlackListMgr{
BlackList: make(map[int32]*BlackInfo),
}
for i := uint(0); i < BlackState_Max; i++ {
this.BlackListByPlatform[i] = make(map[string]map[int32]*BlackInfo)
this.AlipayAccByPlatform[i] = make(map[string]map[string]*BlackInfo)
this.AlipayNameByPlatform[i] = make(map[string]map[string]*BlackInfo)
this.BankcardByPlatform[i] = make(map[string]map[string]*BlackInfo)
this.IpByPlatform[i] = make(map[string]map[string]*BlackInfo)
this.IpNetByPlatform[i] = make(map[string][]*BlackInfo)
this.PackageTagByPlatform[i] = make(map[string]*BlackInfo)
this.DeviceByPlatform[i] = make(map[string]map[string]*BlackInfo)
ret.BlackListByPlatform[i] = make(map[string]map[int32]*BlackInfo)
ret.AlipayAccByPlatform[i] = make(map[string]map[string]*BlackInfo)
ret.AlipayNameByPlatform[i] = make(map[string]map[string]*BlackInfo)
ret.BankcardByPlatform[i] = make(map[string]map[string]*BlackInfo)
ret.IpByPlatform[i] = make(map[string]map[string]*BlackInfo)
ret.IpNetByPlatform[i] = make(map[string][]*BlackInfo)
ret.PackageTagByPlatform[i] = make(map[string]*BlackInfo)
ret.DeviceByPlatform[i] = make(map[string]map[string]*BlackInfo)
}
if !model.GameParamData.UseEtcd {
} else {
EtcdMgrSington.InitBlackList()
}
return ret
}
func (this *BlackListMgr) DivBlackInfo(blackInfo *BlackInfo) {

View File

@ -1,7 +1,6 @@
package main
import (
"mongo.games.com/game/model"
webapi_proto "mongo.games.com/game/protocol/webapi"
"mongo.games.com/goserver/core/module"
"sort"
@ -23,11 +22,7 @@ func (this *ChessRankMgr) ModuleName() string {
}
func (this *ChessRankMgr) Init() {
if !model.GameParamData.UseEtcd {
// 后台说现在没有不走ETCD情况~
} else {
EtcdMgrSington.InitUpdateChessRankcfg()
}
}
func (this *ChessRankMgr) UpdateChessRankConfig(cfg *webapi_proto.ChessRankcfgData) {

View File

@ -112,12 +112,13 @@
"AppId": "5c56d1644966f078bfb90c71",
"IsDevMode": true
},
"etcd": {
"Url": ["127.0.0.1:2379"],
"UserName": "",
"Password": "",
"DialTimeout": 60
},
"costum": {
"etcdurl": [
"127.0.0.1:2379"
],
"etcduser": "root",
"etcdpwd": "win88",
"MgoRpcCliNet": "tcp",
"MgoRpcCliAddr": "127.0.0.1:8999",
"MgoRpcCliReconnInterV": 3,

View File

@ -2,6 +2,7 @@ package main
import (
"context"
"strconv"
"strings"
"go.etcd.io/etcd/client/v3"
@ -10,6 +11,7 @@ import (
"mongo.games.com/game/common"
"mongo.games.com/game/etcd"
hallproto "mongo.games.com/game/protocol/gamehall"
loginproto "mongo.games.com/game/protocol/login"
playerproto "mongo.games.com/game/protocol/player"
"mongo.games.com/game/protocol/webapi"
)
@ -39,6 +41,30 @@ func init() {
etcd.Register(etcd.ETCDKEY_ACT_Collect, webapi.WelfareCollectConfig{}, platformConfigEvent)
// 渠道开关
etcd.Register(etcd.ETCDKEY_ChannelSwitch, webapi.ChannelSwitchConfig{}, platformConfigEvent)
// 组配置
etcd.Register(etcd.ETCDKEY_GROUPCONFIG_PREFIX, webapi.GameConfigGroup{}, platformConfigEvent)
// 黑名单配置
etcd.Register(etcd.ETCDKEY_BLACKLIST_PREFIX, BlackInfoApi{}, handlerEvent)
// 代理
etcd.Register(etcd.ETCDKEY_PROMOTER_PREFIX, PromoterConfig{}, handlerEvent)
// 赠送
etcd.Register(etcd.ETCDKEY_ACT_GIVE_PREFIX, PromoterConfig{}, handlerEvent)
// 7日签到
etcd.Register(etcd.ETCDKEY_ACT_7SIGN, webapi.Welfare7SignDateList{}, platformConfigEvent)
// 转盘
etcd.Register(etcd.ETCDKEY_ACT_TURNPLATE, webapi.WelfareTurnplateDateList{}, platformConfigEvent)
// 盲盒
etcd.Register(etcd.ETCDKEY_ACT_BLINDBOX, webapi.WelfareBlindBoxDataList{}, platformConfigEvent)
// 首充
etcd.Register(etcd.ETCDKEY_ACT_FIRSTPAY, webapi.WelfareFirstPayDataList{}, platformConfigEvent)
// 连充
etcd.Register(etcd.ETCDKEY_ACT_CONTINUOUSPAY, webapi.WelfareContinuousPayDataList{}, platformConfigEvent)
// VIP
etcd.Register(etcd.ETCDKEY_VIP_CFG, webapi.VIPcfgDataList{}, platformConfigEvent)
// 象棋段位
etcd.Register(etcd.ETCDKEY_CHESSRANK_CFG, webapi.ChessRankcfgData{}, platformConfigEvent)
// 手机积分
etcd.Register(etcd.ETCDKEY_ACT_PHONELOTTERY, webapi.WelfarePhoneLotteryStatus{}, platformConfigEvent)
}
func platformConfigEvent(ctx context.Context, completeKey string, isInit bool, event *clientv3.Event, data interface{}) {
@ -144,6 +170,92 @@ func platformConfigEvent(ctx context.Context, completeKey string, isInit bool, e
}
}
}
case *webapi.GameConfigGroup:
PlatformGameGroupMgrSington.UpsertGameGroup(config)
case *webapi.Welfare7SignDateList:
WelfareMgrSington.UpdateSign7(config)
case *webapi.WelfareTurnplateDateList:
WelfareMgrSington.UpdateTurnplate(config)
case *webapi.WelfareBlindBoxDataList:
WelfareMgrSington.UpdateBlindBox(config)
case *webapi.WelfareFirstPayDataList:
WelfareMgrSington.UpdateFirstPay(config)
case *webapi.WelfareContinuousPayDataList:
WelfareMgrSington.UpdateContinuousPay(config)
case *webapi.VIPcfgDataList:
VipMgrSington.UpdateVIPcfg(config)
case *webapi.ChessRankcfgData:
ChessRankMgrSington.UpdateChessRankConfig(config)
case *webapi.WelfarePhoneLotteryStatus:
WelfareMgrSington.UpdatePhoneLotteryStatus(config)
default:
logger.Logger.Errorf("etcd completeKey:%s, Not processed", completeKey)
}
}
func handlerEvent(ctx context.Context, completeKey string, isInit bool, event *clientv3.Event, data interface{}) {
if data == nil {
return
}
switch config := data.(type) {
case *BlackInfoApi:
if isInit {
BlackListMgrSington.InitBlackInfo(config)
} else {
switch event.Type {
case clientv3.EventTypeDelete:
dirs := strings.Split(string(event.Kv.Key), "/")
n := len(dirs)
if n > 0 {
last := dirs[n-1]
id, err := strconv.Atoi(last)
if err == nil {
if value, exist := BlackListMgrSington.BlackList[int32(id)]; exist {
BlackListMgrSington.RemoveBlackInfo(value.Id, value.Platform)
}
}
}
case clientv3.EventTypePut:
BlackListMgrSington.UpsertBlackInfo(config)
if (config.Space & int32(BlackState_Login)) != 0 {
var targetPlayer []*Player //确定用户是否在线
for _, value := range PlayerMgrSington.players {
_, ok := BlackListMgrSington.CheckPlayerInBlack(value.PlayerData, BlackState_Login)
if ok {
targetPlayer = append(targetPlayer, value)
}
}
for _, p := range targetPlayer {
if p.sid != 0 {
p.Kickout(int32(loginproto.SSDisconnectTypeCode_SSDTC_BlackList))
} else {
LoginStateMgrSington.LogoutByAccount(p.AccountId)
}
}
}
}
}
case *PromoterConfig:
if isInit {
PromoterMgrSington.AddConfig(config)
} else {
switch event.Type {
case clientv3.EventTypeDelete:
dirs := strings.Split(string(event.Kv.Key), "/")
n := len(dirs)
if n > 0 {
promoterConfig := dirs[n-1]
PromoterMgrSington.RemoveConfigByKey(promoterConfig)
}
case clientv3.EventTypePut:
PromoterMgrSington.AddConfig(config)
}
}
case *ActGivePlateformConfig:
if isInit || event.Type == clientv3.EventTypePut {
ActMgrSington.AddGiveConfig(config, config.Platform)
}
default:
logger.Logger.Errorf("etcd completeKey:%s, Not processed", completeKey)

View File

@ -1,768 +0,0 @@
package main
import (
"context"
"encoding/json"
"strconv"
"strings"
"time"
"go.etcd.io/etcd/client/v3"
"mongo.games.com/game/common"
"mongo.games.com/game/etcd"
"mongo.games.com/game/model"
"mongo.games.com/game/proto"
loginproto "mongo.games.com/game/protocol/login"
webapiproto "mongo.games.com/game/protocol/webapi"
"mongo.games.com/goserver/core/logger"
)
// EtcdMgrSington etcd数据读取
// Deprecated: use [etcd] instead
// 使用 etcd.Register 代替
// todo EtcdMgrSington 用新方法替换
var EtcdMgrSington = &EtcdMgr{
Client: &etcd.Client{},
}
type EtcdMgr struct {
*etcd.Client
}
// 加载组配置
func (this *EtcdMgr) InitGameGroup() {
initFunc := func() int64 {
if model.GameParamData.UseEtcd {
logger.Logger.Info("ETCD 拉取数据:", etcd.ETCDKEY_GROUPCONFIG_PREFIX)
res, err := this.GetValueWithPrefix(etcd.ETCDKEY_GROUPCONFIG_PREFIX)
if err == nil {
for i := int64(0); i < res.Count; i++ {
var value webapiproto.GameConfigGroup
err = proto.Unmarshal(res.Kvs[i].Value, &value)
if err == nil {
PlatformGameGroupMgrSington.UpsertGameGroup(&value)
} else {
logger.Logger.Errorf("etcd desc WithPrefix(%v) panic:%v", etcd.ETCDKEY_GROUPCONFIG_PREFIX, err)
}
}
if res.Header != nil {
return res.Header.Revision
}
} else {
logger.Logger.Errorf("etcd get WithPrefix(%v) panic:%v", etcd.ETCDKEY_GROUPCONFIG_PREFIX, err)
}
}
return -1
}
// 监控数据变动
watchFunc := func(ctx context.Context, revision int64) {
this.GoWatch(ctx, revision, etcd.ETCDKEY_GROUPCONFIG_PREFIX, func(res clientv3.WatchResponse) error {
for _, ev := range res.Events {
switch ev.Type {
case clientv3.EventTypeDelete:
case clientv3.EventTypePut:
var value webapiproto.GameConfigGroup
err := proto.Unmarshal(ev.Kv.Value, &value)
if err == nil {
PlatformGameGroupMgrSington.UpsertGameGroup(&value)
} else {
logger.Logger.Errorf("etcd desc WithPrefix(%v) panic:%v", etcd.ETCDKEY_GROUPCONFIG_PREFIX, err)
}
}
}
return nil
})
}
this.InitAndWatch(initFunc, watchFunc)
}
// 加载黑名单配置
func (this *EtcdMgr) InitBlackList() {
initFunc := func() int64 {
if model.GameParamData.UseEtcd {
logger.Logger.Info("ETCD 拉取数据:", etcd.ETCDKEY_BLACKLIST_PREFIX)
res, err := this.GetValueWithPrefix(etcd.ETCDKEY_BLACKLIST_PREFIX)
if err == nil {
for i := int64(0); i < res.Count; i++ {
var value BlackInfoApi
err = json.Unmarshal(res.Kvs[i].Value, &value)
if err == nil {
BlackListMgrSington.InitBlackInfo(&value)
} else {
logger.Logger.Errorf("etcd desc WithPrefix(%v) panic:%v", etcd.ETCDKEY_BLACKLIST_PREFIX, err)
}
}
if res.Header != nil {
return res.Header.Revision
}
} else {
logger.Logger.Errorf("etcd get WithPrefix(%v) panic:%v", etcd.ETCDKEY_BLACKLIST_PREFIX, err)
}
}
return -1
}
//@test code
//go func() {
// for {
// i := int32(1)
// data := BlackInfoApi{
// Id: i,
// Snid: i,
// Creator: rand.Int31(),
// }
// buf, err := json.Marshal(data)
// if err == nil {
// key := fmt.Sprintf("%s%d", etcd.ETCDKEY_BLACKLIST_PREFIX, i)
// putResp, err := this.PutValue(key, string(buf))
// if err == nil {
// if putResp.PrevKv != nil {
// logger.Logger.Trace("@etcdtest put", string(putResp.PrevKv.Key), string(putResp.PrevKv.Value))
// }
// //delResp, err := this.DelValue(key)
// //if err == nil {
// // logger.Logger.Trace("@etcdtest del", delResp.Deleted)
// //}
// }
// }
// }
//}()
//@test code
//ETCD中现在只有公共黑名单信息
//如果删除公共黑名单信息使用ETCD删除
//如果删除个人玩家身上的黑名单信息使用API删除
// 监控数据变动
watchFunc := func(ctx context.Context, revision int64) {
this.GoWatch(ctx, revision, etcd.ETCDKEY_BLACKLIST_PREFIX, func(res clientv3.WatchResponse) error {
for _, ev := range res.Events {
switch ev.Type {
case clientv3.EventTypeDelete:
dirs := strings.Split(string(ev.Kv.Key), "/")
n := len(dirs)
if n > 0 {
last := dirs[n-1]
id, err := strconv.Atoi(last)
if err == nil {
if value, exist := BlackListMgrSington.BlackList[int32(id)]; exist {
BlackListMgrSington.RemoveBlackInfo(value.Id, value.Platform)
}
}
}
case clientv3.EventTypePut:
var value BlackInfoApi
err := json.Unmarshal(ev.Kv.Value, &value)
if err == nil {
BlackListMgrSington.UpsertBlackInfo(&value)
if (value.Space & int32(BlackState_Login)) != 0 {
var targetPlayer []*Player //确定用户是否在线
for _, value := range PlayerMgrSington.players {
_, ok := BlackListMgrSington.CheckPlayerInBlack(value.PlayerData, BlackState_Login)
if ok {
targetPlayer = append(targetPlayer, value)
}
}
for _, p := range targetPlayer {
if p.sid != 0 {
p.Kickout(int32(loginproto.SSDisconnectTypeCode_SSDTC_BlackList))
} else {
LoginStateMgrSington.LogoutByAccount(p.AccountId)
}
}
}
} else {
logger.Logger.Errorf("etcd desc WithPrefix(%v) panic:%v", etcd.ETCDKEY_BLACKLIST_PREFIX, err)
}
}
}
return nil
})
}
this.InitAndWatch(initFunc, watchFunc)
}
// 初始化代理数据
func (this *EtcdMgr) InitPromoterConfig() {
initFunc := func() int64 {
if model.GameParamData.UseEtcd {
logger.Logger.Info("ETCD 初始化代理数据 拉取数据:", etcd.ETCDKEY_PROMOTER_PREFIX)
res, err := this.GetValueWithPrefix(etcd.ETCDKEY_PROMOTER_PREFIX)
if err == nil {
for i := int64(0); i < res.Count; i++ {
var promoterConfig *PromoterConfig
err = json.Unmarshal(res.Kvs[i].Value, &promoterConfig)
if err == nil {
PromoterMgrSington.AddConfig(promoterConfig)
} else {
logger.Logger.Errorf("etcd desc WithPrefix(%v) panic:%v", etcd.ETCDKEY_PROMOTER_PREFIX, err)
}
}
if res.Header != nil {
return res.Header.Revision
}
} else {
logger.Logger.Errorf("etcd get WithPrefix(%v) panic:%v", etcd.ETCDKEY_PROMOTER_PREFIX, err)
}
}
return -1
}
// 监控数据变动
watchFunc := func(ctx context.Context, revision int64) {
this.GoWatch(ctx, revision, etcd.ETCDKEY_PROMOTER_PREFIX, func(res clientv3.WatchResponse) error {
for _, ev := range res.Events {
switch ev.Type {
case clientv3.EventTypeDelete:
dirs := strings.Split(string(ev.Kv.Key), "/")
n := len(dirs)
if n > 0 {
promoterConfig := dirs[n-1]
PromoterMgrSington.RemoveConfigByKey(promoterConfig)
}
/*
var promoterConfig *PromoterConfig
err := json.Unmarshal(ev.Kv.Value, &promoterConfig)
if err == nil {
PromoterMgrSington.RemoveConfigByKey(promoterConfig)
} else {
logger.Logger.Errorf("etcd desc WithPrefix(%v) panic:%v", etcd.ETCDKEY_PROMOTER_PREFIX, err)
}
*/
case clientv3.EventTypePut:
var promoterConfig *PromoterConfig
err := json.Unmarshal(ev.Kv.Value, &promoterConfig)
if err == nil {
PromoterMgrSington.AddConfig(promoterConfig)
} else {
logger.Logger.Errorf("etcd desc WithPrefix(%v) panic:%v", etcd.ETCDKEY_PROMOTER_PREFIX, err)
}
}
}
return nil
})
}
this.InitAndWatch(initFunc, watchFunc)
}
// 加载活动give配置
func (this *EtcdMgr) InitPlatformAct() {
initFunc := func() int64 {
if model.GameParamData.UseEtcd {
logger.Logger.Info("ETCD 拉取数据:", etcd.ETCDKEY_ACT_GIVE_PREFIX)
res, err := this.GetValueWithPrefix(etcd.ETCDKEY_ACT_GIVE_PREFIX)
if err == nil {
for i := int64(0); i < res.Count; i++ {
var vipConfig ActGivePlateformConfig
err = json.Unmarshal(res.Kvs[i].Value, &vipConfig)
if err == nil {
ActMgrSington.AddGiveConfig(&vipConfig, vipConfig.Platform)
} else {
logger.Logger.Errorf("etcd desc WithPrefix(%v) panic:%v", etcd.ETCDKEY_ACT_GIVE_PREFIX, err)
}
}
if res.Header != nil {
return res.Header.Revision
}
} else {
logger.Logger.Errorf("etcd get WithPrefix(%v) panic:%v", etcd.ETCDKEY_ACT_GIVE_PREFIX, err)
}
}
return -1
}
// 监控数据变动
watchFunc := func(ctx context.Context, revision int64) {
this.GoWatch(ctx, revision, etcd.ETCDKEY_ACT_GIVE_PREFIX, func(res clientv3.WatchResponse) error {
for _, ev := range res.Events {
switch ev.Type {
case clientv3.EventTypeDelete:
case clientv3.EventTypePut:
var vipConfig ActGivePlateformConfig
err := json.Unmarshal(ev.Kv.Value, &vipConfig)
if err == nil {
ActMgrSington.AddGiveConfig(&vipConfig, vipConfig.Platform)
} else {
logger.Logger.Errorf("etcd desc WithPrefix(%v) panic:%v", etcd.ETCDKEY_ACT_GOLDCOME_PREFIX, err)
}
}
}
return nil
})
}
this.InitAndWatch(initFunc, watchFunc)
}
// 加载七日签到
func (this *EtcdMgr) InitSign7() {
initFunc := func() int64 {
if model.GameParamData.UseEtcd {
logger.Logger.Info("ETCD 拉取数据:", etcd.ETCDKEY_ACT_7SIGN)
res, err := this.GetValueWithPrefix(etcd.ETCDKEY_ACT_7SIGN)
if err == nil {
for i := int64(0); i < res.Count; i++ {
cfg := &webapiproto.Welfare7SignDateList{}
//msg := &webapi.ASSrvCtrlClose{}
err = proto.Unmarshal(res.Kvs[i].Value, cfg)
if err == nil && cfg.Platform != "" {
WelfareMgrSington.UpdateSign7(cfg)
} else {
logger.Logger.Errorf("etcd desc WithPrefix(%v) Platform %v panic:%v", etcd.ETCDKEY_ACT_7SIGN, cfg.Platform, err)
}
}
if res.Header != nil {
return res.Header.Revision
}
} else {
logger.Logger.Errorf("etcd get WithPrefix(%v) panic:%v", etcd.ETCDKEY_ACT_7SIGN, err)
}
}
return -1
}
// 监控数据变动
watchFunc := func(ctx context.Context, revision int64) {
this.GoWatch(ctx, revision, etcd.ETCDKEY_ACT_7SIGN, func(res clientv3.WatchResponse) error {
for _, ev := range res.Events {
switch ev.Type {
case clientv3.EventTypeDelete:
case clientv3.EventTypePut:
cfg := &webapiproto.Welfare7SignDateList{}
err := proto.Unmarshal(ev.Kv.Value, cfg)
if err == nil && cfg.Platform != "" {
WelfareMgrSington.UpdateSign7(cfg)
} else {
logger.Logger.Errorf("etcd desc WithPrefix(%v) Platform %v panic:%v", etcd.ETCDKEY_ACT_7SIGN, cfg.Platform, err)
}
}
}
return nil
})
}
this.InitAndWatch(initFunc, watchFunc)
}
// 加载轮盘
func (this *EtcdMgr) InitTurnplate() {
initFunc := func() int64 {
if model.GameParamData.UseEtcd {
logger.Logger.Info("ETCD 拉取数据:", etcd.ETCDKEY_ACT_TURNPLATE)
res, err := this.GetValueWithPrefix(etcd.ETCDKEY_ACT_TURNPLATE)
if err == nil {
for i := int64(0); i < res.Count; i++ {
cfg := &webapiproto.WelfareTurnplateDateList{}
//msg := &webapi.ASSrvCtrlClose{}
err = proto.Unmarshal(res.Kvs[i].Value, cfg)
if err == nil && cfg.Platform != "" {
WelfareMgrSington.UpdateTurnplate(cfg)
} else {
logger.Logger.Errorf("etcd desc WithPrefix(%v) Platform %v panic:%v", etcd.ETCDKEY_ACT_TURNPLATE, cfg.Platform, err)
}
}
if res.Header != nil {
return res.Header.Revision
}
} else {
logger.Logger.Errorf("etcd get WithPrefix(%v) panic:%v", etcd.ETCDKEY_ACT_TURNPLATE, err)
}
}
return -1
}
// 监控数据变动
watchFunc := func(ctx context.Context, revision int64) {
this.GoWatch(ctx, revision, etcd.ETCDKEY_ACT_TURNPLATE, func(res clientv3.WatchResponse) error {
for _, ev := range res.Events {
switch ev.Type {
case clientv3.EventTypeDelete:
case clientv3.EventTypePut:
cfg := &webapiproto.WelfareTurnplateDateList{}
err := proto.Unmarshal(ev.Kv.Value, cfg)
if err == nil && cfg.Platform != "" {
WelfareMgrSington.UpdateTurnplate(cfg)
} else {
logger.Logger.Errorf("etcd desc WithPrefix(%v) Platform %v panic:%v", etcd.ETCDKEY_ACT_TURNPLATE, cfg.Platform, err)
}
}
}
return nil
})
}
this.InitAndWatch(initFunc, watchFunc)
}
// 加载盲盒
func (this *EtcdMgr) InitBlindBox() {
initFunc := func() int64 {
if model.GameParamData.UseEtcd {
logger.Logger.Info("ETCD 拉取数据:", etcd.ETCDKEY_ACT_BLINDBOX)
res, err := this.GetValueWithPrefix(etcd.ETCDKEY_ACT_BLINDBOX)
if err == nil {
for i := int64(0); i < res.Count; i++ {
cfg := &webapiproto.WelfareBlindBoxDataList{}
//msg := &webapi.ASSrvCtrlClose{}
err = proto.Unmarshal(res.Kvs[i].Value, cfg)
if err == nil && cfg.Platform != "" {
WelfareMgrSington.UpdateBlindBox(cfg)
} else {
logger.Logger.Errorf("etcd desc WithPrefix(%v) Platform %v panic:%v", etcd.ETCDKEY_ACT_BLINDBOX, cfg.Platform, err)
}
}
if res.Header != nil {
return res.Header.Revision
}
} else {
logger.Logger.Errorf("etcd get WithPrefix(%v) panic:%v", etcd.ETCDKEY_ACT_BLINDBOX, err)
}
}
return -1
}
// 监控数据变动
watchFunc := func(ctx context.Context, revision int64) {
this.GoWatch(ctx, revision, etcd.ETCDKEY_ACT_BLINDBOX, func(res clientv3.WatchResponse) error {
for _, ev := range res.Events {
switch ev.Type {
case clientv3.EventTypeDelete:
case clientv3.EventTypePut:
cfg := &webapiproto.WelfareBlindBoxDataList{}
err := proto.Unmarshal(ev.Kv.Value, cfg)
if err == nil && cfg.Platform != "" {
WelfareMgrSington.UpdateBlindBox(cfg)
} else {
logger.Logger.Errorf("etcd desc WithPrefix(%v) Platform %v panic:%v", etcd.ETCDKEY_ACT_BLINDBOX, cfg.Platform, err)
}
}
}
return nil
})
}
this.InitAndWatch(initFunc, watchFunc)
}
// 加载首充
func (this *EtcdMgr) InitFirstPay() {
initFunc := func() int64 {
if model.GameParamData.UseEtcd {
logger.Logger.Info("ETCD 拉取数据:", etcd.ETCDKEY_ACT_FIRSTPAY)
res, err := this.GetValueWithPrefix(etcd.ETCDKEY_ACT_FIRSTPAY)
if err == nil {
for i := int64(0); i < res.Count; i++ {
cfg := &webapiproto.WelfareFirstPayDataList{}
//msg := &webapi.ASSrvCtrlClose{}
err = proto.Unmarshal(res.Kvs[i].Value, cfg)
if err == nil && cfg.Platform != "" {
WelfareMgrSington.UpdateFirstPay(cfg)
} else {
logger.Logger.Errorf("etcd desc WithPrefix(%v) Platform %v panic:%v", etcd.ETCDKEY_ACT_FIRSTPAY, cfg.Platform, err)
}
}
if res.Header != nil {
return res.Header.Revision
}
} else {
logger.Logger.Errorf("etcd get WithPrefix(%v) panic:%v", etcd.ETCDKEY_ACT_FIRSTPAY, err)
}
}
return -1
}
// 监控数据变动
watchFunc := func(ctx context.Context, revision int64) {
this.GoWatch(ctx, revision, etcd.ETCDKEY_ACT_FIRSTPAY, func(res clientv3.WatchResponse) error {
for _, ev := range res.Events {
switch ev.Type {
case clientv3.EventTypeDelete:
case clientv3.EventTypePut:
cfg := &webapiproto.WelfareFirstPayDataList{}
err := proto.Unmarshal(ev.Kv.Value, cfg)
if err == nil && cfg.Platform != "" {
WelfareMgrSington.UpdateFirstPay(cfg)
} else {
logger.Logger.Errorf("etcd desc WithPrefix(%v) Platform %v panic:%v", etcd.ETCDKEY_ACT_FIRSTPAY, cfg.Platform, err)
}
}
}
return nil
})
}
this.InitAndWatch(initFunc, watchFunc)
}
// 加载连续充值
func (this *EtcdMgr) InitContinuousPay() {
initFunc := func() int64 {
if model.GameParamData.UseEtcd {
logger.Logger.Info("ETCD 拉取数据:", etcd.ETCDKEY_ACT_CONTINUOUSPAY)
res, err := this.GetValueWithPrefix(etcd.ETCDKEY_ACT_CONTINUOUSPAY)
if err == nil {
for i := int64(0); i < res.Count; i++ {
cfg := &webapiproto.WelfareContinuousPayDataList{}
//msg := &webapi.ASSrvCtrlClose{}
err = proto.Unmarshal(res.Kvs[i].Value, cfg)
if err == nil && cfg.Platform != "" {
WelfareMgrSington.UpdateContinuousPay(cfg)
} else {
logger.Logger.Errorf("etcd desc WithPrefix(%v) Platform %v panic:%v", etcd.ETCDKEY_ACT_CONTINUOUSPAY, cfg.Platform, err)
}
}
if res.Header != nil {
return res.Header.Revision
}
} else {
logger.Logger.Errorf("etcd get WithPrefix(%v) panic:%v", etcd.ETCDKEY_ACT_CONTINUOUSPAY, err)
}
}
return -1
}
// 监控数据变动
watchFunc := func(ctx context.Context, revision int64) {
this.GoWatch(ctx, revision, etcd.ETCDKEY_ACT_CONTINUOUSPAY, func(res clientv3.WatchResponse) error {
for _, ev := range res.Events {
switch ev.Type {
case clientv3.EventTypeDelete:
case clientv3.EventTypePut:
cfg := &webapiproto.WelfareContinuousPayDataList{}
err := proto.Unmarshal(ev.Kv.Value, cfg)
if err == nil && cfg.Platform != "" {
WelfareMgrSington.UpdateContinuousPay(cfg)
} else {
logger.Logger.Errorf("etcd desc WithPrefix(%v) Platform %v panic:%v", etcd.ETCDKEY_ACT_CONTINUOUSPAY, cfg.Platform, err)
}
}
}
return nil
})
}
this.InitAndWatch(initFunc, watchFunc)
}
// 加载VIP
func (this *EtcdMgr) InitUpdateVIPcfg() {
initFunc := func() int64 {
if model.GameParamData.UseEtcd {
logger.Logger.Info("ETCD 拉取数据:", etcd.ETCDKEY_VIP_CFG)
res, err := this.GetValueWithPrefix(etcd.ETCDKEY_VIP_CFG)
if err == nil {
for i := int64(0); i < res.Count; i++ {
cfg := &webapiproto.VIPcfgDataList{}
//msg := &webapi.ASSrvCtrlClose{}
err = proto.Unmarshal(res.Kvs[i].Value, cfg)
if err == nil && cfg.Platform != "" {
VipMgrSington.UpdateVIPcfg(cfg)
} else {
logger.Logger.Errorf("etcd desc WithPrefix(%v) Platform %v panic:%v", etcd.ETCDKEY_VIP_CFG, cfg.Platform, err)
}
}
if res.Header != nil {
return res.Header.Revision
}
} else {
logger.Logger.Errorf("etcd get WithPrefix(%v) panic:%v", etcd.ETCDKEY_VIP_CFG, err)
}
}
return -1
}
// 监控数据变动
watchFunc := func(ctx context.Context, revision int64) {
this.GoWatch(ctx, revision, etcd.ETCDKEY_VIP_CFG, func(res clientv3.WatchResponse) error {
for _, ev := range res.Events {
switch ev.Type {
case clientv3.EventTypeDelete:
case clientv3.EventTypePut:
cfg := &webapiproto.VIPcfgDataList{}
err := proto.Unmarshal(ev.Kv.Value, cfg)
if err == nil && cfg.Platform != "" {
VipMgrSington.UpdateVIPcfg(cfg)
} else {
logger.Logger.Errorf("etcd desc WithPrefix(%v) Platform %v panic:%v", etcd.ETCDKEY_VIP_CFG, cfg.Platform, err)
}
}
}
return nil
})
}
this.InitAndWatch(initFunc, watchFunc)
}
// 加载段位配置
func (this *EtcdMgr) InitUpdateChessRankcfg() {
initFunc := func() int64 {
if model.GameParamData.UseEtcd {
logger.Logger.Info("ETCD 拉取数据:", etcd.ETCDKEY_CHESSRANK_CFG)
res, err := this.GetValueWithPrefix(etcd.ETCDKEY_CHESSRANK_CFG)
if err == nil {
for i := int64(0); i < res.Count; i++ {
cfg := &webapiproto.ChessRankcfgData{}
err = proto.Unmarshal(res.Kvs[i].Value, cfg)
if err == nil && cfg.Platform != "" {
ChessRankMgrSington.UpdateChessRankConfig(cfg)
logger.Logger.Tracef("ChessRankConfig %v", cfg)
} else {
logger.Logger.Errorf("etcd desc WithPrefix(%v) Platform %v panic:%v", etcd.ETCDKEY_CHESSRANK_CFG, cfg.Platform, err)
}
}
if res.Header != nil {
return res.Header.Revision
}
} else {
logger.Logger.Errorf("etcd get WithPrefix(%v) panic:%v", etcd.ETCDKEY_CHESSRANK_CFG, err)
}
}
return -1
}
// 监控数据变动
watchFunc := func(ctx context.Context, revision int64) {
this.GoWatch(ctx, revision, etcd.ETCDKEY_CHESSRANK_CFG, func(res clientv3.WatchResponse) error {
for _, ev := range res.Events {
switch ev.Type {
case clientv3.EventTypeDelete:
case clientv3.EventTypePut:
cfg := &webapiproto.ChessRankcfgData{}
err := proto.Unmarshal(ev.Kv.Value, cfg)
if err == nil && cfg.Platform != "" {
ChessRankMgrSington.UpdateChessRankConfig(cfg)
} else {
logger.Logger.Errorf("etcd desc WithPrefix(%v) Platform %v panic:%v", etcd.ETCDKEY_CHESSRANK_CFG, cfg.Platform, err)
}
}
}
return nil
})
}
this.InitAndWatch(initFunc, watchFunc)
}
// 加载抽手机活动
func (this *EtcdMgr) InitPhoneLottery() {
initFunc := func() int64 {
if model.GameParamData.UseEtcd {
logger.Logger.Info("ETCD 拉取数据:", etcd.ETCDKEY_ACT_PHONELOTTERY)
res, err := this.GetValueWithPrefix(etcd.ETCDKEY_ACT_PHONELOTTERY)
if err == nil {
for i := int64(0); i < res.Count; i++ {
cfg := &webapiproto.WelfarePhoneLotteryStatus{}
//msg := &webapi.ASSrvCtrlClose{}
err = proto.Unmarshal(res.Kvs[i].Value, cfg)
if err == nil && cfg.Platform != "" {
WelfareMgrSington.UpdatePhoneLotteryStatus(cfg)
} else {
logger.Logger.Errorf("etcd desc WithPrefix(%v) Platform %v panic:%v", etcd.ETCDKEY_ACT_PHONELOTTERY, cfg.Platform, err)
}
}
if res.Header != nil {
return res.Header.Revision
}
} else {
logger.Logger.Errorf("etcd get WithPrefix(%v) panic:%v", etcd.ETCDKEY_ACT_PHONELOTTERY, err)
}
}
return -1
}
// 监控数据变动
watchFunc := func(ctx context.Context, revision int64) {
this.GoWatch(ctx, revision, etcd.ETCDKEY_ACT_PHONELOTTERY, func(res clientv3.WatchResponse) error {
for _, ev := range res.Events {
switch ev.Type {
case clientv3.EventTypeDelete:
case clientv3.EventTypePut:
cfg := &webapiproto.WelfarePhoneLotteryStatus{}
err := proto.Unmarshal(ev.Kv.Value, cfg)
if err == nil && cfg.Platform != "" {
WelfareMgrSington.UpdatePhoneLotteryStatus(cfg)
} else {
logger.Logger.Errorf("etcd desc WithPrefix(%v) Platform %v panic:%v", etcd.ETCDKEY_ACT_PHONELOTTERY, cfg.Platform, err)
}
}
}
return nil
})
}
this.InitAndWatch(initFunc, watchFunc)
}
// 加载 调控黑白名单
//func (this *EtcdMgr) InitWBCtrlCFG() {
// initFunc := func() int64 {
// if model.GameParamData.UseEtcd {
// logger.Logger.Info("ETCD 拉取数据:", etcd.ETCDKEY_WBCtrl_CFG)
// res, err := this.GetValueWithPrefix(etcd.ETCDKEY_WBCtrl_CFG)
// if err == nil {
// for i := int64(0); i < res.Count; i++ {
// cfg := &webapi_proto.WbCtrlCfg{}
// err = proto.Unmarshal(res.Kvs[i].Value, cfg)
// if err == nil && cfg.Platform != "" {
// WBCtrlCfgMgr.UpdateConfig(cfg)
// } else {
// logger.Logger.Errorf("etcd desc WithPrefix(%v) Platform %v panic:%v", etcd.ETCDKEY_WBCtrl_CFG, cfg.Platform, err)
// }
// }
// if res.Header != nil {
// return res.Header.Revision
// }
// } else {
// logger.Logger.Errorf("etcd get WithPrefix(%v) panic:%v", etcd.ETCDKEY_WBCtrl_CFG, err)
// }
// }
// return -1
// }
//
// // 监控数据变动
// watchFunc := func(ctx context.Context, revision int64) {
// this.GoWatch(ctx, revision, etcd.ETCDKEY_WBCtrl_CFG, func(res clientv3.WatchResponse) error {
// for _, ev := range res.Events {
// switch ev.Type {
// case clientv3.EventTypeDelete:
// case clientv3.EventTypePut:
// cfg := &webapi_proto.WbCtrlCfg{}
// err := proto.Unmarshal(ev.Kv.Value, cfg)
// if err == nil && cfg.Platform != "" {
// WBCtrlCfgMgr.UpdateConfig(cfg)
// } else {
// logger.Logger.Errorf("etcd desc WithPrefix(%v) Platform %v panic:%v", etcd.ETCDKEY_WBCtrl_CFG, cfg.Platform, err)
// }
// }
// }
// return nil
// })
// }
//
// this.InitAndWatch(initFunc, watchFunc)
//}
func (this *EtcdMgr) Init() {
if model.GameParamData.UseEtcd {
logger.Logger.Infof("EtcdClient开始连接url:%v;etcduser:%v;etcdpwd:%v", common.CustomConfig.GetStrings("etcdurl"), common.CustomConfig.GetString("etcduser"), common.CustomConfig.GetString("etcdpwd"))
err := this.Open(common.CustomConfig.GetStrings("etcdurl"), common.CustomConfig.GetString("etcduser"), common.CustomConfig.GetString("etcdpwd"), time.Minute)
if err != nil {
logger.Logger.Tracef("EtcdMgr.Open err:%v", err)
return
}
}
}
func (this *EtcdMgr) Shutdown() {
this.Close()
}
func (this *EtcdMgr) Reset() {
this.Close()
this.Init()
this.ReInitAndWatchAll()
}

View File

@ -5,13 +5,13 @@ import (
"github.com/astaxie/beego/cache"
"mongo.games.com/goserver/core"
"mongo.games.com/goserver/core/etcd"
_ "mongo.games.com/goserver/core/i18n"
"mongo.games.com/goserver/core/module"
"mongo.games.com/goserver/core/schedule"
_ "mongo.games.com/game"
"mongo.games.com/game/common"
"mongo.games.com/game/etcd"
"mongo.games.com/game/model"
"mongo.games.com/game/mq"
)
@ -29,8 +29,8 @@ func main() {
core.LoadPackages("config.json")
// core hook
core.RegisteHook(core.HOOK_BEFORE_START, func() error {
etcd.Start()
model.StartupRPClient(common.CustomConfig.GetString("MgoRpcCliNet"), common.CustomConfig.GetString("MgoRpcCliAddr"), time.Duration(common.CustomConfig.GetInt("MgoRpcCliReconnInterV"))*time.Second)
etcd.Start(common.CustomConfig.GetStrings("etcdurl"), common.CustomConfig.GetString("etcduser"), common.CustomConfig.GetString("etcdpwd"), time.Minute)
mq.StartConsumer(common.CustomConfig.GetString("RabbitMQURL"), common.CustomConfig.GetString("RMQExchange"), true)
mq.StartPublisher(common.CustomConfig.GetString("RabbitMQURL"), common.CustomConfig.GetString("RMQExchange"), true, common.CustomConfig.GetInt("RMQPublishBacklog"))
@ -40,19 +40,14 @@ func main() {
return err
}
EtcdMgrSington.Init()
BlackListMgrSington.Init()
gameStateMgr.Init()
HorseRaceLampMgrSington.InitHorseRaceLamp()
model.InitGameKVData()
model.GetAllCoinPoolSettingData()
MsgMgrSington.InitMsg()
PlatformGameGroupMgrSington.LoadGameGroup()
return nil
})
core.RegisteHook(core.HOOK_AFTER_STOP, func() error {
EtcdMgrSington.Close()
etcd.Close()
mq.StopPublisher()
mq.StopConsumer()
model.ShutdownRPClient()

View File

@ -1,13 +1,8 @@
package main
import (
"mongo.games.com/game/common"
"mongo.games.com/game/model"
"mongo.games.com/game/proto"
webapi_proto "mongo.games.com/game/protocol/webapi"
"mongo.games.com/game/srvdata"
"mongo.games.com/game/webapi"
"mongo.games.com/goserver/core/logger"
)
type PlatformGameGroupObserver interface {
@ -56,45 +51,6 @@ func (this *PlatformGameGroupMgr) GetGameGroup(groupId int32) *webapi_proto.Game
return nil
}
func (this *PlatformGameGroupMgr) LoadGameGroup() {
//不使用etcd的情况下走api获取
if model.GameParamData.UseEtcd {
EtcdMgrSington.InitGameGroup()
} else {
//获取平台游戏组信息
logger.Logger.Trace("API_GetGameGroupData")
buf, err := webapi.API_GetGameGroupData(common.GetAppId())
if err == nil {
pcdr := &webapi_proto.ASGameConfigGroup{}
err = proto.Unmarshal(buf, pcdr)
if err == nil && pcdr.Tag == webapi_proto.TagCode_SUCCESS {
gameCfgGroup := pcdr.GetGameConfigGroup()
for _, value := range gameCfgGroup {
groupId := value.GetId()
vDbGameFree := value.GetDbGameFree()
dbGameFree := srvdata.PBDB_GameFreeMgr.GetData(value.LogicId)
if dbGameFree == nil {
continue
}
if vDbGameFree == nil {
vDbGameFree = dbGameFree
} else {
CopyDBGameFreeField(dbGameFree, vDbGameFree)
}
this.groups[groupId] = value
logger.Logger.Trace("PlatformGameGroup data:", value)
}
} else {
logger.Logger.Error("Unmarshal PlatformGameGroup data error:", err)
}
} else {
logger.Logger.Error("Get PlatformGameGroup data error:", err)
}
}
}
func (this *PlatformGameGroupMgr) UpsertGameGroup(conf *webapi_proto.GameConfigGroup) {
if conf == nil {
return

View File

@ -1,11 +1,6 @@
package main
import (
"encoding/json"
"mongo.games.com/game/common"
"mongo.games.com/game/model"
"mongo.games.com/game/webapi"
"mongo.games.com/goserver/core/logger"
"mongo.games.com/goserver/core/module"
"strconv"
"time"
@ -105,34 +100,6 @@ func (this *PromoterMgr) Init() {
if this.PromoterConfigMap == nil {
this.PromoterConfigMap = make(map[string]*PromoterConfig)
}
type ApiResult struct {
Tag int
Msg []PromoterConfig
}
//不使用etcd的情况下走api获取
if !model.GameParamData.UseEtcd {
buff, err := webapi.API_GetPromoterConfig(common.GetAppId())
if err == nil {
ar := ApiResult{}
err = json.Unmarshal(buff, &ar)
if err == nil && ar.Tag == 0 {
logger.Logger.Trace("API_GetPromoterConfig response:", string(buff))
for _, promoterConfig := range ar.Msg {
temp := promoterConfig
this.AddConfig(&temp)
}
} else {
logger.Logger.Error("Unmarshal PromoterMgr data error:", err, " buff:", string(buff))
}
} else {
logger.Logger.Error("Init PromoterMgr list failed.")
}
} else {
EtcdMgrSington.InitPromoterConfig()
}
}
func (this *PromoterMgr) Update() {

View File

@ -16,6 +16,7 @@ import (
"github.com/globalsign/mgo/bson"
"mongo.games.com/goserver/core/basic"
"mongo.games.com/goserver/core/etcd"
"mongo.games.com/goserver/core/logger"
"mongo.games.com/goserver/core/netlib"
"mongo.games.com/goserver/core/task"
@ -3805,7 +3806,7 @@ func init() {
pack.Msg = "数据序列化失败" + err.Error()
return common.ResponseTag_ParamError, pack
}
EtcdMgrSington.Reset()
etcd.Restart()
pack.Tag = webapiproto.TagCode_SUCCESS
pack.Msg = "Etcd Reset success"
return common.ResponseTag_Ok, nil

View File

@ -7,7 +7,6 @@ import (
"mongo.games.com/goserver/core/logger"
"mongo.games.com/game/common"
"mongo.games.com/game/model"
webapi_proto "mongo.games.com/game/protocol/webapi"
"mongo.games.com/goserver/core/module"
)
@ -29,12 +28,7 @@ func (this *VipMgr) ModuleName() string {
}
func (this *VipMgr) Init() {
if !model.GameParamData.UseEtcd {
// 后台说现在没有不走ETCD情况~
} else {
EtcdMgrSington.InitUpdateVIPcfg()
}
}
func (this *VipMgr) UpdateVIPcfg(cfg *webapi_proto.VIPcfgDataList) {

View File

@ -31,12 +31,7 @@ type WelfareMgr struct {
}
func (this *WelfareMgr) Init() {
EtcdMgrSington.InitSign7()
EtcdMgrSington.InitTurnplate()
EtcdMgrSington.InitBlindBox()
EtcdMgrSington.InitFirstPay()
EtcdMgrSington.InitContinuousPay()
EtcdMgrSington.InitPhoneLottery()
}
func (this *WelfareMgr) ModuleName() string {