Adds more unit tests (#133)

This commit is contained in:
Kamron Batman 2020-05-08 20:32:59 -07:00 • committed by GitHub
parent e138706536
commit 8278694105
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
37 changed files with 1406 additions and 996 deletions

View file

@ -29,7 +29,6 @@ using Server.Accounting;
using Server.Compression;
using Server.ContextMenus;
using Server.Gumps;
using Server.HuePickers;
using Server.Items;
using Server.Menus;
using Server.Menus.ItemLists;
@ -58,474 +57,6 @@ namespace Server.Network
Inspecific = 5
}
public sealed class VendorSellList : Packet
{
public VendorSellList(Mobile shopkeeper, ICollection<SellItemState> sis) : base(0x9E)
{
EnsureCapacity(256);
Stream.Write(shopkeeper.Serial);
Stream.Write((ushort)sis.Count);
foreach (var state in sis)
{
Stream.Write(state.Item.Serial);
Stream.Write((ushort)state.Item.ItemID);
Stream.Write((ushort)state.Item.Hue);
Stream.Write((ushort)state.Item.Amount);
Stream.Write((ushort)state.Price);
var name = state.Item.Name?.Trim();
if (string.IsNullOrWhiteSpace(name))
name = state.Name ?? "";
Stream.Write((ushort)name.Length);
Stream.WriteAsciiFixed(name, (ushort)name.Length);
}
}
}
public sealed class EndVendorSell : Packet
{
public EndVendorSell(Mobile vendor) : base(0x3B, 8)
{
Stream.Write((ushort)8); // length
Stream.Write(vendor.Serial);
Stream.Write((byte)0);
}
}
public sealed class EndVendorBuy : Packet
{
public EndVendorBuy(Mobile vendor) : base(0x3B, 8)
{
Stream.Write((ushort)8); // length
Stream.Write(vendor.Serial);
Stream.Write((byte)0);
}
}
public sealed class DeathAnimation : Packet
{
public DeathAnimation(Mobile killed, Item corpse) : base(0xAF, 13)
{
Stream.Write(killed.Serial);
Stream.Write(corpse?.Serial ?? Serial.Zero);
Stream.Write(0);
}
}
public sealed class StatLockInfo : Packet
{
public StatLockInfo(Mobile m) : base(0xBF)
{
EnsureCapacity(12);
Stream.Write((short)0x19);
Stream.Write((byte)2);
Stream.Write(m.Serial);
Stream.Write((byte)0);
var lockBits = ((int)m.StrLock << 4) | ((int)m.DexLock << 2) | (int)m.IntLock;
Stream.Write((byte)lockBits);
}
}
public class EquipInfoAttribute
{
public EquipInfoAttribute(int number, int charges = -1)
{
Number = number;
Charges = charges;
}
public int Number { get; }
public int Charges { get; }
}
public class EquipmentInfo
{
public EquipmentInfo(int number, Mobile crafter, bool unidentified, EquipInfoAttribute[] attributes)
{
Number = number;
Crafter = crafter;
Unidentified = unidentified;
Attributes = attributes;
}
public int Number { get; }
public Mobile Crafter { get; }
public bool Unidentified { get; }
public EquipInfoAttribute[] Attributes { get; }
}
public sealed class DisplayEquipmentInfo : Packet
{
public DisplayEquipmentInfo(Item item, EquipmentInfo info) : base(0xBF)
{
var attrs = info.Attributes;
EnsureCapacity(17 + (info.Crafter?.Name.Length ?? 0) +
(info.Unidentified ? 4 : 0) + attrs.Length * 6);
Stream.Write((short)0x10);
Stream.Write(item.Serial);
Stream.Write(info.Number);
if (info.Crafter != null)
{
var name = info.Crafter.Name;
Stream.Write(-3);
if (name == null)
{
Stream.Write((ushort)0);
}
else
{
var length = name.Length;
Stream.Write((ushort)length);
Stream.WriteAsciiFixed(name, length);
}
}
if (info.Unidentified) Stream.Write(-4);
for (var i = 0; i < attrs.Length; ++i)
{
Stream.Write(attrs[i].Number);
Stream.Write((short)attrs[i].Charges);
}
Stream.Write(-1);
}
}
public sealed class ChangeUpdateRange : Packet
{
private static readonly ChangeUpdateRange[] m_Cache = new ChangeUpdateRange[0x100];
public ChangeUpdateRange(int range) : base(0xC8, 2)
{
Stream.Write((byte)range);
}
public static ChangeUpdateRange Instantiate(int range)
{
var idx = (byte)range;
var p = m_Cache[idx];
if (p == null)
{
m_Cache[idx] = p = new ChangeUpdateRange(range);
p.SetStatic();
}
return p;
}
}
public sealed class ChangeCombatant : Packet
{
public ChangeCombatant(Mobile combatant) : base(0xAA, 5)
{
Stream.Write(combatant?.Serial ?? Serial.Zero);
}
}
public sealed class DisplayHuePicker : Packet
{
public DisplayHuePicker(HuePicker huePicker) : base(0x95, 9)
{
Stream.Write(huePicker.Serial);
Stream.Write((short)0);
Stream.Write((short)huePicker.ItemID);
}
}
public sealed class TripTimeResponse : Packet
{
public TripTimeResponse(int unk) : base(0xC9, 6)
{
Stream.Write((byte)unk);
Stream.Write(Environment.TickCount);
}
}
public sealed class UTripTimeResponse : Packet
{
public UTripTimeResponse(int unk) : base(0xCA, 6)
{
Stream.Write((byte)unk);
Stream.Write(Environment.TickCount);
}
}
public sealed class UnicodePrompt : Packet
{
public UnicodePrompt(Prompt prompt) : base(0xC2)
{
EnsureCapacity(21);
Stream.Write(prompt.Serial);
Stream.Write(prompt.Serial);
Stream.Write(0);
Stream.Write(0);
Stream.Write((short)0);
}
}
public sealed class ChangeCharacter : Packet
{
public ChangeCharacter(IAccount a) : base(0x81)
{
EnsureCapacity(305);
var count = 0;
for (var i = 0; i < a.Length; ++i)
if (a[i] != null)
++count;
Stream.Write((byte)count);
Stream.Write((byte)0);
for (var i = 0; i < a.Length; ++i)
if (a[i] != null)
{
var name = a[i].Name;
if (name == null)
name = "-null-";
else if ((name = name.Trim()).Length == 0)
name = "-empty-";
Stream.WriteAsciiFixed(name, 30);
Stream.Fill(30); // password
}
else
{
Stream.Fill(60);
}
}
}
public sealed class DeathStatus : Packet
{
public static readonly Packet Dead = SetStatic(new DeathStatus(true));
public static readonly Packet Alive = SetStatic(new DeathStatus(false));
public DeathStatus(bool dead) : base(0x2C, 2)
{
Stream.Write((byte)(dead ? 0 : 2));
}
public static Packet Instantiate(bool dead) => dead ? Dead : Alive;
}
public sealed class SpeedControl : Packet
{
public static readonly Packet WalkSpeed = SetStatic(new SpeedControl(2));
public static readonly Packet MountSpeed = SetStatic(new SpeedControl(1));
public static readonly Packet Disable = SetStatic(new SpeedControl(0));
public SpeedControl(int speedControl)
: base(0xBF)
{
EnsureCapacity(3);
Stream.Write((short)0x26);
Stream.Write((byte)speedControl);
}
}
public sealed class InvalidMapEnable : Packet
{
public InvalidMapEnable() : base(0xC6, 1)
{
}
}
public sealed class BondedStatus : Packet
{
public BondedStatus(int val1, Serial serial, int val2) : base(0xBF)
{
EnsureCapacity(11);
Stream.Write((short)0x19);
Stream.Write((byte)val1);
Stream.Write(serial);
Stream.Write((byte)val2);
}
}
public sealed class ToggleSpecialAbility : Packet
{
public ToggleSpecialAbility(int abilityID, bool active)
: base(0xBF)
{
EnsureCapacity(7);
Stream.Write((short)0x25);
Stream.Write((short)abilityID);
Stream.Write(active);
}
}
public sealed class DisplayItemListMenu : Packet
{
public DisplayItemListMenu(ItemListMenu menu) : base(0x7C)
{
EnsureCapacity(256);
Stream.Write(((IMenu)menu).Serial);
Stream.Write((short)0);
var question = menu.Question;
if (question == null)
{
Stream.Write((byte)0);
}
else
{
var questionLength = question.Length;
Stream.Write((byte)questionLength);
Stream.WriteAsciiFixed(question, questionLength);
}
var entries = menu.Entries;
int entriesLength = (byte)entries.Length;
Stream.Write((byte)entriesLength);
for (var i = 0; i < entriesLength; ++i)
{
var e = entries[i];
Stream.Write((ushort)e.ItemID);
Stream.Write((short)e.Hue);
var name = e.Name;
if (name == null)
{
Stream.Write((byte)0);
}
else
{
var nameLength = name.Length;
Stream.Write((byte)nameLength);
Stream.WriteAsciiFixed(name, nameLength);
}
}
}
}
public sealed class DisplayQuestionMenu : Packet
{
public DisplayQuestionMenu(QuestionMenu menu) : base(0x7C)
{
EnsureCapacity(256);
Stream.Write(((IMenu)menu).Serial);
Stream.Write((short)0);
var question = menu.Question;
if (question == null)
{
Stream.Write((byte)0);
}
else
{
var questionLength = question.Length;
Stream.Write((byte)questionLength);
Stream.WriteAsciiFixed(question, questionLength);
}
var answers = menu.Answers;
int answersLength = (byte)answers.Length;
Stream.Write((byte)answersLength);
for (var i = 0; i < answersLength; ++i)
{
Stream.Write(0);
var answer = answers[i];
if (answer == null)
{
Stream.Write((byte)0);
}
else
{
var answerLength = answer.Length;
Stream.Write((byte)answerLength);
Stream.WriteAsciiFixed(answer, answerLength);
}
}
}
}
public sealed class GlobalLightLevel : Packet
{
private static readonly GlobalLightLevel[] m_Cache = new GlobalLightLevel[0x100];
public GlobalLightLevel(int level) : base(0x4F, 2)
{
Stream.Write((sbyte)level);
}
public static GlobalLightLevel Instantiate(int level)
{
var lvl = (byte)level;
var p = m_Cache[lvl];
if (p == null)
{
m_Cache[lvl] = p = new GlobalLightLevel(level);
p.SetStatic();
}
return p;
}
}
public sealed class PersonalLightLevel : Packet
{
public PersonalLightLevel(Mobile m) : this(m, m.LightLevel)
{
}
public PersonalLightLevel(Mobile m, int level) : base(0x4E, 6)
{
Stream.Write(m.Serial);
Stream.Write((sbyte)level);
}
}
public sealed class PersonalLightLevelZero : Packet
{
public PersonalLightLevelZero(Mobile m) : base(0x4E, 6)
{
Stream.Write(m.Serial);
Stream.Write((sbyte)0);
}
}
[Flags]
public enum CMEFlags
{
@ -536,112 +67,6 @@ namespace Server.Network
Colored = 0x20
}
public sealed class DisplayContextMenu : Packet
{
public DisplayContextMenu(ContextMenu menu) : base(0xBF)
{
var entries = menu.Entries;
int length = (byte)entries.Length;
EnsureCapacity(12 + length * 8);
Stream.Write((short)0x14);
Stream.Write((short)0x02);
var target = menu.Target as IEntity;
Stream.Write(target?.Serial ?? Serial.MinusOne);
Stream.Write((byte)length);
Point3D p;
if (target is Mobile)
p = target.Location;
else if (target is Item item)
p = item.GetWorldLocation();
else
p = Point3D.Zero;
for (var i = 0; i < length; ++i)
{
var e = entries[i];
Stream.Write(e.Number);
Stream.Write((short)i);
var range = e.Range;
if (range == -1)
range = 18;
var flags = e.Enabled && menu.From.InRange(p, range) ? CMEFlags.None : CMEFlags.Disabled;
flags |= e.Flags;
Stream.Write((short)flags);
}
}
}
public sealed class DisplayContextMenuOld : Packet
{
public DisplayContextMenuOld(ContextMenu menu) : base(0xBF)
{
var entries = menu.Entries;
int length = (byte)entries.Length;
EnsureCapacity(12 + length * 8);
Stream.Write((short)0x14);
Stream.Write((short)0x01);
var target = menu.Target as IEntity;
Stream.Write(target?.Serial ?? Serial.MinusOne);
Stream.Write((byte)length);
Point3D p;
if (target is Mobile)
p = target.Location;
else if (target is Item item)
p = item.GetWorldLocation();
else
p = Point3D.Zero;
for (var i = 0; i < length; ++i)
{
var e = entries[i];
Stream.Write((short)i);
Stream.Write((ushort)(e.Number - 3000000));
var range = e.Range;
if (range == -1)
range = 18;
var flags = e.Enabled && menu.From.InRange(p, range) ? CMEFlags.None : CMEFlags.Disabled;
var color = e.Color & 0xFFFF;
if (color != 0xFFFF)
flags |= CMEFlags.Colored;
flags |= e.Flags;
Stream.Write((short)flags);
if ((flags & CMEFlags.Colored) != 0)
Stream.Write((short)color);
}
}
}
public sealed class DisplayProfile : Packet
{
public DisplayProfile(bool realSerial, Mobile m, string header, string body, string footer) : base(0xB8)
@ -671,38 +96,6 @@ namespace Server.Network
}
}
public sealed class EquipUpdate : Packet
{
public EquipUpdate(Item item) : base(0x2E, 15)
{
Serial parentSerial;
var parent = item.Parent as Mobile;
if (parent != null)
{
parentSerial = parent.Serial;
}
else
{
Console.WriteLine("Warning: EquipUpdate on item with !(parent is Mobile)");
parentSerial = Serial.Zero;
}
var hue = item.Hue;
if (parent?.SolidHueOverride >= 0)
hue = parent.SolidHueOverride;
Stream.Write(item.Serial);
Stream.Write((short)item.ItemID);
Stream.Write((byte)0);
Stream.Write((byte)item.Layer);
Stream.Write(parentSerial);
Stream.Write((short)hue);
}
}
public sealed class WorldItem : Packet
{
public WorldItem(Item item) : base(0x1A)
@ -909,80 +302,6 @@ namespace Server.Network
}
}
public sealed class UnkD3 : Packet
{
public UnkD3(Mobile beholder, Mobile beheld) : base(0xD3)
{
EnsureCapacity(256);
// int
// short
// short
// short
// byte
// byte
// short
// byte
// byte
// short
// short
// short
// while ( int != 0 )
// {
// short
// byte
// short
// }
Stream.Write(beheld.Serial);
Stream.Write((short)beheld.Body);
Stream.Write((short)beheld.X);
Stream.Write((short)beheld.Y);
Stream.Write((sbyte)beheld.Z);
Stream.Write((byte)beheld.Direction);
Stream.Write((ushort)beheld.Hue);
Stream.Write((byte)beheld.GetPacketFlags());
Stream.Write((byte)Notoriety.Compute(beholder, beheld));
Stream.Write((short)0);
Stream.Write((short)0);
Stream.Write((short)0);
Stream.Write(0);
}
}
public sealed class GQRequest : Packet
{
public GQRequest() : base(0xC3)
{
EnsureCapacity(256);
Stream.Write(1);
Stream.Write(2); // ID
Stream.Write(3); // Customer ? (this)
Stream.Write(4); // Customer this (?)
Stream.Write(0);
Stream.Write((short)0);
Stream.Write((short)6);
Stream.Write((byte)'r');
Stream.Write((byte)'e');
Stream.Write((byte)'g');
Stream.Write((byte)'i');
Stream.Write((byte)'o');
Stream.Write((byte)'n');
Stream.Write(7); // Call time in seconds
Stream.Write((short)2); // Map (0=fel,1=tram,2=ilsh)
Stream.Write(8); // X
Stream.Write(9); // Y
Stream.Write(10); // Z
Stream.Write(11); // Volume
Stream.Write(12); // Rank
Stream.Write(-1);
Stream.Write(1); // type
}
}
/// <summary>
/// Causes the client to walk in a given direction. It does not send a movement request.
/// </summary>
@ -996,18 +315,6 @@ namespace Server.Network
}
}
/// <summary>
/// Displays a message "There are currently [count] available calls in the global queue.".
/// </summary>
public sealed class GQCount : Packet
{
public GQCount(int unk, int count) : base(0xCB, 7)
{
Stream.Write((short)unk);
Stream.Write(count);
}
}
/// <summary>
/// Asks the client for it's version
/// </summary>
@ -1019,19 +326,6 @@ namespace Server.Network
}
}
/// <summary>
/// Asks the client for it's "assist version". (Perhaps for UOAssist?)
/// </summary>
public sealed class AssistVersionReq : Packet
{
public AssistVersionReq(int unk) : base(0xBE)
{
EnsureCapacity(7);
Stream.Write(unk);
}
}
public enum EffectType
{
Moving = 0x00,
@ -3444,70 +2738,6 @@ namespace Server.Network
}
}
[Flags]
public enum ThirdPartyFeature : ulong
{
FilterWeather = 1,
FilterLight = 1 << 1,
SmartTarget = 1 << 2,
RangedTarget = 1 << 3,
AutoOpenDoors = 1 << 4,
DequipOnCast = 1 << 5,
AutoPotionEquip = 1 << 6,
ProtectHeals = 1 << 7,
LoopedMacros = 1 << 8,
UseOnceAgent = 1 << 9,
RestockAgent = 1 << 10,
SellAgent = 1 << 11,
BuyAgent = 1 << 12,
PotionHotkeys = 1 << 13,
RandomTargets = 1 << 14,
ClosestTargets = 1 << 15, // All closest target hotkeys
OverheadHealth = 1 << 16, // Health and Mana/Stam messages shown over player's heads
AutolootAgent = 1 << 17,
BoneCutterAgent = 1 << 18,
AdvancedMacros = 1 << 19,
AutoRemount = 1 << 20,
AutoBandage = 1 << 21,
EnemyTargetShare = 1 << 22,
FilterSeason = 1 << 23,
SpellTargetShare = 1 << 24,
All = ulong.MaxValue
}
public static class FeatureProtection
{
public static ThirdPartyFeature DisabledFeatures { get; private set; } = 0;
public static void Disable(ThirdPartyFeature feature)
{
SetDisabled(feature, true);
}
public static void Enable(ThirdPartyFeature feature)
{
SetDisabled(feature, false);
}
public static void SetDisabled(ThirdPartyFeature feature, bool value)
{
if (value)
DisabledFeatures |= feature;
else
DisabledFeatures &= ~feature;
}
}
public sealed class CharacterList : Packet
{
// private static MD5CryptoServiceProvider m_MD5Provider;
@ -3568,35 +2798,6 @@ namespace Server.Network
Stream.Write((int)(flags | AdditionalFlags)); // Additional Flags
Stream.Write((short)-1);
/*ThirdPartyFeature disabled = FeatureProtection.DisabledFeatures;
if (disabled != 0)
{
if (m_MD5Provider == null)
m_MD5Provider = new MD5CryptoServiceProvider();
m_Stream.UnderlyingStream.Flush();
byte[] hashCode = m_MD5Provider.ComputeHash(m_Stream.UnderlyingStream.GetBuffer(), 0,
(int)m_Stream.UnderlyingStream.Length);
byte[] buffer = new byte[28];
for (int i = 0; i < count; ++i)
{
Utility.RandomBytes(buffer);
m_Stream.Seek(35 + i * 60, SeekOrigin.Begin);
m_Stream.Write(buffer, 0, buffer.Length);
}
m_Stream.Seek(35, SeekOrigin.Begin);
m_Stream.Write((int)((long)disabled >> 32));
m_Stream.Write((int)disabled);
m_Stream.Seek(95, SeekOrigin.Begin);
m_Stream.Write(hashCode, 0, hashCode.Length);
}*/
}
public static CharacterListFlags AdditionalFlags { get; set; }