mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-23 04:32:50 -04:00
Prefer case insensitive string comparisons
This commit is contained in:
parent
66c6082ee0
commit
167b3f5f6d
@ -57,7 +57,7 @@ namespace MCGalaxy.Bots {
|
||||
public override bool Execute(PlayerBot bot, InstructionData data) {
|
||||
string script = (string)data.Metadata;
|
||||
if (File.Exists("bots/" + script)) {
|
||||
Command.all.Find("botset").Use(null, bot.name + " " + script);
|
||||
Command.all.FindByName("botset").Use(null, bot.name + " " + script);
|
||||
return true;
|
||||
}
|
||||
bot.NextInstruction(); return true;
|
||||
|
@ -67,20 +67,21 @@ namespace MCGalaxy.Commands {
|
||||
sw.WriteLine("# it is treated as /help me <args given by user>.");
|
||||
|
||||
foreach (Alias a in aliases) {
|
||||
if (a.Prefix == null)
|
||||
if (a.Prefix == null) {
|
||||
sw.WriteLine(a.Trigger + " : " + a.Target);
|
||||
else
|
||||
} else {
|
||||
sw.WriteLine(a.Trigger + " : " + a.Target + " " + a.Prefix);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Alias Find(string cmd) {
|
||||
foreach (Alias alias in aliases) {
|
||||
if (alias.Trigger == cmd) return alias;
|
||||
if (alias.Trigger.CaselessEq(cmd)) return alias;
|
||||
}
|
||||
foreach (Alias alias in coreAliases) {
|
||||
if (alias.Trigger == cmd) return alias;
|
||||
if (alias.Trigger.CaselessEq(cmd)) return alias;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -111,30 +111,28 @@ namespace MCGalaxy.Commands.CPE {
|
||||
if (args.Length < 4) { Help(p); return; }
|
||||
|
||||
char code = ParseColor(p, args[1]);
|
||||
if (code == '\0') return;
|
||||
if (code == '\0') return;
|
||||
ColorDesc col = Colors.List[code];
|
||||
|
||||
switch (args[2]) {
|
||||
case "name":
|
||||
if (!CheckName(p, args[3])) return;
|
||||
if (args[2].CaselessEq("name")) {
|
||||
if (!CheckName(p, args[3])) return;
|
||||
|
||||
Player.Message(p, "Set name of {0} to {1}", col.Name, args[3]);
|
||||
col.Name = args[3];break;
|
||||
case "fallback":
|
||||
char fallback;
|
||||
if (!CheckFallback(p, args[3], code, out fallback)) return;
|
||||
|
||||
Player.Message(p, "Set fallback of {0} to %&S{1}", col.Name, fallback);
|
||||
col.Fallback = fallback; break;
|
||||
case "hex":
|
||||
case "color":
|
||||
ColorDesc rgb = default(ColorDesc);
|
||||
if (!CommandParser.GetHex(p, args[3], ref rgb)) return;
|
||||
|
||||
Player.Message(p, "Set hex color of {0} to {1}", col.Name, Utils.Hex(rgb.R, rgb.G, rgb.B));
|
||||
col.R = rgb.R; col.G = rgb.G; col.B = rgb.B; break;
|
||||
default:
|
||||
Help(p); return;
|
||||
Player.Message(p, "Set name of {0} to {1}", col.Name, args[3]);
|
||||
col.Name = args[3];
|
||||
} else if (args[2].CaselessEq("fallback")) {
|
||||
char fallback;
|
||||
if (!CheckFallback(p, args[3], code, out fallback)) return;
|
||||
|
||||
Player.Message(p, "Set fallback of {0} to %&S{1}", col.Name, fallback);
|
||||
col.Fallback = fallback;
|
||||
} else if (args[2].CaselessEq("hex") || args[2].CaselessEq("color")) {
|
||||
ColorDesc rgb = default(ColorDesc);
|
||||
if (!CommandParser.GetHex(p, args[3], ref rgb)) return;
|
||||
|
||||
Player.Message(p, "Set hex color of {0} to {1}", col.Name, Utils.Hex(rgb.R, rgb.G, rgb.B));
|
||||
col.R = rgb.R; col.G = rgb.G; col.B = rgb.B;
|
||||
} else {
|
||||
Help(p); return;
|
||||
}
|
||||
|
||||
Colors.Update(col);
|
||||
|
@ -38,9 +38,8 @@ namespace MCGalaxy {
|
||||
|
||||
/// <summary> Finds the command which has the given name or shortcut, or null if not found. </summary>
|
||||
public Command Find(string name) {
|
||||
name = name.ToLower();
|
||||
foreach (Command cmd in commands) {
|
||||
if (cmd.name == name || cmd.shortcut == name) return cmd;
|
||||
if (cmd.name.CaselessEq(name) || cmd.shortcut.CaselessEq(name)) return cmd;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -180,7 +180,7 @@ namespace MCGalaxy.Commands {
|
||||
|
||||
if (File.Exists(Paths.CmdPermsFile)) {
|
||||
string[] lines = File.ReadAllLines(Paths.CmdPermsFile);
|
||||
if (lines.Length > 0 && lines[0] == "#Version 2") {
|
||||
if (lines.Length > 0 && lines[0].CaselessEq("#Version 2")) {
|
||||
LoadVersion2(lines);
|
||||
} else {
|
||||
LoadVersion1(lines);
|
@ -30,7 +30,7 @@ namespace MCGalaxy.Commands.Fun {
|
||||
if (message.Length == 0) { Help(p); return; }
|
||||
string[] args = message.SplitSpaces();
|
||||
if (!(args.Length == 1 || args.Length == 3)) { Help(p); return; }
|
||||
if (message == "me" && p != null) args[0] = p.name;
|
||||
if (message.CaselessEq("me") && p != null) args[0] = p.name;
|
||||
|
||||
ushort x, y, z;
|
||||
if (args.Length == 1) {
|
||||
|
@ -391,7 +391,7 @@ namespace MCGalaxy.Commands.Fun {
|
||||
}
|
||||
|
||||
it.GameStatus = TntWarsGame.TntWarsGameStatus.WaitingForPlayers;
|
||||
Command.all.Find("restore").Use(null, it.BackupNumber + it.lvl.name);
|
||||
Command.all.FindByName("restore").Use(null, it.BackupNumber + it.lvl.name);
|
||||
it.RedScore = 0;
|
||||
it.BlueScore = 0;
|
||||
|
||||
|
@ -33,7 +33,7 @@ namespace MCGalaxy.Commands.Moderation {
|
||||
}
|
||||
|
||||
public override void Use(Player p, string message) {
|
||||
if (message == "check") {
|
||||
if (message.CaselessEq("check")) {
|
||||
string state = p.hidden ? "" : "not ";
|
||||
Player.Message(p, "You are " + state + "currently hidden!"); return;
|
||||
}
|
||||
|
@ -114,8 +114,10 @@ namespace MCGalaxy.Commands.Moderation {
|
||||
if (p == null) { Player.Message(p, "Console cannot leave the review queue."); return; }
|
||||
|
||||
bool inQueue = false;
|
||||
foreach (string who in Server.reviewlist)
|
||||
inQueue |= who == p.name;
|
||||
foreach (string who in Server.reviewlist) {
|
||||
inQueue |= who.CaselessEq(p.name);
|
||||
}
|
||||
|
||||
if (!inQueue) {
|
||||
Player.Message(p, "You aren't in the review queue so you cannot leave it."); return;
|
||||
}
|
||||
|
@ -48,9 +48,9 @@ namespace MCGalaxy.Commands.Moderation {
|
||||
MessageTooHighRank(p, "xjail", false); return;
|
||||
}
|
||||
|
||||
Command spawn = Command.all.Find("spawn");
|
||||
Command freeze = Command.all.Find("freeze");
|
||||
Command mute = Command.all.Find("mute");
|
||||
Command spawn = Command.all.FindByName("spawn");
|
||||
Command freeze = Command.all.FindByName("freeze");
|
||||
Command mute = Command.all.FindByName("mute");
|
||||
|
||||
if (!Server.jailed.Contains(who.name)) {
|
||||
if (!who.muted) mute.Use(p, message + " 10000d");
|
||||
|
@ -35,9 +35,9 @@ namespace MCGalaxy.Commands.Moderation {
|
||||
if (message.Length == 0) { Help(p); return; }
|
||||
|
||||
string name = message.SplitSpaces()[0];
|
||||
Command.all.Find("undoplayer").Use(p, name + " all");
|
||||
if (banIP) Command.all.Find("banip").Use(p, "@" + name);
|
||||
Command.all.Find("kickban").Use(p, message);
|
||||
Command.all.FindByName("undoplayer").Use(p, name + " all");
|
||||
if (banIP) Command.all.FindByName("banip").Use(p, "@" + name);
|
||||
Command.all.FindByName("kickban").Use(p, message);
|
||||
}
|
||||
|
||||
public override void Help(Player p) {
|
||||
|
@ -24,17 +24,13 @@ namespace MCGalaxy.Commands.Scripting {
|
||||
public override bool museumUsable { get { return true; } }
|
||||
|
||||
public override void Use(Player p, string message) {
|
||||
string[] param = message.SplitSpaces();
|
||||
string[] args = message.SplitSpaces();
|
||||
if (message.Length == 0) { Help(p); return; }
|
||||
|
||||
if (param.Length == 1) {
|
||||
Command.all.Find("compile").Use(p, message);
|
||||
Command.all.Find("cmdload").Use(p, message);
|
||||
Command.all.Find("help").Use(p, message);
|
||||
} else if (param[1].CaselessEq("vb")) {
|
||||
Command.all.Find("compile").Use(p, message + " vb");
|
||||
Command.all.Find("cmdload").Use(p, message + " vb");
|
||||
Command.all.Find("help").Use(p, message);
|
||||
if (args.Length == 1 || args[1].CaselessEq("vb")) {
|
||||
Command.all.FindByName("compile").Use(p, message);
|
||||
Command.all.FindByName("cmdload").Use(p, args[0]);
|
||||
Command.all.FindByName("help").Use(p, args[0]);
|
||||
} else {
|
||||
Help(p);
|
||||
}
|
||||
|
@ -97,10 +97,10 @@ namespace MCGalaxy.Commands.World {
|
||||
} else if (cmd == "DELETE" || cmd == "REMOVE") {
|
||||
DeleteMap(p, value);
|
||||
} else if (cmd == "SAVE") {
|
||||
Command.all.Find("save").Use(p, "");
|
||||
Command.all.FindByName("save").Use(p, "");
|
||||
Player.Message(p, "Map has been saved.");
|
||||
} else if (cmd == "RESTORE") {
|
||||
Command.all.Find("restore").Use(p, value);
|
||||
Command.all.FindByName("restore").Use(p, value);
|
||||
} else if (cmd == "RESIZE") {
|
||||
value = p.level.name + " " + value;
|
||||
string[] args = value.SplitSpaces();
|
||||
@ -117,15 +117,15 @@ namespace MCGalaxy.Commands.World {
|
||||
Command.all.Find("perbuild").Use(p, rank);
|
||||
} else if (cmd == "TEXTURE") {
|
||||
if (value.Length == 0) {
|
||||
Command.all.Find("texture").Use(p, "level normal");
|
||||
Command.all.FindByName("texture").Use(p, "level normal");
|
||||
} else {
|
||||
Command.all.Find("texture").Use(p, "level " + value);
|
||||
Command.all.FindByName("texture").Use(p, "level " + value);
|
||||
}
|
||||
} else if (cmd == "TEXTUREZIP") {
|
||||
if (value.Length == 0) {
|
||||
Command.all.Find("texture").Use(p, "levelzip normal");
|
||||
Command.all.FindByName("texture").Use(p, "levelzip normal");
|
||||
} else {
|
||||
Command.all.Find("texture").Use(p, "levelzip " + value);
|
||||
Command.all.FindByName("texture").Use(p, "levelzip " + value);
|
||||
}
|
||||
} else {
|
||||
cmd = LevelOptions.Map(cmd.ToLower());
|
||||
|
@ -34,9 +34,9 @@ namespace MCGalaxy.Commands.World {
|
||||
public override void Use(Player p, string message) {
|
||||
if (CheckSuper(p, message, "player or level name")) return;
|
||||
if (message.Length == 0) message = p.name;
|
||||
string[] parts = message.ToLower().SplitSpaces();
|
||||
string[] parts = message.SplitSpaces();
|
||||
|
||||
if (parts[0] == "all") {
|
||||
if (parts[0].CaselessEq("all")) {
|
||||
if (!ReloadAll(p, parts)) return;
|
||||
} else {
|
||||
Player who = PlayerInfo.FindMatches(p, parts[0]);
|
||||
|
@ -32,7 +32,7 @@ namespace MCGalaxy.Commands.World {
|
||||
int phys = p.level.physics;
|
||||
CmdPhysics.SetPhysics(p.level, 0);
|
||||
|
||||
Command cmd = Command.all.Find("replaceall");
|
||||
Command cmd = Command.all.FindByName("replaceall");
|
||||
string args = message.CaselessEq("all") ?
|
||||
"lavafall waterfall lava_fast active_lava active_water " +
|
||||
"active_hot_lava active_cold_water fast_hot_lava magma geyser" : message;
|
||||
|
@ -23,14 +23,13 @@ namespace MCGalaxy.Commands.World {
|
||||
public override LevelPermission defaultRank { get { return LevelPermission.Operator; } }
|
||||
|
||||
public override void Use(Player p, string message) {
|
||||
string name = message.ToLower();
|
||||
if (CheckSuper(p, message, "level name")) return;
|
||||
|
||||
if (name.Length == 0) {
|
||||
if (message.Length == 0) {
|
||||
if (!p.level.Unload()) {
|
||||
Player.Message(p, "You cannot unload this level.");
|
||||
}
|
||||
} else if (name == "empty") {
|
||||
} else if (message.CaselessEq("empty")) {
|
||||
Level[] loaded = LevelInfo.Loaded.Items;
|
||||
for (int i = 0; i < loaded.Length; i++) {
|
||||
Level lvl = loaded[i];
|
||||
@ -38,7 +37,7 @@ namespace MCGalaxy.Commands.World {
|
||||
lvl.Unload(true);
|
||||
}
|
||||
} else {
|
||||
Level level = Matcher.FindLevels(p, name);
|
||||
Level level = Matcher.FindLevels(p, message);
|
||||
if (level == null) return;
|
||||
|
||||
if (!level.Unload()) {
|
||||
|
@ -36,10 +36,10 @@ namespace MCGalaxy.Core {
|
||||
}
|
||||
|
||||
static void CheckReviewList(Player p) {
|
||||
Command cmd = Command.all.Find("review");
|
||||
Command cmd = Command.all.FindByName("review");
|
||||
LevelPermission perm = CommandExtraPerms.MinPerm("review");
|
||||
|
||||
if (p.group.Permission < perm || !p.group.Commands.Contains(cmd)) return;
|
||||
if (p.group.Permission < perm || !p.group.CanExecute(cmd)) return;
|
||||
int count = Server.reviewlist.Count;
|
||||
if (count == 0) return;
|
||||
|
||||
|
@ -161,8 +161,8 @@ namespace MCGalaxy.Drawing.Brushes {
|
||||
};
|
||||
|
||||
public override Brush Construct(BrushArgs args) {
|
||||
if (args.Message == "random") return new RandomRainbowBrush();
|
||||
if (args.Message == "bw") return new BWRainbowBrush();
|
||||
if (args.Message.CaselessEq("random")) return new RandomRainbowBrush();
|
||||
if (args.Message.CaselessEq("bw")) return new BWRainbowBrush();
|
||||
return new RainbowBrush();
|
||||
}
|
||||
}
|
||||
|
@ -357,7 +357,7 @@ namespace MCGalaxy.Games
|
||||
}
|
||||
}
|
||||
//Reset map
|
||||
Command.all.Find("restore").Use(null, BackupNumber + " " + lvl.name);
|
||||
Command.all.FindByName("restore").Use(null, BackupNumber + " " + lvl.name);
|
||||
if (lvl.Config.PhysicsOverload == 2501)
|
||||
{
|
||||
lvl.Config.PhysicsOverload = 1500;
|
||||
|
@ -74,7 +74,7 @@ namespace MCGalaxy.Games.ZS {
|
||||
} else if (p.Game.BlocksStacked == 4) {
|
||||
if (!p.Game.PillarFined) {
|
||||
Chat.MessageOps(" &cWarning: " + p.ColoredName + " %Sis pillaring!");
|
||||
Command.all.Find("take").Use(null, p.name + " 10 Auto fine for pillaring");
|
||||
Command.all.FindByName("take").Use(null, p.name + " 10 Auto fine for pillaring");
|
||||
Player.Message(p, " &cThe next time you pillar, you will be &4kicked&c.");
|
||||
} else {
|
||||
ModAction action = new ModAction(p.name, null, ModActionType.Kicked, "Auto kick for pillaring");
|
||||
|
@ -196,8 +196,10 @@
|
||||
<Compile Include="Commands\Chat\MessageCmd.cs" />
|
||||
<Compile Include="Commands\Command.cs" />
|
||||
<Compile Include="Commands\Command.Helpers.cs" />
|
||||
<Compile Include="Commands\CommandExtraPerms.cs" />
|
||||
<Compile Include="Commands\CommandList.cs" />
|
||||
<Compile Include="Commands\CommandParser.cs" />
|
||||
<Compile Include="Commands\CommandPerms.cs" />
|
||||
<Compile Include="Commands\CPE\CmdCustomColors.cs" />
|
||||
<Compile Include="Commands\CPE\CmdEntityRot.cs" />
|
||||
<Compile Include="Commands\CPE\CmdEnvironment.cs" />
|
||||
@ -351,8 +353,6 @@
|
||||
<Compile Include="Commands\other\CmdWarp.cs" />
|
||||
<Compile Include="Commands\other\CmdWaypoint.cs" />
|
||||
<Compile Include="Commands\other\QuitCmds.cs" />
|
||||
<Compile Include="Commands\Permissions\CommandExtraPerms.cs" />
|
||||
<Compile Include="Commands\Permissions\CommandPerms.cs" />
|
||||
<Compile Include="Commands\Scripting\CmdCmdCreate.cs" />
|
||||
<Compile Include="Commands\Scripting\CmdCmdLoad.cs" />
|
||||
<Compile Include="Commands\Scripting\CmdCmdUnload.cs" />
|
||||
@ -728,7 +728,6 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Commands\Maintenance" />
|
||||
<Folder Include="Commands\Permissions" />
|
||||
<Folder Include="Database\Stats" />
|
||||
<Folder Include="Network\Heartbeat" />
|
||||
<Folder Include="Network\IRCPlugin" />
|
||||
|
@ -699,7 +699,7 @@ namespace MCGalaxy {
|
||||
if (cmd != "pass") Logger.Log(LogType.CommandUsage, "{0} used /{1} {2}", name, cmd, message);
|
||||
|
||||
try { //opstats patch (since 5.5.11)
|
||||
if (Server.Opstats.Contains(cmd) || (cmd == "review" && message.ToLower() == "next" && Server.reviewlist.Count > 0)) {
|
||||
if (Server.Opstats.Contains(cmd) || (cmd == "review" && message.CaselessEq("next") && Server.reviewlist.Count > 0)) {
|
||||
Database.Backend.AddRow("Opstats", "Time, Name, Cmd, Cmdmsg",
|
||||
DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), name, cmd, message);
|
||||
}
|
||||
|
@ -70,13 +70,13 @@ namespace MCGalaxy {
|
||||
}
|
||||
|
||||
static long GetTicks(int num, string unit) {
|
||||
if (unit == "s" || unit == "S") return num * TimeSpan.TicksPerSecond;
|
||||
if (unit == "m" || unit == "M") return num * TimeSpan.TicksPerMinute;
|
||||
if (unit == "h" || unit == "H") return num * TimeSpan.TicksPerHour;
|
||||
if (unit == "d" || unit == "D") return num * TimeSpan.TicksPerDay;
|
||||
if (unit == "w" || unit == "W") return num * TimeSpan.TicksPerDay * 7;
|
||||
if (unit.CaselessEq("s")) return num * TimeSpan.TicksPerSecond;
|
||||
if (unit.CaselessEq("m")) return num * TimeSpan.TicksPerMinute;
|
||||
if (unit.CaselessEq("h")) return num * TimeSpan.TicksPerHour;
|
||||
if (unit.CaselessEq("d")) return num * TimeSpan.TicksPerDay;
|
||||
if (unit.CaselessEq("w")) return num * TimeSpan.TicksPerDay * 7;
|
||||
|
||||
if (unit == "ms" || unit == "MS") return num * TimeSpan.TicksPerMillisecond;
|
||||
if (unit.CaselessEq("ms")) return num * TimeSpan.TicksPerMillisecond;
|
||||
throw new FormatException(unit);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user