From 8d3aaaeb2a01dc9ff0ca9cd4b8c6f274c4f3ad09 Mon Sep 17 00:00:00 2001 From: Kamron Batman <3953314+kamronbatman@users.noreply.github.com> Date: Sun, 26 Jun 2022 08:33:53 -0700 Subject: [PATCH] fix: Removes razor negotiations since they arent maintained (#1090) --- Projects/Server/Assistants/AssistantEvents.cs | 43 ------------- .../Network/Packets/IncomingAccountPackets.cs | 64 ++----------------- .../Network/Packets/OutgoingAccountPackets.cs | 38 ----------- Projects/Server/Server.csproj | 3 + .../Assistants/AssistantConfiguration.cs | 15 ----- .../Assistants/AssistantFeatures.cs | 15 ----- .../UOContent/Assistants/AssistantHandler.cs | 24 ++----- 7 files changed, 14 insertions(+), 188 deletions(-) delete mode 100644 Projects/Server/Assistants/AssistantEvents.cs rename Projects/{Server => UOContent}/Assistants/AssistantConfiguration.cs (74%) rename Projects/{Server => UOContent}/Assistants/AssistantFeatures.cs (63%) diff --git a/Projects/Server/Assistants/AssistantEvents.cs b/Projects/Server/Assistants/AssistantEvents.cs deleted file mode 100644 index 9eee49e73..000000000 --- a/Projects/Server/Assistants/AssistantEvents.cs +++ /dev/null @@ -1,43 +0,0 @@ -/************************************************************************* - * ModernUO * - * Copyright 2019-2022 - ModernUO Development Team * - * Email: hi@modernuo.com * - * File: AssistantEvents.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 . * - *************************************************************************/ - -using System; -using System.Runtime.CompilerServices; -using Server.Accounting; -using Server.Network; - -namespace Server; - -public class AssistantAuthEventArgs -{ - public NetState State { get; } - public IAccount Account { get; } - public bool AuthOk { get; } - - public AssistantAuthEventArgs(NetState state, IAccount acct, bool authOK) - { - State = state; - Account = acct; - AuthOk = authOK; - } -} - -public static partial class EventSink -{ - public static event Action AssistantAuth; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void InvokeAssistantAuth(AssistantAuthEventArgs e) => AssistantAuth?.Invoke(e); -} diff --git a/Projects/Server/Network/Packets/IncomingAccountPackets.cs b/Projects/Server/Network/Packets/IncomingAccountPackets.cs index a5a078268..11ef399bc 100644 --- a/Projects/Server/Network/Packets/IncomingAccountPackets.cs +++ b/Projects/Server/Network/Packets/IncomingAccountPackets.cs @@ -16,7 +16,6 @@ using System; using System.Collections.Generic; using System.IO; -using Server.Assistants; using CV = Server.ClientVersion; namespace Server.Network; @@ -70,32 +69,9 @@ public static class IncomingAccountPackets var flags = reader.ReadInt32(); reader.Seek(8, SeekOrigin.Current); int prof = reader.ReadByte(); + reader.Seek(15, SeekOrigin.Current); - int genderRace; - if (AssistantConfiguration.Enabled && AssistantConfiguration.Settings.DisallowedFeatures != AssistantFeatures.None) - { - var razorFeatures = (AssistantFeatures)reader.ReadUInt64(); - var key = reader.ReadUInt64(); - - var authOk = razorFeatures == AssistantConfiguration.Settings.DisallowedFeatures && - // Highly recommend a shard changes these here, in razor and redistribute the assistant. - (key & 0xFFFFFFFFFFFFFF00ul) == 0x0911832B04178300ul; - - EventSink.InvokeAssistantAuth(new AssistantAuthEventArgs(state, state.Account, authOk)); - - if (!state.Running) - { - return; - } - - genderRace = (int)(key & 0xFF); - } - else - { - reader.Seek(15, SeekOrigin.Current); - genderRace = reader.ReadByte(); - } - + var genderRace = reader.ReadByte(); var stats = new StatNameValue[] { @@ -246,41 +222,9 @@ public static class IncomingAccountPackets public static void PlayCharacter(NetState state, CircularBufferReader reader, int packetLength) { - reader.Seek(4, SeekOrigin.Current); // 0xEDEDEDED - - reader.Seek(30, SeekOrigin.Current); // var name = reader.ReadAscii(30); - - reader.Seek(2, SeekOrigin.Current); - + reader.Seek(36, SeekOrigin.Current); // 4 = 0xEDEDEDED, 30 = Name, 2 = unknown var flags = reader.ReadInt32(); - - if (AssistantConfiguration.Enabled && AssistantConfiguration.Settings.DisallowedFeatures != AssistantFeatures.None) - { - var razorFeatures = (AssistantFeatures)reader.ReadUInt64(); - var key1 = reader.ReadUInt64(); - var key2 = reader.ReadUInt64(); - - var authOk = razorFeatures == AssistantConfiguration.Settings.DisallowedFeatures && - // Highly recommend a shard changes these here, in razor and redistribute the assistant. - key1 == 0x0911832B04178305ul && key2 == 0x2485071787061988ul; - - EventSink.InvokeAssistantAuth(new AssistantAuthEventArgs(state, state.Account, authOk)); - } - else - { - reader.Seek(22, SeekOrigin.Current); - - if (reader.ReadUInt16() == 0xDEAD) - { - EventSink.InvokeAssistantAuth(new AssistantAuthEventArgs(state, state.Account, false)); - } - } - - if (!state.Running) - { - return; - } - + reader.Seek(24, SeekOrigin.Current); var charSlot = reader.ReadInt32(); reader.Seek(4, SeekOrigin.Current); // var clientIP = reader.ReadInt32(); diff --git a/Projects/Server/Network/Packets/OutgoingAccountPackets.cs b/Projects/Server/Network/Packets/OutgoingAccountPackets.cs index 3df92939c..b462c497b 100644 --- a/Projects/Server/Network/Packets/OutgoingAccountPackets.cs +++ b/Projects/Server/Network/Packets/OutgoingAccountPackets.cs @@ -17,9 +17,7 @@ using System; using System.IO; using System.Buffers; using System.Runtime.CompilerServices; -using System.Security.Cryptography; using Server.Accounting; -using Server.Assistants; namespace Server.Network; @@ -286,8 +284,6 @@ public static class OutgoingAccountPackets ns.Send(writer.Span); } - private static MD5 _md5Provider; - /** * Packet: 0xA9 * Length: 1410 or more bytes @@ -334,11 +330,6 @@ public static class OutgoingAccountPackets writer.Write((ushort)length); writer.Write((byte)count); // TODO: It is probably more proper to use count. - var enforceRazor = AssistantConfiguration.Enabled && - AssistantConfiguration.Settings.DisallowedFeatures != AssistantFeatures.None; - - Span hashBuffer = enforceRazor ? stackalloc byte[16] : null; - for (int i = 0; i < count; i++) { var m = acct[i]; @@ -351,35 +342,6 @@ public static class OutgoingAccountPackets { var name = (m.RawName?.Trim()).DefaultIfNullOrEmpty("-no name-"); writer.WriteAscii(name, 30); - } - - if (enforceRazor) - { - writer.Write((byte)0); - var pos = writer.Position; - - if (i == 0) - { - writer.Write((ulong)AssistantConfiguration.Settings.DisallowedFeatures); - } - - if (count > 1 && i == 2 || count == 1 && i == 0) - { - _md5Provider ??= MD5.Create(); - if (_md5Provider.TryComputeHash(writer.Span, hashBuffer, out var bytesWritten) && bytesWritten == 16) - { - writer.Write(hashBuffer); - } - } - - var remaining = 28 - pos; - Utility.RandomBytes(writer.RawBuffer.Slice(writer.Position, remaining)); - writer.Seek(remaining, SeekOrigin.Current); - - writer.Write((byte)0); - } - else - { writer.Clear(30); // password } } diff --git a/Projects/Server/Server.csproj b/Projects/Server/Server.csproj index bb8e91949..0e310043d 100755 --- a/Projects/Server/Server.csproj +++ b/Projects/Server/Server.csproj @@ -46,4 +46,7 @@ + + + diff --git a/Projects/Server/Assistants/AssistantConfiguration.cs b/Projects/UOContent/Assistants/AssistantConfiguration.cs similarity index 74% rename from Projects/Server/Assistants/AssistantConfiguration.cs rename to Projects/UOContent/Assistants/AssistantConfiguration.cs index db275ee9d..7b74b0c67 100644 --- a/Projects/Server/Assistants/AssistantConfiguration.cs +++ b/Projects/UOContent/Assistants/AssistantConfiguration.cs @@ -1,18 +1,3 @@ -/************************************************************************* - * ModernUO * - * Copyright 2019-2022 - ModernUO Development Team * - * Email: hi@modernuo.com * - * File: AssistantConfiguration.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 . * - *************************************************************************/ - using System; using System.IO; using System.Runtime.CompilerServices; diff --git a/Projects/Server/Assistants/AssistantFeatures.cs b/Projects/UOContent/Assistants/AssistantFeatures.cs similarity index 63% rename from Projects/Server/Assistants/AssistantFeatures.cs rename to Projects/UOContent/Assistants/AssistantFeatures.cs index 5d29254ad..a72566312 100644 --- a/Projects/Server/Assistants/AssistantFeatures.cs +++ b/Projects/UOContent/Assistants/AssistantFeatures.cs @@ -1,18 +1,3 @@ -/************************************************************************* - * ModernUO * - * Copyright 2019-2022 - ModernUO Development Team * - * Email: hi@modernuo.com * - * File: AssistantFeatures.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 . * - *************************************************************************/ - using System; namespace Server.Assistants; diff --git a/Projects/UOContent/Assistants/AssistantHandler.cs b/Projects/UOContent/Assistants/AssistantHandler.cs index c924f1db5..fcce10624 100644 --- a/Projects/UOContent/Assistants/AssistantHandler.cs +++ b/Projects/UOContent/Assistants/AssistantHandler.cs @@ -14,28 +14,20 @@ public static class AssistantHandler public static unsafe void Configure() { - Enabled = ServerConfiguration.GetOrUpdateSetting("assistants.enableAssistUONegotiation", false); - - EventSink.AssistantAuth += OnAssistantAuth; + Enabled = ServerConfiguration.GetOrUpdateSetting("assistants.enableNegotiation", false); EventSink.Login -= OnLogin; - AssistantProtocol.Register(0xFF, false, &AssistUOHandshakeResponse); + AssistantProtocol.Register(0xFF, false, &HandshakeResponse); } - private static void OnAssistantAuth(AssistantAuthEventArgs e) + private static void FailedNegotiation(Mobile m) { - 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."); + m.NetState.Disconnect("Failed to negotiate assistant features."); return; } @@ -60,7 +52,7 @@ public static class AssistantHandler _handshakes[m] = Timer.DelayCall(delay, OnForceDisconnect, m); } - e.State.LogInfo("Failed to negotiate assistant features."); + m.NetState.LogInfo("Failed to negotiate assistant features."); } private static void OnLogin(Mobile m) @@ -80,7 +72,7 @@ public static class AssistantHandler _handshakes[m] = Timer.DelayCall(TimeSpan.FromSeconds(30), OnTimeout, m); } - private static void AssistUOHandshakeResponse(NetState state, CircularBufferReader reader, int packetLength) + private static void HandshakeResponse(NetState state, CircularBufferReader reader, int packetLength) { Mobile m = state.Mobile; @@ -91,8 +83,6 @@ public static class AssistantHandler t?.Stop(); _handshakes.Remove(m); - - EventSink.InvokeAssistantAuth(new AssistantAuthEventArgs(m.NetState, m.Account, true)); } private static void OnTimeout(Mobile m) @@ -110,7 +100,7 @@ public static class AssistantHandler return; } - EventSink.InvokeAssistantAuth(new AssistantAuthEventArgs(m.NetState, m.Account, false)); + FailedNegotiation(m); } private static void OnForceDisconnect(Mobile m)