Compare commits
No commits in common. "d27c0270f8b02a5a655a74424899327f0b535825" and "bc77fe87496ec208f28fd336af63da302bceca07" have entirely different histories.
d27c0270f8
...
bc77fe8749
|
@ -254,7 +254,7 @@ const (
|
||||||
GainWay_Collect = 64 //64.集卡活动
|
GainWay_Collect = 64 //64.集卡活动
|
||||||
GainWay_WeekCardAward = 65 //65.周卡每日奖励
|
GainWay_WeekCardAward = 65 //65.周卡每日奖励
|
||||||
GainWay_PigrankTakeCoin = 66 //66.存钱罐领取耗费钻石
|
GainWay_PigrankTakeCoin = 66 //66.存钱罐领取耗费钻石
|
||||||
GainWay_PigrankGainCoin = 67 //67.存钱罐打开获取金币
|
GainWay_PigrankGainCoin = 67 //66.存钱罐打开获取金币
|
||||||
GainWay_ItemMove = 68 //68.道具赠送
|
GainWay_ItemMove = 68 //68.道具赠送
|
||||||
GainWay_RoleUpgrade = 69 //69.角色升级
|
GainWay_RoleUpgrade = 69 //69.角色升级
|
||||||
GainWay_PetUpgrade = 70 //70.宠物升级
|
GainWay_PetUpgrade = 70 //70.宠物升级
|
||||||
|
|
|
@ -47,12 +47,6 @@
|
||||||
"data":{
|
"data":{
|
||||||
"RootPath":"../data"
|
"RootPath":"../data"
|
||||||
},
|
},
|
||||||
"etcd": {
|
|
||||||
"Url": ["127.0.0.1:2379"],
|
|
||||||
"UserName": "",
|
|
||||||
"Password": "",
|
|
||||||
"DialTimeout": 60
|
|
||||||
},
|
|
||||||
"costum": {
|
"costum": {
|
||||||
"MgoRpcCliNet": "tcp",
|
"MgoRpcCliNet": "tcp",
|
||||||
"MgoRpcCliAddr": "127.0.0.1:8999",
|
"MgoRpcCliAddr": "127.0.0.1:8999",
|
||||||
|
@ -60,6 +54,11 @@
|
||||||
"RMQExchange": "win88",
|
"RMQExchange": "win88",
|
||||||
"RMQQosPrefetchCount": 2,
|
"RMQQosPrefetchCount": 2,
|
||||||
"RMQQosPrefetchSize": 0,
|
"RMQQosPrefetchSize": 0,
|
||||||
"RMQQosGlobal": true
|
"RMQQosGlobal": true,
|
||||||
|
"etcdurl": [
|
||||||
|
"127.0.0.1:2379"
|
||||||
|
],
|
||||||
|
"etcduser": "",
|
||||||
|
"etcdpwd": ""
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -5,14 +5,15 @@ import (
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/rpc"
|
"net/rpc"
|
||||||
|
"time"
|
||||||
|
|
||||||
"mongo.games.com/goserver/core"
|
"mongo.games.com/goserver/core"
|
||||||
"mongo.games.com/goserver/core/etcd"
|
|
||||||
"mongo.games.com/goserver/core/module"
|
"mongo.games.com/goserver/core/module"
|
||||||
|
|
||||||
_ "mongo.games.com/game"
|
_ "mongo.games.com/game"
|
||||||
"mongo.games.com/game/common"
|
"mongo.games.com/game/common"
|
||||||
"mongo.games.com/game/dbproxy/svc"
|
"mongo.games.com/game/dbproxy/svc"
|
||||||
|
"mongo.games.com/game/etcd"
|
||||||
"mongo.games.com/game/model"
|
"mongo.games.com/game/model"
|
||||||
"mongo.games.com/game/mq"
|
"mongo.games.com/game/mq"
|
||||||
_ "mongo.games.com/game/srvdata"
|
_ "mongo.games.com/game/srvdata"
|
||||||
|
@ -26,7 +27,7 @@ func main() {
|
||||||
core.LoadPackages("config.json")
|
core.LoadPackages("config.json")
|
||||||
// core hook
|
// core hook
|
||||||
core.RegisteHook(core.HOOK_BEFORE_START, func() error {
|
core.RegisteHook(core.HOOK_BEFORE_START, func() error {
|
||||||
etcd.Start()
|
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.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"))
|
mq.StartPublisher(common.CustomConfig.GetString("RabbitMQURL"), common.CustomConfig.GetString("RMQExchange"), true, common.CustomConfig.GetInt("RMQPublishBacklog"))
|
||||||
// 尝试初始化玩家id
|
// 尝试初始化玩家id
|
||||||
|
@ -41,6 +42,7 @@ func main() {
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
core.RegisteHook(core.HOOK_AFTER_STOP, func() error {
|
core.RegisteHook(core.HOOK_AFTER_STOP, func() error {
|
||||||
|
etcd.Close()
|
||||||
mq.StopConsumer()
|
mq.StopConsumer()
|
||||||
mq.StopPublisher()
|
mq.StopPublisher()
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -0,0 +1,247 @@
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
|
@ -0,0 +1,133 @@
|
||||||
|
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
120
etcd/register.go
|
@ -1,120 +0,0 @@
|
||||||
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)
|
|
||||||
}
|
|
|
@ -148,19 +148,18 @@
|
||||||
"profile": {
|
"profile": {
|
||||||
"SlowMS": 500
|
"SlowMS": 500
|
||||||
},
|
},
|
||||||
"etcd": {
|
|
||||||
"Url": ["127.0.0.1:2379"],
|
|
||||||
"UserName": "",
|
|
||||||
"Password": "",
|
|
||||||
"DialTimeout": 60
|
|
||||||
},
|
|
||||||
"costum": {
|
"costum": {
|
||||||
"MgoRpcCliNet": "tcp",
|
"MgoRpcCliNet": "tcp",
|
||||||
"MgoRpcCliAddr": "127.0.0.1:8999",
|
"MgoRpcCliAddr": "127.0.0.1:8999",
|
||||||
"MgoRpcCliReconnInterV": 3,
|
"MgoRpcCliReconnInterV": 3,
|
||||||
"RabbitMQURL": "amqp://win88:123456@127.0.0.1:5672/win88",
|
"RabbitMQURL": "amqp://win88:123456@127.0.0.1:5672/win88",
|
||||||
"RMQExchange": "win88",
|
"RMQExchange": "win88",
|
||||||
"RMQPublishBacklog": 1024
|
"RMQPublishBacklog": 1024,
|
||||||
|
"etcdurl": [
|
||||||
|
"127.0.0.1:2379"
|
||||||
|
],
|
||||||
|
"etcduser": "",
|
||||||
|
"etcdpwd": ""
|
||||||
},
|
},
|
||||||
"webapi": {
|
"webapi": {
|
||||||
"GameApiURL": "http://127.0.0.1:8000/api/game_srv"
|
"GameApiURL": "http://127.0.0.1:8000/api/game_srv"
|
||||||
|
|
|
@ -4,12 +4,12 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"mongo.games.com/goserver/core"
|
"mongo.games.com/goserver/core"
|
||||||
"mongo.games.com/goserver/core/etcd"
|
|
||||||
_ "mongo.games.com/goserver/core/i18n"
|
_ "mongo.games.com/goserver/core/i18n"
|
||||||
"mongo.games.com/goserver/core/module"
|
"mongo.games.com/goserver/core/module"
|
||||||
|
|
||||||
_ "mongo.games.com/game"
|
_ "mongo.games.com/game"
|
||||||
"mongo.games.com/game/common"
|
"mongo.games.com/game/common"
|
||||||
|
"mongo.games.com/game/etcd"
|
||||||
_ "mongo.games.com/game/gamesrv/action"
|
_ "mongo.games.com/game/gamesrv/action"
|
||||||
_ "mongo.games.com/game/gamesrv/base"
|
_ "mongo.games.com/game/gamesrv/base"
|
||||||
_ "mongo.games.com/game/gamesrv/transact"
|
_ "mongo.games.com/game/gamesrv/transact"
|
||||||
|
@ -45,13 +45,14 @@ func main() {
|
||||||
core.LoadPackages("config.json")
|
core.LoadPackages("config.json")
|
||||||
// core hook
|
// core hook
|
||||||
core.RegisteHook(core.HOOK_BEFORE_START, func() error {
|
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)
|
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"))
|
mq.StartPublisher(common.CustomConfig.GetString("RabbitMQURL"), common.CustomConfig.GetString("RMQExchange"), true, common.CustomConfig.GetInt("RMQPublishBacklog"))
|
||||||
model.InitGameKVData()
|
model.InitGameKVData()
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
core.RegisteHook(core.HOOK_AFTER_STOP, func() error {
|
core.RegisteHook(core.HOOK_AFTER_STOP, func() error {
|
||||||
|
etcd.Close()
|
||||||
mq.StopPublisher()
|
mq.StopPublisher()
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,13 +1,12 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"mongo.games.com/goserver/core"
|
|
||||||
"mongo.games.com/goserver/core/module"
|
|
||||||
|
|
||||||
_ "mongo.games.com/game"
|
_ "mongo.games.com/game"
|
||||||
"mongo.games.com/game/common"
|
"mongo.games.com/game/common"
|
||||||
"mongo.games.com/game/model"
|
"mongo.games.com/game/model"
|
||||||
"mongo.games.com/game/mq"
|
"mongo.games.com/game/mq"
|
||||||
|
"mongo.games.com/goserver/core"
|
||||||
|
"mongo.games.com/goserver/core/module"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
|
@ -83,12 +83,6 @@
|
||||||
"SupportAdmin": true,
|
"SupportAdmin": true,
|
||||||
"AdminHttpPort": 9899
|
"AdminHttpPort": 9899
|
||||||
},
|
},
|
||||||
"etcd": {
|
|
||||||
"Url": ["127.0.0.1:2379"],
|
|
||||||
"UserName": "",
|
|
||||||
"Password": "",
|
|
||||||
"DialTimeout": 60
|
|
||||||
},
|
|
||||||
"costum": {
|
"costum": {
|
||||||
"MgoRpcCliNet": "tcp",
|
"MgoRpcCliNet": "tcp",
|
||||||
"MgoRpcCliAddr": "127.0.0.1:8999",
|
"MgoRpcCliAddr": "127.0.0.1:8999",
|
||||||
|
|
|
@ -97,12 +97,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"etcd": {
|
|
||||||
"Url": ["127.0.0.1:2379"],
|
|
||||||
"UserName": "",
|
|
||||||
"Password": "",
|
|
||||||
"DialTimeout": 60
|
|
||||||
},
|
|
||||||
"costum": {
|
"costum": {
|
||||||
"MgoRpcCliNet": "tcp",
|
"MgoRpcCliNet": "tcp",
|
||||||
"MgoRpcCliAddr": "127.0.0.1:8999",
|
"MgoRpcCliAddr": "127.0.0.1:8999",
|
||||||
|
@ -111,6 +106,13 @@
|
||||||
"RabbitMQURL": "amqp://win88:123456@127.0.0.1:5672/win88",
|
"RabbitMQURL": "amqp://win88:123456@127.0.0.1:5672/win88",
|
||||||
"RMQExchange": "win88",
|
"RMQExchange": "win88",
|
||||||
"RMQPublishBacklog": 1024,
|
"RMQPublishBacklog": 1024,
|
||||||
|
|
||||||
|
"etcdurl":[
|
||||||
|
"127.0.0.1:2379"
|
||||||
|
],
|
||||||
|
"etcduser": "root",
|
||||||
|
"etcdpwd": "win88",
|
||||||
|
|
||||||
"GameIdFilter": []
|
"GameIdFilter": []
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -4,11 +4,11 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"mongo.games.com/goserver/core"
|
"mongo.games.com/goserver/core"
|
||||||
"mongo.games.com/goserver/core/etcd"
|
|
||||||
"mongo.games.com/goserver/core/module"
|
"mongo.games.com/goserver/core/module"
|
||||||
|
|
||||||
_ "mongo.games.com/game"
|
_ "mongo.games.com/game"
|
||||||
"mongo.games.com/game/common"
|
"mongo.games.com/game/common"
|
||||||
|
"mongo.games.com/game/etcd"
|
||||||
"mongo.games.com/game/model"
|
"mongo.games.com/game/model"
|
||||||
"mongo.games.com/game/mq"
|
"mongo.games.com/game/mq"
|
||||||
)
|
)
|
||||||
|
@ -21,12 +21,13 @@ func main() {
|
||||||
defer core.ClosePackages()
|
defer core.ClosePackages()
|
||||||
// core hook
|
// core hook
|
||||||
core.RegisteHook(core.HOOK_BEFORE_START, func() error {
|
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)
|
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.StartConsumer(common.CustomConfig.GetString("RabbitMQURL"), common.CustomConfig.GetString("RMQExchange"), true)
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
core.RegisteHook(core.HOOK_AFTER_STOP, func() error {
|
core.RegisteHook(core.HOOK_AFTER_STOP, func() error {
|
||||||
|
etcd.Close()
|
||||||
mq.StopConsumer()
|
mq.StopConsumer()
|
||||||
model.ShutdownRPClient()
|
model.ShutdownRPClient()
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -154,9 +154,7 @@ func (this *Configuration) Init() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Configuration) Close() error {
|
func (this *Configuration) Close() error {
|
||||||
if this.watcher != nil {
|
|
||||||
this.watcher.Close()
|
this.watcher.Close()
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,14 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"mongo.games.com/game/common"
|
||||||
|
"mongo.games.com/game/webapi"
|
||||||
|
|
||||||
|
"encoding/json"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"mongo.games.com/game/model"
|
||||||
|
"mongo.games.com/goserver/core/logger"
|
||||||
"mongo.games.com/goserver/core/module"
|
"mongo.games.com/goserver/core/module"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -98,6 +104,33 @@ func (this *ActMgr) Init() {
|
||||||
if this.ConfigByPlateform == nil {
|
if this.ConfigByPlateform == nil {
|
||||||
this.ConfigByPlateform = make(map[string]*ActGivePlateformConfig)
|
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() {
|
func (this *ActMgr) Update() {
|
||||||
|
|
|
@ -16,7 +16,34 @@ const (
|
||||||
BlackState_Max
|
BlackState_Max
|
||||||
)
|
)
|
||||||
|
|
||||||
var BlackListMgrSington = NewBlackListMgr()
|
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
|
||||||
|
}
|
||||||
|
|
||||||
type BlackInfoApi struct {
|
type BlackInfoApi struct {
|
||||||
Id int32
|
Id int32
|
||||||
|
@ -35,46 +62,26 @@ type BlackInfoApi struct {
|
||||||
DeviceId string //设备ID
|
DeviceId string //设备ID
|
||||||
}
|
}
|
||||||
|
|
||||||
type BlackInfo struct {
|
func (this *BlackListMgr) Init() {
|
||||||
Id int32
|
if this.BlackList == nil {
|
||||||
BlackType int //1.游戏2.兑换3.充值4.比赛
|
this.BlackList = make(map[int32]*BlackInfo)
|
||||||
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++ {
|
for i := uint(0); i < BlackState_Max; i++ {
|
||||||
ret.BlackListByPlatform[i] = make(map[string]map[int32]*BlackInfo)
|
this.BlackListByPlatform[i] = make(map[string]map[int32]*BlackInfo)
|
||||||
ret.AlipayAccByPlatform[i] = make(map[string]map[string]*BlackInfo)
|
this.AlipayAccByPlatform[i] = make(map[string]map[string]*BlackInfo)
|
||||||
ret.AlipayNameByPlatform[i] = make(map[string]map[string]*BlackInfo)
|
this.AlipayNameByPlatform[i] = make(map[string]map[string]*BlackInfo)
|
||||||
ret.BankcardByPlatform[i] = make(map[string]map[string]*BlackInfo)
|
this.BankcardByPlatform[i] = make(map[string]map[string]*BlackInfo)
|
||||||
ret.IpByPlatform[i] = make(map[string]map[string]*BlackInfo)
|
this.IpByPlatform[i] = make(map[string]map[string]*BlackInfo)
|
||||||
ret.IpNetByPlatform[i] = make(map[string][]*BlackInfo)
|
this.IpNetByPlatform[i] = make(map[string][]*BlackInfo)
|
||||||
ret.PackageTagByPlatform[i] = make(map[string]*BlackInfo)
|
this.PackageTagByPlatform[i] = make(map[string]*BlackInfo)
|
||||||
ret.DeviceByPlatform[i] = make(map[string]map[string]*BlackInfo)
|
this.DeviceByPlatform[i] = make(map[string]map[string]*BlackInfo)
|
||||||
}
|
}
|
||||||
return ret
|
if !model.GameParamData.UseEtcd {
|
||||||
|
|
||||||
|
} else {
|
||||||
|
EtcdMgrSington.InitBlackList()
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *BlackListMgr) DivBlackInfo(blackInfo *BlackInfo) {
|
func (this *BlackListMgr) DivBlackInfo(blackInfo *BlackInfo) {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"mongo.games.com/game/model"
|
||||||
webapi_proto "mongo.games.com/game/protocol/webapi"
|
webapi_proto "mongo.games.com/game/protocol/webapi"
|
||||||
"mongo.games.com/goserver/core/module"
|
"mongo.games.com/goserver/core/module"
|
||||||
"sort"
|
"sort"
|
||||||
|
@ -22,7 +23,11 @@ func (this *ChessRankMgr) ModuleName() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *ChessRankMgr) Init() {
|
func (this *ChessRankMgr) Init() {
|
||||||
|
if !model.GameParamData.UseEtcd {
|
||||||
|
// 后台说现在没有不走ETCD情况~
|
||||||
|
} else {
|
||||||
|
EtcdMgrSington.InitUpdateChessRankcfg()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *ChessRankMgr) UpdateChessRankConfig(cfg *webapi_proto.ChessRankcfgData) {
|
func (this *ChessRankMgr) UpdateChessRankConfig(cfg *webapi_proto.ChessRankcfgData) {
|
||||||
|
|
|
@ -112,13 +112,12 @@
|
||||||
"AppId": "5c56d1644966f078bfb90c71",
|
"AppId": "5c56d1644966f078bfb90c71",
|
||||||
"IsDevMode": true
|
"IsDevMode": true
|
||||||
},
|
},
|
||||||
"etcd": {
|
|
||||||
"Url": ["127.0.0.1:2379"],
|
|
||||||
"UserName": "",
|
|
||||||
"Password": "",
|
|
||||||
"DialTimeout": 60
|
|
||||||
},
|
|
||||||
"costum": {
|
"costum": {
|
||||||
|
"etcdurl": [
|
||||||
|
"127.0.0.1:2379"
|
||||||
|
],
|
||||||
|
"etcduser": "root",
|
||||||
|
"etcdpwd": "win88",
|
||||||
"MgoRpcCliNet": "tcp",
|
"MgoRpcCliNet": "tcp",
|
||||||
"MgoRpcCliAddr": "127.0.0.1:8999",
|
"MgoRpcCliAddr": "127.0.0.1:8999",
|
||||||
"MgoRpcCliReconnInterV": 3,
|
"MgoRpcCliReconnInterV": 3,
|
||||||
|
|
116
worldsrv/etcd.go
116
worldsrv/etcd.go
|
@ -2,7 +2,6 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"strconv"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"go.etcd.io/etcd/client/v3"
|
"go.etcd.io/etcd/client/v3"
|
||||||
|
@ -11,7 +10,6 @@ import (
|
||||||
"mongo.games.com/game/common"
|
"mongo.games.com/game/common"
|
||||||
"mongo.games.com/game/etcd"
|
"mongo.games.com/game/etcd"
|
||||||
hallproto "mongo.games.com/game/protocol/gamehall"
|
hallproto "mongo.games.com/game/protocol/gamehall"
|
||||||
loginproto "mongo.games.com/game/protocol/login"
|
|
||||||
playerproto "mongo.games.com/game/protocol/player"
|
playerproto "mongo.games.com/game/protocol/player"
|
||||||
"mongo.games.com/game/protocol/webapi"
|
"mongo.games.com/game/protocol/webapi"
|
||||||
)
|
)
|
||||||
|
@ -19,10 +17,10 @@ import (
|
||||||
func init() {
|
func init() {
|
||||||
// 平台配置
|
// 平台配置
|
||||||
etcd.Register(etcd.ETCDKEY_PLATFORM_PREFIX, webapi.Platform{}, platformConfigEvent)
|
etcd.Register(etcd.ETCDKEY_PLATFORM_PREFIX, webapi.Platform{}, platformConfigEvent)
|
||||||
// 超管平台游戏开关
|
|
||||||
etcd.Register(etcd.ETCDKEY_GAME_CONFIG_GLOBAL, webapi.GameConfigGlobal{}, platformConfigEvent)
|
|
||||||
// 游戏场次配置
|
// 游戏场次配置
|
||||||
etcd.Register(etcd.ETCDKEY_GAMECONFIG_PREFIX, webapi.GameFree{}, platformConfigEvent)
|
etcd.Register(etcd.ETCDKEY_GAMECONFIG_PREFIX, webapi.GameFree{}, platformConfigEvent)
|
||||||
|
// 超管平台游戏开关
|
||||||
|
etcd.Register(etcd.ETCDKEY_GAME_CONFIG_GLOBAL, webapi.GameConfigGlobal{}, platformConfigEvent)
|
||||||
// 平台包数据
|
// 平台包数据
|
||||||
etcd.Register(etcd.ETCDKEY_PACKAGE_PREFIX, webapi.AppInfo{}, platformConfigEvent)
|
etcd.Register(etcd.ETCDKEY_PACKAGE_PREFIX, webapi.AppInfo{}, platformConfigEvent)
|
||||||
// 客户端游戏入口开关
|
// 客户端游戏入口开关
|
||||||
|
@ -41,30 +39,6 @@ func init() {
|
||||||
etcd.Register(etcd.ETCDKEY_ACT_Collect, webapi.WelfareCollectConfig{}, platformConfigEvent)
|
etcd.Register(etcd.ETCDKEY_ACT_Collect, webapi.WelfareCollectConfig{}, platformConfigEvent)
|
||||||
// 渠道开关
|
// 渠道开关
|
||||||
etcd.Register(etcd.ETCDKEY_ChannelSwitch, webapi.ChannelSwitchConfig{}, 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{}) {
|
func platformConfigEvent(ctx context.Context, completeKey string, isInit bool, event *clientv3.Event, data interface{}) {
|
||||||
|
@ -170,92 +144,6 @@ 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:
|
default:
|
||||||
logger.Logger.Errorf("etcd completeKey:%s, Not processed", completeKey)
|
logger.Logger.Errorf("etcd completeKey:%s, Not processed", completeKey)
|
||||||
|
|
|
@ -0,0 +1,768 @@
|
||||||
|
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()
|
||||||
|
}
|
|
@ -5,13 +5,13 @@ import (
|
||||||
|
|
||||||
"github.com/astaxie/beego/cache"
|
"github.com/astaxie/beego/cache"
|
||||||
"mongo.games.com/goserver/core"
|
"mongo.games.com/goserver/core"
|
||||||
"mongo.games.com/goserver/core/etcd"
|
|
||||||
_ "mongo.games.com/goserver/core/i18n"
|
_ "mongo.games.com/goserver/core/i18n"
|
||||||
"mongo.games.com/goserver/core/module"
|
"mongo.games.com/goserver/core/module"
|
||||||
"mongo.games.com/goserver/core/schedule"
|
"mongo.games.com/goserver/core/schedule"
|
||||||
|
|
||||||
_ "mongo.games.com/game"
|
_ "mongo.games.com/game"
|
||||||
"mongo.games.com/game/common"
|
"mongo.games.com/game/common"
|
||||||
|
"mongo.games.com/game/etcd"
|
||||||
"mongo.games.com/game/model"
|
"mongo.games.com/game/model"
|
||||||
"mongo.games.com/game/mq"
|
"mongo.games.com/game/mq"
|
||||||
)
|
)
|
||||||
|
@ -29,8 +29,8 @@ func main() {
|
||||||
core.LoadPackages("config.json")
|
core.LoadPackages("config.json")
|
||||||
// core hook
|
// core hook
|
||||||
core.RegisteHook(core.HOOK_BEFORE_START, func() error {
|
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)
|
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.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"))
|
mq.StartPublisher(common.CustomConfig.GetString("RabbitMQURL"), common.CustomConfig.GetString("RMQExchange"), true, common.CustomConfig.GetInt("RMQPublishBacklog"))
|
||||||
|
|
||||||
|
@ -40,14 +40,19 @@ func main() {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
EtcdMgrSington.Init()
|
||||||
|
BlackListMgrSington.Init()
|
||||||
gameStateMgr.Init()
|
gameStateMgr.Init()
|
||||||
HorseRaceLampMgrSington.InitHorseRaceLamp()
|
HorseRaceLampMgrSington.InitHorseRaceLamp()
|
||||||
model.InitGameKVData()
|
model.InitGameKVData()
|
||||||
model.GetAllCoinPoolSettingData()
|
model.GetAllCoinPoolSettingData()
|
||||||
MsgMgrSington.InitMsg()
|
MsgMgrSington.InitMsg()
|
||||||
|
PlatformGameGroupMgrSington.LoadGameGroup()
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
core.RegisteHook(core.HOOK_AFTER_STOP, func() error {
|
core.RegisteHook(core.HOOK_AFTER_STOP, func() error {
|
||||||
|
EtcdMgrSington.Close()
|
||||||
|
etcd.Close()
|
||||||
mq.StopPublisher()
|
mq.StopPublisher()
|
||||||
mq.StopConsumer()
|
mq.StopConsumer()
|
||||||
model.ShutdownRPClient()
|
model.ShutdownRPClient()
|
||||||
|
|
|
@ -1,8 +1,13 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"mongo.games.com/game/common"
|
||||||
|
"mongo.games.com/game/model"
|
||||||
|
"mongo.games.com/game/proto"
|
||||||
webapi_proto "mongo.games.com/game/protocol/webapi"
|
webapi_proto "mongo.games.com/game/protocol/webapi"
|
||||||
"mongo.games.com/game/srvdata"
|
"mongo.games.com/game/srvdata"
|
||||||
|
"mongo.games.com/game/webapi"
|
||||||
|
"mongo.games.com/goserver/core/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
type PlatformGameGroupObserver interface {
|
type PlatformGameGroupObserver interface {
|
||||||
|
@ -51,6 +56,45 @@ func (this *PlatformGameGroupMgr) GetGameGroup(groupId int32) *webapi_proto.Game
|
||||||
return nil
|
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) {
|
func (this *PlatformGameGroupMgr) UpsertGameGroup(conf *webapi_proto.GameConfigGroup) {
|
||||||
if conf == nil {
|
if conf == nil {
|
||||||
return
|
return
|
||||||
|
|
|
@ -1,6 +1,11 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
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"
|
"mongo.games.com/goserver/core/module"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
@ -100,6 +105,34 @@ func (this *PromoterMgr) Init() {
|
||||||
if this.PromoterConfigMap == nil {
|
if this.PromoterConfigMap == nil {
|
||||||
this.PromoterConfigMap = make(map[string]*PromoterConfig)
|
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() {
|
func (this *PromoterMgr) Update() {
|
||||||
|
|
|
@ -16,7 +16,6 @@ import (
|
||||||
|
|
||||||
"github.com/globalsign/mgo/bson"
|
"github.com/globalsign/mgo/bson"
|
||||||
"mongo.games.com/goserver/core/basic"
|
"mongo.games.com/goserver/core/basic"
|
||||||
"mongo.games.com/goserver/core/etcd"
|
|
||||||
"mongo.games.com/goserver/core/logger"
|
"mongo.games.com/goserver/core/logger"
|
||||||
"mongo.games.com/goserver/core/netlib"
|
"mongo.games.com/goserver/core/netlib"
|
||||||
"mongo.games.com/goserver/core/task"
|
"mongo.games.com/goserver/core/task"
|
||||||
|
@ -3806,7 +3805,7 @@ func init() {
|
||||||
pack.Msg = "数据序列化失败" + err.Error()
|
pack.Msg = "数据序列化失败" + err.Error()
|
||||||
return common.ResponseTag_ParamError, pack
|
return common.ResponseTag_ParamError, pack
|
||||||
}
|
}
|
||||||
etcd.Restart()
|
EtcdMgrSington.Reset()
|
||||||
pack.Tag = webapiproto.TagCode_SUCCESS
|
pack.Tag = webapiproto.TagCode_SUCCESS
|
||||||
pack.Msg = "Etcd Reset success"
|
pack.Msg = "Etcd Reset success"
|
||||||
return common.ResponseTag_Ok, nil
|
return common.ResponseTag_Ok, nil
|
||||||
|
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"mongo.games.com/goserver/core/logger"
|
"mongo.games.com/goserver/core/logger"
|
||||||
|
|
||||||
"mongo.games.com/game/common"
|
"mongo.games.com/game/common"
|
||||||
|
"mongo.games.com/game/model"
|
||||||
webapi_proto "mongo.games.com/game/protocol/webapi"
|
webapi_proto "mongo.games.com/game/protocol/webapi"
|
||||||
"mongo.games.com/goserver/core/module"
|
"mongo.games.com/goserver/core/module"
|
||||||
)
|
)
|
||||||
|
@ -28,7 +29,12 @@ func (this *VipMgr) ModuleName() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *VipMgr) Init() {
|
func (this *VipMgr) Init() {
|
||||||
|
if !model.GameParamData.UseEtcd {
|
||||||
|
// 后台说现在没有不走ETCD情况~
|
||||||
|
} else {
|
||||||
|
|
||||||
|
EtcdMgrSington.InitUpdateVIPcfg()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *VipMgr) UpdateVIPcfg(cfg *webapi_proto.VIPcfgDataList) {
|
func (this *VipMgr) UpdateVIPcfg(cfg *webapi_proto.VIPcfgDataList) {
|
||||||
|
|
|
@ -31,7 +31,12 @@ type WelfareMgr struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *WelfareMgr) Init() {
|
func (this *WelfareMgr) Init() {
|
||||||
|
EtcdMgrSington.InitSign7()
|
||||||
|
EtcdMgrSington.InitTurnplate()
|
||||||
|
EtcdMgrSington.InitBlindBox()
|
||||||
|
EtcdMgrSington.InitFirstPay()
|
||||||
|
EtcdMgrSington.InitContinuousPay()
|
||||||
|
EtcdMgrSington.InitPhoneLottery()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *WelfareMgr) ModuleName() string {
|
func (this *WelfareMgr) ModuleName() string {
|
||||||
|
|
Loading…
Reference in New Issue