* Fixes a bug with the main loop. Removes unnecessary optimizations for RDRand. * WIP - Rewriting packets. * Cleanup and updates README * Converts more packets * Fixes header * Converts Effects packets. * Forgot the send command * Adds the start of containers packets. * Adds message packets with caching * Extends the send methods * Starts to add Acquire methods * Converted the packets * Cleanup * Cleanup * Adds more packets * Adds more packets * Fixes clearing arrays from pool. Adds Mobile Incoming * Converts more packets. * Moves more packets * Moves more packets * Test compression * Merges * Migrating to an idiomatic syntax that also supports compression, and proxying. * Optimize the stack alloc. Changes attributes * Converted container packets * Visual Studio doesn't auto save files. I am still getting used to subpar IDEs. * Adds static packet caching. Will profile later. Converts more packets * Fixes packets and changes how compression is configured * WIP - Adds basics for Gumps. Not finished though. * Fix file * Fixes formatting * Changed SpanWriter to be more idiomatic. * Fixes Span vs RawSpan and missing stackallocs * Converts over some more gumps * WIP - Deletes 32bit support. * Drops RDRand32 support. * Fixes gump compilation * Converting gump components * Removes old huffman compression function * Revert signature for backwards compatibility * WIP - Converting more gump components * Creates ArraySet for the strings. Updates AppendTo to reference that. * Converts the maining gump components * Cleans up gump components * Cleans up directives * Cleans up ArraySet and moves it. Adds null-coalescing-assignment * Cleanup, Target Packets, and C# 8 changes. * Removed OPL Packet * World packets * Fixing packet uses * Cleans up code. Fixes packet uses in various places. * More cleanup for packets * Code cleanup * Converts more packet uses and cleans up more code * More code cleanup * Finishes fixing the packets in Item * Updates secure trade packets * Updates core and gets it to compile. * Moved packets to scripts. Fixed account handler use of packets * Code cleanup * Updates chat packets * Code cleanuo * Adds party packets, but need to implement them. * Party packets WIP * Finishes party packets * Rearrange movement namespaces and classes * Finishes plant packets * Code Formatting * Fixes moving effects * Code cleanup, eliminates equipinfo * Adds more packets. Fixes bugs with various packets. * Finishes mahjon packets * Fixes mahjong packet * Code cleanup * Finishes mahjong packets * Adds Map packets * Add multifacet maps and charts * Cleans up some packets with UTF8 * Optimizes packets * Cleans up more packets. Moves the MessageHelper * Removes assistant support. Removes extended protocol. Incorporates MapUO packets as normal packets. * Updates protocol extensions packet receiver * Fixes a few bugs. Fixes a few more packets. * Code cleanup and fixing more packets * Fixes packet effects * Cleaned up more code * Buff Icon cleanup * Removed unused constructors * Code Cleanup. Adds BoatHS Packets * Moves house files. Updates house foundation packets. * Deployment cleanup * Fixes: * Code cleanup * More code cleanup * More code cleanup * Cleaned up BaseHouse * Enforces styling * Converts foreach to linq where possible. * Dont need that * Goals/Readme updates * Removes 32bit support at the highest level. Turns on HRT by default. * Code cleanup. Fixes extended features packet. * Fixes various bugs * Code cleanup * Code cleanup * Code cleanup. Fixes gump X/Y assignment. * Code cleanup using |= operator * More code cleanup * Cleanup * Fixes spacing issues. Thanks Visual Studio. You suck. * Compiler error * Fixes NPE from RunUO 2.7 * Renames ScriptCompiler to AssemblyHandler. Fixes packets. Updates README * Fixes more packets. Stupid trailing nulls. * Fixes various bugs. * Fixes for gumps * Fixes more gump stuff. Going to split it out later since it is getting insane * Recoded the gump writing * WIP * *Added output path of scripts project to dev branch *Activated debugging in code
194 lines
6.7 KiB
C#
194 lines
6.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace Server.Commands.Generic
|
|
{
|
|
public sealed class ObjectConditional
|
|
{
|
|
private static readonly Type typeofItem = typeof(Item);
|
|
private static readonly Type typeofMobile = typeof(Mobile);
|
|
|
|
public static readonly ObjectConditional Empty = new ObjectConditional(null, null);
|
|
|
|
private IConditional[] m_Conditionals;
|
|
|
|
private ICondition[][] m_Conditions;
|
|
|
|
public ObjectConditional(Type objectType, ICondition[][] conditions)
|
|
{
|
|
Type = objectType;
|
|
m_Conditions = conditions;
|
|
}
|
|
|
|
public Type Type{ get; }
|
|
|
|
public bool IsItem => Type == null || Type == typeofItem || Type.IsSubclassOf(typeofItem);
|
|
|
|
public bool IsMobile => Type == null || Type == typeofMobile || Type.IsSubclassOf(typeofMobile);
|
|
|
|
public bool HasCompiled => m_Conditionals != null;
|
|
|
|
public void Compile(ref AssemblyEmitter emitter)
|
|
{
|
|
emitter ??= new AssemblyEmitter("__dynamic");
|
|
|
|
m_Conditionals = new IConditional[m_Conditions.Length];
|
|
|
|
for (int i = 0; i < m_Conditionals.Length; ++i)
|
|
m_Conditionals[i] = ConditionalCompiler.Compile(emitter, Type, m_Conditions[i], i);
|
|
}
|
|
|
|
public bool CheckCondition(object obj)
|
|
{
|
|
if (Type == null)
|
|
return true; // null type means no condition
|
|
|
|
if (!HasCompiled)
|
|
{
|
|
AssemblyEmitter emitter = null;
|
|
|
|
Compile(ref emitter);
|
|
}
|
|
|
|
for (int i = 0; i < m_Conditionals.Length; ++i)
|
|
if (m_Conditionals[i].Verify(obj))
|
|
return true;
|
|
|
|
return false; // all conditions false
|
|
}
|
|
|
|
public static ObjectConditional Parse(Mobile from, ref string[] args)
|
|
{
|
|
string[] conditionArgs = null;
|
|
|
|
for (int i = 0; i < args.Length; ++i)
|
|
if (Insensitive.Equals(args[i], "where"))
|
|
{
|
|
string[] origArgs = args;
|
|
|
|
args = new string[i];
|
|
|
|
for (int j = 0; j < args.Length; ++j)
|
|
args[j] = origArgs[j];
|
|
|
|
conditionArgs = new string[origArgs.Length - i - 1];
|
|
|
|
for (int j = 0; j < conditionArgs.Length; ++j)
|
|
conditionArgs[j] = origArgs[i + j + 1];
|
|
|
|
break;
|
|
}
|
|
|
|
return ParseDirect(from, conditionArgs, 0, conditionArgs?.Length ?? 0);
|
|
}
|
|
|
|
public static ObjectConditional ParseDirect(Mobile from, string[] args, int offset, int size)
|
|
{
|
|
if (args == null || size == 0)
|
|
return Empty;
|
|
|
|
int index = 0;
|
|
|
|
Type objectType = AssemblyHandler.FindTypeByName(args[offset + index], true);
|
|
|
|
if (objectType == null)
|
|
throw new Exception($"No type with that name ({args[offset + index]}) was found.");
|
|
|
|
++index;
|
|
|
|
List<ICondition[]> conditions = new List<ICondition[]>();
|
|
List<ICondition> current = new List<ICondition>();
|
|
|
|
current.Add(TypeCondition.Default);
|
|
|
|
while (index < size)
|
|
{
|
|
string cur = args[offset + index];
|
|
|
|
bool inverse = false;
|
|
|
|
if (Insensitive.Equals(cur, "not") || cur == "!")
|
|
{
|
|
inverse = true;
|
|
++index;
|
|
|
|
if (index >= size)
|
|
throw new Exception("Improperly formatted object conditional.");
|
|
}
|
|
else if (Insensitive.Equals(cur, "or") || cur == "||")
|
|
{
|
|
if (current.Count > 1)
|
|
{
|
|
conditions.Add(current.ToArray());
|
|
|
|
current.Clear();
|
|
current.Add(TypeCondition.Default);
|
|
}
|
|
|
|
++index;
|
|
|
|
continue;
|
|
}
|
|
|
|
string binding = args[offset + index];
|
|
index++;
|
|
|
|
if (index >= size)
|
|
throw new Exception("Improperly formatted object conditional.");
|
|
|
|
string oper = args[offset + index];
|
|
index++;
|
|
|
|
if (index >= size)
|
|
throw new Exception("Improperly formatted object conditional.");
|
|
|
|
string val = args[offset + index];
|
|
index++;
|
|
|
|
Property prop = new Property(binding);
|
|
|
|
prop.BindTo(objectType, PropertyAccess.Read);
|
|
prop.CheckAccess(from);
|
|
|
|
var condition = oper switch
|
|
{
|
|
"=" => (ICondition)new ComparisonCondition(prop, inverse, ComparisonOperator.Equal, val),
|
|
"==" => new ComparisonCondition(prop, inverse, ComparisonOperator.Equal, val),
|
|
"is" => new ComparisonCondition(prop, inverse, ComparisonOperator.Equal, val),
|
|
"!=" => new ComparisonCondition(prop, inverse, ComparisonOperator.NotEqual, val),
|
|
">" => new ComparisonCondition(prop, inverse, ComparisonOperator.Greater, val),
|
|
"<" => new ComparisonCondition(prop, inverse, ComparisonOperator.Lesser, val),
|
|
">=" => new ComparisonCondition(prop, inverse, ComparisonOperator.GreaterEqual, val),
|
|
"<=" => new ComparisonCondition(prop, inverse, ComparisonOperator.LesserEqual, val),
|
|
"==~" => new StringCondition(prop, inverse, StringOperator.Equal, val, true),
|
|
"~==" => new StringCondition(prop, inverse, StringOperator.Equal, val, true),
|
|
"=~" => new StringCondition(prop, inverse, StringOperator.Equal, val, true),
|
|
"~=" => new StringCondition(prop, inverse, StringOperator.Equal, val, true),
|
|
"is~" => new StringCondition(prop, inverse, StringOperator.Equal, val, true),
|
|
"~is" => new StringCondition(prop, inverse, StringOperator.Equal, val, true),
|
|
"!=~" => new StringCondition(prop, inverse, StringOperator.NotEqual, val, true),
|
|
"~!=" => new StringCondition(prop, inverse, StringOperator.NotEqual, val, true),
|
|
"starts" => new StringCondition(prop, inverse, StringOperator.StartsWith, val, false),
|
|
"starts~" => new StringCondition(prop, inverse, StringOperator.StartsWith, val, true),
|
|
"~starts" => new StringCondition(prop, inverse, StringOperator.StartsWith, val, true),
|
|
"ends" => new StringCondition(prop, inverse, StringOperator.EndsWith, val, false),
|
|
"ends~" => new StringCondition(prop, inverse, StringOperator.EndsWith, val, true),
|
|
"~ends" => new StringCondition(prop, inverse, StringOperator.EndsWith, val, true),
|
|
"contains" => new StringCondition(prop, inverse, StringOperator.Contains, val, false),
|
|
"contains~" => new StringCondition(prop, inverse, StringOperator.Contains, val, true),
|
|
"~contains" => new StringCondition(prop, inverse, StringOperator.Contains, val, true),
|
|
_ => null
|
|
};
|
|
|
|
if (condition == null)
|
|
throw new InvalidOperationException($"Unrecognized operator (\"{oper}\").");
|
|
|
|
current.Add(condition);
|
|
}
|
|
|
|
conditions.Add(current.ToArray());
|
|
|
|
return new ObjectConditional(objectType, conditions.ToArray());
|
|
}
|
|
}
|
|
}
|