コード例 #1
0
        //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.");
        }
コード例 #2
0
        //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.");
        }
コード例 #3
0
        //Tries using the command arguments for performing an account info search
        private void TryAccountInfoSearch(string[] Input)
        {
            //Get the accounts name
            string AccountName = Input[1];

            //Make sure the account exists
            if (!AccountsDatabase.DoesAccountExist(AccountName))
            {
                MessageLog.Print("ERROR: There is no account called " + AccountName + ", no information to display.");
                return;
            }

            //Get the accounts information from the database
            AccountData Data = AccountsDatabase.GetAccountData(AccountName);

            //Define a string display all the accounts info, then display it all in the message window
            string AccountInfo = "ACCOUNT INFO: " + AccountName + " has " +
                                 Data.CharacterCount + (Data.CharacterCount == 1 ? " character" : " characters");

            switch (Data.CharacterCount)
            {
            case (0):
                AccountInfo += ".";
                break;

            case (1):
                AccountInfo += ", named " + Data.FirstCharacterName;
                break;

            case (2):
                AccountInfo += ", named " + Data.FirstCharacterName + " and " + Data.SecondCharacterName;
                break;

            case (3):
                AccountInfo += ", named " + Data.FirstCharacterName + ", " + Data.SecondCharacterName + " and " + Data.ThirdCharacterName;
                break;
            }
            AccountInfo += ".";
            MessageLog.Print(AccountInfo);
        }