mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-23 04:32:50 -04:00
Ban, Freeze, Jail, Warn now use ModActionEvent
This commit is contained in:
parent
38a0e751f7
commit
ea6518bfea
@ -49,32 +49,9 @@ namespace MCGalaxy.Commands.Moderation {
|
||||
Group group = who == null ? Group.findPlayerGroup(args[0]) : who.group;
|
||||
if (!CheckPerms(target, group, p)) return;
|
||||
|
||||
string banReason = reason == "-" ? "" : " (" + reason + ")";
|
||||
string banner = p == null ? "(console)" : p.ColoredName;
|
||||
string banMsg = null;
|
||||
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);
|
||||
ModAction action = new ModAction(who.name, p, ModActionType.Ban, reason);
|
||||
action.Metadata = stealth && who != null;
|
||||
OnModActionEvent.Call(action);
|
||||
}
|
||||
|
||||
bool CheckPerms(string name, Group group, Player p) {
|
||||
|
@ -30,29 +30,15 @@ namespace MCGalaxy.Commands.Moderation {
|
||||
if (message == "") { Help(p); return; }
|
||||
Player who = PlayerInfo.FindMatches(p, message);
|
||||
if (who == null) return;
|
||||
|
||||
if (p == who) { Player.Message(p, "Cannot freeze yourself."); return; }
|
||||
if (p != null && who.Rank >= p.Rank) {
|
||||
MessageTooHighRank(p, "freeze", false); return;
|
||||
}
|
||||
|
||||
string frozenby = (p == null) ? "(console)" : p.ColoredName;
|
||||
if (!who.frozen) {
|
||||
Chat.MessageGlobal(who, who.ColoredName + " %Swas &bfrozen %Sby " + frozenby + "%S.", false);
|
||||
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;
|
||||
ModActionType actionType = who.frozen ? ModActionType.Unfrozen : ModActionType.Frozen;
|
||||
ModAction action = new ModAction(who.name, p, actionType);
|
||||
OnModActionEvent.Call(action);
|
||||
}
|
||||
|
||||
public override void Help(Player p) {
|
||||
|
@ -40,30 +40,12 @@ namespace MCGalaxy.Commands.Moderation {
|
||||
if (p != null && who.Rank >= p.Rank) {
|
||||
MessageTooHighRank(p, "jail", false); return;
|
||||
}
|
||||
Player.Message(p, "You jailed " + who.DisplayName);
|
||||
Entities.GlobalDespawn(who, false);
|
||||
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);
|
||||
ModAction action = new ModAction(who.name, p, ModActionType.Jailed);
|
||||
OnModActionEvent.Call(action);
|
||||
} else {
|
||||
Server.jailed.Remove(who.name);
|
||||
who.jailed = false;
|
||||
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);
|
||||
ModAction action = new ModAction(who.name, p, ModActionType.Unjailed);
|
||||
OnModActionEvent.Call(action);
|
||||
}
|
||||
Server.jailed.Save(true);
|
||||
}
|
||||
|
||||
public override void Help(Player p) {
|
||||
|
@ -50,8 +50,8 @@ namespace MCGalaxy.Commands.Moderation {
|
||||
return;
|
||||
}
|
||||
|
||||
ModerationAction action = new ModerationAction(who.name, p, ModerationActionType.Kicked, reason);
|
||||
OnModerationActionEvent.Call(action);
|
||||
ModAction action = new ModAction(who.name, p, ModActionType.Kicked, reason);
|
||||
OnModActionEvent.Call(action);
|
||||
who.Kick(kickMsg, "Kicked " + kickMsg);
|
||||
}
|
||||
|
||||
|
@ -52,8 +52,8 @@ namespace MCGalaxy.Commands.Moderation {
|
||||
Chat.MessageGlobal(who, who.ColoredName + " %Swas &8muted", false);
|
||||
Server.muted.AddIfNotExists(who.name);
|
||||
|
||||
ModerationAction action = new ModerationAction(who.name, p, ModerationActionType.Muted);
|
||||
OnModerationActionEvent.Call(action);
|
||||
ModAction action = new ModAction(who.name, p, ModActionType.Muted);
|
||||
OnModActionEvent.Call(action);
|
||||
}
|
||||
Server.muted.Save();
|
||||
}
|
||||
|
@ -60,8 +60,8 @@ namespace MCGalaxy.Commands.Moderation {
|
||||
}
|
||||
|
||||
Player.Message(p, "Temp banned " + target + " for " + time.Shorten(true) + ".");
|
||||
ModerationAction action = new ModerationAction(who.name, p, ModerationActionType.Ban, reason, time);
|
||||
OnModerationActionEvent.Call(action);
|
||||
ModAction action = new ModAction(who.name, p, ModActionType.Ban, reason, time);
|
||||
OnModActionEvent.Call(action);
|
||||
}
|
||||
|
||||
public override void Help(Player p) {
|
||||
|
@ -28,6 +28,7 @@ namespace MCGalaxy.Commands.Moderation {
|
||||
if (message == "") { Help(p); return; }
|
||||
string[] args = message.SplitSpaces(2);
|
||||
Player who = PlayerInfo.FindMatches(p, args[0]);
|
||||
|
||||
string reason = args.Length == 1 ? "you know why." : args[1];
|
||||
reason = ModActionCmd.ExpandReason(p, reason);
|
||||
if (reason == null) return;
|
||||
@ -37,41 +38,18 @@ namespace MCGalaxy.Commands.Moderation {
|
||||
if (p != null && p.Rank <= who.Rank) {
|
||||
MessageTooHighRank(p, "warn", false); return;
|
||||
}
|
||||
|
||||
string warnedby = (p == null) ? "(console)" : p.ColoredName;
|
||||
Chat.MessageGlobal("{0} %ewarned {1} %ebecause:", warnedby, who.ColoredName);
|
||||
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++;
|
||||
|
||||
ModAction action = new ModAction(who.name, p, ModActionType.Warned, reason);
|
||||
OnModActionEvent.Call(action);
|
||||
}
|
||||
|
||||
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..");
|
||||
string offName = PlayerInfo.FindOfflineNameMatches(p, args[0]);
|
||||
if (offName == null) return;
|
||||
reason = args.Length > 1 ? " for: " + reason : "";
|
||||
|
||||
ModerationAction action = new ModerationAction(offName, p, ModerationActionType.Warned, reason);
|
||||
OnModerationActionEvent.Call(action);
|
||||
Player.Message(p, "Warned {0}{1}.", offName, reason);
|
||||
|
||||
ModAction action = new ModAction(offName, p, ModActionType.Warned, reason);
|
||||
OnModActionEvent.Call(action);
|
||||
}
|
||||
|
||||
public override void Help(Player p) {
|
||||
|
@ -46,6 +46,8 @@ namespace MCGalaxy.Core {
|
||||
Priority.Critical, this);
|
||||
OnEcoTransactionEvent.Register(EcoHandlers.HandleEcoTransaction,
|
||||
Priority.Critical, this);
|
||||
OnModActionEvent.Register(ModActionHandler.HandleModAction,
|
||||
Priority.Critical, this);
|
||||
|
||||
clearTask = Server.Background.QueueRepeat(IPThrottler.CleanupTask, null,
|
||||
TimeSpan.FromMinutes(10));
|
||||
@ -60,6 +62,7 @@ namespace MCGalaxy.Core {
|
||||
OnPlayerMoveEvent.UnRegister(this);
|
||||
OnPlayerClickEvent.UnRegister(this);
|
||||
OnEcoTransactionEvent.UnRegister(this);
|
||||
OnModActionEvent.UnRegister(this);
|
||||
|
||||
Server.Background.Cancel(clearTask);
|
||||
}
|
||||
|
140
MCGalaxy/CorePlugin/ModActionHandler.cs
Normal file
140
MCGalaxy/CorePlugin/ModActionHandler.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -23,36 +23,35 @@ namespace MCGalaxy.Core {
|
||||
public sealed class NotesPlugin : Plugin_Simple {
|
||||
public override string creator { get { return Server.SoftwareName + " team"; } }
|
||||
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) {
|
||||
OnModerationActionEvent.Register(HandleModerationAction, Priority.Low, this);
|
||||
OnModActionEvent.Register(HandleModerationAction, Priority.Low, this);
|
||||
}
|
||||
|
||||
public override void Unload(bool shutdown) {
|
||||
OnModerationActionEvent.UnRegister(this);
|
||||
OnModActionEvent.UnRegister(this);
|
||||
}
|
||||
|
||||
void HandleModerationAction(ModerationAction action) {
|
||||
static void HandleModerationAction(ModAction action) {
|
||||
switch (action.Type) {
|
||||
case ModerationActionType.Frozen:
|
||||
case ModActionType.Frozen:
|
||||
AddNote(action, "F"); break;
|
||||
case ModerationActionType.Jailed:
|
||||
case ModActionType.Jailed:
|
||||
AddNote(action, "J"); break;
|
||||
case ModerationActionType.Kicked:
|
||||
case ModActionType.Kicked:
|
||||
AddNote(action, "K"); break;
|
||||
case ModerationActionType.Muted:
|
||||
case ModActionType.Muted:
|
||||
AddNote(action, "M"); break;
|
||||
case ModerationActionType.Warned:
|
||||
case ModActionType.Warned:
|
||||
AddNote(action, "W"); break;
|
||||
case ModerationActionType.Ban:
|
||||
case ModActionType.Ban:
|
||||
string banType = action.Duration.Ticks == 0 ? "B" : "T";
|
||||
AddNote(action, banType); break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
static void AddNote(ModerationAction action, string type) {
|
||||
static void AddNote(ModAction action, string type) {
|
||||
if (!Server.LogNotes) return;
|
||||
string src = action.Actor == null ? "(console)" : action.Actor.name;
|
||||
|
||||
|
@ -73,9 +73,9 @@ namespace MCGalaxy.Games.ZS {
|
||||
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.");
|
||||
} else {
|
||||
ModerationAction action = new ModerationAction(p.name, null,
|
||||
ModerationActionType.Kicked, "Auto kick for pillaring");
|
||||
OnModerationActionEvent.Call(action);
|
||||
ModAction action = new ModAction(p.name, null,
|
||||
ModActionType.Kicked, "Auto kick for pillaring");
|
||||
OnModActionEvent.Call(action);
|
||||
p.Kick("No pillaring allowed!");
|
||||
}
|
||||
|
||||
|
@ -398,6 +398,7 @@
|
||||
<Compile Include="CorePlugin\EcoHandlers.cs" />
|
||||
<Compile Include="CorePlugin\IPThrottler.cs" />
|
||||
<Compile Include="CorePlugin\MiscHandlers.cs" />
|
||||
<Compile Include="CorePlugin\ModActionHandler.cs" />
|
||||
<Compile Include="CorePlugin\NotesPlugin.cs" />
|
||||
<Compile Include="Database\Backends\SQLite.cs" />
|
||||
<Compile Include="Database\BlockDB\BlockDB.cs" />
|
||||
@ -597,7 +598,7 @@
|
||||
<Compile Include="Plugins\Events\GroupEvents.cs" />
|
||||
<Compile Include="Plugins\Events\IPluginEvent.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\ServerEvents.cs" />
|
||||
<Compile Include="Network\Player.Networking.cs" />
|
||||
|
@ -23,13 +23,14 @@ namespace MCGalaxy.Network {
|
||||
public sealed class IRCPlugin : Plugin_Simple {
|
||||
public override string creator { get { return Server.SoftwareName + " team"; } }
|
||||
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) {
|
||||
OnPlayerConnectEvent.Register(HandleConnect, Priority.Low, this);
|
||||
OnPlayerDisconnectEvent.Register(HandleDisconnect, Priority.Low, this);
|
||||
OnPlayerChatEvent.Register(HandleChat, Priority.Low, this);
|
||||
Player.DoPlayerAction += Player_PlayerAction;
|
||||
OnModActionEvent.Register(HandleModerationAction, Priority.Low, this);
|
||||
}
|
||||
|
||||
public override void Unload(bool shutdown) {
|
||||
@ -37,10 +38,33 @@ namespace MCGalaxy.Network {
|
||||
OnPlayerDisconnectEvent.UnRegister(this);
|
||||
OnPlayerChatEvent.UnRegister(this);
|
||||
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,
|
||||
string message, bool stealth) {
|
||||
string message, bool stealth) {
|
||||
if (!Server.IRC.Enabled) return;
|
||||
string msg = null;
|
||||
|
||||
@ -62,6 +86,7 @@ namespace MCGalaxy.Network {
|
||||
if (msg != null) Server.IRC.Say(msg, stealth);
|
||||
}
|
||||
|
||||
|
||||
static void HandleDisconnect(Player p, string reason) {
|
||||
if (!Server.IRC.Enabled || p.hidden) 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);
|
||||
}
|
||||
|
||||
static char[] trimChars = new char[] { ' ' };
|
||||
static char[] trimChars = new char[] { ' ' };
|
||||
static void HandleChat(Player p, string message) {
|
||||
if (!Server.IRC.Enabled) return;
|
||||
if (message.Trim(trimChars) == "") return;
|
||||
|
@ -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>
|
||||
public static void BanPlayer(Player banner, string target, string reason, bool stealth, string oldrank) {
|
||||
if (reason == null) reason = "-";
|
||||
reason = reason.Replace(" ", "%20");
|
||||
|
||||
string player = banner == null ? "(console)" : banner.truename;
|
||||
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>
|
||||
public static void UnbanPlayer(Player unbanner, string target, string reason) {
|
||||
if (reason == null) reason = "-";
|
||||
reason = reason.Replace(" ", "%20");
|
||||
|
||||
string player = unbanner == null ? "(console)" : unbanner.truename;
|
||||
AddUnbanEntry(player, target.ToLower(), reason, FormatDate());
|
||||
}
|
||||
|
@ -20,20 +20,37 @@ using System;
|
||||
namespace MCGalaxy.Events {
|
||||
|
||||
/// <summary> Represents a moderation action. </summary>
|
||||
public sealed class ModerationAction {
|
||||
public sealed class ModAction {
|
||||
|
||||
/// <summary> Target player name or IP. </summary>
|
||||
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>
|
||||
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>
|
||||
public ModerationActionType Type;
|
||||
public ModActionType Type;
|
||||
|
||||
/// <summary> Reason provided for the action, can be null. </summary>
|
||||
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>
|
||||
/// <remarks> Duration of 0 means the action is permanent. (e.g. regular /ban) </remarks>
|
||||
public TimeSpan Duration;
|
||||
@ -41,7 +58,7 @@ namespace MCGalaxy.Events {
|
||||
/// <summary> Action-specific metadata, see remarks in ModerationActionType for what is in this. </summary>
|
||||
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)) {
|
||||
Target = target;
|
||||
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>
|
||||
public enum ModerationActionType {
|
||||
public enum ModActionType {
|
||||
|
||||
/// <summary> Player is banned. </summary>
|
||||
/// <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>
|
||||
public sealed class OnModerationActionEvent : IPluginEvent<OnModerationAction> {
|
||||
internal OnModerationActionEvent(OnModerationAction method, Priority priority, Plugin plugin)
|
||||
public sealed class OnModActionEvent : IPluginEvent<OnModAction> {
|
||||
internal OnModActionEvent(OnModAction method, Priority priority, Plugin plugin)
|
||||
: base(method, priority, plugin) { }
|
||||
|
||||
public static void Call(ModerationAction e) {
|
||||
public static void Call(ModAction e) {
|
||||
if (handlers.Count == 0) return;
|
||||
CallImpl(pl => pl(e));
|
||||
}
|
@ -141,6 +141,7 @@ namespace MCGalaxy {
|
||||
ctf.Load(true);
|
||||
Plugin.all.Add(ctf);
|
||||
LoadCorePlugin(new CorePlugin());
|
||||
LoadCorePlugin(new NotesPlugin());
|
||||
}
|
||||
|
||||
internal static void LoadCorePlugin(Plugin plugin) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user