remoteadmin system changes

This commit is contained in:
mark 2011-12-18 05:20:05 +00:00
parent 28f3bd15b2
commit ff10a7cfb8
4 changed files with 265 additions and 51 deletions

View file

@ -70,6 +70,8 @@ namespace Server.RemoteAdmin
foreach ( Account a in Accounts.GetAccounts() )
{
if ( !CanAccessAccount( state.Account, a ) ) continue;
switch ( type )
{
case AcctSearchType.Username:
@ -106,20 +108,36 @@ namespace Server.RemoteAdmin
}
}
static bool CanAccessAccount( IAccount beholder, IAccount beheld )
{
return beholder.AccessLevel == AccessLevel.Owner || beheld.AccessLevel < beholder.AccessLevel; // Cannot see accounts of equal or greater access level unless Owner
}
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" ) );
}
@ -127,47 +145,96 @@ namespace Server.RemoteAdmin
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 )
a = new Account( username, pass );
else if ( pass != "(hidden)" )
a.SetPassword( pass );
if ( a != state.Account )
if ( a != null && !CanAccessAccount( state.Account, a ) )
{
a.AccessLevel = (AccessLevel)pvSrc.ReadByte();
a.Banned = pvSrc.ReadBoolean();
state.Send( new MessageBoxMessage( "You cannot edit an account with an access level greater than or equal to your own.", "Account Access Exception" ) );
}
else
{
pvSrc.ReadInt16();//skip both
state.Send( new MessageBoxMessage( "Warning: When editing your own account, account status and accesslevel 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 );
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
invalid = true;
}
if ( list.Count > 0 )
a.IPRestrictions = (string[])list.ToArray( typeof( string ) );
else
a.IPRestrictions = new string[0];
{
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" ) );
}
if ( invalid )
state.Send( new MessageBoxMessage( "Warning: one or more of the IP Restrictions you specified was not valid.", "Invalid IP Restriction" ) );
state.Send( new MessageBoxMessage( "Account updated successfully.", "Account Updated" ) );
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" ) );
}
}
}
}