Now /mute always requires a timespan. Fixes #177 and fixes #377

This commit is contained in:
UnknownShadow200 2017-06-08 15:52:07 +10:00
parent b211c57568
commit 8d86e6a397
9 changed files with 70 additions and 125 deletions

View File

@ -34,15 +34,15 @@ namespace MCGalaxy.Commands.Moderation {
Player who = PlayerInfo.FindMatches(p, args[0]);
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;
}
if (p != null && p == who) { Player.Message(p, "Cannot freeze yourself."); return; }
if (p != null && who.Rank >= p.Rank) { MessageTooHighRank(p, "freeze", false); return; }
TimeSpan duration = TimeSpan.Zero;
if (!CommandParser.GetTimespan(p, args[1], ref duration, "freeze for", 'm')) return;
string reason = args.Length > 2 ? args[2] : "";
reason = ModActionCmd.ExpandReason(p, reason);
if (reason == null) return;
ModActionType actionType = who.frozen ? ModActionType.Unfrozen : ModActionType.Frozen;
ModAction action = new ModAction(who.name, p, actionType, reason, duration);
@ -52,6 +52,7 @@ namespace MCGalaxy.Commands.Moderation {
public override void Help(Player p) {
Player.Message(p, "%T/freeze [name] [timespan] <reason>");
Player.Message(p, "%HStops [name] from moving for [timespan] time, or until manually unfrozen.");
Player.Message(p, "%HFor <reason>, @number can be used as a shortcut for that rule.");
}
}
}

View File

@ -14,7 +14,7 @@
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 System.IO;
using MCGalaxy.Events;
@ -28,37 +28,44 @@ namespace MCGalaxy.Commands.Moderation {
public override void Use(Player p, string message) {
if (message == "") { Help(p); return; }
string[] args = message.SplitSpaces(2);
string reason = args.Length > 1 ? args[1] : "";
reason = ModActionCmd.ExpandReason(p, reason);
if (reason == null) return;
string[] args = message.SplitSpaces(3);
Player who = PlayerInfo.FindMatches(p, args[0]);
if (who == null) {
if (Server.muted.Contains(args[0])) {
ModAction action = new ModAction(args[0], p, ModActionType.Unmuted, reason);
OnModActionEvent.Call(action);
}
if (Server.muted.Contains(args[0])) Unmute(p, args[0], args);
return;
}
if (p != null && p == who) { Player.Message(p, "You cannot mute or unmute yourself."); return; }
if (who.muted) {
ModAction action = new ModAction(who.name, p, ModActionType.Unmuted, reason);
OnModActionEvent.Call(action);
} else {
if (p != null && who.Rank >= p.Rank) {
MessageTooHighRank(p, "mute", false); return;
}
Unmute(p, who.name, args);
} else {
if (p != null && who.Rank >= p.Rank) { MessageTooHighRank(p, "mute", false); return; }
if (args.Length < 2) { Help(p); return; }
ModAction action = new ModAction(who.name, p, ModActionType.Muted, reason);
TimeSpan duration = TimeSpan.Zero;
if (!CommandParser.GetTimespan(p, args[1], ref duration, "mute for", 's')) return;
string reason = args.Length > 2 ? args[2] : "";
reason = ModActionCmd.ExpandReason(p, reason);
if (reason == null) return;
ModAction action = new ModAction(who.name, p, ModActionType.Muted, reason, duration);
OnModActionEvent.Call(action);
}
}
static void Unmute(Player p, string name, string[] args) {
string reason = args.Length > 1 ? args[1] : "";
reason = ModActionCmd.ExpandReason(p, reason);
if (reason == null) return;
ModAction action = new ModAction(name, p, ModActionType.Unmuted, reason);
OnModActionEvent.Call(action);
}
public override void Help(Player p) {
Player.Message(p, "%T/mute [player] <reason>");
Player.Message(p, "%T/mute [player] [timespan] <reason>");
Player.Message(p, "%HMutes or unmutes that player.");
Player.Message(p, "%HFor <reason>, @number can be used as a shortcut for that rule.");
}

View File

@ -1,63 +0,0 @@
/*
Copyright 2011 MCForge
Written by GamezGalaxy (hypereddie10)
Licensed under the
Educational Community License, Version 2.0 (the "License"); you may
not use this file except in compliance with the License. You may
obtain a copy of the License at
http://www.opensource.org/licenses/ecl2.php
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an "AS IS"
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
or implied. See the License for the specific language governing
permissions and limitations under the License.
*/
using System;
using System.Threading;
namespace MCGalaxy.Commands.Moderation {
public sealed class CmdXmute : Command {
public override string name { get { return "xmute"; } }
public override string type { get { return CommandTypes.Moderation; } }
public override bool museumUsable { get { return false; } }
public override LevelPermission defaultRank { get { return LevelPermission.Operator; } }
public override void Use(Player p, string message) {
if (message == "") { Help(p); return; }
if (p == null) {
Player.Message(p, "This command can only be used in-game. Use /mute [Player] instead."); return;
}
string[] args = message.SplitSpaces();
Player muter = PlayerInfo.FindMatches(p, args[0]);
if (muter == null) return;
if (p != null && muter.group.Permission > p.Rank) {
MessageTooHighRank(p, "xmute", true); return;
}
if (p == muter) {
Player.Message(p, "You cannot use xmute on yourself!"); return;
}
Command.all.Find("mute").Use(p, muter.name);
int time = 120;
if (args.Length > 1 && !CommandParser.GetInt(p, args[1], "Time", ref time, 1)) return;
Chat.MessageGlobal("{0} %Shas been muted for {1} seconds", muter.ColoredName, time);
Player.Message(muter, "You have been muted for " + time + " seconds");
Thread.Sleep(time * 1000);
Command.all.Find("mute").Use(p, muter.name);
}
public override void Help(Player p) {
Player.Message(p, "%T/xmute [player] [seconds]");
Player.Message(p, "%HMutes [player] for [seconds] seconds");
}
}
}

View File

@ -61,8 +61,7 @@ namespace MCGalaxy.Core {
if (who != null) who.frozen = true;
LogAction(e, who, "&bfrozen");
string data = FormatModTaskData(e);
Server.frozen.AddOrReplace(e.Target, data);
Server.frozen.AddOrReplace(e.Target, FormatModTaskData(e));
ModerationTasks.FreezeCalcNextRun();
Server.frozen.Save();
}
@ -107,21 +106,23 @@ namespace MCGalaxy.Core {
static void DoMute(ModAction e) {
Player who = PlayerInfo.FindExact(e.Target);
Server.muted.AddIfNotExists(e.Target);
Server.muted.Save();
Player who = PlayerInfo.FindExact(e.Target);
if (who != null) who.muted = true;
LogAction(e, who, "&8muted");
Server.muted.AddOrReplace(e.Target, FormatModTaskData(e));
ModerationTasks.MuteCalcNextRun();
Server.muted.Save();
}
static void DoUnmute(ModAction e) {
Player who = PlayerInfo.FindExact(e.Target);
Server.muted.Remove(e.Target);
Server.muted.Save();
if (who != null) who.muted = false;
LogAction(e, who, "&aun-muted");
Server.muted.Remove(e.Target);
ModerationTasks.MuteCalcNextRun();
Server.muted.Save();
}
@ -249,7 +250,11 @@ namespace MCGalaxy.Core {
static string FormatModTaskData(ModAction e) {
long assign = DateTime.UtcNow.ToUnixTime();
long expiry = DateTime.UtcNow.Add(e.Duration).ToUnixTime();
DateTime expiryTime = DateTime.UtcNow.Add(e.Duration);
if (e.Duration == TimeSpan.Zero)
expiryTime = DateTime.MaxValue;
long expiry = expiryTime.ToUnixTime();
string assigner = e.Actor == null ? "(console)" : e.Actor.name;
return assigner + " " + assign + " " + expiry;
}

View File

@ -327,7 +327,6 @@
<Compile Include="Commands\Moderation\CmdWhitelist.cs" />
<Compile Include="Commands\Moderation\CmdXban.cs" />
<Compile Include="Commands\Moderation\CmdXJail.cs" />
<Compile Include="Commands\Moderation\CmdXmute.cs" />
<Compile Include="Commands\Moderation\CmdZone.cs" />
<Compile Include="Commands\Moderation\ModActionCmd.cs" />
<Compile Include="Commands\other\CmdAscend.cs" />

View File

@ -14,6 +14,7 @@ permissions and limitations under the Licenses.
*/
using System;
using System.Collections.Generic;
using MCGalaxy.Events;
using MCGalaxy.Tasks;
namespace MCGalaxy {
@ -59,10 +60,9 @@ namespace MCGalaxy {
if (chatLog.AddSpamEntry(Server.spamcounter, Server.spamcountreset))
return false;
Command.all.Find("mute").Use(null, p.name);
Chat.MessageGlobal("{0} %Shas been &0muted %Sfor spamming!", p.ColoredName);
Server.MainScheduler.QueueOnce(UnmuteTask, p.name,
TimeSpan.FromSeconds(Server.mutespamtime));
TimeSpan duration = TimeSpan.FromSeconds(Server.mutespamtime);
ModAction action = new ModAction(p.name, null, ModActionType.Muted, "&0Auto mute for spamming", duration);
OnModActionEvent.Call(action);
return true;
}
}
@ -80,19 +80,5 @@ namespace MCGalaxy {
return true;
}
}
static void UnmuteTask(SchedulerTask task) {
string name = (string)task.State;
Player who = PlayerInfo.FindExact(name);
if (who != null) {
if (who.muted) Command.all.Find("mute").Use(null, who.name);
Player.Message(who, "Remember, no &cspamming %Snext time!");
} else {
Server.muted.Remove(name);
Server.muted.Save();
}
}
}
}

View File

@ -78,10 +78,10 @@ namespace MCGalaxy {
public static bool UseCTF = false;
public static bool ServerSetupFinished = false;
public static CTFGame ctf = null;
public static PlayerList bannedIP, whiteList, ircControllers, muted, invalidIds;
public static PlayerList bannedIP, whiteList, ircControllers, invalidIds;
public static PlayerList ignored, hidden, agreed, vip, noEmotes, lockdown;
public static PlayerExtList models, skins, reach, rotations;
public static PlayerExtList frozen, jailed, tempBans, tempRanks;
public static PlayerExtList frozen, muted, jailed, tempBans, tempRanks;
public static readonly List<string> Devs = new List<string>(), Mods = new List<string>();

View File

@ -60,7 +60,6 @@ namespace MCGalaxy {
bannedIP = PlayerList.Load("banned-ip.txt");
ircControllers = PlayerList.Load("IRC_Controllers.txt");
muted = PlayerList.Load("muted.txt");
hidden = PlayerList.Load("hidden.txt");
vip = PlayerList.Load("text/vip.txt");
noEmotes = PlayerList.Load("text/emotelist.txt");
@ -72,6 +71,7 @@ namespace MCGalaxy {
invalidIds = PlayerList.Load("extra/invalidids.txt");
rotations = PlayerExtList.Load("extra/rotations.txt");
muted = PlayerExtList.Load("ranks/muted.txt");
frozen = PlayerExtList.Load("ranks/frozen.txt");
tempRanks = PlayerExtList.Load(Paths.TempRanksFile);
tempBans = PlayerExtList.Load(Paths.TempBansFile);

View File

@ -22,12 +22,14 @@ using MCGalaxy.Events;
namespace MCGalaxy.Tasks {
internal static class ModerationTasks {
static SchedulerTask temprankTask, freezeTask;
static SchedulerTask temprankTask, freezeTask, muteTask;
internal static void QueueTasks() {
temprankTask = Server.MainScheduler.QueueRepeat(
TemprankCheckTask, null, NextRun(Server.tempRanks));
freezeTask = Server.MainScheduler.QueueRepeat(
FreezeCheckTask, null, NextRun(Server.frozen));
muteTask = Server.MainScheduler.QueueRepeat(
MuteCheckTask, null, NextRun(Server.muted));
}
@ -35,9 +37,7 @@ namespace MCGalaxy.Tasks {
DoTask(task, Server.tempRanks, TemprankCallback);
}
internal static void TemprankCalcNextRun() {
CalcNextRun(temprankTask, Server.tempRanks);
}
internal static void TemprankCalcNextRun() { CalcNextRun(temprankTask, Server.tempRanks); }
static void TemprankCallback(string[] args) {
Command.all.Find("temprank").Use(null, args[0] + " delete");
@ -50,18 +50,28 @@ namespace MCGalaxy.Tasks {
internal static void FreezeCheckTask(SchedulerTask task) {
DoTask(task, Server.frozen, FreezeCallback);
}
internal static void FreezeCalcNextRun() {
CalcNextRun(freezeTask, Server.frozen);
}
internal static void FreezeCalcNextRun() { CalcNextRun(freezeTask, Server.frozen); }
static void FreezeCallback(string[] args) {
ModAction action = new ModAction(args[0], null, ModActionType.Unfrozen, "auto unfreeze");
OnModActionEvent.Call(action);
}
internal static void MuteCheckTask(SchedulerTask task) {
DoTask(task, Server.muted, MuteCallback);
}
internal static void MuteCalcNextRun() { CalcNextRun(muteTask, Server.muted); }
static void MuteCallback(string[] args) {
ModAction action = new ModAction(args[0], null, ModActionType.Unmuted, "auto unmute");
OnModActionEvent.Call(action);
}
static void DoTask(SchedulerTask task, PlayerExtList list, Action<string[]> callback) {
List<string> lines = list.AllLines();
foreach (string line in lines) {