mirror of
https://github.com/project-redbud/FunGame-Core.git
synced 2025-12-05 08:09:02 +00:00
Add UpdateRoomMaster; Update RoomList, Constants. (#14)
* Add UpdateRoomMaster, DissolveRoom; Update RoomList; Update MISC. * Update RoomList, Constants
This commit is contained in:
parent
690e4c34dc
commit
e1c3f7cce1
@ -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<User>());
|
||||
}
|
||||
|
||||
public void AddRooms(List<Room> 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<User> GetPlayerList(string RoomID)
|
||||
{
|
||||
List<User>? list = new();
|
||||
if (_PlayerList.ContainsKey(RoomID) && _PlayerList[RoomID] != null)
|
||||
{
|
||||
list = (List<User>?)_PlayerList[RoomID];
|
||||
}
|
||||
list ??= new();
|
||||
return list;
|
||||
}
|
||||
|
||||
public int GetPlayerCount(string RoomID) => GetPlayerList(RoomID).Count;
|
||||
|
||||
public IEnumerator GetEnumerator()
|
||||
{
|
||||
foreach(Room room in ListRoom)
|
||||
|
||||
@ -16,6 +16,11 @@
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 需要同步更新
|
||||
/// Milimoe.FunGame.Core.Library.Constant.SocketMessageType,
|
||||
/// Milimoe.FunGame.Core.Service.SocketManager.GetTypeString(SocketMessageType type)
|
||||
/// </summary>
|
||||
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
|
||||
|
||||
@ -48,6 +48,9 @@
|
||||
Red
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 需要同步更新Milimoe.FunGame.Core.Library.Constant.SocketSet
|
||||
/// </summary>
|
||||
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
|
||||
|
||||
@ -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,
|
||||
};
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user