コード例 #1
0
        private void btnLogIn_Click(object sender, EventArgs e)
        {
            string username = txtUserName.Text;
            string password = txtPassword.Text;

            var  uv        = new UserValidation();
            bool validated = uv.ValidateUsername(username);

            if (validated)
            {
                var ad = new AccountsDatabase();
                //get relevant user information needed to log in
                var    userInformation = ad.GetAccountPassword(username, password);
                bool   passwordMatch   = userInformation.Item1; //does password match hashed password in database
                string currentUserId   = userInformation.Item2;
                string accessLevel     = userInformation.Item3;

                if (passwordMatch)
                {
                    MessageBox.Show("Log in Successful");
                    Close();

                    myForm.SetUserName(username, accessLevel, currentUserId);
                }
                else if (string.IsNullOrEmpty(currentUserId) || string.IsNullOrEmpty(accessLevel) || string.IsNullOrEmpty(password))
                {
                    MessageBox.Show("Username was not found or the wrong password was entered");
                }
            }
            else
            {
                MessageBox.Show("Username entered is not valid");
            }
        }
コード例 #2
0
        //Tries using the command arguments for performing a database purge
        private void TryPurgeDatabase(string[] Input)
        {
            //Log what is happening here
            MessageLog.Print("Purging all entries from all databases.");

            //Purge all the databases
            AccountsDatabase.PurgeAccounts();
            ActionBarsDatabase.PurgeActionBars();
            CharactersDatabase.PurgeCharacters();
            EquipmentsDatabase.PurgeEquipments();
            InventoriesDatabase.PurgeInventories();
        }
コード例 #3
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.");
        }
コード例 #4
0
        private void AddOrder_Load(object sender, System.EventArgs e)
        {
            //which product dropdown setup
            boxWhichProduct.DropDownStyle = ComboBoxStyle.DropDownList;
            boxWhichProduct.Items.Add("Pick a game");
            boxWhichProduct.SelectedIndex  = 0;
            boxWhichProduct.DropDownHeight = boxWhichProduct.Font.Height * 10;  //only allow 10 items at a time while scrolling

            //which location dropdown setup
            boxWhichLocation.DropDownStyle = ComboBoxStyle.DropDownList;
            boxWhichLocation.Items.Add("Pickup location");
            boxWhichLocation.SelectedIndex = 0;

            //fake locations for pickup for ordering purposes
            boxWhichLocation.Items.Add("415 19th Street SE, Calgary");
            boxWhichLocation.Items.Add("2991 13th Avenue NE, Calgary");
            boxWhichLocation.Items.Add("17-299 2nd Street NW, Calgary");

            //find product in order list and add to dropdown
            foreach (var p in ProductList)
            {
                int timeSinceRelease = (DateTime.Now.Year - p.ReleaseDate.Year) * 12 + DateTime.Now.Month - p.ReleaseDate.Month;
                //only add to games that can be ordered if there's a quantity greater then 0 or it's a PreOrder game
                if (p.QuantityInStock > 0 || timeSinceRelease < 0)
                {
                    boxWhichProduct.Items.Add($"{p.GameID} ~ {p.Title}");
                }
            }

            //don't allow user to edit these inputs
            txtEmail.Enabled = false;
            txtName.Enabled  = false;
            txtPrice.Enabled = false;

            //auto fill disabled inputs with logged in users information
            var  ad           = new AccountsDatabase();;
            var  customerInfo = ad.GetAccountInformation(CustomerID);
            bool success      = customerInfo.Item1;
            var  user         = customerInfo.Item2;

            if (success)
            {
                txtName.Text  = user.Name;
                txtEmail.Text = user.Email;
            }

            MessageBox.Show("Please note that any orders not picked up within 30 days will be automatically cancelled.");
        }
コード例 #5
0
        // TODO
        private static void DefaultMain()
        {
            var loader = new JsonConfigLoader();
            var config = new DatabasesConfig
            {
                Accounts = new DatabaseSettings
                {
                    FileName = "accounts.db",
                    Password = "******"
                },

                Characters = new DatabaseSettings
                {
                    FileName = "characters.db",
                    Password = null
                },

                World = new DatabaseSettings
                {
                    FileName = "world.db",
                    Password = null
                }
            };

            var accounts = new AccountsDatabase(config.Accounts);

            try
            {
                config = loader.Load <DatabasesConfig>("database");
                ConnectToMasterRouterAsync(IPAddress.Loopback, 12000).RunAsync();
                Console.ReadLine();
            }
            catch (DirectoryNotFoundException ex)
            {
                Console.Error.WriteLine("Config directory not found, attempting to create default file...");
                Directory.CreateDirectory(loader.RootDirectory);
                loader.CreateDefault("database", config);
            }
            catch (FileNotFoundException ex)
            {
                Console.Error.WriteLine("Config file not found, attempting to create default file...");
                loader.CreateDefault("database", config);
            }
            finally
            {
                accounts.Dispose();
            }
        }
コード例 #6
0
        //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.");
        }
コード例 #7
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.");
        }
コード例 #8
0
        //add new notifications if they don't yet exist in our notifications table
        public bool AddNewNotification(string message, string messageType, int productId)
        {
            bool success = false;

            //add to list and update database if the message is new
            if (!NotificationList.Any(m => m.MessageType.Contains(messageType) && m.ProductId.ToString().Contains(productId.ToString())))
            {
                var notification = new Notifications(message, false, messageType, productId);
                //add message to notifications database table so it can be dismissed
                var ad = new AccountsDatabase();
                success = ad.InsertAccountsNotifications(notification);

                //add to list if notifications have been successfully added to database
                if (success)
                {
                    NotificationList.Add(notification);
                }
            }

            return(success);
        }
コード例 #9
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);
        }
コード例 #10
0
        //so that an admin is able to choose a notification and dismiss it
        private void btnDismissNotification_Click(object sender, EventArgs e)
        {
            string message = lbNotifications.Text;

            //try to update dismissed value in notifications table, if successful then remove from list
            var  ad      = new AccountsDatabase();
            bool success = ad.UpdateNotificationsDismissed(message, true);

            if (success && lbNotifications.SelectedIndex >= 0)
            {
                lbNotifications.Items.Remove(message);
                MessageBox.Show("Notification has been dismissed.");
            }
            else if (lbNotifications.SelectedIndex <= -1)
            {
                MessageBox.Show("There was no notification selected");
            }
            else
            {
                MessageBox.Show("There was an issue while trying to dismiss this notification.");
            }
        }