Fixes code according to modern code style. Fixes a few expression bugs.
This commit is contained in:
parent
89eea25e5f
commit
970fd563b2
3324 changed files with 441118 additions and 433755 deletions
|
|
@ -1,277 +1,283 @@
|
|||
using System;
|
||||
using System.Text;
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using Server.Accounting;
|
||||
using Server.Items;
|
||||
using Server.Misc;
|
||||
using Server.Network;
|
||||
|
||||
namespace Server.RemoteAdmin
|
||||
{
|
||||
public class AdminNetwork
|
||||
{
|
||||
private const string ProtocolVersion = "2";
|
||||
public class AdminNetwork
|
||||
{
|
||||
private const string ProtocolVersion = "2";
|
||||
|
||||
private static ArrayList m_Auth = new ArrayList();
|
||||
private static bool m_NewLine = true;
|
||||
private static StringBuilder m_ConsoleData = new StringBuilder();
|
||||
private const string DateFormat = "MMMM dd hh:mm:ss.f tt";
|
||||
|
||||
private const string DateFormat = "MMMM dd hh:mm:ss.f tt";
|
||||
private static ArrayList m_Auth = new ArrayList();
|
||||
private static bool m_NewLine = true;
|
||||
private static StringBuilder m_ConsoleData = new StringBuilder();
|
||||
|
||||
public static void Configure()
|
||||
{
|
||||
PacketHandlers.Register( 0xF1, 0, false, OnReceive );
|
||||
public static void Configure()
|
||||
{
|
||||
PacketHandlers.Register(0xF1, 0, false, OnReceive);
|
||||
|
||||
#if !MONO
|
||||
Core.MultiConsoleOut.Add( new EventTextWriter( OnConsoleChar, OnConsoleLine, OnConsoleString ) );
|
||||
Core.MultiConsoleOut.Add(new EventTextWriter(OnConsoleChar, OnConsoleLine, OnConsoleString));
|
||||
#endif
|
||||
Timer.DelayCall( TimeSpan.FromMinutes( 2.5 ), TimeSpan.FromMinutes( 2.5 ), CleanUp );
|
||||
}
|
||||
Timer.DelayCall(TimeSpan.FromMinutes(2.5), TimeSpan.FromMinutes(2.5), CleanUp);
|
||||
}
|
||||
|
||||
public static void OnConsoleString( string str )
|
||||
{
|
||||
string outStr;
|
||||
if ( m_NewLine )
|
||||
{
|
||||
outStr = $"[{DateTime.UtcNow.ToString(DateFormat)}]: {str}";
|
||||
m_NewLine = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
outStr = str;
|
||||
}
|
||||
public static void OnConsoleString(string str)
|
||||
{
|
||||
string outStr;
|
||||
if (m_NewLine)
|
||||
{
|
||||
outStr = $"[{DateTime.UtcNow.ToString(DateFormat)}]: {str}";
|
||||
m_NewLine = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
outStr = str;
|
||||
}
|
||||
|
||||
m_ConsoleData.Append( outStr );
|
||||
RoughTrimConsoleData();
|
||||
m_ConsoleData.Append(outStr);
|
||||
RoughTrimConsoleData();
|
||||
|
||||
SendToAll( outStr );
|
||||
}
|
||||
SendToAll(outStr);
|
||||
}
|
||||
|
||||
public static void OnConsoleChar( char ch )
|
||||
{
|
||||
if ( m_NewLine )
|
||||
{
|
||||
string outStr;
|
||||
outStr = $"[{DateTime.UtcNow.ToString(DateFormat)}]: {ch}";
|
||||
public static void OnConsoleChar(char ch)
|
||||
{
|
||||
if (m_NewLine)
|
||||
{
|
||||
string outStr;
|
||||
outStr = $"[{DateTime.UtcNow.ToString(DateFormat)}]: {ch}";
|
||||
|
||||
m_ConsoleData.Append( outStr );
|
||||
SendToAll( outStr );
|
||||
m_ConsoleData.Append(outStr);
|
||||
SendToAll(outStr);
|
||||
|
||||
m_NewLine = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_ConsoleData.Append( ch );
|
||||
SendToAll( ch );
|
||||
}
|
||||
m_NewLine = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_ConsoleData.Append(ch);
|
||||
SendToAll(ch);
|
||||
}
|
||||
|
||||
RoughTrimConsoleData();
|
||||
}
|
||||
RoughTrimConsoleData();
|
||||
}
|
||||
|
||||
public static void OnConsoleLine( string line )
|
||||
{
|
||||
string outStr;
|
||||
if ( m_NewLine )
|
||||
outStr = $"[{DateTime.UtcNow.ToString(DateFormat)}]: {line}{Console.Out.NewLine}";
|
||||
else
|
||||
outStr = $"{line}{Console.Out.NewLine}";
|
||||
public static void OnConsoleLine(string line)
|
||||
{
|
||||
string outStr;
|
||||
if (m_NewLine)
|
||||
outStr = $"[{DateTime.UtcNow.ToString(DateFormat)}]: {line}{Console.Out.NewLine}";
|
||||
else
|
||||
outStr = $"{line}{Console.Out.NewLine}";
|
||||
|
||||
m_ConsoleData.Append( outStr );
|
||||
RoughTrimConsoleData();
|
||||
m_ConsoleData.Append(outStr);
|
||||
RoughTrimConsoleData();
|
||||
|
||||
SendToAll( outStr );
|
||||
SendToAll(outStr);
|
||||
|
||||
m_NewLine = true;
|
||||
}
|
||||
m_NewLine = true;
|
||||
}
|
||||
|
||||
static void SendToAll( string outStr )
|
||||
{
|
||||
SendToAll( new ConsoleData( outStr ) );
|
||||
}
|
||||
private static void SendToAll(string outStr)
|
||||
{
|
||||
SendToAll(new ConsoleData(outStr));
|
||||
}
|
||||
|
||||
static void SendToAll( char ch )
|
||||
{
|
||||
SendToAll( new ConsoleData( ch ) );
|
||||
}
|
||||
private static void SendToAll(char ch)
|
||||
{
|
||||
SendToAll(new ConsoleData(ch));
|
||||
}
|
||||
|
||||
static void SendToAll( ConsoleData packet )
|
||||
{
|
||||
packet.Acquire();
|
||||
for ( int i = 0; i < m_Auth.Count; i++ )
|
||||
((NetState)m_Auth[i]).Send( packet );
|
||||
packet.Release();
|
||||
}
|
||||
private static void SendToAll(ConsoleData packet)
|
||||
{
|
||||
packet.Acquire();
|
||||
for (int i = 0; i < m_Auth.Count; i++)
|
||||
((NetState)m_Auth[i]).Send(packet);
|
||||
packet.Release();
|
||||
}
|
||||
|
||||
static void RoughTrimConsoleData()
|
||||
{
|
||||
if ( m_ConsoleData.Length >= 4096 )
|
||||
m_ConsoleData.Remove( 0, 2048 );
|
||||
}
|
||||
private static void RoughTrimConsoleData()
|
||||
{
|
||||
if (m_ConsoleData.Length >= 4096)
|
||||
m_ConsoleData.Remove(0, 2048);
|
||||
}
|
||||
|
||||
static void TightTrimConsoleData()
|
||||
{
|
||||
if ( m_ConsoleData.Length > 1024 )
|
||||
m_ConsoleData.Remove( 0, m_ConsoleData.Length - 1024 );
|
||||
}
|
||||
private static void TightTrimConsoleData()
|
||||
{
|
||||
if (m_ConsoleData.Length > 1024)
|
||||
m_ConsoleData.Remove(0, m_ConsoleData.Length - 1024);
|
||||
}
|
||||
|
||||
public static void OnReceive( NetState state, PacketReader pvSrc )
|
||||
{
|
||||
byte cmd = pvSrc.ReadByte();
|
||||
if ( cmd == 0x02 )
|
||||
{
|
||||
Authenticate( state, pvSrc );
|
||||
}
|
||||
else if ( cmd == 0xFE )
|
||||
{
|
||||
state.Send( new CompactServerInfo() );
|
||||
state.Dispose();
|
||||
}
|
||||
else if ( cmd == 0xFF )
|
||||
{
|
||||
string statStr =
|
||||
$", Name={Misc.ServerList.ServerName}, Age={(int) (DateTime.UtcNow - Items.Clock.ServerStart).TotalHours}, Clients={NetState.Instances.Count}, Items={World.Items.Count}, Chars={World.Mobiles.Count}, Mem={(int) (GC.GetTotalMemory(false) / 1024)}K, Ver={ProtocolVersion}";
|
||||
state.Send( new UOGInfo( statStr ) );
|
||||
state.Dispose();
|
||||
}
|
||||
else if ( !IsAuth( state ) )
|
||||
{
|
||||
Console.WriteLine( "ADMIN: Unauthorized packet from {0}, disconnecting", state );
|
||||
Disconnect( state );
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( !RemoteAdminHandlers.Handle( cmd, state, pvSrc ) )
|
||||
Disconnect( state );
|
||||
}
|
||||
}
|
||||
public static void OnReceive(NetState state, PacketReader pvSrc)
|
||||
{
|
||||
byte cmd = pvSrc.ReadByte();
|
||||
if (cmd == 0x02)
|
||||
{
|
||||
Authenticate(state, pvSrc);
|
||||
}
|
||||
else if (cmd == 0xFE)
|
||||
{
|
||||
state.Send(new CompactServerInfo());
|
||||
state.Dispose();
|
||||
}
|
||||
else if (cmd == 0xFF)
|
||||
{
|
||||
string statStr =
|
||||
$", Name={ServerList.ServerName}, Age={(int)(DateTime.UtcNow - Clock.ServerStart).TotalHours}, Clients={NetState.Instances.Count}, Items={World.Items.Count}, Chars={World.Mobiles.Count}, Mem={(int)(GC.GetTotalMemory(false) / 1024)}K, Ver={ProtocolVersion}";
|
||||
state.Send(new UOGInfo(statStr));
|
||||
state.Dispose();
|
||||
}
|
||||
else if (!IsAuth(state))
|
||||
{
|
||||
Console.WriteLine("ADMIN: Unauthorized packet from {0}, disconnecting", state);
|
||||
Disconnect(state);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!RemoteAdminHandlers.Handle(cmd, state, pvSrc))
|
||||
Disconnect(state);
|
||||
}
|
||||
}
|
||||
|
||||
private static void DelayedDisconnect( NetState state )
|
||||
{
|
||||
Timer.DelayCall( TimeSpan.FromSeconds( 15.0 ), new TimerStateCallback( Disconnect ), state );
|
||||
}
|
||||
private static void DelayedDisconnect(NetState state)
|
||||
{
|
||||
Timer.DelayCall(TimeSpan.FromSeconds(15.0), new TimerStateCallback(Disconnect), state);
|
||||
}
|
||||
|
||||
private static void Disconnect( object state )
|
||||
{
|
||||
m_Auth.Remove( state );
|
||||
((NetState)state).Dispose();
|
||||
}
|
||||
private static void Disconnect(object state)
|
||||
{
|
||||
m_Auth.Remove(state);
|
||||
((NetState)state).Dispose();
|
||||
}
|
||||
|
||||
public static void Authenticate( NetState state, PacketReader pvSrc )
|
||||
{
|
||||
string user = pvSrc.ReadString( 30 );
|
||||
string pw = pvSrc.ReadString( 30 );
|
||||
public static void Authenticate(NetState state, PacketReader pvSrc)
|
||||
{
|
||||
string user = pvSrc.ReadString(30);
|
||||
string pw = pvSrc.ReadString(30);
|
||||
|
||||
if ( !(Accounts.GetAccount( user ) is Account a) )
|
||||
{
|
||||
state.Send( new Login( LoginResponse.NoUser ) );
|
||||
Console.WriteLine( "ADMIN: Invalid username '{0}' from {1}", user, state );
|
||||
DelayedDisconnect( state );
|
||||
}
|
||||
else if ( !a.HasAccess( state ) )
|
||||
{
|
||||
state.Send( new Login( LoginResponse.BadIP ) );
|
||||
Console.WriteLine( "ADMIN: Access to '{0}' from {1} denied.", user, state );
|
||||
DelayedDisconnect( state );
|
||||
}
|
||||
else if ( !a.CheckPassword( pw ) )
|
||||
{
|
||||
state.Send( new Login( LoginResponse.BadPass ) );
|
||||
Console.WriteLine( "ADMIN: Invalid password for user '{0}' from {1}", user, state );
|
||||
DelayedDisconnect( state );
|
||||
}
|
||||
else if ( a.AccessLevel < AccessLevel.Administrator || a.Banned )
|
||||
{
|
||||
Console.WriteLine( "ADMIN: Account '{0}' does not have admin access. Connection Denied.", user );
|
||||
state.Send( new Login( LoginResponse.NoAccess ) );
|
||||
DelayedDisconnect( state );
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine( "ADMIN: Access granted to '{0}' from {1}", user, state );
|
||||
state.Account = a;
|
||||
a.LogAccess( state );
|
||||
a.LastLogin = DateTime.UtcNow;
|
||||
if (!(Accounts.GetAccount(user) is Account a))
|
||||
{
|
||||
state.Send(new Login(LoginResponse.NoUser));
|
||||
Console.WriteLine("ADMIN: Invalid username '{0}' from {1}", user, state);
|
||||
DelayedDisconnect(state);
|
||||
}
|
||||
else if (!a.HasAccess(state))
|
||||
{
|
||||
state.Send(new Login(LoginResponse.BadIP));
|
||||
Console.WriteLine("ADMIN: Access to '{0}' from {1} denied.", user, state);
|
||||
DelayedDisconnect(state);
|
||||
}
|
||||
else if (!a.CheckPassword(pw))
|
||||
{
|
||||
state.Send(new Login(LoginResponse.BadPass));
|
||||
Console.WriteLine("ADMIN: Invalid password for user '{0}' from {1}", user, state);
|
||||
DelayedDisconnect(state);
|
||||
}
|
||||
else if (a.AccessLevel < AccessLevel.Administrator || a.Banned)
|
||||
{
|
||||
Console.WriteLine("ADMIN: Account '{0}' does not have admin access. Connection Denied.", user);
|
||||
state.Send(new Login(LoginResponse.NoAccess));
|
||||
DelayedDisconnect(state);
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("ADMIN: Access granted to '{0}' from {1}", user, state);
|
||||
state.Account = a;
|
||||
a.LogAccess(state);
|
||||
a.LastLogin = DateTime.UtcNow;
|
||||
|
||||
state.Send( new Login( LoginResponse.OK ) );
|
||||
TightTrimConsoleData();
|
||||
state.Send( Compress( new ConsoleData( m_ConsoleData.ToString() ) ) );
|
||||
m_Auth.Add( state );
|
||||
}
|
||||
}
|
||||
state.Send(new Login(LoginResponse.OK));
|
||||
TightTrimConsoleData();
|
||||
state.Send(Compress(new ConsoleData(m_ConsoleData.ToString())));
|
||||
m_Auth.Add(state);
|
||||
}
|
||||
}
|
||||
|
||||
public static bool IsAuth( NetState state )
|
||||
{
|
||||
return m_Auth.Contains( state );
|
||||
}
|
||||
public static bool IsAuth(NetState state)
|
||||
{
|
||||
return m_Auth.Contains(state);
|
||||
}
|
||||
|
||||
private static void CleanUp()
|
||||
{//remove dead instances from m_Auth
|
||||
ArrayList list = new ArrayList();
|
||||
for (int i=0;i<m_Auth.Count;i++)
|
||||
{
|
||||
NetState ns = (NetState) m_Auth[i];
|
||||
if ( ns.Running )
|
||||
list.Add( ns );
|
||||
}
|
||||
private static void CleanUp()
|
||||
{
|
||||
//remove dead instances from m_Auth
|
||||
ArrayList list = new ArrayList();
|
||||
for (int i = 0; i < m_Auth.Count; i++)
|
||||
{
|
||||
NetState ns = (NetState)m_Auth[i];
|
||||
if (ns.Running)
|
||||
list.Add(ns);
|
||||
}
|
||||
|
||||
m_Auth = list;
|
||||
}
|
||||
m_Auth = list;
|
||||
}
|
||||
|
||||
public static Packet Compress( Packet p )
|
||||
{
|
||||
int length;
|
||||
byte[] source = p.Compile( false, out length );
|
||||
public static Packet Compress(Packet p)
|
||||
{
|
||||
int length;
|
||||
byte[] source = p.Compile(false, out length);
|
||||
|
||||
if ( length > 100 && length < 60000 )
|
||||
{
|
||||
byte[] dest = new byte[(int)(length * 1.001) + 10];
|
||||
int destSize = dest.Length;
|
||||
if (length > 100 && length < 60000)
|
||||
{
|
||||
byte[] dest = new byte[(int)(length * 1.001) + 10];
|
||||
int destSize = dest.Length;
|
||||
|
||||
ZLibError error = Compression.Pack( dest, ref destSize, source, length, ZLibQuality.Default );
|
||||
ZLibError error = Compression.Pack(dest, ref destSize, source, length, ZLibQuality.Default);
|
||||
|
||||
if ( error != ZLibError.Okay )
|
||||
{
|
||||
Console.WriteLine( "WARNING: Unable to compress admin packet, zlib error: {0}", error );
|
||||
return p;
|
||||
}
|
||||
if (error != ZLibError.Okay)
|
||||
{
|
||||
Console.WriteLine("WARNING: Unable to compress admin packet, zlib error: {0}", error);
|
||||
return p;
|
||||
}
|
||||
|
||||
return new AdminCompressedPacket( dest, destSize, length );
|
||||
}
|
||||
return new AdminCompressedPacket(dest, destSize, length);
|
||||
}
|
||||
|
||||
return p;
|
||||
}
|
||||
}
|
||||
return p;
|
||||
}
|
||||
}
|
||||
|
||||
public class EventTextWriter : System.IO.TextWriter
|
||||
{
|
||||
public delegate void OnConsoleChar( char ch );
|
||||
public delegate void OnConsoleLine( string line );
|
||||
public delegate void OnConsoleStr( string str );
|
||||
public class EventTextWriter : TextWriter
|
||||
{
|
||||
public delegate void OnConsoleChar(char ch);
|
||||
|
||||
private OnConsoleChar m_OnChar;
|
||||
private OnConsoleLine m_OnLine;
|
||||
private OnConsoleStr m_OnStr;
|
||||
public delegate void OnConsoleLine(string line);
|
||||
|
||||
public EventTextWriter( OnConsoleChar onChar, OnConsoleLine onLine, OnConsoleStr onStr )
|
||||
{
|
||||
m_OnChar = onChar;
|
||||
m_OnLine = onLine;
|
||||
m_OnStr = onStr;
|
||||
}
|
||||
public delegate void OnConsoleStr(string str);
|
||||
|
||||
public override void Write( char ch )
|
||||
{
|
||||
m_OnChar?.Invoke( ch );
|
||||
}
|
||||
private OnConsoleChar m_OnChar;
|
||||
private OnConsoleLine m_OnLine;
|
||||
private OnConsoleStr m_OnStr;
|
||||
|
||||
public override void Write( string str )
|
||||
{
|
||||
m_OnStr?.Invoke( str );
|
||||
}
|
||||
public EventTextWriter(OnConsoleChar onChar, OnConsoleLine onLine, OnConsoleStr onStr)
|
||||
{
|
||||
m_OnChar = onChar;
|
||||
m_OnLine = onLine;
|
||||
m_OnStr = onStr;
|
||||
}
|
||||
|
||||
public override void WriteLine( string line )
|
||||
{
|
||||
m_OnLine?.Invoke( line );
|
||||
}
|
||||
public override Encoding Encoding => Encoding.ASCII;
|
||||
|
||||
public override Encoding Encoding => Encoding.ASCII;
|
||||
}
|
||||
}
|
||||
public override void Write(char ch)
|
||||
{
|
||||
m_OnChar?.Invoke(ch);
|
||||
}
|
||||
|
||||
public override void Write(string str)
|
||||
{
|
||||
m_OnStr?.Invoke(str);
|
||||
}
|
||||
|
||||
public override void WriteLine(string line)
|
||||
{
|
||||
m_OnLine?.Invoke(line);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,234 +1,257 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using Server.Network;
|
||||
using Server.Accounting;
|
||||
using Server.Network;
|
||||
|
||||
namespace Server.RemoteAdmin
|
||||
{
|
||||
public class RemoteAdminHandlers
|
||||
{
|
||||
public enum AcctSearchType : byte
|
||||
{
|
||||
Username = 0,
|
||||
IP = 1,
|
||||
}
|
||||
public class RemoteAdminHandlers
|
||||
{
|
||||
public enum AcctSearchType : byte
|
||||
{
|
||||
Username = 0,
|
||||
IP = 1
|
||||
}
|
||||
|
||||
private static OnPacketReceive[] m_Handlers = new OnPacketReceive[256];
|
||||
private static OnPacketReceive[] m_Handlers = new OnPacketReceive[256];
|
||||
|
||||
static RemoteAdminHandlers()
|
||||
{
|
||||
//0x02 = login request, handled by AdminNetwork
|
||||
Register( 0x04, ServerInfoRequest );
|
||||
Register( 0x05, AccountSearch );
|
||||
Register( 0x06, RemoveAccount );
|
||||
Register( 0x07, UpdateAccount );
|
||||
}
|
||||
static RemoteAdminHandlers()
|
||||
{
|
||||
//0x02 = login request, handled by AdminNetwork
|
||||
Register(0x04, ServerInfoRequest);
|
||||
Register(0x05, AccountSearch);
|
||||
Register(0x06, RemoveAccount);
|
||||
Register(0x07, UpdateAccount);
|
||||
}
|
||||
|
||||
public static void Register( byte command, OnPacketReceive handler )
|
||||
{
|
||||
m_Handlers[command] = handler;
|
||||
}
|
||||
public static void Register(byte command, OnPacketReceive handler)
|
||||
{
|
||||
m_Handlers[command] = handler;
|
||||
}
|
||||
|
||||
public static bool Handle( byte command, NetState state, PacketReader pvSrc )
|
||||
{
|
||||
if ( m_Handlers[command] == null )
|
||||
{
|
||||
Console.WriteLine( "ADMIN: Invalid packet 0x{0:X2} from {1}, disconnecting", command, state );
|
||||
return false;
|
||||
}
|
||||
public static bool Handle(byte command, NetState state, PacketReader pvSrc)
|
||||
{
|
||||
if (m_Handlers[command] == null)
|
||||
{
|
||||
Console.WriteLine("ADMIN: Invalid packet 0x{0:X2} from {1}, disconnecting", command, state);
|
||||
return false;
|
||||
}
|
||||
|
||||
m_Handlers[command]( state, pvSrc );
|
||||
return true;
|
||||
}
|
||||
m_Handlers[command](state, pvSrc);
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void ServerInfoRequest( NetState state, PacketReader pvSrc )
|
||||
{
|
||||
state.Send( AdminNetwork.Compress( new ServerInfo() ) );
|
||||
}
|
||||
private static void ServerInfoRequest(NetState state, PacketReader pvSrc)
|
||||
{
|
||||
state.Send(AdminNetwork.Compress(new ServerInfo()));
|
||||
}
|
||||
|
||||
private static void AccountSearch( NetState state, PacketReader pvSrc )
|
||||
{
|
||||
AcctSearchType type = (AcctSearchType)pvSrc.ReadByte();
|
||||
string term = pvSrc.ReadString();
|
||||
private static void AccountSearch(NetState state, PacketReader pvSrc)
|
||||
{
|
||||
AcctSearchType type = (AcctSearchType)pvSrc.ReadByte();
|
||||
string term = pvSrc.ReadString();
|
||||
|
||||
if ( type == AcctSearchType.IP && !Utility.IsValidIP( term ) )
|
||||
{
|
||||
state.Send( new MessageBoxMessage( "Invalid search term.\nThe IP sent was not valid.", "Invalid IP" ) );
|
||||
return;
|
||||
}
|
||||
if (type == AcctSearchType.IP && !Utility.IsValidIP(term))
|
||||
{
|
||||
state.Send(new MessageBoxMessage("Invalid search term.\nThe IP sent was not valid.", "Invalid IP"));
|
||||
return;
|
||||
}
|
||||
|
||||
term = term.ToUpper();
|
||||
term = term.ToUpper();
|
||||
|
||||
ArrayList list = new ArrayList();
|
||||
ArrayList list = new ArrayList();
|
||||
|
||||
foreach ( Account a in Accounts.GetAccounts() )
|
||||
{
|
||||
if ( !CanAccessAccount( state.Account, a ) ) continue;
|
||||
foreach (Account a in Accounts.GetAccounts())
|
||||
{
|
||||
if (!CanAccessAccount(state.Account, a)) continue;
|
||||
|
||||
switch ( type )
|
||||
{
|
||||
case AcctSearchType.Username:
|
||||
{
|
||||
if ( a.Username.ToUpper().IndexOf( term ) != -1 )
|
||||
list.Add( a );
|
||||
break;
|
||||
}
|
||||
case AcctSearchType.IP:
|
||||
{
|
||||
for( int i=0;i<a.LoginIPs.Length;i++ )
|
||||
{
|
||||
if ( Utility.IPMatch( term, a.LoginIPs[i] ) )
|
||||
{
|
||||
list.Add( a );
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
switch (type)
|
||||
{
|
||||
case AcctSearchType.Username:
|
||||
{
|
||||
if (a.Username.ToUpper().IndexOf(term) != -1)
|
||||
list.Add(a);
|
||||
break;
|
||||
}
|
||||
case AcctSearchType.IP:
|
||||
{
|
||||
for (int i = 0; i < a.LoginIPs.Length; i++)
|
||||
if (Utility.IPMatch(term, a.LoginIPs[i]))
|
||||
{
|
||||
list.Add(a);
|
||||
break;
|
||||
}
|
||||
|
||||
if ( list.Count > 0 )
|
||||
{
|
||||
if ( list.Count <= 25 )
|
||||
state.Send( AdminNetwork.Compress( new AccountSearchResults( list ) ) );
|
||||
else
|
||||
state.Send( new MessageBoxMessage( "There were more than 25 matches to your search.\nNarrow the search parameters and try again.", "Too Many Results" ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
state.Send( new MessageBoxMessage( "There were no results to your search.\nPlease try again.", "No Matches" ) );
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
if (list.Count > 0)
|
||||
{
|
||||
if (list.Count <= 25)
|
||||
state.Send(AdminNetwork.Compress(new AccountSearchResults(list)));
|
||||
else
|
||||
state.Send(new MessageBoxMessage(
|
||||
"There were more than 25 matches to your search.\nNarrow the search parameters and try again.",
|
||||
"Too Many Results"));
|
||||
}
|
||||
else
|
||||
{
|
||||
state.Send(new MessageBoxMessage("There were no results to your search.\nPlease try again.", "No Matches"));
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
private 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
|
||||
}
|
||||
|
||||
IAccount a = Accounts.GetAccount( pvSrc.ReadString() );
|
||||
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;
|
||||
}
|
||||
|
||||
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" ) );
|
||||
}
|
||||
}
|
||||
IAccount a = Accounts.GetAccount(pvSrc.ReadString());
|
||||
|
||||
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;
|
||||
}
|
||||
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"));
|
||||
}
|
||||
}
|
||||
|
||||
string username = pvSrc.ReadString();
|
||||
string pass = pvSrc.ReadString();
|
||||
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;
|
||||
}
|
||||
|
||||
Account a = Accounts.GetAccount( username ) as Account;
|
||||
string username = pvSrc.ReadString();
|
||||
string pass = pvSrc.ReadString();
|
||||
|
||||
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?.Banned ?? false;
|
||||
AccessLevel oldAcessLevel = a?.AccessLevel ?? 0;
|
||||
Account a = Accounts.GetAccount(username) as Account;
|
||||
|
||||
if ( a == null )
|
||||
{
|
||||
a = new Account( username, pass );
|
||||
CreatedAccount = true;
|
||||
}
|
||||
else if ( pass != "(hidden)" )
|
||||
{
|
||||
a.SetPassword( pass );
|
||||
UpdatedPass = true;
|
||||
}
|
||||
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?.Banned ?? false;
|
||||
AccessLevel oldAcessLevel = a?.AccessLevel ?? 0;
|
||||
|
||||
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" ) );
|
||||
}
|
||||
if (a == null)
|
||||
{
|
||||
a = new Account(username, pass);
|
||||
CreatedAccount = true;
|
||||
}
|
||||
else if (pass != "(hidden)")
|
||||
{
|
||||
a.SetPassword(pass);
|
||||
UpdatedPass = true;
|
||||
}
|
||||
|
||||
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 (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;
|
||||
}
|
||||
|
||||
if ( list.Count > 0 )
|
||||
a.IPRestrictions = (string[])list.ToArray( typeof( string ) );
|
||||
else
|
||||
a.IPRestrictions = new string[0];
|
||||
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"));
|
||||
}
|
||||
|
||||
if ( invalid )
|
||||
state.Send( new MessageBoxMessage( "Warning: one or more of the IP Restrictions you specified was not valid.", "Invalid IP Restriction" ) );
|
||||
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 ( 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 =
|
||||
$"{changes} Access level changed from {oldAcessLevel} to {a.AccessLevel}.";
|
||||
if ( oldbanned != a.Banned ) changes += a.Banned ? " Banned." : " Unbanned.";
|
||||
RemoteAdminLogging.WriteLine( state, "Updated account {0}:{1}", a.Username, changes );
|
||||
}
|
||||
if (list.Count > 0)
|
||||
a.IPRestrictions = (string[])list.ToArray(typeof(string));
|
||||
else
|
||||
a.IPRestrictions = new string[0];
|
||||
|
||||
state.Send( new MessageBoxMessage( "Account updated successfully.", "Account Updated" ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
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 =
|
||||
$"{changes} Access level changed from {oldAcessLevel} to {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"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,160 +1,162 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using Server.Accounting;
|
||||
using Server.Items;
|
||||
using Server.Network;
|
||||
using Server.Accounting;
|
||||
|
||||
namespace Server.RemoteAdmin
|
||||
{
|
||||
public enum LoginResponse : byte
|
||||
{
|
||||
NoUser = 0,
|
||||
BadIP,
|
||||
BadPass,
|
||||
NoAccess,
|
||||
OK
|
||||
}
|
||||
public enum LoginResponse : byte
|
||||
{
|
||||
NoUser = 0,
|
||||
BadIP,
|
||||
BadPass,
|
||||
NoAccess,
|
||||
OK
|
||||
}
|
||||
|
||||
public sealed class AdminCompressedPacket : Packet
|
||||
{
|
||||
public AdminCompressedPacket( byte[] CompData, int CDLen, int unCompSize ) : base( 0x01 )
|
||||
{
|
||||
EnsureCapacity( 1 + 2 + 2 + CDLen );
|
||||
m_Stream.Write( (ushort)unCompSize );
|
||||
m_Stream.Write( CompData, 0, CDLen );
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class Login : Packet
|
||||
{
|
||||
public Login( LoginResponse resp ) : base( 0x02, 2 )
|
||||
{
|
||||
m_Stream.Write( (byte)resp );
|
||||
}
|
||||
}
|
||||
public sealed class AdminCompressedPacket : Packet
|
||||
{
|
||||
public AdminCompressedPacket(byte[] CompData, int CDLen, int unCompSize) : base(0x01)
|
||||
{
|
||||
EnsureCapacity(1 + 2 + 2 + CDLen);
|
||||
m_Stream.Write((ushort)unCompSize);
|
||||
m_Stream.Write(CompData, 0, CDLen);
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class ConsoleData : Packet
|
||||
{
|
||||
public ConsoleData( string str ) : base( 0x03 )
|
||||
{
|
||||
EnsureCapacity( 1 + 2 + 1 + str.Length + 1 );
|
||||
m_Stream.Write( (byte) 2 );
|
||||
public sealed class Login : Packet
|
||||
{
|
||||
public Login(LoginResponse resp) : base(0x02, 2)
|
||||
{
|
||||
m_Stream.Write((byte)resp);
|
||||
}
|
||||
}
|
||||
|
||||
m_Stream.WriteAsciiNull( str );
|
||||
}
|
||||
public sealed class ConsoleData : Packet
|
||||
{
|
||||
public ConsoleData(string str) : base(0x03)
|
||||
{
|
||||
EnsureCapacity(1 + 2 + 1 + str.Length + 1);
|
||||
m_Stream.Write((byte)2);
|
||||
|
||||
public ConsoleData( char ch ) : base( 0x03 )
|
||||
{
|
||||
EnsureCapacity( 1 + 2 + 1 + 1 );
|
||||
m_Stream.Write( (byte) 3 );
|
||||
m_Stream.WriteAsciiNull(str);
|
||||
}
|
||||
|
||||
m_Stream.Write( (byte) ch );
|
||||
}
|
||||
}
|
||||
public ConsoleData(char ch) : base(0x03)
|
||||
{
|
||||
EnsureCapacity(1 + 2 + 1 + 1);
|
||||
m_Stream.Write((byte)3);
|
||||
|
||||
public sealed class ServerInfo : Packet
|
||||
{
|
||||
public ServerInfo() : base( 0x04 )
|
||||
{
|
||||
string netVer = Environment.Version.ToString();
|
||||
string os = Environment.OSVersion.ToString();
|
||||
m_Stream.Write((byte)ch);
|
||||
}
|
||||
}
|
||||
|
||||
EnsureCapacity( 1 + 2 + (10*4) + netVer.Length+1 + os.Length+1 );
|
||||
int banned = 0;
|
||||
int active = 0;
|
||||
public sealed class ServerInfo : Packet
|
||||
{
|
||||
public ServerInfo() : base(0x04)
|
||||
{
|
||||
string netVer = Environment.Version.ToString();
|
||||
string os = Environment.OSVersion.ToString();
|
||||
|
||||
foreach ( Account acct in Accounts.GetAccounts() )
|
||||
{
|
||||
if ( acct.Banned )
|
||||
++banned;
|
||||
else
|
||||
++active;
|
||||
}
|
||||
EnsureCapacity(1 + 2 + 10 * 4 + netVer.Length + 1 + os.Length + 1);
|
||||
int banned = 0;
|
||||
int active = 0;
|
||||
|
||||
m_Stream.Write( (int) active );
|
||||
m_Stream.Write( (int) banned );
|
||||
m_Stream.Write( (int) Firewall.List.Count );
|
||||
m_Stream.Write( (int) NetState.Instances.Count );
|
||||
foreach (Account acct in Accounts.GetAccounts())
|
||||
if (acct.Banned)
|
||||
++banned;
|
||||
else
|
||||
++active;
|
||||
|
||||
m_Stream.Write( (int) World.Mobiles.Count );
|
||||
m_Stream.Write( (int) Core.ScriptMobiles );
|
||||
m_Stream.Write( (int) World.Items.Count );
|
||||
m_Stream.Write( (int) Core.ScriptItems );
|
||||
m_Stream.Write(active);
|
||||
m_Stream.Write(banned);
|
||||
m_Stream.Write(Firewall.List.Count);
|
||||
m_Stream.Write(NetState.Instances.Count);
|
||||
|
||||
m_Stream.Write( (uint)(DateTime.UtcNow - Clock.ServerStart).TotalSeconds );
|
||||
m_Stream.Write( (uint) GC.GetTotalMemory( false ) ); // TODO: uint not sufficient for TotalMemory (long). Fix protocol.
|
||||
m_Stream.WriteAsciiNull( netVer );
|
||||
m_Stream.WriteAsciiNull( os );
|
||||
}
|
||||
}
|
||||
m_Stream.Write(World.Mobiles.Count);
|
||||
m_Stream.Write(Core.ScriptMobiles);
|
||||
m_Stream.Write(World.Items.Count);
|
||||
m_Stream.Write(Core.ScriptItems);
|
||||
|
||||
public sealed class AccountSearchResults : Packet
|
||||
{
|
||||
public AccountSearchResults( ArrayList results ) : base( 0x05 )
|
||||
{
|
||||
EnsureCapacity( 1 + 2 + 2 );
|
||||
m_Stream.Write((uint)(DateTime.UtcNow - Clock.ServerStart).TotalSeconds);
|
||||
m_Stream.Write(
|
||||
(uint)GC.GetTotalMemory(false)); // TODO: uint not sufficient for TotalMemory (long). Fix protocol.
|
||||
m_Stream.WriteAsciiNull(netVer);
|
||||
m_Stream.WriteAsciiNull(os);
|
||||
}
|
||||
}
|
||||
|
||||
m_Stream.Write( (byte)results.Count );
|
||||
|
||||
foreach ( Account a in results )
|
||||
{
|
||||
m_Stream.WriteAsciiNull( a.Username );
|
||||
public sealed class AccountSearchResults : Packet
|
||||
{
|
||||
public AccountSearchResults(ArrayList results) : base(0x05)
|
||||
{
|
||||
EnsureCapacity(1 + 2 + 2);
|
||||
|
||||
string pwToSend = a.PlainPassword;
|
||||
m_Stream.Write((byte)results.Count);
|
||||
|
||||
if ( pwToSend == null )
|
||||
pwToSend = "(hidden)";
|
||||
foreach (Account a in results)
|
||||
{
|
||||
m_Stream.WriteAsciiNull(a.Username);
|
||||
|
||||
m_Stream.WriteAsciiNull( pwToSend );
|
||||
m_Stream.Write( (byte)a.AccessLevel );
|
||||
m_Stream.Write( a.Banned );
|
||||
unchecked { m_Stream.Write( (uint)a.LastLogin.Ticks ); } // TODO: This doesn't work, uint.MaxValue is only 7 minutes of ticks. Fix protocol.
|
||||
|
||||
m_Stream.Write( (ushort)a.LoginIPs.Length );
|
||||
for (int i=0;i<a.LoginIPs.Length;i++)
|
||||
m_Stream.WriteAsciiNull( a.LoginIPs[i].ToString() );
|
||||
string pwToSend = a.PlainPassword;
|
||||
|
||||
m_Stream.Write( (ushort)a.IPRestrictions.Length );
|
||||
for (int i=0;i<a.IPRestrictions.Length;i++)
|
||||
m_Stream.WriteAsciiNull( a.IPRestrictions[i] );
|
||||
}
|
||||
}
|
||||
}
|
||||
if (pwToSend == null)
|
||||
pwToSend = "(hidden)";
|
||||
|
||||
public sealed class CompactServerInfo : Packet
|
||||
{
|
||||
public CompactServerInfo() : base( 0x51 )
|
||||
{
|
||||
EnsureCapacity( 1 + 2 + (4 * 4) + 8 );
|
||||
m_Stream.WriteAsciiNull(pwToSend);
|
||||
m_Stream.Write((byte)a.AccessLevel);
|
||||
m_Stream.Write(a.Banned);
|
||||
unchecked
|
||||
{
|
||||
m_Stream.Write((uint)a.LastLogin.Ticks);
|
||||
} // TODO: This doesn't work, uint.MaxValue is only 7 minutes of ticks. Fix protocol.
|
||||
|
||||
m_Stream.Write( (int)NetState.Instances.Count - 1 ); // Clients
|
||||
m_Stream.Write( (int)World.Items.Count ); // Items
|
||||
m_Stream.Write( (int)World.Mobiles.Count ); // Mobiles
|
||||
m_Stream.Write( (uint)(DateTime.UtcNow - Clock.ServerStart).TotalSeconds ); // Age (seconds)
|
||||
m_Stream.Write((ushort)a.LoginIPs.Length);
|
||||
for (int i = 0; i < a.LoginIPs.Length; i++)
|
||||
m_Stream.WriteAsciiNull(a.LoginIPs[i].ToString());
|
||||
|
||||
long memory = GC.GetTotalMemory( false );
|
||||
m_Stream.Write( (uint)(memory >> 32) ); // Memory high bytes
|
||||
m_Stream.Write( (uint)memory ); // Memory low bytes
|
||||
}
|
||||
}
|
||||
m_Stream.Write((ushort)a.IPRestrictions.Length);
|
||||
for (int i = 0; i < a.IPRestrictions.Length; i++)
|
||||
m_Stream.WriteAsciiNull(a.IPRestrictions[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class UOGInfo : Packet
|
||||
{
|
||||
public UOGInfo( string str ) : base( 0x52, str.Length+6 ) // 'R'
|
||||
{
|
||||
m_Stream.WriteAsciiFixed( "unUO", 4 );
|
||||
m_Stream.WriteAsciiNull( str );
|
||||
}
|
||||
}
|
||||
public sealed class CompactServerInfo : Packet
|
||||
{
|
||||
public CompactServerInfo() : base(0x51)
|
||||
{
|
||||
EnsureCapacity(1 + 2 + 4 * 4 + 8);
|
||||
|
||||
public sealed class MessageBoxMessage : Packet
|
||||
{
|
||||
public MessageBoxMessage( string msg, string caption ) : base( 0x08 )
|
||||
{
|
||||
EnsureCapacity( 1 + 2 + msg.Length + 1 + caption.Length + 1 );
|
||||
m_Stream.Write(NetState.Instances.Count - 1); // Clients
|
||||
m_Stream.Write(World.Items.Count); // Items
|
||||
m_Stream.Write(World.Mobiles.Count); // Mobiles
|
||||
m_Stream.Write((uint)(DateTime.UtcNow - Clock.ServerStart).TotalSeconds); // Age (seconds)
|
||||
|
||||
m_Stream.WriteAsciiNull( msg );
|
||||
m_Stream.WriteAsciiNull( caption );
|
||||
}
|
||||
}
|
||||
}
|
||||
long memory = GC.GetTotalMemory(false);
|
||||
m_Stream.Write((uint)(memory >> 32)); // Memory high bytes
|
||||
m_Stream.Write((uint)memory); // Memory low bytes
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class UOGInfo : Packet
|
||||
{
|
||||
public UOGInfo(string str) : base(0x52, str.Length + 6) // 'R'
|
||||
{
|
||||
m_Stream.WriteAsciiFixed("unUO", 4);
|
||||
m_Stream.WriteAsciiNull(str);
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class MessageBoxMessage : Packet
|
||||
{
|
||||
public MessageBoxMessage(string msg, string caption) : base(0x08)
|
||||
{
|
||||
EnsureCapacity(1 + 2 + msg.Length + 1 + caption.Length + 1);
|
||||
|
||||
m_Stream.WriteAsciiNull(msg);
|
||||
m_Stream.WriteAsciiNull(caption);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,97 +1,103 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using Server.Accounting;
|
||||
using Server.Commands;
|
||||
using Server.Network;
|
||||
|
||||
namespace Server.RemoteAdmin
|
||||
{
|
||||
public class RemoteAdminLogging
|
||||
{
|
||||
const string LogBaseDirectory = "Logs";
|
||||
const string LogSubDirectory = "RemoteAdmin";
|
||||
public class RemoteAdminLogging
|
||||
{
|
||||
private const string LogBaseDirectory = "Logs";
|
||||
private const string LogSubDirectory = "RemoteAdmin";
|
||||
|
||||
public static bool Enabled { get; set; } = true;
|
||||
private static bool Initialized;
|
||||
|
||||
public static StreamWriter Output { get; private set; }
|
||||
public static bool Enabled{ get; set; } = true;
|
||||
|
||||
private static bool Initialized;
|
||||
public static void LazyInitialize()
|
||||
{
|
||||
if ( Initialized || !Enabled ) return;
|
||||
Initialized = true;
|
||||
public static StreamWriter Output{ get; private set; }
|
||||
|
||||
if ( !Directory.Exists( LogBaseDirectory ) )
|
||||
Directory.CreateDirectory( LogBaseDirectory );
|
||||
public static void LazyInitialize()
|
||||
{
|
||||
if (Initialized || !Enabled) return;
|
||||
Initialized = true;
|
||||
|
||||
string directory = Path.Combine( LogBaseDirectory, LogSubDirectory );
|
||||
if (!Directory.Exists(LogBaseDirectory))
|
||||
Directory.CreateDirectory(LogBaseDirectory);
|
||||
|
||||
if ( !Directory.Exists( directory ) )
|
||||
Directory.CreateDirectory( directory );
|
||||
string directory = Path.Combine(LogBaseDirectory, LogSubDirectory);
|
||||
|
||||
try
|
||||
{
|
||||
Output = new StreamWriter( Path.Combine( directory, string.Format( LogSubDirectory + "{0}.log", DateTime.UtcNow.ToString( "yyyyMMdd" ) ) ), true );
|
||||
if (!Directory.Exists(directory))
|
||||
Directory.CreateDirectory(directory);
|
||||
|
||||
Output.AutoFlush = true;
|
||||
try
|
||||
{
|
||||
Output = new StreamWriter(
|
||||
Path.Combine(directory,
|
||||
string.Format(LogSubDirectory + "{0}.log", DateTime.UtcNow.ToString("yyyyMMdd"))), true);
|
||||
|
||||
Output.WriteLine( "##############################" );
|
||||
Output.WriteLine( "Log started on {0}", DateTime.UtcNow );
|
||||
Output.WriteLine();
|
||||
}
|
||||
catch
|
||||
{
|
||||
Utility.PushColor( ConsoleColor.Red );
|
||||
Console.WriteLine( "RemoteAdminLogging: Failed to initialize LogWriter." );
|
||||
Utility.PopColor();
|
||||
Enabled = false;
|
||||
}
|
||||
}
|
||||
Output.AutoFlush = true;
|
||||
|
||||
public static object Format( object o )
|
||||
{
|
||||
o = Commands.CommandLogging.Format( o );
|
||||
if ( o == null )
|
||||
return "(null)";
|
||||
Output.WriteLine("##############################");
|
||||
Output.WriteLine("Log started on {0}", DateTime.UtcNow);
|
||||
Output.WriteLine();
|
||||
}
|
||||
catch
|
||||
{
|
||||
Utility.PushColor(ConsoleColor.Red);
|
||||
Console.WriteLine("RemoteAdminLogging: Failed to initialize LogWriter.");
|
||||
Utility.PopColor();
|
||||
Enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
return o;
|
||||
}
|
||||
public static object Format(object o)
|
||||
{
|
||||
o = CommandLogging.Format(o);
|
||||
if (o == null)
|
||||
return "(null)";
|
||||
|
||||
public static void WriteLine( NetState state, string format, params object[] args )
|
||||
{
|
||||
for ( int i = 0; i < args.Length; i++ )
|
||||
args[i] = Commands.CommandLogging.Format( args[i] );
|
||||
return o;
|
||||
}
|
||||
|
||||
WriteLine( state, string.Format( format, args ) );
|
||||
}
|
||||
public static void WriteLine(NetState state, string format, params object[] args)
|
||||
{
|
||||
for (int i = 0; i < args.Length; i++)
|
||||
args[i] = CommandLogging.Format(args[i]);
|
||||
|
||||
public static void WriteLine( NetState state, string text )
|
||||
{
|
||||
LazyInitialize();
|
||||
WriteLine(state, string.Format(format, args));
|
||||
}
|
||||
|
||||
if ( !Enabled ) return;
|
||||
public static void WriteLine(NetState state, string text)
|
||||
{
|
||||
LazyInitialize();
|
||||
|
||||
try
|
||||
{
|
||||
Account acct = state.Account as Account;
|
||||
string name = acct == null ? "(UNKNOWN)" : acct.Username;
|
||||
string accesslevel = acct == null ? "NoAccount" : acct.AccessLevel.ToString();
|
||||
string statestr = state == null ? "NULLSTATE" : state.ToString();
|
||||
if (!Enabled) return;
|
||||
|
||||
Output.WriteLine( "{0}: {1}: {2}: {3}", DateTime.UtcNow, statestr, name, text );
|
||||
try
|
||||
{
|
||||
Account acct = state.Account as Account;
|
||||
string name = acct == null ? "(UNKNOWN)" : acct.Username;
|
||||
string accesslevel = acct == null ? "NoAccount" : acct.AccessLevel.ToString();
|
||||
string statestr = state == null ? "NULLSTATE" : state.ToString();
|
||||
|
||||
string path = Core.BaseDirectory;
|
||||
Output.WriteLine("{0}: {1}: {2}: {3}", DateTime.UtcNow, statestr, name, text);
|
||||
|
||||
Commands.CommandLogging.AppendPath( ref path, LogBaseDirectory );
|
||||
Commands.CommandLogging.AppendPath( ref path, LogSubDirectory );
|
||||
Commands.CommandLogging.AppendPath( ref path, accesslevel );
|
||||
path = Path.Combine( path, $"{name}.log");
|
||||
string path = Core.BaseDirectory;
|
||||
|
||||
using ( StreamWriter sw = new StreamWriter( path, true ) )
|
||||
sw.WriteLine( "{0}: {1}: {2}", DateTime.UtcNow, statestr, text );
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
CommandLogging.AppendPath(ref path, LogBaseDirectory);
|
||||
CommandLogging.AppendPath(ref path, LogSubDirectory);
|
||||
CommandLogging.AppendPath(ref path, accesslevel);
|
||||
path = Path.Combine(path, $"{name}.log");
|
||||
|
||||
using (StreamWriter sw = new StreamWriter(path, true))
|
||||
{
|
||||
sw.WriteLine("{0}: {1}: {2}", DateTime.UtcNow, statestr, text);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue