Ban, Freeze, Jail, Warn now use ModActionEvent

This commit is contained in:
UnknownShadow200 2017-05-19 10:29:37 +10:00
parent 38a0e751f7
commit ea6518bfea
16 changed files with 241 additions and 128 deletions

View File

@ -49,32 +49,9 @@ namespace MCGalaxy.Commands.Moderation {
Group group = who == null ? Group.findPlayerGroup(args[0]) : who.group; Group group = who == null ? Group.findPlayerGroup(args[0]) : who.group;
if (!CheckPerms(target, group, p)) return; if (!CheckPerms(target, group, p)) return;
string banReason = reason == "-" ? "" : " (" + reason + ")"; ModAction action = new ModAction(who.name, p, ModActionType.Ban, reason);
string banner = p == null ? "(console)" : p.ColoredName; action.Metadata = stealth && who != null;
string banMsg = null; OnModActionEvent.Call(action);
if (who == null) {
banMsg = target + " &f(offline) %Swas &8banned %Sby " + banner + "%S." + banReason;
Chat.MessageGlobal(banMsg);
} else {
if (stealth) {
banMsg = who.ColoredName + " %Swas STEALTH &8banned %Sby " + banner + "%S." + banReason;
Chat.MessageOps(banMsg);
} else {
banMsg = who.ColoredName + " %Swas &8banned %Sby " + banner + "%S." + banReason;
Chat.MessageGlobal(banMsg);
}
who.color = "";
}
Ban.DeleteBan(target);
Ban.BanPlayer(p, target, reason, stealth, group.name);
ModActionCmd.ChangeRank(target, group, Group.BannedRank, who);
ModerationAction action = new ModerationAction(who.name, p, ModerationActionType.Ban, reason);
action.Metadata = stealth;
OnModerationActionEvent.Call(action);
Server.IRC.Say(banMsg);
Server.s.Log("BANNED: " + target.ToLower() + " by " + banner);
} }
bool CheckPerms(string name, Group group, Player p) { bool CheckPerms(string name, Group group, Player p) {

View File

@ -30,29 +30,15 @@ namespace MCGalaxy.Commands.Moderation {
if (message == "") { Help(p); return; } if (message == "") { Help(p); return; }
Player who = PlayerInfo.FindMatches(p, message); Player who = PlayerInfo.FindMatches(p, message);
if (who == null) return; if (who == null) return;
if (p == who) { Player.Message(p, "Cannot freeze yourself."); return; } if (p == who) { Player.Message(p, "Cannot freeze yourself."); return; }
if (p != null && who.Rank >= p.Rank) { if (p != null && who.Rank >= p.Rank) {
MessageTooHighRank(p, "freeze", false); return; MessageTooHighRank(p, "freeze", false); return;
} }
string frozenby = (p == null) ? "(console)" : p.ColoredName; ModActionType actionType = who.frozen ? ModActionType.Unfrozen : ModActionType.Frozen;
if (!who.frozen) { ModAction action = new ModAction(who.name, p, actionType);
Chat.MessageGlobal(who, who.ColoredName + " %Swas &bfrozen %Sby " + frozenby + "%S.", false); OnModActionEvent.Call(action);
Server.s.Log(who.name + " was frozen by " + frozenby);
Server.frozen.AddIfNotExists(who.name);
ModerationAction action = new ModerationAction(who.name, p, ModerationActionType.Frozen);
OnModerationActionEvent.Call(action);
} else {
Chat.MessageGlobal(who, who.ColoredName + " %Swas &adefrosted %Sby " + frozenby + "%S.", false);
Server.s.Log(who.name + " was defrosted by " + frozenby);
Server.frozen.Remove(who.name);
ModerationAction action = new ModerationAction(who.name, p, ModerationActionType.Unfrozen);
OnModerationActionEvent.Call(action);
}
Server.frozen.Save();
who.frozen = !who.frozen;
} }
public override void Help(Player p) { public override void Help(Player p) {

View File

@ -40,30 +40,12 @@ namespace MCGalaxy.Commands.Moderation {
if (p != null && who.Rank >= p.Rank) { if (p != null && who.Rank >= p.Rank) {
MessageTooHighRank(p, "jail", false); return; MessageTooHighRank(p, "jail", false); return;
} }
Player.Message(p, "You jailed " + who.DisplayName); ModAction action = new ModAction(who.name, p, ModActionType.Jailed);
Entities.GlobalDespawn(who, false); OnModActionEvent.Call(action);
who.jailed = true;
Position pos = new Position(who.level.jailx, who.level.jaily, who.level.jailz);
Orientation rot = new Orientation(who.level.jailrotx, who.level.jailroty);
Entities.GlobalSpawn(who, pos, rot, true);
Server.jailed.AddOrReplace(who.name, who.level.name);
Chat.MessageGlobal(who, who.ColoredName + " %Swas &8jailed", false);
ModerationAction action = new ModerationAction(who.name, p, ModerationActionType.Jailed);
OnModerationActionEvent.Call(action);
} else { } else {
Server.jailed.Remove(who.name); ModAction action = new ModAction(who.name, p, ModActionType.Unjailed);
who.jailed = false; OnModActionEvent.Call(action);
Command.all.Find("spawn").Use(who, "");
Player.Message(p, "You freed " + who.name + " from jail");
Chat.MessageGlobal(who, who.ColoredName + " %Swas &afreed %Sfrom jail", false);
ModerationAction action = new ModerationAction(who.name, p, ModerationActionType.Unjailed);
OnModerationActionEvent.Call(action);
} }
Server.jailed.Save(true);
} }
public override void Help(Player p) { public override void Help(Player p) {

View File

@ -50,8 +50,8 @@ namespace MCGalaxy.Commands.Moderation {
return; return;
} }
ModerationAction action = new ModerationAction(who.name, p, ModerationActionType.Kicked, reason); ModAction action = new ModAction(who.name, p, ModActionType.Kicked, reason);
OnModerationActionEvent.Call(action); OnModActionEvent.Call(action);
who.Kick(kickMsg, "Kicked " + kickMsg); who.Kick(kickMsg, "Kicked " + kickMsg);
} }

View File

@ -52,8 +52,8 @@ namespace MCGalaxy.Commands.Moderation {
Chat.MessageGlobal(who, who.ColoredName + " %Swas &8muted", false); Chat.MessageGlobal(who, who.ColoredName + " %Swas &8muted", false);
Server.muted.AddIfNotExists(who.name); Server.muted.AddIfNotExists(who.name);
ModerationAction action = new ModerationAction(who.name, p, ModerationActionType.Muted); ModAction action = new ModAction(who.name, p, ModActionType.Muted);
OnModerationActionEvent.Call(action); OnModActionEvent.Call(action);
} }
Server.muted.Save(); Server.muted.Save();
} }

View File

@ -60,8 +60,8 @@ namespace MCGalaxy.Commands.Moderation {
} }
Player.Message(p, "Temp banned " + target + " for " + time.Shorten(true) + "."); Player.Message(p, "Temp banned " + target + " for " + time.Shorten(true) + ".");
ModerationAction action = new ModerationAction(who.name, p, ModerationActionType.Ban, reason, time); ModAction action = new ModAction(who.name, p, ModActionType.Ban, reason, time);
OnModerationActionEvent.Call(action); OnModActionEvent.Call(action);
} }
public override void Help(Player p) { public override void Help(Player p) {

View File

@ -28,6 +28,7 @@ namespace MCGalaxy.Commands.Moderation {
if (message == "") { Help(p); return; } if (message == "") { Help(p); return; }
string[] args = message.SplitSpaces(2); string[] args = message.SplitSpaces(2);
Player who = PlayerInfo.FindMatches(p, args[0]); Player who = PlayerInfo.FindMatches(p, args[0]);
string reason = args.Length == 1 ? "you know why." : args[1]; string reason = args.Length == 1 ? "you know why." : args[1];
reason = ModActionCmd.ExpandReason(p, reason); reason = ModActionCmd.ExpandReason(p, reason);
if (reason == null) return; if (reason == null) return;
@ -37,41 +38,18 @@ namespace MCGalaxy.Commands.Moderation {
if (p != null && p.Rank <= who.Rank) { if (p != null && p.Rank <= who.Rank) {
MessageTooHighRank(p, "warn", false); return; MessageTooHighRank(p, "warn", false); return;
} }
string warnedby = (p == null) ? "(console)" : p.ColoredName; ModAction action = new ModAction(who.name, p, ModActionType.Warned, reason);
Chat.MessageGlobal("{0} %ewarned {1} %ebecause:", warnedby, who.ColoredName); OnModActionEvent.Call(action);
Chat.MessageGlobal("&c" + reason);
Server.IRC.Say(warnedby + " %ewarned " + who.ColoredName + " %efor: %c" + reason);
Server.s.Log(warnedby + " warned " + who.name);
ModerationAction action = new ModerationAction(who.name, p, ModerationActionType.Warned, reason);
OnModerationActionEvent.Call(action);
if (who.warn == 0) {
Player.Message(who, "Do it again twice and you will get kicked!");
} else if (who.warn == 1) {
Player.Message(who, "Do it one more time and you will get kicked!");
} else if (who.warn == 2) {
Chat.MessageGlobal("{0} %Swas warn-kicked by {1}", who.ColoredName, warnedby);
string chatMsg = "by " + warnedby + "%S: " + reason;
string kickMsg = "Kicked by " + warnedby + "&f: " + reason;
who.Kick(chatMsg, kickMsg);
}
who.warn++;
} }
static void WarnOffline(Player p, string[] args, string reason) { static void WarnOffline(Player p, string[] args, string reason) {
if (!Server.LogNotes) {
Player.Message(p, "Notes logging must be enabled to warn offline players."); return;
}
Player.Message(p, "Searching PlayerDB.."); Player.Message(p, "Searching PlayerDB..");
string offName = PlayerInfo.FindOfflineNameMatches(p, args[0]); string offName = PlayerInfo.FindOfflineNameMatches(p, args[0]);
if (offName == null) return; if (offName == null) return;
reason = args.Length > 1 ? " for: " + reason : "";
ModAction action = new ModAction(offName, p, ModActionType.Warned, reason);
ModerationAction action = new ModerationAction(offName, p, ModerationActionType.Warned, reason); OnModActionEvent.Call(action);
OnModerationActionEvent.Call(action);
Player.Message(p, "Warned {0}{1}.", offName, reason);
} }
public override void Help(Player p) { public override void Help(Player p) {

View File

@ -46,6 +46,8 @@ namespace MCGalaxy.Core {
Priority.Critical, this); Priority.Critical, this);
OnEcoTransactionEvent.Register(EcoHandlers.HandleEcoTransaction, OnEcoTransactionEvent.Register(EcoHandlers.HandleEcoTransaction,
Priority.Critical, this); Priority.Critical, this);
OnModActionEvent.Register(ModActionHandler.HandleModAction,
Priority.Critical, this);
clearTask = Server.Background.QueueRepeat(IPThrottler.CleanupTask, null, clearTask = Server.Background.QueueRepeat(IPThrottler.CleanupTask, null,
TimeSpan.FromMinutes(10)); TimeSpan.FromMinutes(10));
@ -60,6 +62,7 @@ namespace MCGalaxy.Core {
OnPlayerMoveEvent.UnRegister(this); OnPlayerMoveEvent.UnRegister(this);
OnPlayerClickEvent.UnRegister(this); OnPlayerClickEvent.UnRegister(this);
OnEcoTransactionEvent.UnRegister(this); OnEcoTransactionEvent.UnRegister(this);
OnModActionEvent.UnRegister(this);
Server.Background.Cancel(clearTask); Server.Background.Cancel(clearTask);
} }

View File

@ -0,0 +1,140 @@
/*
Copyright 2010 MCSharp team (Modified for use with MCZall/MCLawl/MCGalaxy)
Copyright 2011 MCForge
Dual-licensed under the Educational Community License, Version 2.0 and
the GNU General Public License, Version 3 (the "Licenses"); you may
not use this file except in compliance with the Licenses. You may
obtain a copy of the Licenses at
http://www.opensource.org/licenses/ecl2.php
http://www.gnu.org/licenses/gpl-3.0.html
Unless required by applicable law or agreed to in writing,
software distributed under the Licenses are distributed on an "AS IS"
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
or implied. See the Licenses for the specific language governing
permissions and limitations under the Licenses.
*/
using System;
using MCGalaxy.Commands.Moderation;
using MCGalaxy.Events;
namespace MCGalaxy.Core {
internal static class ModActionHandler {
internal static void HandleModAction(ModAction action) {
switch (action.Type) {
case ModActionType.Frozen: DoFreeze(action); break;
case ModActionType.Unfrozen: DoUnfreeze(action); break;
case ModActionType.Jailed: DoJail(action); break;
case ModActionType.Unjailed: DoUnjail(action); break;
case ModActionType.Ban: DoBan(action); break;
case ModActionType.Warned: DoWarn(action); break;
}
}
static void DoFreeze(ModAction e) {
Player who = PlayerInfo.FindExact(e.Target);
if (who != null) {
Chat.MessageGlobal(who, who.ColoredName + " %Swas &bfrozen %Sby " + e.ActorName + "%S.", false);
who.frozen = true;
}
Server.s.Log(e.Target + " was frozen by " + e.ActorName);
Server.frozen.AddIfNotExists(e.Target);
Server.frozen.Save();
}
static void DoUnfreeze(ModAction e) {
Player who = PlayerInfo.FindExact(e.Target);
if (who != null) {
Chat.MessageGlobal(who, who.ColoredName + " %Swas &adefrosted %Sby " + e.ActorName + "%S.", false);
who.frozen = false;
}
Server.s.Log(e.Target + " was defrosted by " + e.ActorName);
Server.frozen.Remove(e.Target);
Server.frozen.Save();
}
static void DoJail(ModAction e) {
Player who = PlayerInfo.FindExact(e.Target);
if (who == null) return;
Player.Message(e.Actor, "You jailed " + who.ColoredName);
who.jailed = true;
Server.jailed.AddOrReplace(who.name, who.level.name);
Chat.MessageGlobal(who, who.ColoredName + " %Swas &8jailed", false);
Entities.GlobalDespawn(who, false);
Position pos = new Position(who.level.jailx, who.level.jaily, who.level.jailz);
Orientation rot = new Orientation(who.level.jailrotx, who.level.jailroty);
Entities.GlobalSpawn(who, pos, rot, true);
Server.jailed.Save(true);
}
static void DoUnjail(ModAction e) {
Player who = PlayerInfo.FindExact(e.Target);
if (who == null) return;
Player.Message(e.Actor, "You freed " + who.ColoredName + " %Sfrom jail");
who.jailed = false;
Server.jailed.Remove(who.name);
Chat.MessageGlobal(who, who.ColoredName + " %Swas &afreed %Sfrom jail", false);
Command.all.Find("spawn").Use(who, "");
Server.jailed.Save(true);
}
static void DoBan(ModAction e) {
bool banSealth = e.Metadata != null && (bool)e.Metadata;
if (banSealth) {
string msg = e.TargetName + " %Swas STEALTH &8banned %Sby " + e.ActorName + "%S." + e.ReasonSuffixed;
Chat.MessageOps(msg);
} else {
string msg = e.TargetName + " %Swas &8banned %Sby " + e.ActorName + "%S." + e.ReasonSuffixed;
Chat.MessageGlobal(msg);
}
Player who = PlayerInfo.FindExact(e.Target);
if (who != null) who.color = "";
Group group = who != null ? who.group : Group.findPlayerGroup(e.Target); // TODO: pass this in ??
Ban.DeleteBan(e.Target);
Ban.BanPlayer(e.Actor, e.Target, e.Reason, banSealth, group.name);
ModActionCmd.ChangeRank(e.Target, group, Group.BannedRank, who);
Server.s.Log("BANNED: " + e.Target + " by " + e.ActorName);
}
static void DoWarn(ModAction e) {
Player who = PlayerInfo.FindExact(e.Target);
if (who != null) {
Chat.MessageGlobal("{0} &ewarned {1} &efor: &c{2}", e.ActorName, who.ColoredName, e.Reason);
Server.s.Log(e.ActorName + " warned " + who.name);
if (who.warn == 0) {
Player.Message(who, "Do it again twice and you will get kicked!");
} else if (who.warn == 1) {
Player.Message(who, "Do it one more time and you will get kicked!");
} else if (who.warn == 2) {
Chat.MessageGlobal("{0} %Swas warn-kicked by {1}", who.ColoredName, e.ActorName);
string chatMsg = "by " + e.ActorName + "%S: " + e.Reason;
string kickMsg = "Kicked by " + e.ActorName + "&f: " + e.Reason;
who.Kick(chatMsg, kickMsg);
}
who.warn++;
} else {
if (!Server.LogNotes) {
Player.Message(e.Actor, "Notes logging must be enabled to warn offline players."); return;
}
string reason = e.Reason != null ? " for: " + e.Reason : "";
Player.Message(e.Actor, "Warned {0}{1}.", e.TargetName, reason);
}
}
}
}

View File

@ -23,36 +23,35 @@ namespace MCGalaxy.Core {
public sealed class NotesPlugin : Plugin_Simple { public sealed class NotesPlugin : Plugin_Simple {
public override string creator { get { return Server.SoftwareName + " team"; } } public override string creator { get { return Server.SoftwareName + " team"; } }
public override string MCGalaxy_Version { get { return Server.VersionString; } } public override string MCGalaxy_Version { get { return Server.VersionString; } }
public override string name { get { return "NotesPlugin"; } } public override string name { get { return "Core_NotesPlugin"; } }
public override void Load(bool startup) { public override void Load(bool startup) {
OnModerationActionEvent.Register(HandleModerationAction, Priority.Low, this); OnModActionEvent.Register(HandleModerationAction, Priority.Low, this);
} }
public override void Unload(bool shutdown) { public override void Unload(bool shutdown) {
OnModerationActionEvent.UnRegister(this); OnModActionEvent.UnRegister(this);
} }
void HandleModerationAction(ModerationAction action) { static void HandleModerationAction(ModAction action) {
switch (action.Type) { switch (action.Type) {
case ModerationActionType.Frozen: case ModActionType.Frozen:
AddNote(action, "F"); break; AddNote(action, "F"); break;
case ModerationActionType.Jailed: case ModActionType.Jailed:
AddNote(action, "J"); break; AddNote(action, "J"); break;
case ModerationActionType.Kicked: case ModActionType.Kicked:
AddNote(action, "K"); break; AddNote(action, "K"); break;
case ModerationActionType.Muted: case ModActionType.Muted:
AddNote(action, "M"); break; AddNote(action, "M"); break;
case ModerationActionType.Warned: case ModActionType.Warned:
AddNote(action, "W"); break; AddNote(action, "W"); break;
case ModerationActionType.Ban: case ModActionType.Ban:
string banType = action.Duration.Ticks == 0 ? "B" : "T"; string banType = action.Duration.Ticks == 0 ? "B" : "T";
AddNote(action, banType); break; AddNote(action, banType); break;
} }
} }
static void AddNote(ModerationAction action, string type) { static void AddNote(ModAction action, string type) {
if (!Server.LogNotes) return; if (!Server.LogNotes) return;
string src = action.Actor == null ? "(console)" : action.Actor.name; string src = action.Actor == null ? "(console)" : action.Actor.name;

View File

@ -73,9 +73,9 @@ namespace MCGalaxy.Games.ZS {
Command.all.Find("take").Use(null, p.name + " 10 Auto fine for pillaring"); Command.all.Find("take").Use(null, p.name + " 10 Auto fine for pillaring");
Player.Message(p, " &cThe next time you pillar, you will be &4kicked&c."); Player.Message(p, " &cThe next time you pillar, you will be &4kicked&c.");
} else { } else {
ModerationAction action = new ModerationAction(p.name, null, ModAction action = new ModAction(p.name, null,
ModerationActionType.Kicked, "Auto kick for pillaring"); ModActionType.Kicked, "Auto kick for pillaring");
OnModerationActionEvent.Call(action); OnModActionEvent.Call(action);
p.Kick("No pillaring allowed!"); p.Kick("No pillaring allowed!");
} }

View File

@ -398,6 +398,7 @@
<Compile Include="CorePlugin\EcoHandlers.cs" /> <Compile Include="CorePlugin\EcoHandlers.cs" />
<Compile Include="CorePlugin\IPThrottler.cs" /> <Compile Include="CorePlugin\IPThrottler.cs" />
<Compile Include="CorePlugin\MiscHandlers.cs" /> <Compile Include="CorePlugin\MiscHandlers.cs" />
<Compile Include="CorePlugin\ModActionHandler.cs" />
<Compile Include="CorePlugin\NotesPlugin.cs" /> <Compile Include="CorePlugin\NotesPlugin.cs" />
<Compile Include="Database\Backends\SQLite.cs" /> <Compile Include="Database\Backends\SQLite.cs" />
<Compile Include="Database\BlockDB\BlockDB.cs" /> <Compile Include="Database\BlockDB\BlockDB.cs" />
@ -597,7 +598,7 @@
<Compile Include="Plugins\Events\GroupEvents.cs" /> <Compile Include="Plugins\Events\GroupEvents.cs" />
<Compile Include="Plugins\Events\IPluginEvent.cs" /> <Compile Include="Plugins\Events\IPluginEvent.cs" />
<Compile Include="Plugins\Events\LevelEvents.cs" /> <Compile Include="Plugins\Events\LevelEvents.cs" />
<Compile Include="Plugins\Events\ModerationActionEvent.cs" /> <Compile Include="Plugins\Events\ModActionEvent.cs" />
<Compile Include="Plugins\Events\PlayerEvents.cs" /> <Compile Include="Plugins\Events\PlayerEvents.cs" />
<Compile Include="Plugins\Events\ServerEvents.cs" /> <Compile Include="Plugins\Events\ServerEvents.cs" />
<Compile Include="Network\Player.Networking.cs" /> <Compile Include="Network\Player.Networking.cs" />

View File

@ -23,13 +23,14 @@ namespace MCGalaxy.Network {
public sealed class IRCPlugin : Plugin_Simple { public sealed class IRCPlugin : Plugin_Simple {
public override string creator { get { return Server.SoftwareName + " team"; } } public override string creator { get { return Server.SoftwareName + " team"; } }
public override string MCGalaxy_Version { get { return Server.VersionString; } } public override string MCGalaxy_Version { get { return Server.VersionString; } }
public override string name { get { return "IRC_CorePlugin"; } } public override string name { get { return "Core_IRCPlugin"; } }
public override void Load(bool startup) { public override void Load(bool startup) {
OnPlayerConnectEvent.Register(HandleConnect, Priority.Low, this); OnPlayerConnectEvent.Register(HandleConnect, Priority.Low, this);
OnPlayerDisconnectEvent.Register(HandleDisconnect, Priority.Low, this); OnPlayerDisconnectEvent.Register(HandleDisconnect, Priority.Low, this);
OnPlayerChatEvent.Register(HandleChat, Priority.Low, this); OnPlayerChatEvent.Register(HandleChat, Priority.Low, this);
Player.DoPlayerAction += Player_PlayerAction; Player.DoPlayerAction += Player_PlayerAction;
OnModActionEvent.Register(HandleModerationAction, Priority.Low, this);
} }
public override void Unload(bool shutdown) { public override void Unload(bool shutdown) {
@ -37,10 +38,33 @@ namespace MCGalaxy.Network {
OnPlayerDisconnectEvent.UnRegister(this); OnPlayerDisconnectEvent.UnRegister(this);
OnPlayerChatEvent.UnRegister(this); OnPlayerChatEvent.UnRegister(this);
Player.DoPlayerAction -= Player_PlayerAction; Player.DoPlayerAction -= Player_PlayerAction;
OnModActionEvent.UnRegister(this);
} }
static void HandleModerationAction(ModAction e) {
if (!Server.IRC.Enabled) return;
switch (e.Type) {
case ModActionType.Warned: LogWarn(e); break;
case ModActionType.Ban: LogBan(e); break;
}
}
static void LogWarn(ModAction e) {
Server.IRC.Say(e.ActorName + " &ewarned " + e.TargetName + " &efor: &c" + e.Reason);
}
static void LogBan(ModAction e) {
string reason = e.ReasonSuffixed;
if (e.Duration.Ticks != 0) reason = " " + e.Duration.Shorten() + " " + reason;
bool banSealth = e.Metadata != null && (bool)e.Metadata;
Server.IRC.Say(e.ActorName + " &8banned " + e.TargetName + reason);
}
static void Player_PlayerAction(Player p, PlayerAction action, static void Player_PlayerAction(Player p, PlayerAction action,
string message, bool stealth) { string message, bool stealth) {
if (!Server.IRC.Enabled) return; if (!Server.IRC.Enabled) return;
string msg = null; string msg = null;
@ -62,6 +86,7 @@ namespace MCGalaxy.Network {
if (msg != null) Server.IRC.Say(msg, stealth); if (msg != null) Server.IRC.Say(msg, stealth);
} }
static void HandleDisconnect(Player p, string reason) { static void HandleDisconnect(Player p, string reason) {
if (!Server.IRC.Enabled || p.hidden) return; if (!Server.IRC.Enabled || p.hidden) return;
if (!Server.guestLeaveNotify && p.Rank <= LevelPermission.Guest) return; if (!Server.guestLeaveNotify && p.Rank <= LevelPermission.Guest) return;
@ -77,7 +102,7 @@ namespace MCGalaxy.Network {
Server.IRC.Say(p.ColoredName + " %Sjoined the game", false); Server.IRC.Say(p.ColoredName + " %Sjoined the game", false);
} }
static char[] trimChars = new char[] { ' ' }; static char[] trimChars = new char[] { ' ' };
static void HandleChat(Player p, string message) { static void HandleChat(Player p, string message) {
if (!Server.IRC.Enabled) return; if (!Server.IRC.Enabled) return;
if (message.Trim(trimChars) == "") return; if (message.Trim(trimChars) == "") return;

View File

@ -51,14 +51,18 @@ namespace MCGalaxy {
/// <summary> Adds a ban entry for the given user, and who banned them and why they were banned. </summary> /// <summary> Adds a ban entry for the given user, and who banned them and why they were banned. </summary>
public static void BanPlayer(Player banner, string target, string reason, bool stealth, string oldrank) { public static void BanPlayer(Player banner, string target, string reason, bool stealth, string oldrank) {
if (reason == null) reason = "-";
reason = reason.Replace(" ", "%20"); reason = reason.Replace(" ", "%20");
string player = banner == null ? "(console)" : banner.truename; string player = banner == null ? "(console)" : banner.truename;
AddBanEntry(player, target.ToLower(), reason, stealth.ToString(), FormatDate(), oldrank); AddBanEntry(player, target.ToLower(), reason, stealth.ToString(), FormatDate(), oldrank);
} }
/// <summary> Adds a ban entry for the given user, and who banned them and why they were banned. </summary> /// <summary> Adds a ban entry for the given user, and who banned them and why they were banned. </summary>
public static void UnbanPlayer(Player unbanner, string target, string reason) { public static void UnbanPlayer(Player unbanner, string target, string reason) {
if (reason == null) reason = "-";
reason = reason.Replace(" ", "%20"); reason = reason.Replace(" ", "%20");
string player = unbanner == null ? "(console)" : unbanner.truename; string player = unbanner == null ? "(console)" : unbanner.truename;
AddUnbanEntry(player, target.ToLower(), reason, FormatDate()); AddUnbanEntry(player, target.ToLower(), reason, FormatDate());
} }

View File

@ -20,20 +20,37 @@ using System;
namespace MCGalaxy.Events { namespace MCGalaxy.Events {
/// <summary> Represents a moderation action. </summary> /// <summary> Represents a moderation action. </summary>
public sealed class ModerationAction { public sealed class ModAction {
/// <summary> Target player name or IP. </summary> /// <summary> Target player name or IP. </summary>
public string Target; public string Target;
/// <summary> Gets the colored name of the target. (Not nickname) </summary>
public string TargetName {
get { return PlayerInfo.GetColoredName(Actor, Target); }
}
/// <summary> Player performing the action (e.g. person who is banning). </summary> /// <summary> Player performing the action (e.g. person who is banning). </summary>
public Player Actor; public Player Actor;
/// <summary> Gets the colored name of the actor. (Not nickname) </summary>
public string ActorName {
get { return Actor == null ? "(console)" : Actor.ColoredName; }
}
/// <summary> Type of this action. </summary> /// <summary> Type of this action. </summary>
public ModerationActionType Type; public ModActionType Type;
/// <summary> Reason provided for the action, can be null. </summary> /// <summary> Reason provided for the action, can be null. </summary>
public string Reason; public string Reason;
/// <summary> Returns " (reason)" if reason is given, "" if not. </summary>
public string ReasonSuffixed {
get { return Reason == null ? "" : " (" + Reason + ")"; }
}
/// <summary> How long the action lasts for (e.g. duration of a tempban), before reverting. </summary> /// <summary> How long the action lasts for (e.g. duration of a tempban), before reverting. </summary>
/// <remarks> Duration of 0 means the action is permanent. (e.g. regular /ban) </remarks> /// <remarks> Duration of 0 means the action is permanent. (e.g. regular /ban) </remarks>
public TimeSpan Duration; public TimeSpan Duration;
@ -41,7 +58,7 @@ namespace MCGalaxy.Events {
/// <summary> Action-specific metadata, see remarks in ModerationActionType for what is in this. </summary> /// <summary> Action-specific metadata, see remarks in ModerationActionType for what is in this. </summary>
public object Metadata; public object Metadata;
public ModerationAction(string target, Player actor, ModerationActionType type, public ModAction(string target, Player actor, ModActionType type,
string reason = null, TimeSpan duration = default(TimeSpan)) { string reason = null, TimeSpan duration = default(TimeSpan)) {
Target = target; Target = target;
Actor = actor; Actor = actor;
@ -53,10 +70,10 @@ namespace MCGalaxy.Events {
} }
} }
public delegate void OnModerationAction(ModerationAction action); public delegate void OnModAction(ModAction action);
/// <summary> Types of moderation actions that can occur. </summary> /// <summary> Types of moderation actions that can occur. </summary>
public enum ModerationActionType { public enum ModActionType {
/// <summary> Player is banned. </summary> /// <summary> Player is banned. </summary>
/// <remarks> Metadata is a boolean, true if the ban is a stealth ban. </remarks> /// <remarks> Metadata is a boolean, true if the ban is a stealth ban. </remarks>
@ -88,11 +105,11 @@ namespace MCGalaxy.Events {
} }
/// <summary> Raised when a moderation action occurs. </summary> /// <summary> Raised when a moderation action occurs. </summary>
public sealed class OnModerationActionEvent : IPluginEvent<OnModerationAction> { public sealed class OnModActionEvent : IPluginEvent<OnModAction> {
internal OnModerationActionEvent(OnModerationAction method, Priority priority, Plugin plugin) internal OnModActionEvent(OnModAction method, Priority priority, Plugin plugin)
: base(method, priority, plugin) { } : base(method, priority, plugin) { }
public static void Call(ModerationAction e) { public static void Call(ModAction e) {
if (handlers.Count == 0) return; if (handlers.Count == 0) return;
CallImpl(pl => pl(e)); CallImpl(pl => pl(e));
} }

View File

@ -141,6 +141,7 @@ namespace MCGalaxy {
ctf.Load(true); ctf.Load(true);
Plugin.all.Add(ctf); Plugin.all.Add(ctf);
LoadCorePlugin(new CorePlugin()); LoadCorePlugin(new CorePlugin());
LoadCorePlugin(new NotesPlugin());
} }
internal static void LoadCorePlugin(Plugin plugin) { internal static void LoadCorePlugin(Plugin plugin) {