parent
75c1b32513
commit
54b0a7dcb5
6 changed files with 59 additions and 75 deletions
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -2064,17 +2064,14 @@ namespace Server
|
|||
|
||||
m_Prompt = null;
|
||||
|
||||
// TODO: Cancel the prompt anyway?
|
||||
if (newPrompt != null)
|
||||
{
|
||||
oldPrompt?.OnCancel(this);
|
||||
}
|
||||
|
||||
m_Prompt = newPrompt;
|
||||
|
||||
if (newPrompt != null)
|
||||
{
|
||||
Send(new UnicodePrompt(newPrompt));
|
||||
}
|
||||
NetState.SendPrompt(newPrompt);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ using System;
|
|||
using System.Buffers;
|
||||
using System.IO;
|
||||
using System.Runtime.CompilerServices;
|
||||
using Server.Prompts;
|
||||
|
||||
namespace Server.Network
|
||||
{
|
||||
|
|
@ -230,5 +231,23 @@ namespace Server.Network
|
|||
|
||||
ns.Send(ref buffer, 9);
|
||||
}
|
||||
|
||||
public static void SendPrompt(this NetState ns, Prompt prompt)
|
||||
{
|
||||
if (ns == null || prompt == null || !ns.GetSendBuffer(out var buffer))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var writer = new CircularBufferWriter(buffer);
|
||||
writer.Write((byte)0xC2); // Packet ID
|
||||
writer.Write((ushort)21);
|
||||
writer.Write(prompt.Serial);
|
||||
writer.Write(prompt.Serial);
|
||||
writer.Write((long)0);
|
||||
writer.Write((short)0);
|
||||
|
||||
ns.Send(ref buffer, writer.Position);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,33 +0,0 @@
|
|||
/*************************************************************************
|
||||
* ModernUO *
|
||||
* Copyright 2019-2020 - ModernUO Development Team *
|
||||
* Email: hi@modernuo.com *
|
||||
* File: UnicodePromptPackets.cs *
|
||||
* *
|
||||
* This program is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation, either version 3 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
*************************************************************************/
|
||||
|
||||
using Server.Prompts;
|
||||
|
||||
namespace Server.Network
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue