fix(core): Converts some packets & misc fixes/cleanup (#414)

- [X] Adds a stop music packet
- [X] Converts chat packets
- [X] Breaks out chat code a little bit more
- [X] Converts character statue animation packet
- [X] Renames some folders to have spaces
- [X] Organizes and consolidates incoming/outgoing packets for other content
- [X] Fixes virtual checks
This commit is contained in:
Kamron Batman 2021-01-16 21:01:54 -08:00 committed by GitHub
parent a146955f6c
commit fbafd7210d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
49 changed files with 814 additions and 662 deletions

View file

@ -0,0 +1,25 @@
using System;
using Server.Engines.Chat;
using Server.Tests;
using Server.Tests.Network;
using Xunit;
namespace UOContent.Tests
{
public class ChatPacketTests
{
[Theory]
[InlineData(null, 100, "some param", "some other param")]
[InlineData("ENU", 200, "a third param", "another param")]
public void TestSendChatMessage(string lang, int number, string param1, string param2)
{
var expected = new ChatMessagePacket(lang, number, param1, param2).Compile();
using var ns = PacketTestUtilities.CreateTestNetState();
ns.SendChatMessage(lang, number, param1, param2);
var result = ns.SendPipe.Reader.TryRead();
AssertThat.Equal(result.Buffer[0].AsSpan(0), expected);
}
}
}

View file

@ -0,0 +1,29 @@
using Server.Network;
namespace Server.Engines.Chat
{
public sealed class ChatMessagePacket : Packet
{
public ChatMessagePacket(string lang, int number, string param1, string param2) : base(0xB2)
{
param1 ??= string.Empty;
param2 ??= string.Empty;
EnsureCapacity(13 + (param1.Length + param2.Length) * 2);
Stream.Write((ushort)(number - 20));
if (lang != null)
{
Stream.WriteAsciiFixed(lang, 4);
}
else
{
Stream.Write(0);
}
Stream.WriteBigUniNull(param1);
Stream.WriteBigUniNull(param2);
}
}
}

View file

@ -0,0 +1,27 @@
using System;
using Server;
using Server.Engines.VeteranRewards;
using Server.Network;
using Server.Tests;
using Server.Tests.Network;
using Xunit;
namespace UOContent.Tests
{
public class CharacterStatuePacketTests
{
[Theory]
[InlineData(0x1024u, 1, 100, 200)]
public void TestSendStatueAnimation(uint s, int status, int anim, int frame)
{
Serial serial = s;
var expected = new UpdateStatueAnimation(serial, status, anim, frame).Compile();
using var ns = PacketTestUtilities.CreateTestNetState();
ns.SendStatueAnimation(serial, status, anim, frame);
var result = ns.SendPipe.Reader.TryRead();
AssertThat.Equal(result.Buffer[0].AsSpan(0), expected);
}
}
}

View file

@ -0,0 +1,20 @@
namespace Server.Network
{
public class UpdateStatueAnimation : Packet
{
public UpdateStatueAnimation(Serial serial, int status, int animation, int frame) : base(0xBF, 17)
{
Stream.Write((short)0x11);
Stream.Write((short)0x19);
Stream.Write((byte)0x5);
Stream.Write(serial);
Stream.Write((byte)0);
Stream.Write((byte)0xFF);
Stream.Write((byte)status);
Stream.Write((byte)0);
Stream.Write((byte)animation);
Stream.Write((byte)0);
Stream.Write((byte)frame);
}
}
}