Example #1
0
        /// <summary>
        /// //Tells a client where all the other players are in the world so they can be spawned in before they can enter the world
        /// </summary>
        /// <param name="ClientID">NetworkID for target client</param>
        public static void SendActivePlayerList(int ClientID)
        {
            CommunicationLog.LogOut(ClientID + " active player list");

            //Create a new NetworkPacket object to store the data for this active player list
            NetworkPacket Packet = new NetworkPacket();

            //Grab the list of all the other active game clients
            List <ClientConnection> OtherClients = ClientSubsetFinder.GetInGameClientsExceptFor(ClientID);

            //Write the relevant data values into the packet data
            Packet.WriteType(ServerPacketType.ActivePlayerList);
            Packet.WriteInt(OtherClients.Count);

            //Loop through the list of other clients and write each of their information into the packet data
            foreach (ClientConnection OtherClient in OtherClients)
            {
                //Write each characters name, and current location and rotation values
                Packet.WriteString(OtherClient.Character.Name);
                Packet.WriteBool(OtherClient.Character.IsAlive);
                Packet.WriteVector3(OtherClient.Character.Position);
                Packet.WriteQuaternion(OtherClient.Character.Rotation);
                Packet.WriteInt(OtherClient.Character.CurrentHealth);
                Packet.WriteInt(OtherClient.Character.MaxHealth);
            }

            //Add this packet to the target clients outgoing packet queue
            PacketQueue.QueuePacket(ClientID, Packet);
        }
Example #2
0
        private void TryRevivePlayer(string[] Input)
        {
            string CharacterName = Input[1];

            if (!CharactersDatabase.DoesCharacterExist(CharacterName))
            {
                MessageLog.Print("That character doesnt exist, cant revive them.");
                return;
            }
            ClientConnection Client = ClientSubsetFinder.GetClientUsingCharacter(CharacterName);

            if (Client == null)
            {
                MessageLog.Print("That character is not ingame right now, cant revive them.");
                return;
            }
            if (Client.Character.IsAlive)
            {
                MessageLog.Print("That character is not dead, cant revive them.");
                return;
            }
            MessageLog.Print("Reviving " + CharacterName + "...");
            Client.Character.IsAlive = true;
            Client.Character.SetDefaultValues();
            CombatPacketSenders.SendLocalPlayerRespawn(Client.ClientID, Client.Character);
            foreach (ClientConnection OtherClient in ClientSubsetFinder.GetInGameClientsExceptFor(Client.ClientID))
            {
                CombatPacketSenders.SendRemotePlayerRespawn(OtherClient.ClientID, Client.Character);
            }
        }
Example #3
0
        public void UpdateWorld(float DeltaTime)
        {
            //Poll User Input from the server window
            ProcessInput(ApplicationWindow.Focused, DeltaTime);

            //Manage all client connections and their player characters
            ConnectionManager.CheckClients(DeltaTime);
            ConnectionManager.CleanDeadClients(World);
            ConnectionManager.AddNewClients(World);
            ConnectionManager.UpdateClientPositions(World);
            ConnectionManager.RespawnDeadPlayers(World);

            //Track current inhabitants of the PVP Battle Arena, then process the players PVP attacks
            List <CharacterData> InGameCharacters = ClientSubsetFinder.GetInGameCharacters();

            PVPBattleArena.UpdateArenaInhabitants(InGameCharacters);
            PVPBattleArena.AlertTravellers();
            ConnectionManager.PerformPlayerAttacks(World);

            //Update the packet queue, transmitting all messages to the client connections
            PacketQueue.UpdateQueue(DeltaTime, TransmitPackets);

            //Update the physics simulation
            World.Timestep(DeltaTime, ThreadDispatcher);
            TimeSamples.RecordFrame(World);
        }
Example #4
0
        //Tries using the command arguments for killing one of the player characters
        private void TryKillPlayer(string[] Input)
        {
            string CharacterName = Input[1];

            if (!CharactersDatabase.DoesCharacterExist(CharacterName))
            {
                MessageLog.Print("That character doesnt exist, cant kill them.");
                return;
            }
            ClientConnection Client = ClientSubsetFinder.GetClientUsingCharacter(CharacterName);

            if (Client == null)
            {
                MessageLog.Print("That character is not ingame right now, cant kill them.");
                return;
            }
            //Make sure the character is still alive
            if (!Client.Character.IsAlive)
            {
                MessageLog.Print("That character is already dead, cant kill them.");
                return;
            }
            MessageLog.Print("Killing " + CharacterName + "...");
            Client.Character.IsAlive = false;
            Client.Character.RemoveBody(Program.World.World);
            //Client.RemovePhysicsBody(Program.World.WorldSimulation);
            CombatPacketSenders.SendLocalPlayerDead(Client.ClientID);
            foreach (ClientConnection OtherClient in ClientSubsetFinder.GetInGameClientsExceptFor(Client.ClientID))
            {
                CombatPacketSenders.SendRemotePlayerDead(OtherClient.ClientID, Client.Character.Name);
            }
        }
Example #5
0
        public static void HandleClientChatMessage(int ClientID, ref NetworkPacket Packet)
        {
            CommunicationLog.LogIn(ClientID + " chat message");

            //Fetch this ClientConnection and make sure they were able to be found
            ClientConnection Client = ConnectionManager.GetClient(ClientID);

            if (Client == null)
            {
                MessageLog.Print("ERROR: Client not found, unable to handle chat message.");
                return;
            }

            //Extract the message content from the network packet
            string ChatMessage = Packet.ReadString();

            //Get the list of all the other game clients who are already ingame
            List <ClientConnection> OtherClients = ClientSubsetFinder.GetInGameClientsExceptFor(ClientID);

            //Pass this chat message on to all the other clients that are ingame
            foreach (ClientConnection OtherClient in OtherClients)
            {
                PlayerCommunicationPacketSender.SendChatMessage(OtherClient.ClientID, Client.Character.Name, ChatMessage);
            }
        }
Example #6
0
        public static void HandlePlayerRotationUpdate(int ClientID, ref NetworkPacket Packet)
        {
            Quaternion       Rotation = Packet.ReadQuaternion();
            ClientConnection Client   = ConnectionManager.GetClient(ClientID);

            if (Client != null)
            {
                Client.Character.Rotation    = Rotation;
                Client.Character.NewRotation = true;
                foreach (ClientConnection OtherClient in ClientSubsetFinder.GetInGameClientsExceptFor(ClientID))
                {
                    PlayerManagementPacketSender.SendPlayerRotationUpdate(OtherClient.ClientID, Client.Character);
                }
            }
        }
Example #7
0
        public static void HandlePlayAnimationAlert(int ClientID, ref NetworkPacket Packet)
        {
            CommunicationLog.LogIn(ClientID + " Play Animation Alert");
            string           AnimationName = Packet.ReadString();
            ClientConnection Client        = ConnectionManager.GetClient(ClientID);

            if (Client == null)
            {
                MessageLog.Print("ERROR: Client not found, unable to handle play animation alert.");
                return;
            }
            List <ClientConnection> OtherClients = ClientSubsetFinder.GetInGameClientsExceptFor(ClientID);

            foreach (ClientConnection OtherClient in OtherClients)
            {
                PlayerManagementPacketSender.SendPlayAnimationAlert(OtherClient.ClientID, Client.Character.Name, AnimationName);
            }
        }
Example #8
0
        //Tries using the command arguments for performing a character info search
        private void TryCharacterInfoSearch(string[] Input)
        {
            //Get the characters name
            string CharacterName = Input[1];

            //Make sure the character exists
            if (!CharactersDatabase.DoesCharacterExist(CharacterName))
            {
                //Say the character doesnt exist and exit the function
                MessageLog.Print("No character named " + CharacterName + " exists, couldnt look up their info.");
                return;
            }

            //Characters Data will be stored here once we acquire it
            Server.Data.CharacterData Data;

            //Find the client currently controlling this character
            ClientConnection Client = ClientSubsetFinder.GetClientUsingCharacter(CharacterName);

            //If no client was found then we want to get the characters info from the database
            if (Client == null)
            {
                Data = CharactersDatabase.GetCharacterData(CharacterName);
            }
            //Otherwise we get the currently live data from the client who is currently using the character
            else
            {
                Data = Client.Character;
            }

            //Define some nicely formatted strings containing all the characters data
            string CharacterInfo     = CharacterName + " level " + Data.Level + (Data.IsMale ? " male." : "female.") + " with " + Data.CurrentHealth + "/" + Data.MaxHealth + " HP.";
            string CharacterPosition = "Position: " + "(" + Data.Position.X + "," + Data.Position.Y + "," + Data.Position.Z + ").";
            string CharacterRotation = "Rotation: (" + Data.Rotation.X + "," + Data.Rotation.Y + "," + Data.Rotation.Z + "," + Data.Rotation.W + ").";
            string CharacterCamera   = "Camera: Zoom:" + Data.CameraZoom + " XRot:" + Data.CameraXRotation + " YRot:" + Data.CameraYRotation + ".";

            //Display all the information to the message window
            MessageLog.Print(CharacterInfo);
            MessageLog.Print(CharacterPosition);
            MessageLog.Print(CharacterRotation);
            MessageLog.Print(CharacterCamera);
        }
Example #9
0
        //Tries using the command arguments for performing a server shutdown
        private void TryServerShutdown(string[] Input)
        {
            //Log what is happening here
            MessageLog.Print("Server shutting down...");

            //Get a list of all ingame clients who are logged in and playing right now
            List <ClientConnection> ActiveClients = ClientSubsetFinder.GetInGameClients();

            //Loop through all the active players and backup their data
            foreach (ClientConnection ActiveClient in ActiveClients)
            {
                CharactersDatabase.SaveCharacterData(ActiveClient.Character);
            }

            //Close and save the current log file
            MessageLog.Close();

            //Close the application
            Program.ApplicationWindow.Close();
        }
Example #10
0
        //Tries using the command arguments for performing a player kick
        private void TryKickPlayer(string[] Input)
        {
            //Get the characters name
            string CharacterName = Input[1];

            //Make sure the character exists
            if (!CharactersDatabase.DoesCharacterExist(CharacterName))
            {
                MessageLog.Print("That character doesnt exist, cant kick them.");
                return;
            }

            //Get the client who this character belongs to
            ClientConnection Client = ClientSubsetFinder.GetClientUsingCharacter(CharacterName);

            //If the client couldnt be found then the character isnt logged in currently
            if (Client == null)
            {
                MessageLog.Print("That character is not in the game right now, cant kick them.");
                return;
            }

            //Show that the player is being kicked
            MessageLog.Print("Kicking " + CharacterName + " from the game...");

            //Tell the client that they have been kicked from the game and mark them to be cleaned up from the game
            SystemPacketSender.SendKickedFromServer(Client.ClientID);
            Client.ConnectionDead = true;

            //Tell everyone else to remove the client from their games
            List <ClientConnection> OtherClients = ClientSubsetFinder.GetInGameClientsExceptFor(Client.ClientID);

            foreach (ClientConnection OtherClient in OtherClients)
            {
                PlayerManagementPacketSender.SendRemoveRemotePlayer(OtherClient.ClientID, Client.Character.Name, Client.Character.IsAlive);
            }
        }