using System; using NitroxModel.Packets; namespace NitroxClient.Communication; /// /// Suppresses the given packet type from being sent. Disables the suppression when disposed. /// /// The packet type to suppress. public readonly struct PacketSuppressor : IDisposable where T : Packet { private static bool isSuppressed; public static bool IsSuppressed => isSuppressed; private static readonly PacketSuppressor instance = new(); public static PacketSuppressor Suppress() { isSuppressed = true; return instance; } public void Dispose() { isSuppressed = false; } } /// /// First packet type to suppress. /// Second packet type to suppress. /// Third packet type to suppress. /// Fourth packet type to suppress. /// Fifth packet type to suppress. public readonly struct PacketSuppressor : IDisposable where T1 : Packet where T2 : Packet where T3 : Packet where T4 : Packet where T5 : Packet { private static readonly PacketSuppressor instance1 = new(); private static readonly PacketSuppressor instance2 = new(); private static readonly PacketSuppressor instance3 = new(); private static readonly PacketSuppressor instance4 = new(); private static readonly PacketSuppressor instance5 = new(); public static PacketSuppressor Suppress() { PacketSuppressor.Suppress(); PacketSuppressor.Suppress(); PacketSuppressor.Suppress(); PacketSuppressor.Suppress(); PacketSuppressor.Suppress(); return new PacketSuppressor(); } public void Dispose() { instance1.Dispose(); instance2.Dispose(); instance3.Dispose(); instance4.Dispose(); instance5.Dispose(); } }