2013-10-28 07:09:42 +00:00
|
|
|
using System;
|
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
|
|
namespace Server.Commands.Generic
|
|
|
|
|
{
|
|
|
|
|
public delegate BaseExtension ExtensionConstructor();
|
|
|
|
|
|
|
|
|
|
public sealed class ExtensionInfo
|
|
|
|
|
{
|
|
|
|
|
private static readonly Dictionary<string, ExtensionInfo> m_Table = new Dictionary<string, ExtensionInfo>(StringComparer.InvariantCultureIgnoreCase);
|
|
|
|
|
private readonly int m_Order;
|
|
|
|
|
private readonly string m_Name;
|
|
|
|
|
private readonly int m_Size;
|
|
|
|
|
private readonly ExtensionConstructor m_Constructor;
|
|
|
|
|
public ExtensionInfo(int order, string name, int size, ExtensionConstructor constructor)
|
|
|
|
|
{
|
2020-04-16 21:29:55 -04:00
|
|
|
m_Name = name;
|
|
|
|
|
m_Size = size;
|
2013-10-28 07:09:42 +00:00
|
|
|
|
2020-04-16 21:29:55 -04:00
|
|
|
m_Order = order;
|
2013-10-28 07:09:42 +00:00
|
|
|
|
2020-04-16 21:29:55 -04:00
|
|
|
m_Constructor = constructor;
|
2013-10-28 07:09:42 +00:00
|
|
|
}
|
|
|
|
|
|
2020-04-16 20:21:33 -04:00
|
|
|
public static Dictionary<string, ExtensionInfo> Table => m_Table;
|
2020-04-16 21:29:55 -04:00
|
|
|
public int Order => m_Order;
|
|
|
|
|
public string Name => m_Name;
|
|
|
|
|
public int Size => m_Size;
|
|
|
|
|
public bool IsFixedSize => (m_Size >= 0);
|
|
|
|
|
public ExtensionConstructor Constructor => m_Constructor;
|
2013-10-28 07:09:42 +00:00
|
|
|
public static void Register(ExtensionInfo ext)
|
|
|
|
|
{
|
|
|
|
|
m_Table[ext.m_Name] = ext;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public sealed class Extensions : List<BaseExtension>
|
|
|
|
|
{
|
|
|
|
|
public static Extensions Parse(Mobile from, ref string[] args)
|
|
|
|
|
{
|
|
|
|
|
Extensions parsed = new Extensions();
|
|
|
|
|
|
|
|
|
|
int size = args.Length;
|
|
|
|
|
|
|
|
|
|
Type baseType = null;
|
|
|
|
|
|
|
|
|
|
for (int i = args.Length - 1; i >= 0; --i)
|
|
|
|
|
{
|
|
|
|
|
ExtensionInfo extInfo = null;
|
|
|
|
|
|
|
|
|
|
if (!ExtensionInfo.Table.TryGetValue(args[i], out extInfo))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (extInfo.IsFixedSize && i != (size - extInfo.Size - 1))
|
|
|
|
|
throw new Exception("Invalid extended argument count.");
|
|
|
|
|
|
|
|
|
|
BaseExtension ext = extInfo.Constructor();
|
|
|
|
|
|
|
|
|
|
ext.Parse(from, args, i + 1, size - i - 1);
|
|
|
|
|
|
|
|
|
|
if (ext is WhereExtension)
|
|
|
|
|
baseType = (ext as WhereExtension).Conditional.Type;
|
|
|
|
|
|
|
|
|
|
parsed.Add(ext);
|
|
|
|
|
|
|
|
|
|
size = i;
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-13 23:43:52 -04:00
|
|
|
parsed.Sort(delegate (BaseExtension a, BaseExtension b)
|
2013-10-28 07:09:42 +00:00
|
|
|
{
|
|
|
|
|
return (a.Order - b.Order);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
AssemblyEmitter emitter = null;
|
|
|
|
|
|
|
|
|
|
foreach (BaseExtension update in parsed)
|
|
|
|
|
update.Optimize(from, baseType, ref emitter);
|
|
|
|
|
|
|
|
|
|
if (size != args.Length)
|
|
|
|
|
{
|
|
|
|
|
string[] old = args;
|
|
|
|
|
args = new string[size];
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < args.Length; ++i)
|
|
|
|
|
args[i] = old[i];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return parsed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool IsValid(object obj)
|
|
|
|
|
{
|
2020-04-16 21:29:55 -04:00
|
|
|
for (int i = 0; i < Count; ++i)
|
2013-10-28 07:09:42 +00:00
|
|
|
{
|
|
|
|
|
if (!this[i].IsValid(obj))
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Filter(ArrayList list)
|
|
|
|
|
{
|
2020-04-16 21:29:55 -04:00
|
|
|
for (int i = 0; i < Count; ++i)
|
2013-10-28 07:09:42 +00:00
|
|
|
this[i].Filter(list);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public abstract class BaseExtension
|
|
|
|
|
{
|
|
|
|
|
public abstract ExtensionInfo Info { get; }
|
2020-04-16 21:29:55 -04:00
|
|
|
public string Name => Info.Name;
|
|
|
|
|
public int Size => Info.Size;
|
|
|
|
|
public bool IsFixedSize => Info.IsFixedSize;
|
|
|
|
|
public int Order => Info.Order;
|
2013-10-28 07:09:42 +00:00
|
|
|
public virtual void Optimize(Mobile from, Type baseType, ref AssemblyEmitter assembly)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public virtual void Parse(Mobile from, string[] arguments, int offset, int size)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public virtual bool IsValid(object obj)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public virtual void Filter(ArrayList list)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-04-21 20:25:24 -04:00
|
|
|
}
|