Ejemplo n.º 1
0
        private void SubmitAccount(RelayInfo info, bool submit, int command)
        {
            string oldMessages    = Messages;
            string oldAccountName = accountName;

            if (submit)
            {
                if (AddAccount)
                {
                    MessagesTitle = "Submit Account";
                }
                else
                {
                    MessagesTitle = "Update Account";
                }

                Messages = null;
            }

            bool invalid = false;

            if (pg == 1)
            {
                accountName = info.GetTextEntry(1).Text;

                int switchNum = MC.GetSwitchNum(info, 1, 4);
                accessSwitch = (Access)switchNum + 1;

                accountsMgmtSwitch = info.IsSwitched(5);
                systemConfigSwitch = info.IsSwitched(6);
            }

// *************** First Check ***************

            if (submit)
            {
                if (oldAccountName == "default user" && accountName != oldAccountName.ToLower())
                {
                    invalid  = true;
                    Messages = "You cannot change the name of the default user account.";
                }
                else if (oldAccountName != "default user" && accountName.ToLower() == "default user")
                {
                    invalid  = true;
                    Messages = "You cannot add default user as an account. The default user account is hard-coded and already exists.";
                }
                else if (((Account)gumpMobile.Account).Username.ToLower() == accountName)
                {
                    invalid  = true;
                    Messages = "You cannot add your own account into the system.";
                }
                else if (MC.AccountNotExist(accountName))
                {
                    invalid  = true;
                    Messages = String.Format("That account does not exist and cannot be {0}.", AddAccount ? "added" : "updated");
                }
                else if (MC.AccountBanned(accountName))
                {
                    invalid  = true;
                    Messages = "That account is banned and cannot be added for security reasons.";
                }
                else if (MC.AccountNoCommandAccess(accountName))
                {
                    invalid  = true;
                    Messages = String.Format("That account does not have access to the \"{0}MegaSpawner\" command and cannot be added.", Server.Commands.CommandPrefix);
                }
            }

// *************** Final Check ***************

            if (invalid)
            {
                UpdatePage(command);

                return;
            }

// *************** Applying Settings ***************

            if (AddAccount && submit)
            {
                if (MC.AccountExists(accountName))
                {
                    Messages = "That account is already in the Mega Spawner System.";

                    UpdatePage(command);

                    return;
                }

                MC.AccountsList.Add(accountName);
                MC.AccessList.Add(accessSwitch);

                ArrayList List = new ArrayList();

                List.Add(accountsMgmtSwitch);
                List.Add(systemConfigSwitch);

                MC.AdminMenuAccessList.Add(List);
                MC.AccountEditors.Add(null);

                Messages = String.Format("Account \"{0}\" has been added.", accountName);
            }
            else if (submit)
            {
                if (oldAccountName != accountName && MC.AccountExists(accountName))
                {
                    Messages = "That account is already in the Mega Spawner System.";

                    UpdatePage(command);

                    return;
                }

                MC.AccountsList[index] = accountName;
                MC.AccessList[index]   = accessSwitch;

                ArrayList List = new ArrayList();

                List.Add(accountsMgmtSwitch);
                List.Add(systemConfigSwitch);

                MC.AdminMenuAccessList[index] = List;
                MC.AccountEditors[index]      = null;

                Messages = String.Format("Account \"{0}\" has been updated.", accountName);
            }

            if (submit)
            {
                MC.SaveAccountsAccess();

                if (!AddAccount)
                {
                    MC.AccountEditors[index] = null;
                }

                SetArgsList();

                gumpMobile.SendGump(new AccountsManagementGump(gumpMobile, ArgsList));
            }
            else
            {
                UpdatePage(command);
            }
        }