fix: Adds back razor/assistuo negotiations (#1089)
* [X] Adds Razor negotiations
* [X] Adds AssistUO "handshake" 🙄
This commit is contained in:
parent
bc2ed44440
commit
4f28e1e3c4
10 changed files with 655 additions and 212 deletions
|
|
@ -448,8 +448,7 @@ namespace Server.Accounting
|
|||
/// Gets the maximum amount of characters allowed to be created on this account. Values other than 1, 5, 6, or 7 are not
|
||||
/// supported by the client.
|
||||
/// </summary>
|
||||
public int Limit => Core.SA ? 7 :
|
||||
Core.AOS ? 6 : 5;
|
||||
public int Limit => Core.SA ? 7 : Core.AOS ? 6 : 5;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the maximum amount of characters that this account can hold.
|
||||
|
|
|
|||
140
Projects/UOContent/Assistants/AssistantHandler.cs
Normal file
140
Projects/UOContent/Assistants/AssistantHandler.cs
Normal file
|
|
@ -0,0 +1,140 @@
|
|||
using System;
|
||||
using System.Buffers;
|
||||
using System.Collections.Generic;
|
||||
using Server.Gumps;
|
||||
using Server.Network;
|
||||
|
||||
namespace Server.Assistants;
|
||||
|
||||
public static class AssistantHandler
|
||||
{
|
||||
public static bool Enabled { get; private set; }
|
||||
|
||||
private static Dictionary<Mobile, Timer> _handshakes = new();
|
||||
|
||||
public static unsafe void Configure()
|
||||
{
|
||||
Enabled = ServerConfiguration.GetOrUpdateSetting("assistants.enableAssistUONegotiation", false);
|
||||
|
||||
EventSink.AssistantAuth += OnAssistantAuth;
|
||||
EventSink.Login -= OnLogin;
|
||||
AssistantProtocol.Register(0xFF, false, &AssistUOHandshakeResponse);
|
||||
}
|
||||
|
||||
private static void OnAssistantAuth(AssistantAuthEventArgs e)
|
||||
{
|
||||
if (e.AuthOk)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var m = e.State.Mobile;
|
||||
var isPlayer = m.AccessLevel <= AccessLevel.Player;
|
||||
var willKick = AssistantConfiguration.Settings.KickOnFailure;
|
||||
var delay = AssistantConfiguration.Settings.DisconnectDelay;
|
||||
|
||||
if (willKick && isPlayer && delay <= TimeSpan.Zero)
|
||||
{
|
||||
e.State.Disconnect("Failed to negotiate assistant features.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (AssistantConfiguration.Settings.WarnOnFailure)
|
||||
{
|
||||
var warningGump = new WarningGump(
|
||||
1060635,
|
||||
30720,
|
||||
AssistantConfiguration.Settings.WarningMessage,
|
||||
0xFFC000,
|
||||
420,
|
||||
250,
|
||||
null,
|
||||
false
|
||||
);
|
||||
|
||||
m.SendGump(warningGump);
|
||||
}
|
||||
|
||||
if (isPlayer)
|
||||
{
|
||||
_handshakes[m] = Timer.DelayCall(delay, OnForceDisconnect, m);
|
||||
}
|
||||
|
||||
e.State.LogInfo("Failed to negotiate assistant features.");
|
||||
}
|
||||
|
||||
private static void OnLogin(Mobile m)
|
||||
{
|
||||
if (m?.NetState?.Running != true || !AssistantConfiguration.Enabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
m.NetState.SendAssistUOHandshake();
|
||||
|
||||
if (_handshakes.TryGetValue(m, out var t))
|
||||
{
|
||||
t?.Stop();
|
||||
}
|
||||
|
||||
_handshakes[m] = Timer.DelayCall(TimeSpan.FromSeconds(30), OnTimeout, m);
|
||||
}
|
||||
|
||||
private static void AssistUOHandshakeResponse(NetState state, CircularBufferReader reader, int packetLength)
|
||||
{
|
||||
Mobile m = state.Mobile;
|
||||
|
||||
if (m == null || !_handshakes.TryGetValue(m, out var t))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
t?.Stop();
|
||||
_handshakes.Remove(m);
|
||||
|
||||
EventSink.InvokeAssistantAuth(new AssistantAuthEventArgs(m.NetState, m.Account, true));
|
||||
}
|
||||
|
||||
private static void OnTimeout(Mobile m)
|
||||
{
|
||||
if (m == null || !_handshakes.TryGetValue(m, out var t))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
t?.Stop();
|
||||
_handshakes.Remove(m);
|
||||
|
||||
if (m.NetState?.Running != true || !Enabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
EventSink.InvokeAssistantAuth(new AssistantAuthEventArgs(m.NetState, m.Account, false));
|
||||
}
|
||||
|
||||
private static void OnForceDisconnect(Mobile m)
|
||||
{
|
||||
if (m == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
m.NetState?.Disconnect($"Player {m} kicked (Failed assistant handshake)");
|
||||
_handshakes.Remove(m);
|
||||
}
|
||||
|
||||
public static void SendAssistUOHandshake(this NetState ns)
|
||||
{
|
||||
if (ns?.CannotSendPackets() != false)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var writer = new SpanWriter(stackalloc byte[12]);
|
||||
writer.Write((byte)0xF0); // Packet ID
|
||||
writer.Write((ushort)12);
|
||||
writer.Write((byte)0xFE); // Command
|
||||
writer.Write((ulong)AssistantConfiguration.Settings.DisallowedFeatures);
|
||||
}
|
||||
}
|
||||
19
Projects/UOContent/Assistants/AssistantProtocol.cs
Normal file
19
Projects/UOContent/Assistants/AssistantProtocol.cs
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
namespace Server.Network;
|
||||
|
||||
public static class AssistantProtocol
|
||||
{
|
||||
private static PacketHandler[] _handlers;
|
||||
|
||||
public static void Configure()
|
||||
{
|
||||
_handlers = ProtocolExtensions<AssistantsProtocolInfo>.Register(new AssistantsProtocolInfo());
|
||||
}
|
||||
|
||||
public static unsafe void Register(int cmd, bool ingame, delegate*<NetState, CircularBufferReader, int, void> onReceive) =>
|
||||
_handlers[cmd] = new PacketHandler(cmd, 0, ingame, onReceive);
|
||||
|
||||
private struct AssistantsProtocolInfo : IProtocolExtensionsInfo
|
||||
{
|
||||
public int PacketId => 0xF0;
|
||||
}
|
||||
}
|
||||
|
|
@ -3,7 +3,7 @@ using ModernUO.Serialization;
|
|||
namespace Server.Items
|
||||
{
|
||||
[SerializationGenerator(0, false)]
|
||||
public partial class StaffOfTheMagi : BlackStaff
|
||||
public partial class StaffOfTheMagi : BlackStaff
|
||||
{
|
||||
[Constructible]
|
||||
public StaffOfTheMagi()
|
||||
|
|
|
|||
|
|
@ -19,151 +19,138 @@ using System.IO;
|
|||
using Server.Engines.PartySystem;
|
||||
using Server.Guilds;
|
||||
|
||||
namespace Server.Network
|
||||
namespace Server.Network;
|
||||
|
||||
public static class MapUO
|
||||
{
|
||||
public static class MapUO
|
||||
public static unsafe void Configure()
|
||||
{
|
||||
private static PacketHandler[] _handlers;
|
||||
AssistantProtocol.Register(0x00, true, &QueryPartyMemberLocations);
|
||||
AssistantProtocol.Register(0x01, true, &QueryGuildMemberLocations);
|
||||
}
|
||||
|
||||
public static unsafe void Configure()
|
||||
public static void QueryGuildMemberLocations(NetState state, CircularBufferReader reader, int packetLength)
|
||||
{
|
||||
Mobile from = state.Mobile;
|
||||
|
||||
state.SendGuildMemberLocations(from, from.Guild as Guild, reader.ReadBoolean());
|
||||
}
|
||||
|
||||
public static void QueryPartyMemberLocations(NetState state, CircularBufferReader reader, int packetLength)
|
||||
{
|
||||
Mobile from = state.Mobile;
|
||||
var party = Party.Get(from);
|
||||
|
||||
if (party != null)
|
||||
{
|
||||
_handlers = ProtocolExtensions<MapUOProtocolInfo>.Register(new MapUOProtocolInfo());
|
||||
|
||||
Register(0x00, true, &QueryPartyMemberLocations);
|
||||
Register(0x01, true, &QueryGuildMemberLocations);
|
||||
}
|
||||
|
||||
public static unsafe void Register(int cmd, bool ingame, delegate*<NetState, CircularBufferReader, int, void> onReceive) =>
|
||||
_handlers[cmd] = new PacketHandler(cmd, 0, ingame, onReceive);
|
||||
|
||||
public static void QueryGuildMemberLocations(NetState state, CircularBufferReader reader, int packetLength)
|
||||
{
|
||||
Mobile from = state.Mobile;
|
||||
|
||||
state.SendGuildMemberLocations(from, from.Guild as Guild, reader.ReadBoolean());
|
||||
}
|
||||
|
||||
public static void QueryPartyMemberLocations(NetState state, CircularBufferReader reader, int packetLength)
|
||||
{
|
||||
Mobile from = state.Mobile;
|
||||
var party = Party.Get(from);
|
||||
|
||||
if (party != null)
|
||||
{
|
||||
state.SendPartyMemberLocations(from, party);
|
||||
}
|
||||
}
|
||||
|
||||
public static void SendGuildMemberLocations(this NetState ns, Mobile from, Guild guild, bool sendLocations)
|
||||
{
|
||||
if (ns.CannotSendPackets())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var count = guild?.Members.Count ?? 0;
|
||||
var maxLength = 9 + (count > 1 ? (count - 1) * (sendLocations ? 10 : 4) : 0);
|
||||
var writer = new SpanWriter(stackalloc byte[maxLength]);
|
||||
writer.Write((byte)0xF0); // Packet ID
|
||||
writer.Seek(2, SeekOrigin.Current);
|
||||
writer.Write((byte)0x02); // Command
|
||||
writer.Write(count > 0 && sendLocations);
|
||||
|
||||
bool sendPacket = false;
|
||||
for (var i = 0; i < count; i++)
|
||||
{
|
||||
var m = guild!.Members[i];
|
||||
|
||||
if (m?.NetState == null || m == from)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (sendLocations && Utility.InUpdateRange(from.Location, m.Location) && from.CanSee(m))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
sendPacket = true;
|
||||
writer.Write(m.Serial);
|
||||
|
||||
if (sendLocations)
|
||||
{
|
||||
writer.Write((short)m.X);
|
||||
writer.Write((short)m.Y);
|
||||
writer.Write((byte)(m.Map?.MapID ?? 0));
|
||||
|
||||
if (m.Alive)
|
||||
{
|
||||
writer.Write((byte)(m.Hits * 100 / Math.Max(m.HitsMax, 1)));
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.Write((byte)0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!sendPacket)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
writer.Write(0);
|
||||
writer.WritePacketLength();
|
||||
ns.Send(writer.Span);
|
||||
}
|
||||
|
||||
public static void SendPartyMemberLocations(this NetState ns, Mobile from, Party party)
|
||||
{
|
||||
if (ns.CannotSendPackets())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var count = party?.Members.Count ?? 0;
|
||||
var maxLength = 9 + (count > 1 ? (count - 1) * 9 : 0);
|
||||
var writer = new SpanWriter(stackalloc byte[maxLength]);
|
||||
writer.Write((byte)0xF0); // Packet ID
|
||||
writer.Seek(2, SeekOrigin.Current);
|
||||
writer.Write((byte)0x01); // Command
|
||||
|
||||
bool sendPacket = false;
|
||||
for (var i = 0; i < count; i++)
|
||||
{
|
||||
var pmi = party!.Members[i];
|
||||
Mobile mob = pmi?.Mobile;
|
||||
|
||||
if (mob?.NetState == null || mob == from)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (Utility.InUpdateRange(from.Location, mob.Location) && from.CanSee(mob))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
sendPacket = true;
|
||||
writer.Write(mob.Serial);
|
||||
writer.Write((short)mob.X);
|
||||
writer.Write((short)mob.Y);
|
||||
writer.Write((byte)(mob.Map?.MapID ?? 0));
|
||||
}
|
||||
|
||||
if (!sendPacket)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
writer.Write(0);
|
||||
writer.WritePacketLength();
|
||||
ns.Send(writer.Span);
|
||||
}
|
||||
|
||||
private struct MapUOProtocolInfo : IProtocolExtensionsInfo
|
||||
{
|
||||
public int PacketId => 0xF0;
|
||||
state.SendPartyMemberLocations(from, party);
|
||||
}
|
||||
}
|
||||
|
||||
public static void SendGuildMemberLocations(this NetState ns, Mobile from, Guild guild, bool sendLocations)
|
||||
{
|
||||
if (ns.CannotSendPackets())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var count = guild?.Members.Count ?? 0;
|
||||
var maxLength = 9 + (count > 1 ? (count - 1) * (sendLocations ? 10 : 4) : 0);
|
||||
var writer = new SpanWriter(stackalloc byte[maxLength]);
|
||||
writer.Write((byte)0xF0); // Packet ID
|
||||
writer.Seek(2, SeekOrigin.Current);
|
||||
writer.Write((byte)0x02); // Command
|
||||
writer.Write(count > 0 && sendLocations);
|
||||
|
||||
bool sendPacket = false;
|
||||
for (var i = 0; i < count; i++)
|
||||
{
|
||||
var m = guild!.Members[i];
|
||||
|
||||
if (m?.NetState == null || m == from)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (sendLocations && Utility.InUpdateRange(from.Location, m.Location) && from.CanSee(m))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
sendPacket = true;
|
||||
writer.Write(m.Serial);
|
||||
|
||||
if (sendLocations)
|
||||
{
|
||||
writer.Write((short)m.X);
|
||||
writer.Write((short)m.Y);
|
||||
writer.Write((byte)(m.Map?.MapID ?? 0));
|
||||
|
||||
if (m.Alive)
|
||||
{
|
||||
writer.Write((byte)(m.Hits * 100 / Math.Max(m.HitsMax, 1)));
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.Write((byte)0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!sendPacket)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
writer.Write(0);
|
||||
writer.WritePacketLength();
|
||||
ns.Send(writer.Span);
|
||||
}
|
||||
|
||||
public static void SendPartyMemberLocations(this NetState ns, Mobile from, Party party)
|
||||
{
|
||||
if (ns.CannotSendPackets())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var count = party?.Members.Count ?? 0;
|
||||
var maxLength = 9 + (count > 1 ? (count - 1) * 9 : 0);
|
||||
var writer = new SpanWriter(stackalloc byte[maxLength]);
|
||||
writer.Write((byte)0xF0); // Packet ID
|
||||
writer.Seek(2, SeekOrigin.Current);
|
||||
writer.Write((byte)0x01); // Command
|
||||
|
||||
bool sendPacket = false;
|
||||
for (var i = 0; i < count; i++)
|
||||
{
|
||||
var pmi = party!.Members[i];
|
||||
Mobile mob = pmi?.Mobile;
|
||||
|
||||
if (mob?.NetState == null || mob == from)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (Utility.InUpdateRange(from.Location, mob.Location) && from.CanSee(mob))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
sendPacket = true;
|
||||
writer.Write(mob.Serial);
|
||||
writer.Write((short)mob.X);
|
||||
writer.Write((short)mob.Y);
|
||||
writer.Write((byte)(mob.Map?.MapID ?? 0));
|
||||
}
|
||||
|
||||
if (!sendPacket)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
writer.Write(0);
|
||||
writer.WritePacketLength();
|
||||
ns.Send(writer.Span);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue