fix: Adds AssistVersion packet support for Razor (#1094)

- [X] Fixes razor negotiations via 0xF0 packet (open negotiation)
- [X] Adds AssistVersion handling for Razor
- [X] Displays Assistant in Client/Admin gump
This commit is contained in:
Kamron Batman 2022-06-28 01:05:00 -07:00 committed by GitHub
parent 7099329dfe
commit a37b8b285c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 87 additions and 52 deletions

View file

@ -220,6 +220,8 @@ public partial class NetState : IComparable<NetState>
public IAccount Account { get; set; }
public string Assistant { get; set; }
public int CompareTo(NetState other) => string.CompareOrdinal(_toString, other?._toString);
private void SetPacketTime(int packetID)

View file

@ -48,7 +48,6 @@ public static class IncomingAccountPackets
IncomingPackets.Register(0xA0, 3, false, &PlayServer);
IncomingPackets.Register(0xBB, 9, false, &AccountID);
IncomingPackets.Register(0xBD, 0, false, &ClientVersion);
IncomingPackets.Register(0xBE, 0, true, &AssistVersion);
IncomingPackets.Register(0xCF, 0, false, &AccountLogin);
IncomingPackets.Register(0xE1, 0, false, &ClientType);
IncomingPackets.Register(0xEF, 21, false, &LoginServerSeed);
@ -197,12 +196,6 @@ public static class IncomingAccountPackets
{
}
public static void AssistVersion(NetState state, CircularBufferReader reader, int packetLength)
{
var unk = reader.ReadInt32();
var av = reader.ReadAscii();
}
public static void ClientVersion(NetState state, CircularBufferReader reader, int packetLength)
{
var version = state.Version = new CV(reader.ReadAscii());

View file

@ -10,8 +10,6 @@ public static class AssistantConfiguration
{
private const string _path = "Configuration/assistants.json";
public static bool Enabled { get; private set; }
public static AssistantSettings Settings { get; private set; }
private const string _defaultWarningMessage = "The server was unable to negotiate features with your assistant. "
@ -23,8 +21,6 @@ public static class AssistantConfiguration
public static void Configure()
{
Enabled = ServerConfiguration.GetOrUpdateSetting("assistants.enableRazorNegotiation", false);
var path = Path.Join(Core.BaseDirectory, _path);
if (File.Exists(path))

View file

@ -15,7 +15,10 @@ public static class AssistantHandler
public static unsafe void Configure()
{
Enabled = ServerConfiguration.GetOrUpdateSetting("assistants.enableNegotiation", false);
EventSink.Login -= OnLogin;
EventSink.Login += OnLogin;
IncomingPackets.Register(0xBE, 0, false, &AssistVersion);
AssistantProtocol.Register(0xFF, false, &HandshakeResponse);
}
@ -57,12 +60,13 @@ public static class AssistantHandler
private static void OnLogin(Mobile m)
{
if (m?.NetState?.Running != true || !AssistantConfiguration.Enabled)
if (m?.NetState?.Running != true || !Enabled)
{
return;
}
m.NetState.SendAssistUOHandshake();
m.NetState.SendAssistVersionReq();
m.NetState.SendAssistHandshake();
if (_handshakes.TryGetValue(m, out var t))
{
@ -72,6 +76,17 @@ public static class AssistantHandler
_handshakes[m] = Timer.DelayCall(TimeSpan.FromSeconds(30), OnTimeout, m);
}
public static void AssistVersion(NetState state, CircularBufferReader reader, int packetLength)
{
// We are not supporting the old UOAssist protocol
// var assistVersion = reader.ReadInt32();
// var clientVersion = reader.ReadAscii();
// Instead we are supporting razor community edition.
var assistVersion = reader.ReadAscii();
state.Assistant = assistVersion.Contains(' ') ? assistVersion : $"RazorCE {assistVersion}";
}
private static void HandshakeResponse(NetState state, CircularBufferReader reader, int packetLength)
{
Mobile m = state.Mobile;
@ -114,9 +129,19 @@ public static class AssistantHandler
_handshakes.Remove(m);
}
public static void SendAssistUOHandshake(this NetState ns)
public static void SendAssistVersionReq(this NetState ns)
{
if (ns?.CannotSendPackets() != false)
if (ns.CannotSendPackets())
{
return;
}
ns.Send(stackalloc byte[] { 0xBE, 0x00, 0x03 });
}
public static void SendAssistHandshake(this NetState ns)
{
if (ns.CannotSendPackets())
{
return;
}
@ -126,5 +151,7 @@ public static class AssistantHandler
writer.Write((ushort)12);
writer.Write((byte)0xFE); // Command
writer.Write((ulong)AssistantConfiguration.Settings.DisallowedFeatures);
ns.Send(writer.Span);
}
}

View file

@ -550,7 +550,15 @@ namespace Server.Gumps
var v = ns.Version;
AddLabel(20, y, LabelHue, "Version:");
AddLabel(200, y, LabelHue, v == null ? "(null)" : v.ToString());
if (ns.Assistant != null)
{
AddLabel(200, y, LabelHue, $"{v.SourceString ?? "(null)"} ({ns.Assistant})");
}
else
{
AddLabel(200, y, LabelHue, v.SourceString ?? "(null)");
}
y += 20;
AddLabel(20, y, LabelHue, "Location:");

View file

@ -23,13 +23,13 @@ namespace Server.Gumps
AddPage(0);
AddBackground(0, 0, 400, 274, 5054);
AddBackground(0, 0, 420, 314, 5054);
AddImageTiled(10, 10, 380, 19, 0xA40);
AddAlphaRegion(10, 10, 380, 19);
AddImageTiled(10, 10, 400, 19, 0xA40);
AddAlphaRegion(10, 10, 400, 19);
AddImageTiled(10, 32, 380, 232, 0xA40);
AddAlphaRegion(10, 32, 380, 232);
AddImageTiled(10, 32, 400, 272, 0xA40);
AddAlphaRegion(10, 32, 400, 272);
AddHtml(10, 10, 380, 20, Color(Center("User Information"), LabelColor32));
@ -40,11 +40,20 @@ namespace Server.Gumps
AddHtml(14, 36 + line * 20, 200, 20, Color("Client:", LabelColor32));
AddHtml(
70,
72,
36 + line++ * 20,
200,
20,
Color(state.Version == null ? "(null)" : state.Version.ToString(), LabelColor32)
Color(state.Version?.SourceString ?? "(null)", LabelColor32)
);
AddHtml(14, 36 + line * 20, 200, 20, Color("Assistant:", LabelColor32));
AddHtml(
72,
36 + line++ * 20,
200,
20,
Color(state.Assistant ?? "(-none-)", LabelColor32)
);
AddHtml(14, 36 + line * 20, 200, 20, Color("Version:", LabelColor32));
@ -52,7 +61,7 @@ namespace Server.Gumps
var info = state.ExpansionInfo;
var expansionName = info.Name;
AddHtml(70, 36 + line++ * 20, 200, 20, Color(expansionName, LabelColor32));
AddHtml(72, 36 + line++ * 20, 200, 20, Color(expansionName, LabelColor32));
var a = state.Account as Account;
var m = state.Mobile;
@ -60,70 +69,70 @@ namespace Server.Gumps
if (from.AccessLevel >= AccessLevel.GameMaster && a != null)
{
AddHtml(14, 36 + line * 20, 200, 20, Color("Account:", LabelColor32));
AddHtml(70, 36 + line++ * 20, 200, 20, Color(a.Username, LabelColor32));
AddHtml(72, 36 + line++ * 20, 200, 20, Color(a.Username, LabelColor32));
}
if (m != null)
{
AddHtml(14, 36 + line * 20, 200, 20, Color("Mobile:", LabelColor32));
AddHtml(70, 36 + line++ * 20, 200, 20, Color($"{m.Name} ({m.Serial})", LabelColor32));
AddHtml(72, 36 + line++ * 20, 200, 20, Color($"{m.Name} ({m.Serial})", LabelColor32));
AddHtml(14, 36 + line * 20, 200, 20, Color("Location:", LabelColor32));
AddHtml(70, 36 + line++ * 20, 200, 20, Color($"{m.Location} [{m.Map}]", LabelColor32));
AddHtml(72, 36 + line++ * 20, 200, 20, Color($"{m.Location} [{m.Map}]", LabelColor32));
AddButton(13, 157, 0xFAB, 0xFAD, 1);
AddHtml(48, 158, 200, 20, Color("Send Message", LabelColor32));
AddButton(13, 197, 0xFAB, 0xFAD, 1);
AddHtml(48, 198, 200, 20, Color("Send Message", LabelColor32));
AddImageTiled(12, 182, 376, 80, 0xA40);
AddImageTiled(13, 183, 374, 78, 0xBBC);
AddTextEntry(15, 183, 372, 78, 0x480, 0, "");
AddImageTiled(12, 222, 376, 80, 0xA40);
AddImageTiled(13, 223, 374, 78, 0xBBC);
AddTextEntry(15, 223, 372, 78, 0x480, 0, initialText);
AddImageTiled(245, 35, 142, 144, 5058);
AddImageTiled(265, 35, 142, 144, 5058);
AddImageTiled(246, 36, 140, 142, 0xA40);
AddAlphaRegion(246, 36, 140, 142);
AddImageTiled(266, 36, 140, 142, 0xA40);
AddAlphaRegion(266, 36, 140, 142);
line = 0;
if (BaseCommand.IsAccessible(from, m))
{
AddButton(246, 36 + line * 20, 0xFA5, 0xFA7, 4);
AddHtml(280, 38 + line++ * 20, 100, 20, Color("Properties", LabelColor32));
AddButton(266, 36 + line * 20, 0xFA5, 0xFA7, 4);
AddHtml(300, 38 + line++ * 20, 100, 20, Color("Properties", LabelColor32));
}
if (from != m)
{
AddButton(246, 36 + line * 20, 0xFA5, 0xFA7, 5);
AddHtml(280, 38 + line++ * 20, 100, 20, Color("Go to them", LabelColor32));
AddButton(266, 36 + line * 20, 0xFA5, 0xFA7, 5);
AddHtml(300, 38 + line++ * 20, 100, 20, Color("Go to them", LabelColor32));
AddButton(246, 36 + line * 20, 0xFA5, 0xFA7, 6);
AddHtml(280, 38 + line++ * 20, 100, 20, Color("Bring them here", LabelColor32));
AddButton(266, 36 + line * 20, 0xFA5, 0xFA7, 6);
AddHtml(300, 38 + line++ * 20, 100, 20, Color("Bring them here", LabelColor32));
}
AddButton(246, 36 + line * 20, 0xFA5, 0xFA7, 7);
AddHtml(280, 38 + line++ * 20, 100, 20, Color("Move to target", LabelColor32));
AddButton(266, 36 + line * 20, 0xFA5, 0xFA7, 7);
AddHtml(300, 38 + line++ * 20, 100, 20, Color("Move to target", LabelColor32));
if (from.AccessLevel >= AccessLevel.GameMaster && from.AccessLevel > m.AccessLevel)
{
AddButton(246, 36 + line * 20, 0xFA5, 0xFA7, 8);
AddHtml(280, 38 + line++ * 20, 100, 20, Color("Disconnect", LabelColor32));
AddButton(266, 36 + line * 20, 0xFA5, 0xFA7, 8);
AddHtml(300, 38 + line++ * 20, 100, 20, Color("Disconnect", LabelColor32));
if (m.Alive)
{
AddButton(246, 36 + line * 20, 0xFA5, 0xFA7, 9);
AddHtml(280, 38 + line++ * 20, 100, 20, Color("Kill", LabelColor32));
AddButton(266, 36 + line * 20, 0xFA5, 0xFA7, 9);
AddHtml(300, 38 + line++ * 20, 100, 20, Color("Kill", LabelColor32));
}
else
{
AddButton(246, 36 + line * 20, 0xFA5, 0xFA7, 10);
AddHtml(280, 38 + line++ * 20, 100, 20, Color("Resurrect", LabelColor32));
AddButton(266, 36 + line * 20, 0xFA5, 0xFA7, 10);
AddHtml(300, 38 + line++ * 20, 100, 20, Color("Resurrect", LabelColor32));
}
}
if (from.AccessLevel >= AccessLevel.Counselor && from.AccessLevel > m.AccessLevel)
{
AddButton(246, 36 + line * 20, 0xFA5, 0xFA7, 11);
AddHtml(280, 38 + line++ * 20, 100, 20, Color("Skills browser", LabelColor32));
AddButton(266, 36 + line * 20, 0xFA5, 0xFA7, 11);
AddHtml(300, 38 + line++ * 20, 100, 20, Color("Skills browser", LabelColor32));
}
}
}