Пример #1
0
        private static void RemoveAccount(NetState state, PacketReader pvSrc)
        {
            if (state.Account.AccessLevel < AccessLevel.Administrator)
            {
                state.Send(new MessageBoxMessage("You do not have permission to delete accounts.", "Account Access Exception"));
                return;
            }

            IAccount a = Accounts.GetAccount(pvSrc.ReadString());

            if (a == null)
            {
                state.Send(new MessageBoxMessage("The account could not be found (and thus was not deleted).", "Account Not Found"));
            }
            else if (!CanAccessAccount(state.Account, a))
            {
                state.Send(new MessageBoxMessage("You cannot delete an account with an access level greater than or equal to your own.", "Account Access Exception"));
            }
            else if (a == state.Account)
            {
                state.Send(new MessageBoxMessage("You may not delete your own account.", "Not Allowed"));
            }
            else
            {
                RemoteAdminLogging.WriteLine(state, "Deleted Account {0}", a);
                a.Delete();
                state.Send(new MessageBoxMessage("The requested account (and all it's characters) has been deleted.", "Account Deleted"));
            }
        }
Пример #2
0
        private static void UpdateAccount(NetState state, PacketReader pvSrc)
        {
            if (state.Account.AccessLevel < AccessLevel.Administrator)
            {
                state.Send(new MessageBoxMessage("You do not have permission to edit accounts.", "Account Access Exception"));
                return;
            }

            string username = pvSrc.ReadString();
            string pass     = pvSrc.ReadString();

            Account a = Accounts.GetAccount(username) as Account;

            if (a != null && !CanAccessAccount(state.Account, a))
            {
                state.Send(new MessageBoxMessage("You cannot edit an account with an access level greater than or equal to your own.", "Account Access Exception"));
            }
            else
            {
                bool        CreatedAccount = false;
                bool        UpdatedPass    = false;
                bool        oldbanned      = a == null ? false : a.Banned;
                AccessLevel oldAcessLevel  = a == null ? 0 : a.AccessLevel;

                if (a == null)
                {
                    a = new Account(username, pass);
                    CreatedAccount = true;
                }
                else if (pass != "(hidden)")
                {
                    a.SetPassword(pass);
                    UpdatedPass = true;
                }

                if (a != state.Account)
                {
                    AccessLevel newAccessLevel = (AccessLevel)pvSrc.ReadByte();
                    if (a.AccessLevel != newAccessLevel)
                    {
                        if (newAccessLevel >= state.Account.AccessLevel)
                        {
                            state.Send(new MessageBoxMessage("Warning: You may not set an access level greater than or equal to your own.", "Account Access Level update denied."));
                        }
                        else
                        {
                            a.AccessLevel = newAccessLevel;
                        }
                    }
                    bool newBanned = pvSrc.ReadBoolean();
                    if (newBanned != a.Banned)
                    {
                        oldbanned = a.Banned;
                        a.Banned  = newBanned;
                        a.Comments.Add(new AccountComment(state.Account.Username, newBanned ? "Banned via Remote Admin" : "Unbanned via Remote Admin"));
                    }
                }
                else
                {
                    pvSrc.ReadInt16();//skip both
                    state.Send(new MessageBoxMessage("Warning: When editing your own account, Account Status and Access Level cannot be changed.", "Editing Own Account"));
                }

                ArrayList list    = new ArrayList();
                ushort    length  = pvSrc.ReadUInt16();
                bool      invalid = false;
                for (int i = 0; i < length; i++)
                {
                    string add = pvSrc.ReadString();
                    if (Utility.IsValidIP(add))
                    {
                        list.Add(add);
                    }
                    else
                    {
                        invalid = true;
                    }
                }

                if (list.Count > 0)
                {
                    a.IPRestrictions = (string[])list.ToArray(typeof(string));
                }
                else
                {
                    a.IPRestrictions = new string[0];
                }

                if (invalid)
                {
                    state.Send(new MessageBoxMessage("Warning: one or more of the IP Restrictions you specified was not valid.", "Invalid IP Restriction"));
                }

                if (CreatedAccount)
                {
                    RemoteAdminLogging.WriteLine(state, "Created account {0} with Access Level {1}", a.Username, a.AccessLevel);
                }
                else
                {
                    string changes = string.Empty;
                    if (UpdatedPass)
                    {
                        changes += " Password Changed.";
                    }
                    if (oldAcessLevel != a.AccessLevel)
                    {
                        changes = string.Format("{0} Access level changed from {1} to {2}.", changes, oldAcessLevel, a.AccessLevel);
                    }
                    if (oldbanned != a.Banned)
                    {
                        changes += a.Banned ? " Banned." : " Unbanned.";
                    }
                    RemoteAdminLogging.WriteLine(state, "Updated account {0}:{1}", a.Username, changes);
                }

                state.Send(new MessageBoxMessage("Account updated successfully.", "Account Updated"));
            }
        }