From f04c7e543d00daec3799d7c1cbc0c89101815c2f Mon Sep 17 00:00:00 2001 From: sin365 <353374337@qq.com> Date: Thu, 2 Jan 2025 15:28:29 +0800 Subject: [PATCH] =?UTF-8?q?=E6=88=BF=E4=B8=BB=E7=A6=BB=E7=BA=BF,=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E9=80=89=E6=8B=A9=E5=BB=B6=E8=BF=9F=E6=9C=80=E4=BD=8E?= =?UTF-8?q?=E5=8F=A6=E4=B8=80=E5=90=8D=E7=8E=A9=E5=AE=B6=E5=81=9A=E6=88=BF?= =?UTF-8?q?=E4=B8=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AxibugEmuOnline.Server/Manager/RoomManager.cs | 34 ++++++++++++++++--- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/AxibugEmuOnline.Server/Manager/RoomManager.cs b/AxibugEmuOnline.Server/Manager/RoomManager.cs index a648cfc8..e0993fd1 100644 --- a/AxibugEmuOnline.Server/Manager/RoomManager.cs +++ b/AxibugEmuOnline.Server/Manager/RoomManager.cs @@ -707,13 +707,13 @@ namespace AxibugEmuOnline.Server } } - public Dictionary GetSlotDataByUID(long uid) + public bool GetSlotDataByUID(long uid, out Dictionary slotIdx2JoyIdx) { - Dictionary slotIdx2JoyIdx = new Dictionary(); + slotIdx2JoyIdx = new Dictionary(); var dataarr = PlayerSlot.Where(w => w.UID == uid).ToArray(); foreach (var slot in dataarr) slotIdx2JoyIdx[slot.SlotIdx] = slot.LocalJoyIdx; - return slotIdx2JoyIdx; + return slotIdx2JoyIdx.Count > 0; } /// /// 按照SlotIdx设置Input @@ -832,7 +832,7 @@ namespace AxibugEmuOnline.Server public void SetPlayerSlotData(ClientInfo _c, ref readonly Dictionary newSlotIdx2JoyIdx) { - Dictionary oldSlotIdx2JoyIdx = GetSlotDataByUID(_c.UID); + GetSlotDataByUID(_c.UID, out Dictionary oldSlotIdx2JoyIdx); HashSet diffSlotIdxs = ObjectPoolAuto.AcquireSet();// new HashSet(); foreach (var old in oldSlotIdx2JoyIdx) { @@ -1132,6 +1132,32 @@ namespace AxibugEmuOnline.Server } break; } + + + + //房主离线,自动选择延迟最低另一名玩家做房主 + if (!GetSlotDataByUID(this.HostUID, out Dictionary slotIdx2JoyIdx)) + { + List userlist = ObjectPoolAuto.AcquireList(); + GetAllPlayerClientList(ref userlist); + if (userlist.Count > 0) + { + ClientInfo? client = userlist.OrderBy(w => w.AveNetDelay).FirstOrDefault(); + this.HostUID = client.UID; + AppSrv.g_Log.DebugCmd($"更换房主为{this.HostUID}"); + bChanged = true; + } + ObjectPoolAuto.Release(userlist); + } + + if (this.GameState > RoomGameState.OnlyHost && newPlayerCount == 1) + { + this.GameState = RoomGameState.OnlyHost; + AppSrv.g_Log.DebugCmd("回到OnlyHost状态"); + bChanged = true; + } + + return bChanged; }