diff --git a/Library/Common/Architecture/RoomList.cs b/Library/Common/Architecture/RoomList.cs index 64bca48..b1408bc 100644 --- a/Library/Common/Architecture/RoomList.cs +++ b/Library/Common/Architecture/RoomList.cs @@ -1,4 +1,5 @@ using System.Collections; +using System.Numerics; using Milimoe.FunGame.Core.Entity; using Milimoe.FunGame.Core.Library.Constant; @@ -7,6 +8,7 @@ namespace Milimoe.FunGame.Core.Library.Common.Architecture public class RoomList : IEnumerable { private readonly Hashtable _List = new(); + private readonly Hashtable _PlayerList = new(); public int Count => _List.Count; @@ -24,24 +26,44 @@ namespace Milimoe.FunGame.Core.Library.Common.Architecture public void Clear() { _List.Clear(); + _PlayerList.Clear(); } public void AddRoom(Room Room) { _List.Add(Room.Roomid, Room); + _PlayerList.Add(Room.Roomid, new List()); } public void AddRooms(List Rooms) { foreach (Room Room in Rooms) { - _List.Add(Room.Roomid, Room); + AddRoom(Room); } } + public void RemoveRoom(string RoomID) + { + _List.Remove(RoomID); + _PlayerList.Remove(RoomID); + } + public void RemoveRoom(Room Room) { - _List.Remove(Room.Roomid); + RemoveRoom(Room.Roomid); + } + + public void IntoRoom(string RoomID, User Player) + { + if (RoomID == "-1" || Player.Id == 0) return; + GetPlayerList(RoomID).Add(Player); + } + + public void QuitRoom(string RoomID, User Player) + { + if (RoomID == "-1" || Player.Id == 0) return; + GetPlayerList(RoomID).Remove(Player); } public Room? GetRoom(string RoomID) @@ -71,6 +93,28 @@ namespace Milimoe.FunGame.Core.Library.Common.Architecture return General.UnknownUserInstance; } + public void SetRoomMaster(string RoomID, User User) + { + Room? room = this[RoomID]; + if (room != null) + { + room.RoomMaster = User; + } + } + + public List GetPlayerList(string RoomID) + { + List? list = new(); + if (_PlayerList.ContainsKey(RoomID) && _PlayerList[RoomID] != null) + { + list = (List?)_PlayerList[RoomID]; + } + list ??= new(); + return list; + } + + public int GetPlayerCount(string RoomID) => GetPlayerList(RoomID).Count; + public IEnumerator GetEnumerator() { foreach(Room room in ListRoom) diff --git a/Library/Constant/ConstantSet.cs b/Library/Constant/ConstantSet.cs index 3fc41ed..bd22d6f 100644 --- a/Library/Constant/ConstantSet.cs +++ b/Library/Constant/ConstantSet.cs @@ -16,6 +16,11 @@ } } + /// + /// 需要同步更新 + /// Milimoe.FunGame.Core.Library.Constant.SocketMessageType, + /// Milimoe.FunGame.Core.Service.SocketManager.GetTypeString(SocketMessageType type) + /// public class SocketSet { public const int MaxRetryTimes = 20; @@ -40,6 +45,9 @@ public const string CreateRoom = "CreateRoom"; public const string UpdateRoom = "UpdateRoom"; public const string ChangeRoomSetting = "ChangeRoomSetting"; + public const string MatchRoom = "MatchRoom"; + public const string UpdateRoomMaster = "UpdateRoomMaster"; + public const string GetRoomPlayerCount = "GetRoomPlayerCount"; } public class ReflectionSet diff --git a/Library/Constant/TypeEnum.cs b/Library/Constant/TypeEnum.cs index 87bcfc9..45f460d 100644 --- a/Library/Constant/TypeEnum.cs +++ b/Library/Constant/TypeEnum.cs @@ -48,6 +48,9 @@ Red } + /// + /// 需要同步更新Milimoe.FunGame.Core.Library.Constant.SocketSet + /// public enum SocketMessageType { Unknown, @@ -68,7 +71,9 @@ CreateRoom, UpdateRoom, ChangeRoomSetting, - MatchRoom + MatchRoom, + UpdateRoomMaster, + GetRoomPlayerCount } public enum DataRequestType @@ -263,7 +268,10 @@ QuitRoom, UpdateRoom, CreateRoom, - Chat + Chat, + MatchRoom, + UpdateRoomMaster, + GetRoomPlayerCount } public enum RegInvokeType diff --git a/Service/SocketManager.cs b/Service/SocketManager.cs index 4833e13..baf77db 100644 --- a/Service/SocketManager.cs +++ b/Service/SocketManager.cs @@ -231,6 +231,9 @@ namespace Milimoe.FunGame.Core.Service SocketMessageType.CreateRoom => SocketSet.CreateRoom, SocketMessageType.UpdateRoom => SocketSet.UpdateRoom, SocketMessageType.ChangeRoomSetting => SocketSet.ChangeRoomSetting, + SocketMessageType.MatchRoom => SocketSet.MatchRoom, + SocketMessageType.UpdateRoomMaster => SocketSet.UpdateRoomMaster, + SocketMessageType.GetRoomPlayerCount => SocketSet.GetRoomPlayerCount, _ => SocketSet.Unknown, }; }