From 8444db2e85cc5ae74b0d09ccbf82739f0886dd58 Mon Sep 17 00:00:00 2001 From: sk <123456@qq.com> Date: Tue, 5 Nov 2024 17:06:02 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=88=BF=E9=97=B4=E6=8E=A8?= =?UTF-8?q?=E8=8D=90=E7=AE=97=E6=B3=95=E6=AF=8F=E6=AC=A1=E6=8E=A8=E8=8D=90?= =?UTF-8?q?=E4=B8=8D=E5=90=8C=E6=88=BF=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- worldsrv/scenemgr.go | 45 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/worldsrv/scenemgr.go b/worldsrv/scenemgr.go index 18003f6..7ca93a1 100644 --- a/worldsrv/scenemgr.go +++ b/worldsrv/scenemgr.go @@ -26,6 +26,7 @@ var SceneMgrSingleton = &SceneMgr{ coinSceneAutoId: common.CoinSceneStartId, hundredSceneAutoId: common.HundredSceneStartId, password: make(map[string]struct{}), + pushList: make(map[int]struct{}), } // SceneMgr 房间管理器 @@ -38,6 +39,8 @@ type SceneMgr struct { coinSceneAutoId int // 金币场房间号 hundredSceneAutoId int // 百人场房间号 password map[string]struct{} // 密码 + pushList map[int]struct{} // 已经推荐过的房间列表 + lastPushSceneId int // 最后推荐的房间id } // AllocReplayCode 获取回访码 @@ -422,7 +425,49 @@ func (m *SceneMgr) FindCustomInviteRoom(p *Player) *Scene { return ret[i].createTime.Unix() < ret[j].createTime.Unix() }) + // 删除没有的房间 + var list []*Scene + var pushList = map[int]struct{}{} + for k := range m.pushList { + var has bool + for _, v := range ret { + if v.sceneId == k { + has = true + break + } + } + if has { + pushList[k] = struct{}{} + } + } + m.pushList = pushList + + // 删除推荐过的房间 + for _, v := range ret { + if _, ok := m.pushList[v.sceneId]; !ok { + list = append(list, v) + } + } + + if len(list) > 0 { + m.pushList[list[0].sceneId] = struct{}{} + return list[0] + } + if len(ret) > 0 { + // 全都推荐过了,循环推荐房间 + var b bool + for _, v := range ret { + if b { + m.lastPushSceneId = v.sceneId + return v + } + if v.sceneId == m.lastPushSceneId { + b = true + } + } + // 没找到,从头开始 + m.lastPushSceneId = ret[0].sceneId return ret[0] }