/// <summary>Welcomes the specified client. The client receives all the nessesary server information. Informs other /// clients that the player count has changed</summary> /// <param name="clientID">The client identifier.</param> /// <param name="packet">The incoming packet.</param> /// <remarks>This function sends a "PlayerCountChange" packet.</remarks> /// <remarks>This function sends a "LobbyList" packet.</remarks> public static void Welcome(int clientID, Packet packet) { int id = packet.ReadInt(); string msg = packet.ReadString(); Console.WriteLine(Constants.HANDSHAKE_COMPLETE + msg); GameServer.connectedClients[id].UserName = msg; PacketSend.PlayerCountChange(id); PacketSend.LobbyList(); ValidatePlayerID(clientID, id); }
/// <summary>Puts a client into the specified lobby (specified in the packet). The client is not connected if the lobby is full. /// If the client is connected, update the lobby list and player list for all other clients.</summary> /// <param name="clientID">The client identifier.</param> /// <param name="packet">The incoming packet.</param> /// <remarks>This function sends a "PlayerList" packet.</remarks> /// <remarks>This function sends a "LobbyList" packet.</remarks> public static void ClientLobbyJoin(int clientID, Packet packet) { int id = packet.ReadInt(); int lobbyID = packet.ReadInt(); var lobby = GameServer.openLobbies[lobbyID]; var player = GameServer.connectedClients[id]; if (!lobby.IsFull) { player.LobbyID = lobbyID; lobby.AddPlayer(player); PacketSend.PlayerList(lobbyID); PacketSend.LobbyList(); } ValidatePlayerID(clientID, id); }
/// <summary>Disconnect the client from the server, notify other users of this event, and reset the state of this client instance. /// If the client was in a lobby, check to see if that lobby is not empty. If so, delete the lobby.</summary> /// <param name="clientID">The clients unique ID</param> /// <remarks> This function sends a "PlayerList" packet.</remarks> /// <remarks> This function sends a "PlayerGameOver" packet.</remarks> /// <remarks> This function sends a "LobbyList" packet.</remarks> /// <remarks> This function sends a "PlayerCountChange" packet.</remarks> public void Disconnect() { Console.WriteLine(Constants.PLAYER_DISSCONECTED + UserName); tcp.Disconnect(); if (LobbyID != -1) { PacketSend.PlayerList(LobbyID); PacketSend.PlayerGameOver(LobbyID, UID, true); GameServer.openLobbies[LobbyID].RemovePlayer(this); } PacketSend.LobbyList(); PacketSend.PlayerCountChange(UID); UserName = null; Status = 0; LobbyID = -1; }
/// <summary>Creates a lobby as requested by a client. The lobby will not be created if there are already four lobbies. /// If the lobby is created, inform all other clients of the new lobby.</summary> /// <param name="clientID">The client identifier.</param> /// <param name="packet">The incoming packet.</param> /// <remarks>This function sends a "LobbyList" packet.</remarks> public static void ClientLobbyCreate(int clientID, Packet packet) { int id = packet.ReadInt(); var player = GameServer.connectedClients[id]; var lobbyList = GameServer.openLobbies; if (lobbyList.Count < 4) { GameLobbyInstance temp = new GameLobbyInstance(id, player); lobbyList.Add(id, temp); player.LobbyID = id; PacketSend.LobbyList(); Console.WriteLine(player.UserName + Constants.LOBBY_OPENED); } ValidatePlayerID(clientID, id); }