//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."); }
//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."); }