Skip to content

Commit

Permalink
Add event for reporting a player (Thanks SpicyCombo)
Browse files Browse the repository at this point in the history
  • Loading branch information
UnknownShadow200 committed Jul 21, 2022
1 parent 799cb97 commit 71f21ef
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 30 deletions.
5 changes: 5 additions & 0 deletions MCGalaxy/Commands/Moderation/CmdReport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ permissions and limitations under the Licenses.
using System.Collections.Generic;
using System.IO;
using MCGalaxy.DB;
using MCGalaxy.Events;

namespace MCGalaxy.Commands.Moderation {
public sealed class CmdReport : Command2 {
Expand Down Expand Up @@ -152,6 +153,10 @@ void HandleAdd(Player p, string[] args) {
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";
Expand Down
17 changes: 10 additions & 7 deletions MCGalaxy/Events/ModActionEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ permissions and limitations under the Licenses.
*/
using System;

namespace MCGalaxy.Events {
namespace MCGalaxy.Events
{
/// <summary> Represents a moderation action. </summary>
public sealed class ModAction {

public sealed class ModAction
{
/// <summary> Target player name or IP. </summary>
public string Target;

Expand Down Expand Up @@ -86,8 +86,8 @@ public ModAction(string target, Player actor, ModActionType type,
public delegate void OnModAction(ModAction action);

/// <summary> Types of moderation actions that can occur. </summary>
public enum ModActionType {
public enum ModActionType
{
/// <summary> Player was banned. </summary>
Ban,
/// <summary> Player was unbanned. </summary>
Expand Down Expand Up @@ -117,10 +117,13 @@ public enum ModActionType {
Rank,
/// <summary> Player was kicked from the server. </summary>
Kicked,
/// <summary> Player was reported </summary>
Reported,
}

/// <summary> Raised when a moderation action occurs. </summary>
public sealed class OnModActionEvent : IEvent<OnModAction> {
public sealed class OnModActionEvent : IEvent<OnModAction>
{
public static void Call(ModAction e) {
if (handlers.Count == 0) return;
CallCommon(pl => pl(e));
Expand Down
36 changes: 18 additions & 18 deletions MCGalaxy/Events/ServerEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ permissions and limitations under the Licenses.
using System.Net.Sockets;
using MCGalaxy.Network;

namespace MCGalaxy.Events.ServerEvents {

namespace MCGalaxy.Events.ServerEvents
{
public delegate void OnSendingHeartbeat(Heartbeat service, ref string name);
/// <summary> Called when a heartbeat is being sent out. </summary>
public sealed class OnSendingHeartbeatEvent : IEvent<OnSendingHeartbeat> {
public sealed class OnSendingHeartbeatEvent : IEvent<OnSendingHeartbeat>
{
public static void Call(Heartbeat service, ref string name) {
IEvent<OnSendingHeartbeat>[] items = handlers.Items;
// Can't use CallCommon because we need to pass arguments by ref
Expand All @@ -38,8 +38,8 @@ public static void Call(Heartbeat service, ref string name) {

public delegate void OnShuttingDown(bool restarting, string reason);
/// <summary> Called when the server is shutting down or restarting. </summary>
public sealed class OnShuttingDownEvent : IEvent<OnShuttingDown> {

public sealed class OnShuttingDownEvent : IEvent<OnShuttingDown>
{
public static void Call(bool restarting, string reason) {
if (handlers.Count == 0) return;
CallCommon(pl => pl(restarting, reason));
Expand All @@ -48,8 +48,8 @@ public static void Call(bool restarting, string reason) {

public delegate void OnConfigUpdated();
/// <summary> Called when the server configuration has been updated. </summary>
public sealed class OnConfigUpdatedEvent : IEvent<OnConfigUpdated> {

public sealed class OnConfigUpdatedEvent : IEvent<OnConfigUpdated>
{
public static void Call() {
if (handlers.Count == 0) return;
CallCommon(pl => pl());
Expand All @@ -58,8 +58,8 @@ public static void Call() {

public delegate void OnConnectionReceived(Socket s, ref bool cancel);
/// <summary> Called when a new connection has been received. </summary>
public sealed class OnConnectionReceivedEvent : IEvent<OnConnectionReceived> {

public sealed class OnConnectionReceivedEvent : IEvent<OnConnectionReceived>
{
public static void Call(Socket s, ref bool cancel) {
IEvent<OnConnectionReceived>[] items = handlers.Items;
// Can't use CallCommon because we need to pass arguments by ref
Expand All @@ -72,8 +72,8 @@ public static void Call(Socket s, ref bool cancel) {

public delegate void OnChatSys(ChatScope scope, string msg, object arg,
ref ChatMessageFilter filter, bool relay);
public sealed class OnChatSysEvent : IEvent<OnChatSys> {

public sealed class OnChatSysEvent : IEvent<OnChatSys>
{
public static void Call(ChatScope scope, string msg, object arg,
ref ChatMessageFilter filter, bool relay) {
IEvent<OnChatSys>[] items = handlers.Items;
Expand All @@ -86,8 +86,8 @@ public static void Call(ChatScope scope, string msg, object arg,

public delegate void OnChatFrom(ChatScope scope, Player source, string msg,
object arg, ref ChatMessageFilter filter, bool relay);
public sealed class OnChatFromEvent : IEvent<OnChatFrom> {

public sealed class OnChatFromEvent : IEvent<OnChatFrom>
{
public static void Call(ChatScope scope,Player source, string msg,
object arg, ref ChatMessageFilter filter, bool relay) {
IEvent<OnChatFrom>[] items = handlers.Items;
Expand All @@ -100,8 +100,8 @@ public static void Call(ChatScope scope,Player source, string msg,

public delegate void OnChat(ChatScope scope, Player source, string msg,
object arg, ref ChatMessageFilter filter, bool relay);
public sealed class OnChatEvent : IEvent<OnChat> {

public sealed class OnChatEvent : IEvent<OnChat>
{
public static void Call(ChatScope scope, Player source, string msg,
object arg, ref ChatMessageFilter filter, bool relay) {
IEvent<OnChat>[] items = handlers.Items;
Expand All @@ -114,8 +114,8 @@ public static void Call(ChatScope scope, Player source, string msg,

public delegate void OnPluginMessageReceived(Player p, byte channel, byte[] data);
/// <summary> Called when a player sends a PluginMessage CPE packet to the server. </summary>
public sealed class OnPluginMessageReceivedEvent : IEvent<OnPluginMessageReceived> {

public sealed class OnPluginMessageReceivedEvent : IEvent<OnPluginMessageReceived>
{
public static void Call(Player p, byte channel, byte[] data) {
if (handlers.Count == 0) return;
CallCommon(pl => pl(p, channel, data));
Expand Down
2 changes: 1 addition & 1 deletion MCGalaxy/Generator/SimpleGen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ unsafe static bool GenFlat(Player p, Level lvl, string seed) {
{
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;
Expand Down
4 changes: 2 additions & 2 deletions MCGalaxy/Modules/Relay/Discord/DiscordWebsocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ protected override void WriteCustomHeaders() {
}

public override void Close() {
Server.Hearbeats.Cancel(heartbeat);
Server.Heartbeats.Cancel(heartbeat);
try {
client.Close();
} catch {
Expand Down Expand Up @@ -182,7 +182,7 @@ void HandleHello(JsonObject obj) {
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();
}
Expand Down
2 changes: 1 addition & 1 deletion MCGalaxy/Network/Heartbeat/Heartbeat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public static void Register(Heartbeat beat) {
/// <summary> Starts pumping heartbeats </summary>
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) {
Expand Down
2 changes: 1 addition & 1 deletion MCGalaxy/Server/Server.Fields.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public static string SoftwareNameVersioned {
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
Expand Down

0 comments on commit 71f21ef

Please sign in to comment.