From 33eab3f5bc517de0fdb12ab8308f2f491a5bf800 Mon Sep 17 00:00:00 2001 From: sk <123456@qq.com> Date: Thu, 29 Aug 2024 16:30:08 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AB=9E=E6=8A=80=E9=A6=86=E6=88=BF=E9=97=B4?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E5=8F=98=E6=9B=B4=E9=80=9A=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/constant.go | 15 +++++++ worldsrv/action_game.go | 2 + worldsrv/cachedata.go | 2 + worldsrv/horseracelamp.go | 2 +- worldsrv/playermgr.go | 21 +++++----- worldsrv/playernotify.go | 79 +++++++++++++++++++++++++++++++++++++ worldsrv/scene.go | 45 +++++++++++++++++++++ worldsrv/scenepolicydata.go | 12 ++++-- 8 files changed, 163 insertions(+), 15 deletions(-) create mode 100644 worldsrv/playernotify.go diff --git a/common/constant.go b/common/constant.go index 625d141..77c7b8d 100644 --- a/common/constant.go +++ b/common/constant.go @@ -887,3 +887,18 @@ const ( // GameHistoryModel . GameHistoryModel ) + +type ListOpType int // 列表操作类型 + +const ( + ListModify ListOpType = 1 // 修改 + ListAdd ListOpType = 2 // 增加 + ListDel ListOpType = 3 // 减少 + ListFind ListOpType = 4 // 查询 +) + +type NotifyType int // 通知类型 + +const ( + NotifyPrivateRoomList NotifyType = 1 // 私人房间列表 +) diff --git a/worldsrv/action_game.go b/worldsrv/action_game.go index ee8f584..d53bca5 100644 --- a/worldsrv/action_game.go +++ b/worldsrv/action_game.go @@ -1410,6 +1410,8 @@ func CSTouchTypeHandler(s *netlib.Session, packetId int, data interface{}, sid i return nil } + PlayerNotifySingle.AddTime(p.SnId, common.NotifyPrivateRoomList, time.Second*15) + return nil } diff --git a/worldsrv/cachedata.go b/worldsrv/cachedata.go index 76ab4b5..dd13cdb 100644 --- a/worldsrv/cachedata.go +++ b/worldsrv/cachedata.go @@ -113,6 +113,7 @@ func (this *CacheDataManager) CacheBillNumber(billNo int, platform string) { key := fmt.Sprintf("BillNo-%v-%v", billNo, platform) this.addCacheData(AfterHour, key, key) } + func (this *CacheDataManager) CacheBillCheck(billNo int, platform string) bool { key := fmt.Sprintf("BillNo-%v-%v", billNo, platform) if _, ok := this.HourCache.Load(key); ok { @@ -121,6 +122,7 @@ func (this *CacheDataManager) CacheBillCheck(billNo int, platform string) bool { return false } } + func (this *CacheDataManager) ClearCacheBill(billNo int, platform string) { key := fmt.Sprintf("BillNo-%v-%v", billNo, platform) this.HourCache.Delete(key) diff --git a/worldsrv/horseracelamp.go b/worldsrv/horseracelamp.go index 85a23e2..bdef8f5 100644 --- a/worldsrv/horseracelamp.go +++ b/worldsrv/horseracelamp.go @@ -400,7 +400,7 @@ func (this *HorseRaceLampMgr) BroadcastHorseRaceLampMsg(horseRaceLamp *HorseRace if len(horseRaceLamp.Target) == 0 { PlayerMgrSington.BroadcastMessageToPlatform(horseRaceLamp.Platform, int(message.MSGPacketID_PACKET_SC_NOTICE), rawpack) } else { - PlayerMgrSington.BroadcastMessageToTarget(horseRaceLamp.Platform, horseRaceLamp.Target, int(message.MSGPacketID_PACKET_SC_NOTICE), rawpack) + PlayerMgrSington.BroadcastMessageToTarget(horseRaceLamp.Target, int(message.MSGPacketID_PACKET_SC_NOTICE), rawpack) } } diff --git a/worldsrv/playermgr.go b/worldsrv/playermgr.go index 9ee00c9..73a1678 100644 --- a/worldsrv/playermgr.go +++ b/worldsrv/playermgr.go @@ -426,20 +426,19 @@ func (this *PlayerMgr) BroadcastMessageToGroup(packetid int, rawpack interface{} } // BroadcastMessageToTarget 给某些玩家发消息 -func (this *PlayerMgr) BroadcastMessageToTarget(platform string, target []int32, packetid int, rawpack interface{}) { - players := this.playerOfPlatform[platform] +func (this *PlayerMgr) BroadcastMessageToTarget(target []int32, packetid int, rawpack interface{}) { mgs := make(map[*netlib.Session][]*srvproto.MCSessionUnion) - for _, p := range players { - if p != nil && p.gateSess != nil && p.IsOnLine() /*&& p.Platform == platform*/ { - if common.InSliceInt32(target, p.SnId) { - mgs[p.gateSess] = append(mgs[p.gateSess], &srvproto.MCSessionUnion{ - Mccs: &srvproto.MCClientSession{ - SId: proto.Int64(p.sid), - }, - }) - } + for _, v := range target { + d := this.snidMap[v] + if d != nil && d.gateSess != nil && d.IsOnLine() { + mgs[d.gateSess] = append(mgs[d.gateSess], &srvproto.MCSessionUnion{ + Mccs: &srvproto.MCClientSession{ + SId: proto.Int64(d.sid), + }, + }) } } + for gateSess, v := range mgs { if gateSess != nil && len(v) != 0 { pack, err := common.CreateMulticastPacket(packetid, rawpack, v...) diff --git a/worldsrv/playernotify.go b/worldsrv/playernotify.go new file mode 100644 index 0000000..64db7bf --- /dev/null +++ b/worldsrv/playernotify.go @@ -0,0 +1,79 @@ +package main + +import ( + "time" + + "mongo.games.com/game/common" +) + +func init() { + ClockMgrSington.RegisteSinker(PlayerNotifySingle) +} + +var PlayerNotifySingle = &PlayerNotify{ + players: make(map[int32]map[int32]*PlayerNotifyInfo), +} + +type PlayerNotifyInfo struct { + SnId int32 // 玩家id + Ts int64 // 失效时间戳 +} + +type PlayerNotify struct { + BaseClockSinker + players map[int32]map[int32]*PlayerNotifyInfo // 消息类型:玩家id:玩家信息 +} + +func (p *PlayerNotify) InterestClockEvent() int { + return 1 << CLOCK_EVENT_MINUTE +} + +func (p *PlayerNotify) OnMiniTimer() { + now := time.Now() + for _, v := range p.players { + var ids []int32 + for k, vv := range v { + if vv == nil || vv.Ts <= now.Unix() { + ids = append(ids, k) + } + } + for _, id := range ids { + delete(v, id) + } + } +} + +// AddTime 延长某个类型消息的通知时间 +// snid 玩家id +// tp 消息类型 +// d 延长时间 +func (p *PlayerNotify) AddTime(snid int32, tp common.NotifyType, d time.Duration) { + if _, ok := p.players[int32(tp)]; !ok { + p.players[int32(tp)] = make(map[int32]*PlayerNotifyInfo) + } + p.players[int32(tp)][snid] = &PlayerNotifyInfo{ + SnId: snid, + Ts: time.Now().Add(d).Unix(), + } +} + +// GetPlayers 获取某个类型消息的玩家id +// tp 消息类型 +func (p *PlayerNotify) GetPlayers(tp common.NotifyType) []int32 { + now := time.Now() + var ret []int32 + for k, v := range p.players[int32(tp)] { + if v == nil || v.Ts <= now.Unix() { + continue + } + ret = append(ret, k) + } + return ret +} + +// SendToClient 发送消息给客户端 +// tp 消息类型 +func (p *PlayerNotify) SendToClient(tp common.NotifyType, packetId int, pack interface{}) { + ids := p.GetPlayers(tp) + PlayerMgrSington.BroadcastMessageToTarget(ids, packetId, pack) +} diff --git a/worldsrv/scene.go b/worldsrv/scene.go index fd9f401..bd5e0eb 100644 --- a/worldsrv/scene.go +++ b/worldsrv/scene.go @@ -15,6 +15,7 @@ import ( "mongo.games.com/game/gamerule/tienlen" "mongo.games.com/game/model" "mongo.games.com/game/proto" + "mongo.games.com/game/protocol/gamehall" hallproto "mongo.games.com/game/protocol/gamehall" serverproto "mongo.games.com/game/protocol/server" "mongo.games.com/game/srvdata" @@ -923,3 +924,47 @@ func (this *Scene) CanAudience() bool { return true } } + +func (this *Scene) ProtoPrivateRoom() *gamehall.PrivateRoomInfo { + if !this.IsCustom() { + return nil + } + needPassword := int32(0) + if this.GetPassword() != "" { + needPassword = int32(1) + } + ret := &gamehall.PrivateRoomInfo{ + GameFreeId: this.dbGameFree.GetId(), + GameId: int32(this.gameId), + RoomTypeId: this.RoomTypeId, + RoomConfigId: this.RoomConfigId, + RoomId: int32(this.sceneId), + NeedPassword: needPassword, + CurrRound: this.currRound, + MaxRound: this.totalRound, + CurrNum: int32(this.GetPlayerCnt()), + MaxPlayer: int32(this.playerNum), + CreateTs: this.createTime.Unix(), + State: this.SceneState, + } + for _, v := range this.players { + ret.Players = append(ret.Players, &gamehall.PrivatePlayerInfo{ + SnId: v.SnId, + Name: v.Name, + UseRoleId: v.GetRoleId(), + }) + } + return ret +} + +// NotifyPrivateRoom 通知私人房列表变更 +func (this *Scene) NotifyPrivateRoom(tp common.ListOpType) { + if this.IsCustom() { + pack := &gamehall.SCGetPrivateRoomList{ + Tp: int32(tp), + Datas: []*gamehall.PrivateRoomInfo{this.ProtoPrivateRoom()}, + } + PlayerNotifySingle.SendToClient(common.NotifyPrivateRoomList, int(gamehall.GameHallPacketID_PACKET_SC_GETPRIVATEROOMLIST), pack) + logger.Logger.Tracef("NotifyPrivateRoom: %v", pack) + } +} diff --git a/worldsrv/scenepolicydata.go b/worldsrv/scenepolicydata.go index 75f4cc6..015e7b0 100644 --- a/worldsrv/scenepolicydata.go +++ b/worldsrv/scenepolicydata.go @@ -22,10 +22,13 @@ func (spd *ScenePolicyData) Init() bool { return true } -func (spd *ScenePolicyData) OnStart(s *Scene) {} +func (spd *ScenePolicyData) OnStart(s *Scene) { + s.NotifyPrivateRoom(common.ListAdd) +} // 场景关闭事件 func (spd *ScenePolicyData) OnStop(s *Scene) { + s.NotifyPrivateRoom(common.ListDel) } // 场景心跳事件 @@ -35,12 +38,12 @@ func (spd *ScenePolicyData) OnTick(s *Scene) { // 玩家进入事件 func (spd *ScenePolicyData) OnPlayerEnter(s *Scene, p *Player) { - + s.NotifyPrivateRoom(common.ListModify) } // 玩家离开事件 func (spd *ScenePolicyData) OnPlayerLeave(s *Scene, p *Player) { - + s.NotifyPrivateRoom(common.ListModify) } // 系统维护关闭事件 @@ -52,8 +55,10 @@ func (spd *ScenePolicyData) OnSceneState(s *Scene, state int) { s.SceneState = int32(state) switch state { case common.SceneStateWaite: + s.NotifyPrivateRoom(common.ListModify) case common.SceneStateStart: + s.NotifyPrivateRoom(common.ListModify) if s.IsCustom() { for _, v := range s.players { spd.CostPayment(s, v) @@ -61,6 +66,7 @@ func (spd *ScenePolicyData) OnSceneState(s *Scene, state int) { } case common.SceneStateEnd: + s.NotifyPrivateRoom(common.ListModify) } }