fix ArgumentOutOfRangeException when trying to undo yourself for extreme amounts of time

This commit is contained in:
UnknownShadow200 2018-07-20 01:03:56 +10:00
parent 7a66ba25c6
commit 58369eb962
4 changed files with 11 additions and 15 deletions

View File

@ -61,11 +61,15 @@ namespace MCGalaxy.Commands {
string action, string defUnit) {
try {
span = input.ParseShort(defUnit);
// Typically span is added to current time, so ensure span isn't too big
DateTime.UtcNow.Add(span).AddYears(1);
return true;
} catch (OverflowException) {
p.Message("Timespan given is too big.");
p.Message("%WTimespan given is too big");
} catch (ArgumentOutOfRangeException) {
p.Message("%WTimespan given is too big");
} catch (FormatException ex) {
p.Message("{0} is not a valid quantifier.", ex.Message);
p.Message("%W{0} is not a valid quantifier.", ex.Message);
p.Message(TimespanHelp, action);
}
return false;

View File

@ -38,13 +38,11 @@ namespace MCGalaxy.Commands.Moderation {
bool area = message.CaselessStarts("area ");
if (area) message = message.Substring("area ".Length);
if (message.Length == 0) message = p.name + " 1800";
if (message.Length == 0) message = p.name;
string[] parts = message.SplitSpaces();
if (parts.Length >= 2) {
if (!CommandParser.GetTimespan(p, parts[1], ref delta, "highlight the past", "s")) return;
} else if (ParseTimespan(parts[0], out delta)) {
parts[0] = p.name;
} else {
delta = TimeSpan.FromMinutes(30);
}
@ -97,14 +95,6 @@ namespace MCGalaxy.Commands.Moderation {
}
}
static bool ParseTimespan(string input, out TimeSpan delta) {
delta = TimeSpan.Zero;
try { delta = input.ParseShort("s"); return true;
} catch (ArgumentException) { return false;
} catch (FormatException) { return false;
}
}
public override void Help(Player p) {
p.Message("%T/Highlight [player] <timespan>");
p.Message("%HHighlights blocks changed by [player] in the past <timespan>");

View File

@ -651,7 +651,9 @@ namespace MCGalaxy {
Message("%WInfinite message block loop detected, aborting");
return false;
}
} else { mbRecursion = 0; }
} else if (data.Context == CommandContext.Normal) {
mbRecursion = 0;
}
return true;
}