ExtinctionOnline/ExtinctionOnline.Server/Room/RoomController.cs

31 lines
1.0 KiB
C#
Raw Normal View History

2022-11-05 17:34:58 +09:00
namespace ExtinctionOnline.Server
2022-11-04 22:05:08 +09:00
{
internal class RoomController
{
internal static void JoinToRoom(RoomMessageData roomData, ClientInfo client)
{
if (client.RoomId != null)
{
throw new Exception("You are already in a room.");
}
else if (roomData.RoomId == null)
{
string roomGuid = Guid.NewGuid().ToString();
RoomData room = new RoomData(roomGuid, roomData.RoomName ?? roomGuid);
room.AddClient(client);
Server.s_lobby.Remove(client);
Server.s_rooms.Add(roomGuid, room);
}
else if (Server.s_rooms.ContainsKey(roomData.RoomId))
{
Server.s_lobby.Remove(client);
Server.s_rooms[roomData.RoomId].AddClient(client);
}
else
{
throw new Exception($"Rooms that do not exist: {roomData.RoomId}");
}
}
}
}