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
|
|
@ -5,299 +5,294 @@ using System.Text;
|
|||
|
||||
namespace Server.Commands.Generic
|
||||
{
|
||||
[Flags]
|
||||
public enum CommandSupport
|
||||
{
|
||||
Single = 0x0001,
|
||||
Global = 0x0002,
|
||||
Online = 0x0004,
|
||||
Multi = 0x0008,
|
||||
Area = 0x0010,
|
||||
Self = 0x0020,
|
||||
Region = 0x0040,
|
||||
Contained = 0x0080,
|
||||
IPAddress = 0x0100,
|
||||
[Flags]
|
||||
public enum CommandSupport
|
||||
{
|
||||
Single = 0x0001,
|
||||
Global = 0x0002,
|
||||
Online = 0x0004,
|
||||
Multi = 0x0008,
|
||||
Area = 0x0010,
|
||||
Self = 0x0020,
|
||||
Region = 0x0040,
|
||||
Contained = 0x0080,
|
||||
IPAddress = 0x0100,
|
||||
|
||||
All = Single | Global | Online | Multi | Area | Self | Region | Contained | IPAddress,
|
||||
AllMobiles = All & ~Contained,
|
||||
AllNPCs = All & ~(IPAddress | Online | Self | Contained),
|
||||
AllItems = All & ~(IPAddress | Online | Self | Region),
|
||||
All = Single | Global | Online | Multi | Area | Self | Region | Contained | IPAddress,
|
||||
AllMobiles = All & ~Contained,
|
||||
AllNPCs = All & ~(IPAddress | Online | Self | Contained),
|
||||
AllItems = All & ~(IPAddress | Online | Self | Region),
|
||||
|
||||
Simple = Single | Multi,
|
||||
Complex = Global | Online | Area | Region | Contained | IPAddress
|
||||
}
|
||||
Simple = Single | Multi,
|
||||
Complex = Global | Online | Area | Region | Contained | IPAddress
|
||||
}
|
||||
|
||||
public abstract class BaseCommandImplementor
|
||||
{
|
||||
public static void RegisterImplementors()
|
||||
{
|
||||
Register( new RegionCommandImplementor() );
|
||||
Register( new GlobalCommandImplementor() );
|
||||
Register( new OnlineCommandImplementor() );
|
||||
Register( new SingleCommandImplementor() );
|
||||
Register( new SerialCommandImplementor() );
|
||||
Register( new MultiCommandImplementor() );
|
||||
Register( new AreaCommandImplementor() );
|
||||
Register( new SelfCommandImplementor() );
|
||||
Register( new ContainedCommandImplementor() );
|
||||
Register( new IPAddressCommandImplementor() );
|
||||
public abstract class BaseCommandImplementor
|
||||
{
|
||||
private static List<BaseCommandImplementor> m_Implementors;
|
||||
|
||||
Register( new RangeCommandImplementor() );
|
||||
Register( new ScreenCommandImplementor() );
|
||||
Register( new FacetCommandImplementor() );
|
||||
}
|
||||
public BaseCommandImplementor()
|
||||
{
|
||||
Commands = new Dictionary<string, BaseCommand>(StringComparer.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
public bool SupportsConditionals { get; set; }
|
||||
public bool SupportsConditionals{ get; set; }
|
||||
|
||||
public string[] Accessors { get; set; }
|
||||
public string[] Accessors{ get; set; }
|
||||
|
||||
public string Usage { get; set; }
|
||||
public string Usage{ get; set; }
|
||||
|
||||
public string Description { get; set; }
|
||||
public string Description{ get; set; }
|
||||
|
||||
public AccessLevel AccessLevel { get; set; }
|
||||
public AccessLevel AccessLevel{ get; set; }
|
||||
|
||||
public CommandSupport SupportRequirement { get; set; }
|
||||
public CommandSupport SupportRequirement{ get; set; }
|
||||
|
||||
public Dictionary<string, BaseCommand> Commands { get; }
|
||||
public Dictionary<string, BaseCommand> Commands{ get; }
|
||||
|
||||
public BaseCommandImplementor()
|
||||
{
|
||||
Commands = new Dictionary<string, BaseCommand>( StringComparer.OrdinalIgnoreCase );
|
||||
}
|
||||
public static List<BaseCommandImplementor> Implementors
|
||||
{
|
||||
get
|
||||
{
|
||||
if (m_Implementors == null)
|
||||
{
|
||||
m_Implementors = new List<BaseCommandImplementor>();
|
||||
RegisterImplementors();
|
||||
}
|
||||
|
||||
public virtual void Compile( Mobile from, BaseCommand command, ref string[] args, ref object obj )
|
||||
{
|
||||
obj = null;
|
||||
}
|
||||
return m_Implementors;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void Register( BaseCommand command )
|
||||
{
|
||||
for ( int i = 0; i < command.Commands.Length; ++i )
|
||||
Commands[command.Commands[i]] = command;
|
||||
}
|
||||
public static void RegisterImplementors()
|
||||
{
|
||||
Register(new RegionCommandImplementor());
|
||||
Register(new GlobalCommandImplementor());
|
||||
Register(new OnlineCommandImplementor());
|
||||
Register(new SingleCommandImplementor());
|
||||
Register(new SerialCommandImplementor());
|
||||
Register(new MultiCommandImplementor());
|
||||
Register(new AreaCommandImplementor());
|
||||
Register(new SelfCommandImplementor());
|
||||
Register(new ContainedCommandImplementor());
|
||||
Register(new IPAddressCommandImplementor());
|
||||
|
||||
public bool CheckObjectTypes( Mobile from, BaseCommand command, Extensions ext, out bool items, out bool mobiles )
|
||||
{
|
||||
items = mobiles = false;
|
||||
Register(new RangeCommandImplementor());
|
||||
Register(new ScreenCommandImplementor());
|
||||
Register(new FacetCommandImplementor());
|
||||
}
|
||||
|
||||
ObjectConditional cond = ObjectConditional.Empty;
|
||||
public virtual void Compile(Mobile from, BaseCommand command, ref string[] args, ref object obj)
|
||||
{
|
||||
obj = null;
|
||||
}
|
||||
|
||||
foreach ( BaseExtension check in ext )
|
||||
{
|
||||
if ( check is WhereExtension extension )
|
||||
{
|
||||
cond = extension.Conditional;
|
||||
public virtual void Register(BaseCommand command)
|
||||
{
|
||||
for (int i = 0; i < command.Commands.Length; ++i)
|
||||
Commands[command.Commands[i]] = command;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
public bool CheckObjectTypes(Mobile from, BaseCommand command, Extensions ext, out bool items, out bool mobiles)
|
||||
{
|
||||
items = mobiles = false;
|
||||
|
||||
bool condIsItem = cond.IsItem;
|
||||
bool condIsMobile = cond.IsMobile;
|
||||
ObjectConditional cond = ObjectConditional.Empty;
|
||||
|
||||
switch ( command.ObjectTypes )
|
||||
{
|
||||
case ObjectTypes.All:
|
||||
case ObjectTypes.Both:
|
||||
{
|
||||
if ( condIsItem )
|
||||
items = true;
|
||||
foreach (BaseExtension check in ext)
|
||||
if (check is WhereExtension extension)
|
||||
{
|
||||
cond = extension.Conditional;
|
||||
|
||||
if ( condIsMobile )
|
||||
mobiles = true;
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case ObjectTypes.Items:
|
||||
{
|
||||
if ( condIsItem )
|
||||
{
|
||||
items = true;
|
||||
}
|
||||
else if ( condIsMobile )
|
||||
{
|
||||
from.SendMessage( "You may not use a mobile type condition for this command." );
|
||||
return false;
|
||||
}
|
||||
bool condIsItem = cond.IsItem;
|
||||
bool condIsMobile = cond.IsMobile;
|
||||
|
||||
break;
|
||||
}
|
||||
case ObjectTypes.Mobiles:
|
||||
{
|
||||
if ( condIsMobile )
|
||||
{
|
||||
mobiles = true;
|
||||
}
|
||||
else if ( condIsItem )
|
||||
{
|
||||
from.SendMessage( "You may not use an item type condition for this command." );
|
||||
return false;
|
||||
}
|
||||
switch (command.ObjectTypes)
|
||||
{
|
||||
case ObjectTypes.All:
|
||||
case ObjectTypes.Both:
|
||||
{
|
||||
if (condIsItem)
|
||||
items = true;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (condIsMobile)
|
||||
mobiles = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ObjectTypes.Items:
|
||||
{
|
||||
if (condIsItem)
|
||||
{
|
||||
items = true;
|
||||
}
|
||||
else if (condIsMobile)
|
||||
{
|
||||
from.SendMessage("You may not use a mobile type condition for this command.");
|
||||
return false;
|
||||
}
|
||||
|
||||
public void RunCommand( Mobile from, BaseCommand command, string[] args )
|
||||
{
|
||||
try
|
||||
{
|
||||
object obj = null;
|
||||
break;
|
||||
}
|
||||
case ObjectTypes.Mobiles:
|
||||
{
|
||||
if (condIsMobile)
|
||||
{
|
||||
mobiles = true;
|
||||
}
|
||||
else if (condIsItem)
|
||||
{
|
||||
from.SendMessage("You may not use an item type condition for this command.");
|
||||
return false;
|
||||
}
|
||||
|
||||
Compile( from, command, ref args, ref obj );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
RunCommand( from, obj, command, args );
|
||||
}
|
||||
catch ( Exception ex )
|
||||
{
|
||||
from.SendMessage( ex.Message );
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public string GenerateArgString( string[] args )
|
||||
{
|
||||
if ( args.Length == 0 )
|
||||
return "";
|
||||
public void RunCommand(Mobile from, BaseCommand command, string[] args)
|
||||
{
|
||||
try
|
||||
{
|
||||
object obj = null;
|
||||
|
||||
// NOTE: this does not preserve the case where quotation marks are used on a single word
|
||||
Compile(from, command, ref args, ref obj);
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
RunCommand(from, obj, command, args);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
from.SendMessage(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
for ( int i = 0; i < args.Length; ++i )
|
||||
{
|
||||
if ( i > 0 )
|
||||
sb.Append( ' ' );
|
||||
public string GenerateArgString(string[] args)
|
||||
{
|
||||
if (args.Length == 0)
|
||||
return "";
|
||||
|
||||
if ( args[i].IndexOf( ' ' ) >= 0 )
|
||||
{
|
||||
sb.Append( '"' );
|
||||
sb.Append( args[i] );
|
||||
sb.Append( '"' );
|
||||
}
|
||||
else
|
||||
{
|
||||
sb.Append( args[i] );
|
||||
}
|
||||
}
|
||||
// NOTE: this does not preserve the case where quotation marks are used on a single word
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
public void RunCommand( Mobile from, object obj, BaseCommand command, string[] args )
|
||||
{
|
||||
// try
|
||||
// {
|
||||
CommandEventArgs e = new CommandEventArgs( from, command.Commands[0], GenerateArgString( args ), args );
|
||||
for (int i = 0; i < args.Length; ++i)
|
||||
{
|
||||
if (i > 0)
|
||||
sb.Append(' ');
|
||||
|
||||
if ( !command.ValidateArgs( this, e ) )
|
||||
return;
|
||||
if (args[i].IndexOf(' ') >= 0)
|
||||
{
|
||||
sb.Append('"');
|
||||
sb.Append(args[i]);
|
||||
sb.Append('"');
|
||||
}
|
||||
else
|
||||
{
|
||||
sb.Append(args[i]);
|
||||
}
|
||||
}
|
||||
|
||||
bool flushToLog = false;
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
if ( obj is ArrayList list )
|
||||
{
|
||||
if ( list.Count > 20 )
|
||||
CommandLogging.Enabled = false;
|
||||
else if ( list.Count == 0 )
|
||||
command.LogFailure( "Nothing was found to use this command on." );
|
||||
public void RunCommand(Mobile from, object obj, BaseCommand command, string[] args)
|
||||
{
|
||||
// try
|
||||
// {
|
||||
CommandEventArgs e = new CommandEventArgs(from, command.Commands[0], GenerateArgString(args), args);
|
||||
|
||||
command.ExecuteList( e, list );
|
||||
if (!command.ValidateArgs(this, e))
|
||||
return;
|
||||
|
||||
if ( list.Count > 20 )
|
||||
{
|
||||
flushToLog = true;
|
||||
CommandLogging.Enabled = true;
|
||||
}
|
||||
}
|
||||
else if ( obj != null )
|
||||
{
|
||||
if ( command.ListOptimized )
|
||||
{
|
||||
command.ExecuteList( e, new ArrayList{ obj } );
|
||||
}
|
||||
else
|
||||
{
|
||||
command.Execute( e, obj );
|
||||
}
|
||||
}
|
||||
bool flushToLog = false;
|
||||
|
||||
command.Flush( from, flushToLog );
|
||||
// }
|
||||
// catch ( Exception ex )
|
||||
// {
|
||||
// from.SendMessage( ex.Message );
|
||||
// }
|
||||
}
|
||||
if (obj is ArrayList list)
|
||||
{
|
||||
if (list.Count > 20)
|
||||
CommandLogging.Enabled = false;
|
||||
else if (list.Count == 0)
|
||||
command.LogFailure("Nothing was found to use this command on.");
|
||||
|
||||
public virtual void Process( Mobile from, BaseCommand command, string[] args )
|
||||
{
|
||||
RunCommand( from, command, args );
|
||||
}
|
||||
command.ExecuteList(e, list);
|
||||
|
||||
public virtual void Execute( CommandEventArgs e )
|
||||
{
|
||||
if ( e.Length >= 1 )
|
||||
{
|
||||
Commands.TryGetValue( e.GetString( 0 ), out BaseCommand command );
|
||||
if (list.Count > 20)
|
||||
{
|
||||
flushToLog = true;
|
||||
CommandLogging.Enabled = true;
|
||||
}
|
||||
}
|
||||
else if (obj != null)
|
||||
{
|
||||
if (command.ListOptimized)
|
||||
command.ExecuteList(e, new ArrayList { obj });
|
||||
else
|
||||
command.Execute(e, obj);
|
||||
}
|
||||
|
||||
if ( command == null )
|
||||
{
|
||||
e.Mobile.SendMessage( "That is either an invalid command name or one that does not support this modifier." );
|
||||
}
|
||||
else if ( e.Mobile.AccessLevel < command.AccessLevel )
|
||||
{
|
||||
e.Mobile.SendMessage( "You do not have access to that command." );
|
||||
}
|
||||
else
|
||||
{
|
||||
string[] oldArgs = e.Arguments;
|
||||
string[] args = new string[oldArgs.Length - 1];
|
||||
command.Flush(from, flushToLog);
|
||||
// }
|
||||
// catch ( Exception ex )
|
||||
// {
|
||||
// from.SendMessage( ex.Message );
|
||||
// }
|
||||
}
|
||||
|
||||
for ( int i = 0; i < args.Length; ++i )
|
||||
args[i] = oldArgs[i + 1];
|
||||
public virtual void Process(Mobile from, BaseCommand command, string[] args)
|
||||
{
|
||||
RunCommand(from, command, args);
|
||||
}
|
||||
|
||||
Process( e.Mobile, command, args );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
e.Mobile.SendMessage( "You must supply a command name." );
|
||||
}
|
||||
}
|
||||
public virtual void Execute(CommandEventArgs e)
|
||||
{
|
||||
if (e.Length >= 1)
|
||||
{
|
||||
Commands.TryGetValue(e.GetString(0), out BaseCommand command);
|
||||
|
||||
public void Register()
|
||||
{
|
||||
if ( Accessors == null )
|
||||
return;
|
||||
if (command == null)
|
||||
{
|
||||
e.Mobile.SendMessage(
|
||||
"That is either an invalid command name or one that does not support this modifier.");
|
||||
}
|
||||
else if (e.Mobile.AccessLevel < command.AccessLevel)
|
||||
{
|
||||
e.Mobile.SendMessage("You do not have access to that command.");
|
||||
}
|
||||
else
|
||||
{
|
||||
string[] oldArgs = e.Arguments;
|
||||
string[] args = new string[oldArgs.Length - 1];
|
||||
|
||||
for ( int i = 0; i < Accessors.Length; ++i )
|
||||
CommandSystem.Register( Accessors[i], AccessLevel, Execute );
|
||||
}
|
||||
for (int i = 0; i < args.Length; ++i)
|
||||
args[i] = oldArgs[i + 1];
|
||||
|
||||
public static void Register( BaseCommandImplementor impl )
|
||||
{
|
||||
m_Implementors.Add( impl );
|
||||
impl.Register();
|
||||
}
|
||||
Process(e.Mobile, command, args);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
e.Mobile.SendMessage("You must supply a command name.");
|
||||
}
|
||||
}
|
||||
|
||||
private static List<BaseCommandImplementor> m_Implementors;
|
||||
public void Register()
|
||||
{
|
||||
if (Accessors == null)
|
||||
return;
|
||||
|
||||
public static List<BaseCommandImplementor> Implementors
|
||||
{
|
||||
get
|
||||
{
|
||||
if ( m_Implementors == null )
|
||||
{
|
||||
m_Implementors = new List<BaseCommandImplementor>();
|
||||
RegisterImplementors();
|
||||
}
|
||||
for (int i = 0; i < Accessors.Length; ++i)
|
||||
CommandSystem.Register(Accessors[i], AccessLevel, Execute);
|
||||
}
|
||||
|
||||
return m_Implementors;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public static void Register(BaseCommandImplementor impl)
|
||||
{
|
||||
m_Implementors.Add(impl);
|
||||
impl.Register();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue