private void OnApplicationQuit()
        {
            for (byte id = 1; id <= MaxPlayers; id++)
            {
                if (Server.clients[id].player != null)
                {
                    Log($"Calling ServerSend.DisconnectPlayer({id})");
                    ServerSend.DisconnectPlayer(id);
                }
            }

            Log("Disconnected All Players");

            Server.Stop();
        }
Beispiel #2
0
        public static void WelcomeReceived(byte fromClient, Packet packet)
        {
            byte    clientIdCheck = packet.ReadByte();
            string  username      = packet.ReadString();
            bool    isHost        = packet.ReadBool();
            string  currentClip   = packet.ReadString();
            string  activeScene   = packet.ReadString();
            Vector3 position      = packet.ReadVector3();
            Vector3 scale         = packet.ReadVector3();
            int     health        = packet.ReadInt();
            int     maxHealth     = packet.ReadInt();
            int     healthBlue    = packet.ReadInt();

            List <bool> charmsData = new List <bool>();

            for (int charmNum = 1; charmNum <= 40; charmNum++)
            {
                charmsData.Add(packet.ReadBool());
            }
            int team = packet.ReadInt();

            if (isHost)
            {
                foreach (Client client in Server.clients.Values)
                {
                    if (client.player == null)
                    {
                        continue;
                    }
                    if (client.player.isHost)
                    {
                        Log("Another player tried to connect with a server DLL active! Disconnecting that player.");
                        ServerSend.DisconnectPlayer(fromClient);

                        return;
                    }
                }
            }

            Server.clients[fromClient].SendIntoGame(username, position, scale, currentClip, health, maxHealth, healthBlue, charmsData, isHost, team);

            /*for (int i = 0; i < Enum.GetNames(typeof(TextureType)).Length; i++)
             * {
             *  byte[] hash = packet.ReadBytes(20);
             *
             *  Player player = Server.clients[fromClient].player;
             *  if (!player.textureHashes.Contains(hash))
             *  {
             *      player.textureHashes.Add(hash);
             *  }
             *
             *  if (!MultiplayerServer.textureCache.ContainsKey(hash))
             *  {
             *      ServerSend.RequestTexture(fromClient, hash);
             *  }
             * }*/

            SceneChanged(fromClient, activeScene);

            Log($"{username} connected successfully and is now player {fromClient}.");
            if (fromClient != clientIdCheck)
            {
                Log($"Player \"{username}\" (ID: {fromClient}) has assumed the wrong client ID ({clientIdCheck}.");
            }
        }
        public static void WelcomeReceived(byte fromClient, Packet packet)
        {
            byte    clientIdCheck = packet.ReadByte();
            string  username      = packet.ReadString();
            bool    isHost        = packet.ReadBool();
            string  currentClip   = packet.ReadString();
            string  activeScene   = packet.ReadString();
            Vector3 position      = packet.ReadVector3();
            Vector3 scale         = packet.ReadVector3();
            int     health        = packet.ReadInt();
            int     maxHealth     = packet.ReadInt();
            int     healthBlue    = packet.ReadInt();

            List <bool> charmsData = new List <bool>();

            for (int charmNum = 1; charmNum <= 40; charmNum++)
            {
                charmsData.Add(packet.ReadBool());
            }
            int modamount = packet.ReadInt();

            for (int modNum = 1; modNum <= modamount; modNum++)
            {
                Log(username + " Has mod " + packet.ReadString() + "  " + modNum + "/" + modamount);
            }
            Log(username + " Has modding api ver " + packet.ReadString());
            int     team        = packet.ReadInt();
            string  chat        = packet.ReadString();
            bool    pinenabled  = packet.ReadBool();
            Vector3 pinposition = packet.ReadVector3();

            if (isHost)
            {
                foreach (Client client in Server.clients.Values)
                {
                    if (client.player == null)
                    {
                        continue;
                    }
                    if (client.player.isHost)
                    {
                        Log("Another player tried to connect with a server DLL active! Disconnecting that player.");
                        ServerSend.DisconnectPlayer(fromClient);

                        return;
                    }
                }
            }

            Server.clients[fromClient].SendIntoGame(username, position, scale, currentClip, health, maxHealth, healthBlue, charmsData, isHost, team, chat, pinenabled, pinposition);
            try{
                foreach (Client client in Server.clients.Values)
                {
                    ServerSend.CreatePin(client.id, fromClient);
                }
                ServerSend.CreatePin(fromClient);
            }
            catch (Exception e) {
                Log("Server could not create pin :" + e.Message + " Object: " + e.Source);
            }

            /*for (int i = 0; i < Enum.GetNames(typeof(TextureType)).Length; i++)
             * {
             *  byte[] hash = packet.ReadBytes(20);
             *
             *  Player player = Server.clients[fromClient].player;
             *  if (!player.textureHashes.Contains(hash))
             *  {
             *      player.textureHashes.Add(hash);
             *  }
             *
             *  if (!MultiplayerServer.textureCache.ContainsKey(hash))
             *  {
             *      ServerSend.RequestTexture(fromClient, hash);
             *  }
             * }*/

            bool otherplayer = false;

            if (Server.clients.Count > 1)
            {
                foreach (Client c in Server.clients.Values)
                {
                    if (c.player == null)
                    {
                        continue;
                    }
                    if (c.player.activeScene == activeScene)
                    {
                        otherplayer = true;
                    }
                }
            }
            SceneChanged(fromClient, activeScene, otherplayer);

            Log($"{username} connected successfully and is now player {fromClient}.");
            if (fromClient != clientIdCheck)
            {
                Log($"Player \"{username}\" (ID: {fromClient}) has assumed the wrong client ID ({clientIdCheck}.");
            }
        }