From 71f21ef01018c1680cfe2616a9f3122c24f2580f Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Thu, 21 Jul 2022 19:13:31 +1000 Subject: [PATCH] Add event for reporting a player (Thanks SpicyCombo) --- MCGalaxy/Commands/Moderation/CmdReport.cs | 5 +++ MCGalaxy/Events/ModActionEvent.cs | 17 +++++---- MCGalaxy/Events/ServerEvents.cs | 36 +++++++++---------- MCGalaxy/Generator/SimpleGen.cs | 2 +- .../Modules/Relay/Discord/DiscordWebsocket.cs | 4 +-- MCGalaxy/Network/Heartbeat/Heartbeat.cs | 2 +- MCGalaxy/Server/Server.Fields.cs | 2 +- 7 files changed, 38 insertions(+), 30 deletions(-) diff --git a/MCGalaxy/Commands/Moderation/CmdReport.cs b/MCGalaxy/Commands/Moderation/CmdReport.cs index 66d50da3c..3906796ba 100644 --- a/MCGalaxy/Commands/Moderation/CmdReport.cs +++ b/MCGalaxy/Commands/Moderation/CmdReport.cs @@ -21,6 +21,7 @@ using System; using System.Collections.Generic; using System.IO; using MCGalaxy.DB; +using MCGalaxy.Events; namespace MCGalaxy.Commands.Moderation { public sealed class CmdReport : Command2 { @@ -152,6 +153,10 @@ namespace MCGalaxy.Commands.Moderation { p.Message("&aReport sent! It should be viewed when a {0} &ais online", checkPerms.Describe()); + ModAction action = new ModAction(target, p, ModActionType.Reported, reason); + OnModActionEvent.Call(action); + if (!action.Announce) return; + string opsMsg = "λNICK &Sreported " + nick + "&S. Reason: " + reason; Chat.MessageFrom(ChatScope.Perms, p, opsMsg, checkPerms, null, true); string allMsg = "Use &T/Report check " + target + " &Sto see all of their reports"; diff --git a/MCGalaxy/Events/ModActionEvent.cs b/MCGalaxy/Events/ModActionEvent.cs index c96c191d0..0ec01d5dc 100644 --- a/MCGalaxy/Events/ModActionEvent.cs +++ b/MCGalaxy/Events/ModActionEvent.cs @@ -17,11 +17,11 @@ */ using System; -namespace MCGalaxy.Events { - +namespace MCGalaxy.Events +{ /// Represents a moderation action. - public sealed class ModAction { - + public sealed class ModAction + { /// Target player name or IP. public string Target; @@ -86,8 +86,8 @@ namespace MCGalaxy.Events { public delegate void OnModAction(ModAction action); /// Types of moderation actions that can occur. - public enum ModActionType { - + public enum ModActionType + { /// Player was banned. Ban, /// Player was unbanned. @@ -117,10 +117,13 @@ namespace MCGalaxy.Events { Rank, /// Player was kicked from the server. Kicked, + /// Player was reported + Reported, } /// Raised when a moderation action occurs. - public sealed class OnModActionEvent : IEvent { + public sealed class OnModActionEvent : IEvent + { public static void Call(ModAction e) { if (handlers.Count == 0) return; CallCommon(pl => pl(e)); diff --git a/MCGalaxy/Events/ServerEvents.cs b/MCGalaxy/Events/ServerEvents.cs index d508721d2..5e4e937dd 100644 --- a/MCGalaxy/Events/ServerEvents.cs +++ b/MCGalaxy/Events/ServerEvents.cs @@ -20,12 +20,12 @@ using System.Collections.Generic; using System.Net.Sockets; using MCGalaxy.Network; -namespace MCGalaxy.Events.ServerEvents { - +namespace MCGalaxy.Events.ServerEvents +{ public delegate void OnSendingHeartbeat(Heartbeat service, ref string name); /// Called when a heartbeat is being sent out. - public sealed class OnSendingHeartbeatEvent : IEvent { - + public sealed class OnSendingHeartbeatEvent : IEvent + { public static void Call(Heartbeat service, ref string name) { IEvent[] items = handlers.Items; // Can't use CallCommon because we need to pass arguments by ref @@ -38,8 +38,8 @@ namespace MCGalaxy.Events.ServerEvents { public delegate void OnShuttingDown(bool restarting, string reason); /// Called when the server is shutting down or restarting. - public sealed class OnShuttingDownEvent : IEvent { - + public sealed class OnShuttingDownEvent : IEvent + { public static void Call(bool restarting, string reason) { if (handlers.Count == 0) return; CallCommon(pl => pl(restarting, reason)); @@ -48,8 +48,8 @@ namespace MCGalaxy.Events.ServerEvents { public delegate void OnConfigUpdated(); /// Called when the server configuration has been updated. - public sealed class OnConfigUpdatedEvent : IEvent { - + public sealed class OnConfigUpdatedEvent : IEvent + { public static void Call() { if (handlers.Count == 0) return; CallCommon(pl => pl()); @@ -58,8 +58,8 @@ namespace MCGalaxy.Events.ServerEvents { public delegate void OnConnectionReceived(Socket s, ref bool cancel); /// Called when a new connection has been received. - public sealed class OnConnectionReceivedEvent : IEvent { - + public sealed class OnConnectionReceivedEvent : IEvent + { public static void Call(Socket s, ref bool cancel) { IEvent[] items = handlers.Items; // Can't use CallCommon because we need to pass arguments by ref @@ -72,8 +72,8 @@ namespace MCGalaxy.Events.ServerEvents { public delegate void OnChatSys(ChatScope scope, string msg, object arg, ref ChatMessageFilter filter, bool relay); - public sealed class OnChatSysEvent : IEvent { - + public sealed class OnChatSysEvent : IEvent + { public static void Call(ChatScope scope, string msg, object arg, ref ChatMessageFilter filter, bool relay) { IEvent[] items = handlers.Items; @@ -86,8 +86,8 @@ namespace MCGalaxy.Events.ServerEvents { public delegate void OnChatFrom(ChatScope scope, Player source, string msg, object arg, ref ChatMessageFilter filter, bool relay); - public sealed class OnChatFromEvent : IEvent { - + public sealed class OnChatFromEvent : IEvent + { public static void Call(ChatScope scope,Player source, string msg, object arg, ref ChatMessageFilter filter, bool relay) { IEvent[] items = handlers.Items; @@ -100,8 +100,8 @@ namespace MCGalaxy.Events.ServerEvents { public delegate void OnChat(ChatScope scope, Player source, string msg, object arg, ref ChatMessageFilter filter, bool relay); - public sealed class OnChatEvent : IEvent { - + public sealed class OnChatEvent : IEvent + { public static void Call(ChatScope scope, Player source, string msg, object arg, ref ChatMessageFilter filter, bool relay) { IEvent[] items = handlers.Items; @@ -114,8 +114,8 @@ namespace MCGalaxy.Events.ServerEvents { public delegate void OnPluginMessageReceived(Player p, byte channel, byte[] data); /// Called when a player sends a PluginMessage CPE packet to the server. - public sealed class OnPluginMessageReceivedEvent : IEvent { - + public sealed class OnPluginMessageReceivedEvent : IEvent + { public static void Call(Player p, byte channel, byte[] data) { if (handlers.Count == 0) return; CallCommon(pl => pl(p, channel, data)); diff --git a/MCGalaxy/Generator/SimpleGen.cs b/MCGalaxy/Generator/SimpleGen.cs index bebc57da0..89fa741d2 100644 --- a/MCGalaxy/Generator/SimpleGen.cs +++ b/MCGalaxy/Generator/SimpleGen.cs @@ -75,7 +75,7 @@ namespace MCGalaxy.Generator { if (grassY > 0) MapSet(lvl.Width, lvl.Length, ptr, 0, grassY - 1, Block.Dirt); - if (grassY < lvl.Height) + if (grassY >= 0 && grassY < lvl.Height) MapSet(lvl.Width, lvl.Length, ptr, grassY, grassY, Block.Grass); } return true; diff --git a/MCGalaxy/Modules/Relay/Discord/DiscordWebsocket.cs b/MCGalaxy/Modules/Relay/Discord/DiscordWebsocket.cs index 47e6394fd..0a729c91a 100644 --- a/MCGalaxy/Modules/Relay/Discord/DiscordWebsocket.cs +++ b/MCGalaxy/Modules/Relay/Discord/DiscordWebsocket.cs @@ -108,7 +108,7 @@ namespace MCGalaxy.Modules.Relay.Discord } public override void Close() { - Server.Hearbeats.Cancel(heartbeat); + Server.Heartbeats.Cancel(heartbeat); try { client.Close(); } catch { @@ -182,7 +182,7 @@ namespace MCGalaxy.Modules.Relay.Discord string interval = (string)data["heartbeat_interval"]; int msInterval = int.Parse(interval); - heartbeat = Server.Hearbeats.QueueRepeat(SendHeartbeat, null, + heartbeat = Server.Heartbeats.QueueRepeat(SendHeartbeat, null, TimeSpan.FromMilliseconds(msInterval)); Identify(); } diff --git a/MCGalaxy/Network/Heartbeat/Heartbeat.cs b/MCGalaxy/Network/Heartbeat/Heartbeat.cs index 15f6f2cfb..2aeffe035 100644 --- a/MCGalaxy/Network/Heartbeat/Heartbeat.cs +++ b/MCGalaxy/Network/Heartbeat/Heartbeat.cs @@ -86,7 +86,7 @@ namespace MCGalaxy.Network /// Starts pumping heartbeats public static void Start() { OnBeat(null); // immedately call so URL is shown as soon as possible in console - Server.Hearbeats.QueueRepeat(OnBeat, null, TimeSpan.FromSeconds(30)); + Server.Heartbeats.QueueRepeat(OnBeat, null, TimeSpan.FromSeconds(30)); } static void OnBeat(SchedulerTask task) { diff --git a/MCGalaxy/Server/Server.Fields.cs b/MCGalaxy/Server/Server.Fields.cs index 0ff59f9c2..a62930005 100644 --- a/MCGalaxy/Server/Server.Fields.cs +++ b/MCGalaxy/Server/Server.Fields.cs @@ -82,7 +82,7 @@ namespace MCGalaxy { public static Scheduler MainScheduler = new Scheduler("MCG_MainScheduler"); public static Scheduler Background = new Scheduler("MCG_BackgroundScheduler"); public static Scheduler Critical = new Scheduler("MCG_CriticalScheduler"); - public static Scheduler Hearbeats = new Scheduler("MCG_HeartbeatsScheduler"); + public static Scheduler Heartbeats = new Scheduler("MCG_HeartbeatsScheduler"); public static Server s = new Server(); public const byte VERSION_0016 = 3; // classic 0.0.16