コード例 #1
0
ファイル: ServerHandle.cs プロジェクト: PetoAdam/Server
        internal static void LeaveLobby(int _fromClient, Packet _packet)
        {
            Player client = Server.playerDatabase.GetPlayerById(_fromClient);
            Lobby  lobby  = Server.lobbyDatabase.FindLobbyWithPlayer(client);

            if (lobby != null)
            {
                if (lobby.leader.username == client.username)
                {
                    foreach (Player p in lobby.GetPlayers())
                    {
                        if (p.username != client.username)
                        {
                            ServerSend.LeaveLobby(p.id, "The leader has left the lobby");
                        }
                    }
                    Server.lobbyDatabase.RemoveLobby(lobby);
                }
                else
                {
                    Server.lobbyDatabase.FindLobbyWithPlayer(client).RemovePlayer(client);
                    lobby.RemovePlayer(client);
                    foreach (Player p in lobby.GetPlayers())
                    {
                        ServerSend.LeaveLobby(p.id, lobby.GetLobbyData());
                    }
                }
            }
        }
コード例 #2
0
ファイル: Client.cs プロジェクト: PetoAdam/Server
        private void Disconnect()
        {
            Console.WriteLine($"{tcp.socket.Client.RemoteEndPoint} has disconnected.");

            Player player = Server.playerDatabase.GetPlayerById(id);

            player.isLoggedIn = false;


            Lobby l = Server.matchmaking.FindLobbyWithPlayer(player);

            if (l != null)
            {
                lock (Server.matchmaking)
                {
                    Server.matchmaking.lobbies.Remove(l);
                }
                foreach (Player p in l.GetPlayers())
                {
                    if (player != p)
                    {
                        ServerSend.DisconnectInMatchmaking(p.id);
                    }
                }
            }

            lock (Server.matchmaking1v1)
            {
                Server.matchmaking1v1.RemovePlayer(player);
            }
            Server.lobbyDatabase.RemoveLobby(l);


            Match    m  = Server.matchDatabase.GetMatchByPlayer(player);
            Match1v1 m1 = Server.match1v1Database.GetMatchByPlayer(player);

            if (m != null)
            {
                player.elo -= 20;
                foreach (Player p in m.GetTeam(0))
                {
                    ServerSend.OnPlayerDisconnect(p.id, p.elo, player.username);
                }
            }
            if (m1 != null)
            {
                player.elo -= 20;
                ServerSend.OnPlayerDisconnect(m1.player1.id, m1.player1.elo, player.username);
                ServerSend.OnPlayerDisconnect(m1.player2.id, m1.player2.elo, player.username);
            }

            Lobby lobby = Server.lobbyDatabase.FindLobbyWithPlayer(player);

            if (lobby != null)
            {
                if (lobby.leader.username == player.username)
                {
                    foreach (Player p in lobby.GetPlayers())
                    {
                        if (p.username != player.username)
                        {
                            ServerSend.LeaveLobby(p.id, "The leader has left the lobby");
                        }
                    }
                    Server.lobbyDatabase.RemoveLobby(lobby);
                }
                else
                {
                    Server.lobbyDatabase.FindLobbyWithPlayer(player).RemovePlayer(player);
                    lobby.RemovePlayer(player);
                    foreach (Player p in lobby.GetPlayers())
                    {
                        ServerSend.LeaveLobby(p.id, lobby.GetLobbyData());
                    }
                }
            }



            tcp.Disconnect();
            udp.Disconnect();
        }