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; }