Ejemplo n.º 1
0
        public static void RemoveFromLobby(int _fromClient, Packet _packet)
        {
            int _clientIdCheck = _packet.ReadInt();

            if (Server.lobbyGames.ContainsKey(_fromClient))
            {
                Server.lobbyGames.Remove(_fromClient);
                ServerSend.RemRoomToAll(_fromClient);
                Console.WriteLine("Hosted game has been removed.");
            }
        }
Ejemplo n.º 2
0
        public static void JoinedGame(int _fromClient, Packet _packet)
        {
            int _clientIdCheck = _packet.ReadInt();
            int _hostingId     = _packet.ReadInt();

            Console.WriteLine("Handling game joiner.");

            if (ConsistencyCheck(_fromClient, _clientIdCheck))
            {
                Server.activeGames.Add(_hostingId, _fromClient);
                Server.clients[_fromClient].player.enemId = _hostingId;
                Server.clients[_hostingId].player.enemId  = _fromClient;
                ServerSend.RemRoomToAll(_hostingId);
                Server.lobbyGames.Remove(_hostingId);
                ServerSend.SendJoinGame(_hostingId, _fromClient);
            }
        }
Ejemplo n.º 3
0
        private void Disconnect()
        {
            Console.WriteLine($"{tcp.socket.Client.RemoteEndPoint} has disconnected.");
            if (Server.lobbyGames.ContainsKey(player.id))
            {
                Server.lobbyGames.Remove(player.id);
                ServerSend.RemRoomToAll(player.id);
            }
            if (Server.activeGames.ContainsKey(player.id))
            {
                Server.activeGames.Remove(player.id);
                ServerSend.SendForfeit(player.enemId);
            }
            if (Server.activeGames.ContainsKey(player.enemId))
            {
                Server.activeGames.Remove(player.enemId);
                ServerSend.SendForfeit(player.enemId);
            }

            player = null;
            tcp.Disconnect();
        }