fix: Removes razor negotiations since they arent maintained (#1090)

This commit is contained in:
Kamron Batman 2022-06-26 08:33:53 -07:00 committed by GitHub
parent 4f28e1e3c4
commit 8d3aaaeb2a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 14 additions and 188 deletions

View file

@ -0,0 +1,92 @@
using System;
using System.IO;
using System.Runtime.CompilerServices;
using System.Text.Json.Serialization;
using Server.Json;
namespace Server.Assistants;
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. "
+ "You must download and run an updated version of <A HREF=\"https://uosteam.com\">UOSteam</A>"
+ " or <A HREF=\"https://github.com/markdwags/Razor/releases/latest\">Razor</A>."
+ "<BR><BR>Make sure you've checked the option <B>Negotiate features with server</B>, "
+ "once you have this box checked you may log in and play normally."
+ "<BR><BR>You will be disconnected shortly.";
public static void Configure()
{
Enabled = ServerConfiguration.GetOrUpdateSetting("assistants.enableRazorNegotiation", false);
var path = Path.Join(Core.BaseDirectory, _path);
if (File.Exists(path))
{
Settings = JsonConfig.Deserialize<AssistantSettings>(path);
}
else
{
Settings = new AssistantSettings
{
WarnOnFailure = true,
KickOnFailure = true,
DisallowedFeatures = AssistantFeatures.None,
DisconnectDelay = TimeSpan.FromSeconds(15.0),
WarningMessage = _defaultWarningMessage
};
Save(path);
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void DisallowFeature(AssistantFeatures feature) => SetDisallowed(feature, true);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void AllowFeature(AssistantFeatures feature) => SetDisallowed(feature, false);
public static void SetDisallowed(AssistantFeatures feature, bool value)
{
if (value)
{
Settings.DisallowedFeatures |= feature;
}
else
{
Settings.DisallowedFeatures &= ~feature;
}
Save();
}
private static void Save(string path = null)
{
path ??= Path.Join(Core.BaseDirectory, _path);
JsonConfig.Serialize(path, Settings);
}
}
public record AssistantSettings
{
[JsonPropertyName("warnOnFailure")]
public bool WarnOnFailure { get; set; }
[JsonPropertyName("kickOnFailure")]
public bool KickOnFailure { get; set; }
[JsonPropertyName("features")]
public AssistantFeatures DisallowedFeatures { get; set; }
[JsonPropertyName("disconnectDelay")]
public TimeSpan DisconnectDelay { get; set; }
[JsonPropertyName("warningMessage")]
public string WarningMessage { get; set; }
}

View file

@ -0,0 +1,40 @@
using System;
namespace Server.Assistants;
[Flags]
public enum AssistantFeatures : ulong
{
None = 0,
FilterWeather = 1ul << 0, // Weather Filter
FilterLight = 1ul << 1, // Light Filter
SmartTarget = 1ul << 2, // Smart Last Target
RangedTarget = 1ul << 3, // Range Check Last Target
AutoOpenDoors = 1ul << 4, // Automatically Open Doors
DequipOnCast = 1ul << 5, // Unequip Weapon on spell cast
AutoPotionEquip = 1ul << 6, // Un/Re-equip weapon on potion use
PoisonedChecks = 1ul << 7, // Block heal If poisoned/Macro If Poisoned condition/Heal or Cure self
LoopedMacros = 1ul << 8, // Disallow Looping macros, For loops, and macros that call other macros
UseOnceAgent = 1ul << 9, // The use once agent
RestockAgent = 1ul << 10, // The restock agent
SellAgent = 1ul << 11, // The sell agent
BuyAgent = 1ul << 12, // The buy agent
PotionHotkeys = 1ul << 13, // All potion hotkeys
RandomTargets = 1ul << 14, // All random target hotkeys (not target next, last target, target self)
ClosestTargets = 1ul << 15, // All closest target hotkeys
OverheadHealth = 1ul << 16, // Health and Mana/Stam messages shown over player's heads
// AssistUO Only
AutolootAgent = 1ul << 17, // The autoloot agent
BoneCutterAgent = 1ul << 18, // The bone cutter agent
JScriptMacros = 1ul << 19, // Javascript macro engine
AutoRemount = 1ul << 20, // Auto remount after dismount
AutoBandage = 1 << 21, // Auto bandage friends, self, last and mount option
EnemyTargetShare = 1 << 22, // Enemy target share on guild, party or alliance chat
FilterSeason = 1 << 23, // Season Filter
SpellTargetShare = 1 << 24, // Spell target share on guild, party or alliance chat
All = ~None // Every feature possible
}

View file

@ -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)