예제 #1
0
        public static void OnPlayerMovement(int _fromClient, Packet _packet)
        {
            bool[] _inputs = new bool[_packet.ReadInt()];
            for (int i = 0; i < _inputs.Length; i++)
            {
                _inputs[i] = _packet.ReadBool();
            }
            Quaternion _rotation   = _packet.ReadQuaternion();
            string     _username   = _packet.ReadString();
            float      _xRot       = _packet.ReadFloat();
            Vector3    _camPos     = _packet.ReadVector3();
            Vector3    _camForward = _packet.ReadVector3();
            Match1v1   m           = Server.match1v1Database.GetMatchByPlayer(Server.playerDatabase.GetPlayerById(_fromClient));

            if (m != null)
            {
                ServerSend.OnPlayerMovement(m.host.id, _inputs, _rotation, _username, _xRot, _camPos, _camForward);
            }

            Match m2 = Server.matchDatabase.GetMatchByPlayer(Server.playerDatabase.GetPlayerById(_fromClient));

            if (m2 != null)
            {
                ServerSend.OnPlayerMovement(m2.host.id, _inputs, _rotation, _username, _xRot, _camPos, _camForward);
            }
        }
예제 #2
0
        public static void OnSendIntoGame1v1(int _fromClient, Packet _packet)
        {
            Match1v1         m         = Server.match1v1Database.GetMatchByPlayer(Server.playerDatabase.GetPlayerById(_fromClient));
            List <Vector3>   spawns    = new List <Vector3>(Constants.team1Spawns);
            List <SpawnInfo> spawnInfo = new List <SpawnInfo>();

            int     team  = 0;
            int     n     = new Random().Next(0, spawns.Count - 1);
            Vector3 spawn = spawns[n];

            spawns.RemoveAt(n);
            spawnInfo.Add(new SpawnInfo(spawn, team, m.player1.username));

            spawns = new List <Vector3>(Constants.team2Spawns);
            team   = 1;
            n      = new Random().Next(0, spawns.Count - 1);
            spawn  = spawns[n];
            spawns.RemoveAt(n);
            spawnInfo.Add(new SpawnInfo(spawn, team, m.player2.username));

            VaccineSpawn v = new VaccineSpawn();
            SickSpawn    s = new SickSpawn();

            ServerSend.SpawnPlayer1v1(m.player1.id, spawnInfo, s, v);

            ServerSend.SpawnPlayer1v1(m.player2.id, spawnInfo, s, v);
        }
예제 #3
0
        public static void OnRoundEnd(int _fromClient, Packet _packet)
        {
            int team0wins = _packet.ReadInt();
            int team1wins = _packet.ReadInt();

            Match1v1 m  = Server.match1v1Database.GetMatchByPlayer(Server.playerDatabase.GetPlayerById(_fromClient));
            Match    m2 = Server.matchDatabase.GetMatchByPlayer(Server.playerDatabase.GetPlayerById(_fromClient));

            if (m != null)
            {
                ServerSend.OnRoundEnd(m.player1.id, team0wins, team1wins);
                ServerSend.OnRoundEnd(m.player2.id, team0wins, team1wins);
            }
            else if (m2 != null)
            {
                foreach (Lobby l in m2.team1)
                {
                    foreach (Player p in l.GetPlayers())
                    {
                        ServerSend.OnRoundEnd(p.id, team0wins, team1wins);
                    }
                }

                foreach (Lobby l in m2.team2)
                {
                    foreach (Player p in l.GetPlayers())
                    {
                        ServerSend.OnRoundEnd(p.id, team0wins, team1wins);
                    }
                }
            }
        }
예제 #4
0
        public static void OnNextRound(int _fromClient, Packet _packet)
        {
            Vector3 vaccinePos = _packet.ReadVector3();
            Vector3 petePos    = _packet.ReadVector3();
            float   peteRot    = _packet.ReadFloat();

            Match1v1 m  = Server.match1v1Database.GetMatchByPlayer(Server.playerDatabase.GetPlayerById(_fromClient));
            Match    m2 = Server.matchDatabase.GetMatchByPlayer(Server.playerDatabase.GetPlayerById(_fromClient));

            if (m != null)
            {
                ServerSend.OnNextRound(m.player1.id, vaccinePos, petePos, peteRot);
                ServerSend.OnNextRound(m.player2.id, vaccinePos, petePos, peteRot);
            }
            else if (m2 != null)
            {
                foreach (Lobby l in m2.team1)
                {
                    foreach (Player p in l.GetPlayers())
                    {
                        ServerSend.OnNextRound(p.id, vaccinePos, petePos, peteRot);
                    }
                }

                foreach (Lobby l in m2.team2)
                {
                    foreach (Player p in l.GetPlayers())
                    {
                        ServerSend.OnNextRound(p.id, vaccinePos, petePos, peteRot);
                    }
                }
            }
        }
예제 #5
0
        public static void EndOfGame(int _fromClient, Packet _packet)
        {
            int      team0wins = _packet.ReadInt();
            int      team1wins = _packet.ReadInt();
            bool     result    = team0wins > team1wins;
            Match1v1 m         = Server.match1v1Database.GetMatchByPlayer(Server.playerDatabase.GetPlayerById(_fromClient));
            Match    m2        = Server.matchDatabase.GetMatchByPlayer(Server.playerDatabase.GetPlayerById(_fromClient));

            if (m != null)
            {
                List <int> newElos = EloSystem.CalculateEloRating(m.player1.elo, m.player2.elo, result);
                m.player1.elo = newElos[0];
                m.player2.elo = newElos[1];
                ServerSend.SendEndOfGame(m.player1.id, team0wins, team1wins, m.player1.elo);
                ServerSend.SendEndOfGame(m.player2.id, team0wins, team1wins, m.player2.elo);
                Server.match1v1Database.matches.Remove(m);
            }
            else if (m2 != null)
            {
                float      team0average = m2.GetAverageEloOfTeam(0);
                float      team1average = m2.GetAverageEloOfTeam(1);
                List <int> newElos      = EloSystem.CalculateEloRating(team0average, team1average, result);
                foreach (Player p in m2.GetTeam(0))
                {
                    p.elo += newElos[0] - (int)team0average;
                    ServerSend.SendEndOfGame(p.id, team0wins, team1wins, p.elo);
                }
                foreach (Player p in m2.GetTeam(1))
                {
                    p.elo += newElos[1] - (int)team1average;
                    ServerSend.SendEndOfGame(p.id, team0wins, team1wins, p.elo);
                }
                Server.matchDatabase.matches.Remove(m2);
            }
        }
예제 #6
0
        public static void PlaySound(int _fromClient, Packet _packet)
        {
            string  name     = _packet.ReadString();
            Vector3 position = _packet.ReadVector3();

            Match1v1 m  = Server.match1v1Database.GetMatchByPlayer(Server.playerDatabase.GetPlayerById(_fromClient));
            Match    m2 = Server.matchDatabase.GetMatchByPlayer(Server.playerDatabase.GetPlayerById(_fromClient));

            if (m != null)
            {
                ServerSend.PlaySound(m.player1.id, name, position);
                ServerSend.PlaySound(m.player2.id, name, position);
            }
            else if (m2 != null)
            {
                foreach (Lobby l in m2.team1)
                {
                    foreach (Player p in l.GetPlayers())
                    {
                        ServerSend.PlaySound(p.id, name, position);
                    }
                }

                foreach (Lobby l in m2.team2)
                {
                    foreach (Player p in l.GetPlayers())
                    {
                        ServerSend.PlaySound(p.id, name, position);
                    }
                }
            }
        }
예제 #7
0
        public static void OnReadyButtonClicked1v1(int _fromClient, Packet _packet)
        {
            string hostname = _packet.ReadString();

            if (Server.playerDatabase.GetPlayerByName(hostname).isLoggedIn)
            {
                ServerSend.OnReadyButtonClicked1v1(Server.playerDatabase.GetPlayerByName(hostname).id);
            }
            else
            {
                Match1v1 m = Server.match1v1Database.GetMatchByPlayer(Server.playerDatabase.GetPlayerById(_fromClient));
                if (m != null)
                {
                    ServerSend.OnPlayerNotReady(m.player1.id);
                    ServerSend.OnPlayerNotReady(m.player2.id);
                }
            }
        }
예제 #8
0
        public static void OnShooting(int _fromClient, Packet _packet)
        {
            string  hitUsername = String.Empty;
            float   health      = 0;
            Vector3 point       = _packet.ReadVector3();
            Vector3 normal      = _packet.ReadVector3();
            string  username    = _packet.ReadString();
            bool    isTargetHit = _packet.ReadBool();

            if (isTargetHit)
            {
                hitUsername = _packet.ReadString();
                health      = _packet.ReadFloat();
            }

            Match1v1 m = Server.match1v1Database.GetMatchByPlayer(Server.playerDatabase.GetPlayerById(_fromClient));

            if (m != null)
            {
                ServerSend.OnShooting(m.player1.id, point, normal, username, isTargetHit, hitUsername, health);
                ServerSend.OnShooting(m.player2.id, point, normal, username, isTargetHit, hitUsername, health);
            }

            Match m2 = Server.matchDatabase.GetMatchByPlayer(Server.playerDatabase.GetPlayerById(_fromClient));

            if (m2 != null)
            {
                foreach (Lobby l in m2.team1)
                {
                    foreach (Player p in l.GetPlayers())
                    {
                        ServerSend.OnShooting(p.id, point, normal, username, isTargetHit, hitUsername, health);
                    }
                }

                foreach (Lobby l in m2.team2)
                {
                    foreach (Player p in l.GetPlayers())
                    {
                        ServerSend.OnShooting(p.id, point, normal, username, isTargetHit, hitUsername, health);
                    }
                }
            }
        }
예제 #9
0
        public static void OnPlayerMovementResponse(int _fromClient, Packet _packet)
        {
            string     username         = _packet.ReadString();
            Vector3    position         = _packet.ReadVector3();
            Quaternion rotation         = _packet.ReadQuaternion();
            float      xRot             = _packet.ReadFloat();
            int        state            = _packet.ReadInt();
            bool       isSprinting      = _packet.ReadBool();
            int        ammoCount        = _packet.ReadInt();
            int        pressEText       = _packet.ReadInt();
            bool       startTimer       = _packet.ReadBool();
            int        invokeFunctionId = _packet.ReadInt();
            float      timeRemaining    = _packet.ReadFloat();
            Match1v1   m = Server.match1v1Database.GetMatchByPlayer(Server.playerDatabase.GetPlayerById(_fromClient));

            if (m != null)
            {
                ServerSend.OnPlayerMovementResponse(m.player1.id, username, position, rotation, xRot, state, isSprinting, ammoCount, pressEText, startTimer, invokeFunctionId, timeRemaining);
                ServerSend.OnPlayerMovementResponse(m.player2.id, username, position, rotation, xRot, state, isSprinting, ammoCount, pressEText, startTimer, invokeFunctionId, timeRemaining);
            }

            Match m2 = Server.matchDatabase.GetMatchByPlayer(Server.playerDatabase.GetPlayerById(_fromClient));

            if (m2 != null)
            {
                foreach (Lobby l in m2.team1)
                {
                    foreach (Player p in l.GetPlayers())
                    {
                        ServerSend.OnPlayerMovementResponse(p.id, username, position, rotation, xRot, state, isSprinting, ammoCount, pressEText, startTimer, invokeFunctionId, timeRemaining);
                    }
                }

                foreach (Lobby l in m2.team2)
                {
                    foreach (Player p in l.GetPlayers())
                    {
                        ServerSend.OnPlayerMovementResponse(p.id, username, position, rotation, xRot, state, isSprinting, ammoCount, pressEText, startTimer, invokeFunctionId, timeRemaining);
                    }
                }
            }
        }
예제 #10
0
        public static void OnPlayerNotReady(int _fromClient, Packet _packet)
        {
            Match1v1 m  = Server.match1v1Database.GetMatchByPlayer(Server.playerDatabase.GetPlayerById(_fromClient));
            Match    m2 = Server.matchDatabase.GetMatchByPlayer(Server.playerDatabase.GetPlayerById(_fromClient));

            if (m != null)
            {
                if (m.player1.isLoggedIn)
                {
                    ServerSend.OnPlayerNotReady(m.player1.id);
                }

                if (m.player2.isLoggedIn)
                {
                    ServerSend.OnPlayerNotReady(m.player2.id);
                }
            }
            else if (m2 != null)
            {
                foreach (Lobby l in m2.team1)
                {
                    foreach (Player p in l.GetPlayers())
                    {
                        if (p.isLoggedIn)
                        {
                            ServerSend.OnPlayerNotReady(p.id);
                        }
                    }
                }

                foreach (Lobby l in m2.team2)
                {
                    foreach (Player p in l.GetPlayers())
                    {
                        if (p.isLoggedIn)
                        {
                            ServerSend.OnPlayerNotReady(p.id);
                        }
                    }
                }
            }
        }
예제 #11
0
        public static void OnDying(int _fromClient, Packet _packet)
        {
            string  username   = _packet.ReadString();
            bool    hasVaccine = _packet.ReadBool();
            Vector3 position   = Vector3.Zero;

            if (hasVaccine)
            {
                position = _packet.ReadVector3();
            }

            Match1v1 m  = Server.match1v1Database.GetMatchByUsername(username);
            Match    m2 = Server.matchDatabase.GetMatchByPlayer(Server.playerDatabase.GetPlayerById(_fromClient));

            if (m != null)
            {
                ServerSend.OnDying(m.player1.id, username, hasVaccine, position);
                ServerSend.OnDying(m.player2.id, username, hasVaccine, position);
            }
            else if (m2 != null)
            {
                foreach (Lobby l in m2.team1)
                {
                    foreach (Player p in l.GetPlayers())
                    {
                        ServerSend.OnDying(p.id, username, hasVaccine, position);
                    }
                }

                foreach (Lobby l in m2.team2)
                {
                    foreach (Player p in l.GetPlayers())
                    {
                        ServerSend.OnDying(p.id, username, hasVaccine, position);
                    }
                }
            }
        }
예제 #12
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();
        }