/// <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>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; }