game_sync/worldsrv/etcd.go

152 lines
5.5 KiB
Go

package main
import (
"context"
"strings"
"go.etcd.io/etcd/client/v3"
"mongo.games.com/goserver/core/logger"
"mongo.games.com/game/common"
"mongo.games.com/game/etcd"
hallproto "mongo.games.com/game/protocol/gamehall"
playerproto "mongo.games.com/game/protocol/player"
"mongo.games.com/game/protocol/webapi"
)
func init() {
// 平台配置
etcd.Register(etcd.ETCDKEY_PLATFORM_PREFIX, webapi.Platform{}, 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_ENTRYSWITCH, webapi.EntrySwitch{}, platformConfigEvent)
// 公告
etcd.Register(etcd.ETCDKEY_GAME_NOTICE, webapi.CommonNoticeList{}, platformConfigEvent)
// 比赛配置
etcd.Register(etcd.ETCDKEY_GAME_MATCH, webapi.GameMatchDateList{}, platformConfigEvent)
// 个人水池配置
etcd.Register(etcd.ETCDKEY_PLAYERPOOL, webapi.PlayerPool{}, platformConfigEvent)
// 商品兑换
etcd.Register(etcd.ETCDKEY_SHOP_EXCHANGE, webapi.ExchangeShopList{}, platformConfigEvent)
// 商城商品
etcd.Register(etcd.ETCDKEY_SHOP_ITEM, webapi.ItemShopList{}, platformConfigEvent)
// 集卡活动
etcd.Register(etcd.ETCDKEY_ACT_Collect, webapi.WelfareCollectConfig{}, platformConfigEvent)
// 渠道开关
etcd.Register(etcd.ETCDKEY_ChannelSwitch, webapi.ChannelSwitchConfig{}, platformConfigEvent)
}
func platformConfigEvent(ctx context.Context, completeKey string, isInit bool, event *clientv3.Event, data interface{}) {
if event.Type == clientv3.EventTypeDelete {
return
}
if data == nil {
return
}
switch config := data.(type) {
case *webapi.WelfareCollectConfig:
WelfareMgrSington.UpdateCollectConfig(config)
case *webapi.ItemShopList:
ShopMgrSington.UpdateItemShop(config)
case *webapi.ExchangeShopList:
ShopMgrSington.UpExShop(config)
case *webapi.PlayerPool:
PlatformMgrSingleton.GetConfig(config.Platform).PlayerPool = config
case *webapi.EntrySwitch:
PlatformMgrSingleton.GetConfig(config.Platform).EntrySwitch = config
PlatformMgrSingleton.ChangeEntrySwitch(config.Platform, config)
case *webapi.CommonNoticeList:
PlatformMgrSingleton.GetConfig(config.Platform).CommonNotices = config
if !isInit {
// 通知公共变更
for _, v := range PlayerMgrSington.playerOfPlatform[config.Platform] {
if v != nil && v.IsOnLine() {
v.SendToClient(int(hallproto.GameHallPacketID_PACKET_SC_NoticeChange), &hallproto.SCNoticeChange{})
}
}
}
case *webapi.GameConfigGlobal:
if isInit {
for _, v := range config.GetGameStatus() {
gameId := v.GetGameId()
status := v.GetStatus()
PlatformMgrSingleton.GetGlobalConfig().GameStatus[gameId] = status
}
} else {
cfgs := make([]*hallproto.GameConfig1, 0)
for _, v := range config.GetGameStatus() {
gameId := v.GetGameId() // gamefreeid
status := v.GetStatus()
if PlatformMgrSingleton.GetGlobalConfig().GameStatus[gameId] != status {
cfgs = append(cfgs, &hallproto.GameConfig1{
LogicId: gameId,
Status: status,
})
}
PlatformMgrSingleton.GetGlobalConfig().GameStatus[gameId] = status
}
PlatformMgrSingleton.ChangeGameStatus(cfgs)
}
case *webapi.Platform:
if isInit {
PlatformMgrSingleton.CreateDefaultPlatform()
}
PlatformMgrSingleton.UpsertPlatform(config.PlatformName, config.Isolated, config.Disabled, config.Id,
config.CustomService, config.BindOption, config.ServiceFlag, config.UpgradeAccountGiveCoin,
config.NewAccountGiveCoin, config.PerBankNoLimitAccount, config.ExchangeMin, config.ExchangeLimit,
config.ExchangeTax, config.ExchangeFlow, config.ExchangeFlag, config.SpreadConfig, config.VipRange, "",
nil, config.VerifyCodeType, nil /*config.ThirdGameMerchant,*/, config.CustomType,
false, config.NeedSameName, config.ExchangeForceTax, config.ExchangeGiveFlow, config.ExchangeVer,
config.ExchangeBankMax, config.ExchangeAlipayMax, 0, config.PerBankNoLimitName, config.IsCanUserBindPromoter,
config.UserBindPromoterPrize, false, config.ExchangeMultiple, false, config.MerchantKey,
config.BindTelReward)
case *webapi.GameFree:
var err error
s := strings.TrimPrefix(completeKey, etcd.ETCDKEY_GAMECONFIG_PREFIX)
arr := strings.Split(s, "/")
if len(arr) > 1 {
pltId := arr[0]
if err == nil {
PlatformMgrSingleton.UpsertGameFree(pltId, config)
}
}
case *webapi.AppInfo:
if config.PlatformId == 0 {
config.PlatformId = int32(DefaultPlatformInt)
}
PlatformMgrSingleton.GetGlobalConfig().PackageList[config.PackageName] = config
PlatformMgrSingleton.GetGlobalConfig().PackageList[config.BundleId] = config
case *webapi.GameMatchDateList:
if isInit {
TournamentMgr.UpdateData(true, config)
} else {
TournamentMgr.UpdateData(false, config)
}
case *webapi.ChannelSwitchConfig:
PlatformMgrSingleton.GetConfig(config.Platform).ChannelSwitch[config.GetTp()] = config
if !isInit {
switch config.GetTp() {
case common.ChannelSwitchExchange:
// 通知变更
for _, v := range PlayerMgrSington.playerOfPlatform[config.Platform] {
if v != nil && v.IsOnLine() {
v.SendToClient(int(playerproto.PlayerPacketID_PACKET_SCExchangeChannel), &playerproto.SCExchangeChannel{
OnChannelName: config.OnChannelName,
})
}
}
}
}
default:
logger.Logger.Errorf("etcd completeKey:%s, Not processed", completeKey)
}
}