//When a client wants to enter the game world, we need to send them a bunch of information to set up their game world before they can enter public static void HandleEnterWorldRequest(int ClientID, ref NetworkPacket Packet) { CommunicationLog.LogIn(ClientID + " enter world request"); //Read the characters name the player is going to use, use it to fetch the rest of the characters data from the database string CharacterName = Packet.ReadString(); CharacterData CharacterData = CharactersDatabase.GetCharacterData(CharacterName); //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 enter world request."); return; } //Store the character data in the client Client.Character = CharacterData; //Send the clients lists of other players, AI entities, item pickups, inventory contents, equipped items and socketed actionbar abilities GameWorldStatePacketSender.SendActivePlayerList(ClientID); GameWorldStatePacketSender.SendActiveEntityList(ClientID); GameWorldStatePacketSender.SendActiveItemList(ClientID); GameWorldStatePacketSender.SendInventoryContents(ClientID, CharacterName); GameWorldStatePacketSender.SendEquippedItems(ClientID, CharacterName); GameWorldStatePacketSender.SendSocketedAbilities(ClientID, CharacterName); }
/// <summary> /// Handles a client players updated camera values to be stored in their ClientConnection, until /// they either leave or the server is being shutdown, to then be backed up into the database /// </summary> /// <param name="ClientID">NetworkID of the target client</param> /// <param name="Packet">Packet containing the information were after</param> public static void HandlePlayerCameraUpdate(int ClientID, ref NetworkPacket Packet) { //Log what we are doing here CommunicationLog.LogIn(ClientID + " Player Camera Update"); //Extract all the values from the packet data float Zoom = Packet.ReadFloat(); float XRotation = Packet.ReadFloat(); float YRotation = Packet.ReadFloat(); //Try getting the ClientConnection object who sent this packet to us ClientConnection Client = ConnectionManager.GetClient(ClientID); //Display an error and exit from the function if they couldnt be found if (Client == null) { MessageLog.Print("ERROR: " + ClientID + " ClientConnection object couldnt be found, Player Camera Update could not be performed."); return; } //Store them in the ClientConnection object Client.Character.CameraZoom = Zoom; Client.Character.CameraXRotation = XRotation; Client.Character.CameraYRotation = YRotation; }
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); } }
//Handles a users account logout alert public static void HandleAccountLogoutAlert(int ClientID, ref NetworkPacket Packet) { //Log what we are doing here CommunicationLog.LogIn(ClientID + " Account Logout Alert."); //Get the client who is logged out ClientConnection Client = ConnectionManager.GetClient(ClientID); //Clear them as being logged in to any account Client.Account = new AccountData(); }
//Handles request from the player asking to have their character respawned public static void HandlePlayerRespawnRequest(int ClientID, ref NetworkPacket Packet) { CommunicationLog.LogIn(ClientID + "Player Respawn Request."); ClientConnection Client = ConnectionManager.GetClient(ClientID); if (Client == null) { MessageLog.Print("ERROR: Connection to this client could not be found, unable to handle their respawn request."); return; } Client.Character.WaitingToRespawn = true; }
//Handles a users account login request public static void HandleAccountLoginRequest(int ClientID, ref NetworkPacket Packet) { //Log what we are doing here CommunicationLog.LogIn(ClientID + "Account Login Request."); //Get the username and password the user provided for trying to login with string AccountName = Packet.ReadString(); string AccountPass = Packet.ReadString(); //Make sure we are still connected to this client ClientConnection Client = ConnectionManager.GetClient(ClientID); if (Client == null) { //Ignore the request if we cant find this clients network connection MessageLog.Print("ERROR: Connection to this client could not be found, no way to reply to their Account Login Request so it has been aborted."); return; } //Make sure there is account that exists with the name that was provided by the user if (!AccountsDatabase.DoesAccountExist(AccountName)) { //Reject the request if that account doesnt exist AccountManagementPacketSenders.SendAccountLoginReply(ClientID, false, "That account doesnt exist."); return; } //Make sure someone else isnt already logged into that account if (ConnectionManager.AccountLoggedIn(AccountName)) { //Reject the request if the account is already being used AccountManagementPacketSenders.SendAccountLoginReply(ClientID, false, "That account is already logged in."); return; } //Check if they provided the correct password if (!AccountsDatabase.IsPasswordCorrect(AccountName, AccountPass)) { //Reject the request if the password was wrong AccountManagementPacketSenders.SendAccountLoginReply(ClientID, false, "The password was incorrect."); return; } //Fetch all of the accounts information from the database and store it with this client AccountData Account = AccountsDatabase.GetAccountData(AccountName); Client.Account = Account; //Grant this users account login request MessageLog.Print(ClientID + " logged into the account " + AccountName); AccountManagementPacketSenders.SendAccountLoginReply(ClientID, true, "Login Request Granted."); }
//Handle reply from client letting us know they are still connected through the network public static void HandleStillConnectedReply(int ClientID, ref NetworkPacket Packet) { CommunicationLog.LogIn(ClientID + " Still Connected Reply"); ClientConnection Client = ConnectionManager.GetClient(ClientID); if (Client == null) { MessageLog.Print("ERROR: Client " + ClientID + " not found, unable to handle still connected reply."); return; } //Update the timer tracking how long since we last heard from this client Client.LastCommunication = new Time.PointInTime(); }
//When a client has finished receiving all the setup information they will let us know when they are entering into the game world finally public static void HandleNewPlayerReady(int ClientID, ref NetworkPacket Packet) { CommunicationLog.LogIn(ClientID + " new player ready alert"); //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 new player ready alert."); return; } //Flag them as needing to be added into the game world Client.Character.WaitingToEnter = true; }
//Handles a users new user account registration request public static void HandleAccountRegisterRequest(int ClientID, ref NetworkPacket Packet) { //Log what we are doing here CommunicationLog.LogIn(ClientID + " Account Registration Request."); //Fetch the username and password the client has provided string AccountName = Packet.ReadString(); string AccountPass = Packet.ReadString(); //Make sure we are still connected to this client ClientConnection Client = ConnectionManager.GetClient(ClientID); if (Client == null) { //Ignore the request if we cant find this clients network connection MessageLog.Print("ERROR: Connection to this client could not be found, no way to reply to their Account Registration Request."); return; } //Make sure this username isnt already taken by someone else if (AccountsDatabase.DoesAccountExist(AccountName)) { //Reject the request is the username is already taken AccountManagementPacketSenders.SendAccountRegistrationReply(ClientID, false, "That username is already taken."); return; } //Make sure they have provided us with a valid username and password if (!ValidInputCheckers.IsValidUsername(AccountName)) { //Reject the request if the username contained any banned characters AccountManagementPacketSenders.SendAccountRegistrationReply(ClientID, false, "The username you provided contained banned characters."); return; } if (!ValidInputCheckers.IsValidUsername(AccountPass)) { //Reject the request if the password contained any banned characters AccountManagementPacketSenders.SendAccountRegistrationReply(ClientID, false, ("The password you provided contained banned characters.")); return; } //Register the new account into the database and tell the client their request has been granted AccountsDatabase.RegisterNewAccount(AccountName, AccountPass); AccountManagementPacketSenders.SendAccountRegistrationReply(ClientID, true, "Account Registered Successfully."); }
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); } }
//Handles a users character data request public static void HandleCharacterDataRequest(int ClientID, ref NetworkPacket Packet) { //Log what we are doing here CommunicationLog.LogIn(ClientID + " Character Data Request."); //Make sure we are still connected to this client ClientConnection Client = ConnectionManager.GetClient(ClientID); if (Client == null) { //Ignore the request if we arent connected to this client anymore MessageLog.Print("ERROR: Cant find this clients network connection, no way to fullfil their Character Data Request."); return; } //Fulfil the users request AccountManagementPacketSenders.SendCharacterDataReply(ClientID, Client.Account.Username); }
//Handles alert from player letting us know they have performed an attack, checks if it hits anyone then updated their health public static void HandlePlayerAttackAlert(int ClientID, ref NetworkPacket Packet) { CommunicationLog.LogIn(ClientID + "Player Attack Alert."); //Get the client who performed this attack, make sure their connection is still active ClientConnection Client = ConnectionManager.GetClient(ClientID); if (Client == null) { //Ignore the request if we cant find their connection open MessageLog.Print("ERROR: Connection to this client could not be found, unable to handle their player attack alert."); Client.ConnectionDead = true; return; } //Flag the client as needing to perform an attack on the next physics update Client.Character.AttackPerformed = true; Client.Character.AttackPosition = Packet.ReadVector3(); }
//Handles a users character creation request public static void HandleCreateCharacterRequest(int ClientID, ref NetworkPacket Packet) { //Log what we are doing here CommunicationLog.LogIn(ClientID + " Character Creation Request."); //Fetch the name that has been provided for the new character string CharacterName = Packet.ReadString(); //Make sure we are still connected to this client ClientConnection Client = ConnectionManager.GetClient(ClientID); if (Client == null) { //Ignore the request if the connection could not be found MessageLog.Print("ERROR: " + ClientID + " network connection could not be found, ignoring their character creation request."); return; } //Make sure they provided a valid character name if (!ValidInputCheckers.IsValidCharacterName(CharacterName)) { //Reject the request if the provided character name contained any banned character AccountManagementPacketSenders.SendCreateCharacterReply(ClientID, false, "Character name provided contained banned characters."); return; } //Make sure the character name isnt already taken if (!CharactersDatabase.IsCharacterNameAvailable(CharacterName)) { //Reject the request if the name is already taken AccountManagementPacketSenders.SendCreateCharacterReply(ClientID, false, "That character name is already taken."); return; } //Register the new character into the database and then reload this clients account information from the database CharactersDatabase.SaveNewCharacter(Client.Account.Username, CharacterName); Client.Account = AccountsDatabase.GetAccountData(Client.Account.Username); //Tell the client their character creation request has been a success AccountManagementPacketSenders.SendCreateCharacterReply(ClientID, true, "Character Created."); }