fix(core): Updates prompt packet (#332)

- [X] Updates prompt packet
This commit is contained in:
Kamron Batman 2020-11-30 23:33:47 -08:00 committed by GitHub
parent 75c1b32513
commit 54b0a7dcb5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 59 additions and 75 deletions

View file

@ -1,3 +1,5 @@
using Server.Prompts;
namespace Server.Network
{
public sealed class MessageLocalized : Packet
@ -125,4 +127,18 @@ namespace Server.Network
Stream.Write(serial2);
}
}
public sealed class UnicodePrompt : Packet
{
public UnicodePrompt(Prompt prompt) : base(0xC2)
{
EnsureCapacity(21);
Stream.Write(prompt.Serial); // TODO: Does this value even matter?
Stream.Write(prompt.Serial);
Stream.Write(0);
Stream.Write(0);
Stream.Write((short)0);
}
}
}

View file

@ -1,5 +1,6 @@
using System;
using Server.Network;
using Server.Prompts;
using Xunit;
namespace Server.Tests.Network
@ -182,5 +183,26 @@ namespace Server.Tests.Network
var result = ns.SendPipe.Reader.TryRead();
AssertThat.Equal(result.Buffer[0].AsSpan(0), expected);
}
internal class TestPrompt : Prompt
{
}
public class UnicodePromptTests
{
[Fact]
public void TestUnicodePrompt()
{
var prompt = new TestPrompt();
var expected = new UnicodePrompt(prompt).Compile();
using var ns = PacketTestUtilities.CreateTestNetState();
ns.SendPrompt(prompt);
var result = ns.SendPipe.Reader.TryRead();
AssertThat.Equal(result.Buffer[0].AsSpan(0), expected);
}
}
}
}

View file

@ -1,37 +0,0 @@
using System;
using System.Buffers;
using Server.Network;
using Server.Prompts;
using Xunit;
namespace Server.Tests.Network
{
internal class TestPrompt : Prompt
{
}
public class UnicodePromptTests
{
[Fact]
public void TestUnicodePrompt()
{
var prompt = new TestPrompt();
var data = new UnicodePrompt(prompt).Compile();
Span<byte> expectedData = stackalloc byte[21];
var pos = 0;
expectedData.Write(ref pos, (byte)0xC2); // Packet ID
expectedData.Write(ref pos, (ushort)0x15); // Length
expectedData.Write(ref pos, prompt.Serial);
expectedData.Write(ref pos, prompt.Serial);
#if NO_LOCAL_INIT
expectedData.Write(ref pos, (ulong)0);
expectedData.Write(ref pos, (ushort)0);
#endif
AssertThat.Equal(data, expectedData);
}
}
}