fix: Removes support for v4 Client and old gump packet. (#1739)

### Summary
* Removes old gump packet support
* Removes support for v4 clients
* Removes `Unpack` flag and assumes it is always true.
* Removes StringToBuffer since this is built into .NET now.

> [!Note]
> View the file changes with white space off: https://github.com/modernuo/ModernUO/pull/1739/files?diff=split&w=1
This commit is contained in:
Kamron Batman 2024-04-24 19:39:37 -07:00 • committed by GitHub
parent 98d31bc707
commit 9cd84ba3d6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 1015 additions and 1191 deletions

View file

@ -2,122 +2,115 @@ using Server.Gumps;
using Server.Network;
using Xunit;
namespace Server.Tests.Network
namespace Server.Tests.Network;
public class GumpPacketTests : IClassFixture<ServerFixture>
{
public class GumpPacketTests : IClassFixture<ServerFixture>
[Theory]
[InlineData(100, 10)]
public void TestCloseGump(int typeId, int buttonId)
{
[Theory]
[InlineData(100, 10)]
public void TestCloseGump(int typeId, int buttonId)
{
var expected = new CloseGump(typeId, buttonId).Compile();
var expected = new CloseGump(typeId, buttonId).Compile();
var ns = PacketTestUtilities.CreateTestNetState();
ns.SendCloseGump(typeId, buttonId);
var ns = PacketTestUtilities.CreateTestNetState();
ns.SendCloseGump(typeId, buttonId);
var result = ns.SendPipe.Reader.AvailableToRead();
AssertThat.Equal(result, expected);
}
[Fact]
public void TestDisplaySignGump()
{
Serial gumpSerial = (Serial)0x1000;
const int gumpId = 100;
const string unknownString = "This is an unknown string";
const string caption = "This is a caption";
var expected = new DisplaySignGump(gumpSerial, gumpId, unknownString, caption).Compile();
var ns = PacketTestUtilities.CreateTestNetState();
ns.SendDisplaySignGump(gumpSerial, gumpId, unknownString, caption);
var result = ns.SendPipe.Reader.AvailableToRead();
AssertThat.Equal(result, expected);
}
[Theory]
[InlineData(ProtocolChanges.None)]
[InlineData(ProtocolChanges.Unpack)]
public void TestGumpPacketNameChange(ProtocolChanges changes)
{
var gump = new NameChangeDeedGump();
var ns = PacketTestUtilities.CreateTestNetState();
ns.ProtocolChanges = changes;
var expected = gump.Compile(ns).Compile();
ns.SendDisplayGump(gump, out _, out _);
var result = ns.SendPipe.Reader.AvailableToRead();
AssertThat.Equal(result, expected);
}
[Theory]
[InlineData(ProtocolChanges.None)]
[InlineData(ProtocolChanges.Unpack)]
public void TestGumpPacketAdmin(ProtocolChanges changes)
{
var m = new Mobile((Serial)0x1);
m.DefaultMobileInit();
m.RawName = "Test Mobile";
m.AccessLevel = AccessLevel.Administrator;
var gump = new AdminGump(m, AdminGumpPage.Clients);
var ns = PacketTestUtilities.CreateTestNetState();
ns.ProtocolChanges = changes;
var expected = gump.Compile(ns).Compile();
ns.SendDisplayGump(gump, out _, out _);
var result = ns.SendPipe.Reader.AvailableToRead();
AssertThat.Equal(result, expected);
}
var result = ns.SendPipe.Reader.AvailableToRead();
AssertThat.Equal(result, expected);
}
public class NameChangeDeedGump : Gump
[Fact]
public void TestDisplaySignGump()
{
public NameChangeDeedGump() : base(50, 50)
{
Closable = false;
Draggable = false;
Resizable = false;
Serial gumpSerial = (Serial)0x1000;
const int gumpId = 100;
const string unknownString = "This is an unknown string";
const string caption = "This is a caption";
AddPage(0);
var expected = new DisplaySignGump(gumpSerial, gumpId, unknownString, caption).Compile();
AddBlackAlpha(10, 120, 250, 85);
AddHtml(10, 125, 250, 20, Color(Center("Name Change Deed"), 0xFFFFFF));
var ns = PacketTestUtilities.CreateTestNetState();
ns.SendDisplaySignGump(gumpSerial, gumpId, unknownString, caption);
AddLabel(73, 15, 1152, "");
AddLabel(20, 150, 0x480, "New Name:");
AddTextField(100, 150, 150, 20, 0);
var result = ns.SendPipe.Reader.AvailableToRead();
AssertThat.Equal(result, expected);
}
AddButtonLabeled(75, 180, 1, "Submit");
}
[Fact]
public void TestGumpPacketNameChange()
{
var gump = new NameChangeDeedGump();
public void AddBlackAlpha(int x, int y, int width, int height)
{
AddImageTiled(x, y, width, height, 2624);
AddAlphaRegion(x, y, width, height);
}
var ns = PacketTestUtilities.CreateTestNetState();
public void AddTextField(int x, int y, int width, int height, int index)
{
AddBackground(x - 2, y - 2, width + 4, height + 4, 0x2486);
AddTextEntry(x + 2, y + 2, width - 4, height - 4, 0, index, "");
}
var expected = gump.Compile(ns).Compile();
public static string Center(string text) => $"<CENTER>{text}</CENTER>";
ns.SendDisplayGump(gump, out _, out _);
public static string Color(string text, int color) => $"<BASEFONT COLOR=#{color:X6}>{text}</BASEFONT>";
var result = ns.SendPipe.Reader.AvailableToRead();
AssertThat.Equal(result, expected);
}
public void AddButtonLabeled(int x, int y, int buttonID, string text)
{
AddButton(x, y - 1, 4005, 4007, buttonID);
AddHtml(x + 35, y, 240, 20, Color(text, 0xFFFFFF));
}
[Fact]
public void TestGumpPacketAdmin()
{
var m = new Mobile((Serial)0x1);
m.DefaultMobileInit();
m.RawName = "Test Mobile";
m.AccessLevel = AccessLevel.Administrator;
var gump = new AdminGump(m, AdminGumpPage.Clients);
var ns = PacketTestUtilities.CreateTestNetState();
var expected = gump.Compile(ns).Compile();
ns.SendDisplayGump(gump, out _, out _);
var result = ns.SendPipe.Reader.AvailableToRead();
AssertThat.Equal(result, expected);
}
}
public class NameChangeDeedGump : Gump
{
public NameChangeDeedGump() : base(50, 50)
{
Closable = false;
Draggable = false;
Resizable = false;
AddPage(0);
AddBlackAlpha(10, 120, 250, 85);
AddHtml(10, 125, 250, 20, Color(Center("Name Change Deed"), 0xFFFFFF));
AddLabel(73, 15, 1152, "");
AddLabel(20, 150, 0x480, "New Name:");
AddTextField(100, 150, 150, 20, 0);
AddButtonLabeled(75, 180, 1, "Submit");
}
public void AddBlackAlpha(int x, int y, int width, int height)
{
AddImageTiled(x, y, width, height, 2624);
AddAlphaRegion(x, y, width, height);
}
public void AddTextField(int x, int y, int width, int height, int index)
{
AddBackground(x - 2, y - 2, width + 4, height + 4, 0x2486);
AddTextEntry(x + 2, y + 2, width - 4, height - 4, 0, index, "");
}
public static string Center(string text) => $"<CENTER>{text}</CENTER>";
public static string Color(string text, int color) => $"<BASEFONT COLOR=#{color:X6}>{text}</BASEFONT>";
public void AddButtonLabeled(int x, int y, int buttonID, string text)
{
AddButton(x, y - 1, 4005, 4007, buttonID);
AddHtml(x + 35, y, 240, 20, Color(text, 0xFFFFFF));
}
}