/// <summary> /// Sent by player how wants to create a new room /// </summary> /// <param name="connectionId">Room creator connection id</param> /// <param name="maxPlayers">Max players in room</param> /// <param name="deckSize">Deck size in room</param> public static void CreateRoom(long connectionId, int maxPlayers, int deckSize, double bet) { var client = ClientManager.GetConnectedClient(connectionId); Log.WriteLine("[" + client + "] wants to create room.", typeof(RoomManager)); if (client.IsInRoom) { Log.WriteLine("[" + client + "] is already in room. Abort.", typeof(RoomManager)); return; } //Validate if (maxPlayers < 2 || maxPlayers > 6 || !(deckSize == 24 || deckSize == 36 || deckSize == 52)) { //Send incorrect room return; } RoomInstance room = CreateNewRoomInstance(connectionId); room.MaxPlayers = maxPlayers; room.DeckSize = deckSize; #if TEST_MODE_TWO_CARDS room.DeckSize = 4; #endif room.HostId = connectionId; room.Bet = bet; //Client joins random room if (room.JoinRoom(connectionId)) { //Send 'OK' if room has free slots ServerSendPackets.Send_JoinRoomOk(connectionId, room.RoomId); } }
/// <summary> /// Adds player to room /// </summary> public static bool JoinRoom(long connectionId, long roomId) { //Getting not-full rooms var availableRooms = GetAvailableRooms().ToArray(); RoomInstance roomToJoin = availableRooms.Single(room => room.RoomId == roomId); //If this room is not present if (roomToJoin == null) { //todo send fail to join //ServerSendPackets.Send_FaliToJoin(connectionId); return(false); } if (roomToJoin.JoinRoom(connectionId)) { //Send 'OK' if room has free slots ServerSendPackets.Send_JoinRoomOk(connectionId, roomToJoin.RoomId); return(true); } return(false); }