diff --git a/EXILED/Exiled.Events/EventArgs/Player/PreAuthenticatingEventArgs.cs b/EXILED/Exiled.Events/EventArgs/Player/PreAuthenticatingEventArgs.cs index 9e5ed782e..f2af6a830 100644 --- a/EXILED/Exiled.Events/EventArgs/Player/PreAuthenticatingEventArgs.cs +++ b/EXILED/Exiled.Events/EventArgs/Player/PreAuthenticatingEventArgs.cs @@ -12,7 +12,7 @@ namespace Exiled.Events.EventArgs.Player using Interfaces; using LiteNetLib; - + using LiteNetLib.Utils; using PluginAPI.Events; #pragma warning disable SA1600 //TODO: @@ -27,8 +27,6 @@ namespace Exiled.Events.EventArgs.Player /// public class PreAuthenticatingEventArgs : IExiledEvent { - private PreauthCancellationData cachedPreauthData = PreauthCancellationData.Accept(); - /// /// Initializes a new instance of the class. /// @@ -105,70 +103,6 @@ public PreAuthenticatingEventArgs( /// public bool IsAllowed { get; private set; } = true; - /// - /// Gets or sets the cached that is returned back to the NwPluginAPI. - /// - internal PreauthCancellationData CachedPreauthData - { - get => cachedPreauthData; - set - { - cachedPreauthData = value; - IsAllowed = false; - } - } - - /// - /// Delays a pre-authentincating player. - /// - /// The seconds of delay. - /// Indicates whether the delay is forced. - public void Delay(byte seconds, bool isForced) => - CachedPreauthData = PreauthCancellationData.RejectDelay(seconds, isForced); - - /// - /// Redirects a pre-authentincating player. - /// - /// The redirection port. - /// Indicates whether the redirection is forced. - public void Redirect(ushort port, bool isForced) => - CachedPreauthData = PreauthCancellationData.RejectRedirect(port, isForced); - - /// - /// Rejects a pre-authentincating banned player. - /// - /// The ban reason.> - /// The ban expiration. - /// Indicates whether the rejection is forced. - public void RejectBanned(string banReason, DateTime expiration, bool isForced) => - CachedPreauthData = PreauthCancellationData.RejectBanned(banReason, expiration, isForced); - - /// - /// Rejects a pre-authentincating banned player. - /// - /// The ban reason. - /// The ban expiration. - /// Indicates whether the rejection is forced. - public void RejectBanned(string banReason, long expiration, bool isForced) => - CachedPreauthData = PreauthCancellationData.RejectBanned(banReason, expiration, isForced); - - /// - /// Rejects a pre-authentincating player. - /// - /// The rejection custom reason. - /// Indicates whether the rejection is forced. - public void Reject(string customReason, bool isForced) => - CachedPreauthData = PreauthCancellationData.Reject(customReason, isForced); - - /// - /// Rejects a pre-authentincating player. - /// - /// The . - /// Indicates whether the rejection is forced. - public void Reject(RejectionReason reason, bool isForced) => - CachedPreauthData = PreauthCancellationData.Reject(reason, isForced); - - /* /// /// Delays the connection. /// @@ -230,6 +164,11 @@ public void Reject(NetDataWriter writer, bool isForced) /// Indicates whether the player has to be rejected forcefully. public void Reject(string rejectionReason, bool isForced) => Reject(RejectionReason.Custom, isForced, rejectionReason); + /// + /// Rejects a player who's trying to authenticate. + /// + public void ForceReject() => Reject(RejectionReason.Custom, true, "Rejected By A Plugin"); + /// /// Rejects a player who's trying to authenticate. /// @@ -278,12 +217,5 @@ public void Reject(RejectionReason rejectionReason, bool isForced, string custom else Request.Reject(rejectData); } - - /// - /// Disallows the connection without sending any reason. Should only be used when the connection has already been - /// terminated by the plugin itself. - /// - public void Disallow() => IsAllowed = false; - */ } } \ No newline at end of file diff --git a/EXILED/Exiled.Events/Handlers/Player.cs b/EXILED/Exiled.Events/Handlers/Player.cs index d87675450..4efe258a3 100644 --- a/EXILED/Exiled.Events/Handlers/Player.cs +++ b/EXILED/Exiled.Events/Handlers/Player.cs @@ -1213,30 +1213,7 @@ public static void OnItemRemoved(ReferenceHub referenceHub, InventorySystem.Item /// /// Called before pre-authenticating a . /// - /// - /// - /// - /// - /// - /// - /// - /// - /// Returns the instance. - [PluginEvent(ServerEventType.PlayerPreauth)] - public PreauthCancellationData OnPreAuthenticating( - string userId, - string ipAddress, - long expiration, - CentralAuthPreauthFlags flags, - string country, - byte[] signature, - LiteNetLib.ConnectionRequest request, - int readerStartPosition) - { - PreAuthenticatingEventArgs ev = new(userId, ipAddress, expiration, flags, country, signature, request, readerStartPosition); - PreAuthenticating.InvokeSafely(ev); - - return ev.CachedPreauthData; - } + /// instance. + public static void OnPreAuthenticating(PreAuthenticatingEventArgs ev) => PreAuthenticating.InvokeSafely(ev); } } diff --git a/EXILED/Exiled.Events/Patches/Events/Player/PreAuthenticating.cs b/EXILED/Exiled.Events/Patches/Events/Player/PreAuthenticating.cs new file mode 100644 index 000000000..9c81f8f27 --- /dev/null +++ b/EXILED/Exiled.Events/Patches/Events/Player/PreAuthenticating.cs @@ -0,0 +1,88 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) ExMod Team. All rights reserved. +// Licensed under the CC BY-SA 3.0 license. +// +// ----------------------------------------------------------------------- + +namespace Exiled.Events.Patches.Events.Player +{ + using System; + using System.Collections.Generic; + using System.Reflection.Emit; + + using API.Features.Pools; + using Exiled.Events.Attributes; + using Exiled.Events.EventArgs.Player; + + using HarmonyLib; + + using Hazards; + using LiteNetLib; + + using static HarmonyLib.AccessTools; + + /// + /// Patches . + /// Adds the event. + /// + [EventPatch(typeof(Handlers.Player), nameof(Handlers.Player.PreAuthenticating))] + [HarmonyPatch(typeof(CustomLiteNetLib4MirrorTransport), nameof(CustomLiteNetLib4MirrorTransport.ProcessConnectionRequest))] + internal static class PreAuthenticating + { + private static IEnumerable Transpiler(IEnumerable instructions, ILGenerator generator) + { + List newInstructions = ListPool.Pool.Get(instructions); + + Label ret = generator.DefineLabel(); + newInstructions[newInstructions.Count - 1].labels.Add(ret); + LocalBuilder ev = generator.DeclareLocal(typeof(PreAuthenticatingEventArgs)); + int index = newInstructions.FindIndex(instruction => instruction.opcode == OpCodes.Ldstr && instruction.operand == (object)"{0};{1};{2};{3}"); + + Label cont = generator.DefineLabel(); + newInstructions[index].labels.Add(cont); + + newInstructions.InsertRange( + index, + new CodeInstruction[] + { + // userid + new CodeInstruction(OpCodes.Ldloc_S, 10), + + // ipaddress + new (OpCodes.Ldloc_S, 15), + + // expiration + new (OpCodes.Ldloc_S, 11), + + // flags + new (OpCodes.Ldloc_S, 12), + + // country + new (OpCodes.Ldloc_S, 13), + + // signature + new (OpCodes.Ldloc_S, 14), + + // request + new (OpCodes.Ldarg_1), + + // position + new (OpCodes.Ldloc_S, 9), + + // PreAuthenticatingEventArgs ev = new (userid, ipaddress, expiration, flags, country, signature, request, position) + new (OpCodes.Newobj, GetDeclaredConstructors(typeof(PreAuthenticatingEventArgs))[0]), + new (OpCodes.Dup), + new (OpCodes.Stloc_S, ev.LocalIndex), + + // OnPreAuthenticating(ev) + new (OpCodes.Call, AccessTools.Method(typeof(Handlers.Player), nameof(Handlers.Player.OnPreAuthenticating))), + }); + + for (int z = 0; z < newInstructions.Count; z++) + yield return newInstructions[z]; + + ListPool.Pool.Return(newInstructions); + } + } +}