diff --git a/common/constant.go b/common/constant.go index 8e66d95..f5b3613 100644 --- a/common/constant.go +++ b/common/constant.go @@ -853,3 +853,9 @@ const ( On = 1 // 开启 Off = 2 // 关闭 ) + +const ( + DataConfigAll = 0 // 全部配置 + DataConfigSprite = 1 // 精灵配置 + DataConfigMatchAudience = 2 // 赛事观战开关 +) diff --git a/model/config.go b/model/config.go index cce71af..f3336f8 100644 --- a/model/config.go +++ b/model/config.go @@ -135,7 +135,7 @@ type AllConfig struct { *webapi.AwardLogConfig // 新手引导配置 *webapi.GuideConfig - MatchAudience map[int32]*webapi.MatchAudience // 比赛观众列表 + MatchAudience map[int32]*webapi.MatchAudience // 比赛观众列表 key: 玩家id // 小精灵配置 *webapi.SpiritConfig } diff --git a/protocol/player/player.pb.go b/protocol/player/player.pb.go index d6670e6..ada7556 100644 --- a/protocol/player/player.pb.go +++ b/protocol/player/player.pb.go @@ -10903,7 +10903,7 @@ type Config struct { // Tp 类型: // 1:小精灵快捷入口 On开关 Value地址 - // 2: ... + // 2:比赛观战开关 On开关 // ... Tp int32 `protobuf:"varint,1,opt,name=Tp,proto3" json:"Tp,omitempty"` On bool `protobuf:"varint,2,opt,name=On,proto3" json:"On,omitempty"` diff --git a/protocol/player/player.proto b/protocol/player/player.proto index 4b45515..d336347 100644 --- a/protocol/player/player.proto +++ b/protocol/player/player.proto @@ -1351,7 +1351,7 @@ message SCGuideConfig{ message Config{ // Tp 类型: // 1:小精灵快捷入口 On开关 Value地址 - // 2: ... + // 2:比赛观战开关 On开关 // ... int32 Tp = 1; bool On = 2; diff --git a/public b/public index 5436469..e754bb1 160000 --- a/public +++ b/public @@ -1 +1 @@ -Subproject commit 5436469c04056f83ab69b52b7cdeb5d21832fa94 +Subproject commit e754bb123f44b0f524ec9dd6d67a1e9d2803a7c5 diff --git a/worldsrv/etcd.go b/worldsrv/etcd.go index a3bf947..ba725f7 100644 --- a/worldsrv/etcd.go +++ b/worldsrv/etcd.go @@ -323,15 +323,7 @@ func platformConfigEvent(ctx context.Context, completeKey string, isInit bool, e case *webapi.SpiritConfig: PlatformMgrSingleton.GetConfig(config.Platform).SpiritConfig = config if !isInit { - PlayerMgrSington.BroadcastMessageToPlatform(config.Platform, int(playerproto.PlayerPacketID_PACKET_SCDataConfig), &playerproto.SCDataConfig{ - Cfg: []*playerproto.Config{ - { - Tp: 1, - On: config.GetOn() == 1, - Value: config.GetUrl(), - }, - }, - }) + PlayerMgrSington.BroadcastDataConfigToPlatform(config.Platform, common.DataConfigSprite) } default: logger.Logger.Errorf("etcd completeKey:%s, Not processed", completeKey) @@ -404,8 +396,20 @@ func handlerEvent(ctx context.Context, completeKey string, isInit bool, event *c switch event.Type { case clientv3.EventTypePut: PlatformMgrSingleton.AddMatchAudience(config) + if !isInit { + p := PlayerMgrSington.GetPlayerBySnId(config.GetSnId()) + if p != nil { + p.SCDataConfig(common.DataConfigMatchAudience) + } + } case clientv3.EventTypeDelete: PlatformMgrSingleton.DelMatchAudience(config) + if !isInit { + p := PlayerMgrSington.GetPlayerBySnId(config.GetSnId()) + if p != nil { + p.SCDataConfig(common.DataConfigMatchAudience) + } + } } default: diff --git a/worldsrv/player.go b/worldsrv/player.go index b7959ed..b02c455 100644 --- a/worldsrv/player.go +++ b/worldsrv/player.go @@ -3101,8 +3101,8 @@ func (this *Player) SendPlayerInfo() { this.SCItems() // 引导配置 this.SCGuide() - // 小精灵配置 - this.SCSpirit() + // 其它配置 + this.SCDataConfig(common.DataConfigAll) } //func (this *Player) SendJackpotInfo() { @@ -4951,20 +4951,66 @@ func (this *Player) SCGuide() { logger.Logger.Tracef("SCGuideConfig: %v", pack) } -func (this *Player) SCSpirit() { - cfg := PlatformMgrSingleton.GetConfig(this.Platform).SpiritConfig - if cfg == nil { +// DataConfigFuncMap 配置查询方法 +var DataConfigFuncMap = map[int]func(platform string, p *Player) *playerproto.Config{ + common.DataConfigSprite: func(platform string, p *Player) *playerproto.Config { + cfg := PlatformMgrSingleton.GetConfig(platform).SpiritConfig + if cfg == nil { + return nil + } + return &playerproto.Config{ + Tp: common.DataConfigSprite, + On: cfg.On == 1, + Value: cfg.Url, + } + }, + common.DataConfigMatchAudience: func(platform string, p *Player) *playerproto.Config { + if p == nil { + return nil + } + cfg := PlatformMgrSingleton.GetConfig(platform).MatchAudience + if cfg == nil { + return nil + } + d, ok := cfg[p.GetSnId()] + if !ok || d == nil { + return &playerproto.Config{ + Tp: common.DataConfigMatchAudience, + On: false, + } + } + return &playerproto.Config{ + Tp: common.DataConfigMatchAudience, + On: true, + } + }, +} + +// SCDataConfig 通知配置 +// tp 类型 0所有 1小精灵 2比赛观众开关 +func (this *Player) SCDataConfig(tp int) { + if this == nil { return } - pack := &playerproto.SCDataConfig{ - Cfg: []*playerproto.Config{ - { - Tp: 1, - On: cfg.On == 1, - Value: cfg.Url, - }, - }, + pack := &playerproto.SCDataConfig{} + if tp == common.DataConfigAll { + for _, f := range DataConfigFuncMap { + d := f(this.Platform, this) + if d != nil { + pack.Cfg = append(pack.Cfg, d) + } + } + } else { + f, ok := DataConfigFuncMap[tp] + if ok { + d := f(this.Platform, this) + if d != nil { + pack.Cfg = append(pack.Cfg, d) + } + } + } + if len(pack.Cfg) > 0 { + this.SendToClient(int(playerproto.PlayerPacketID_PACKET_SCDataConfig), pack) + logger.Logger.Tracef("SCDataConfig: %v", pack) } - this.SendToClient(int(playerproto.PlayerPacketID_PACKET_SCDataConfig), pack) - logger.Logger.Tracef("SCDataConfig: %v", pack) } diff --git a/worldsrv/playermgr.go b/worldsrv/playermgr.go index 7d76256..9ee00c9 100644 --- a/worldsrv/playermgr.go +++ b/worldsrv/playermgr.go @@ -15,6 +15,7 @@ import ( "mongo.games.com/game/common" "mongo.games.com/game/model" "mongo.games.com/game/proto" + playerproto "mongo.games.com/game/protocol/player" serverproto "mongo.games.com/game/protocol/server" "mongo.games.com/game/worldsrv/internal" ) @@ -328,6 +329,21 @@ func (this *PlayerMgr) BroadcastMessageToPlatform(platform string, packetid int, } } +func (this *PlayerMgr) BroadcastDataConfigToPlatform(platform string, tp int) { + packetId := int(playerproto.PlayerPacketID_PACKET_SCDataConfig) + pack := &playerproto.SCDataConfig{} + f, ok := DataConfigFuncMap[tp] + if ok { + d := f(platform, nil) + if d != nil { + pack.Cfg = append(pack.Cfg, d) + } + } + if len(pack.Cfg) > 0 { + this.BroadcastMessageToPlatform(platform, packetId, pack) + } +} + func (this *PlayerMgr) BroadcastMessageToPlatformByFunc(platform string, packetid int, rawpack interface{}, f func(p *Player) bool) { if platform == "" { this.BroadcastMessage(packetid, rawpack)