From c17e37315ee37484f7805db3d84c9205d940c7e1 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Tue, 25 Dec 2018 23:53:59 +1100 Subject: [PATCH] Fix .x not working, if configured IRC channel name's capitalisation differs to its actual channel name capitalisation --- MCGalaxy/Commands/building/tc.cs | 39 +++++++++++++++++++++++ MCGalaxy/Network/IRCPlugin/IRCHandlers.cs | 28 ++++++++-------- 2 files changed, 54 insertions(+), 13 deletions(-) create mode 100644 MCGalaxy/Commands/building/tc.cs diff --git a/MCGalaxy/Commands/building/tc.cs b/MCGalaxy/Commands/building/tc.cs new file mode 100644 index 000000000..8839a5a3d --- /dev/null +++ b/MCGalaxy/Commands/building/tc.cs @@ -0,0 +1,39 @@ +using MCGalaxy.Commands; + +namespace MCGalaxy.Commands { + public sealed class CmdFixTP : Command { + public override string name { get { return "FixTP"; } } + public override string type { get { return CommandTypes.Building; } } + public override LevelPermission defaultRank { get { return LevelPermission.Admin; } } + + public override void Use(Player p, string message) { + string[] urls = message.SplitSpaces(2); + if (urls.Length < 2) { Help(p); return; } + int changed = 0; + + string[] maps = LevelInfo.AllMapNames(); + Level lvl; + foreach (string map in maps) { + LevelConfig cfg = LevelInfo.GetConfig(map, out lvl); + + if (cfg.Terrain.CaselessEq(urls[0])) { + p.Message("Changed terrain.png of map " + cfg.Color + map); + cfg.Terrain = urls[1]; + cfg.SaveFor(map); + changed++; + } else if (cfg.TexturePack.CaselessEq(urls[0])) { + p.Message("Changed texture pack of map " + cfg.Color + map); + cfg.TexturePack = urls[1]; + cfg.SaveFor(map); + changed++; + } + } + p.Message("Gone through all the maps. {0} were changed. "); + } + + public override void Help(Player p) { + p.Message("%T/FixTP [source] [dest]"); + p.Message("%HReplaces any maps using [source] texture pack with [dest] texture pack"); + } + } +} diff --git a/MCGalaxy/Network/IRCPlugin/IRCHandlers.cs b/MCGalaxy/Network/IRCPlugin/IRCHandlers.cs index b45c599bf..1fd6a49e1 100644 --- a/MCGalaxy/Network/IRCPlugin/IRCHandlers.cs +++ b/MCGalaxy/Network/IRCPlugin/IRCHandlers.cs @@ -397,14 +397,14 @@ namespace MCGalaxy.Network { if (newNick.Trim().Length == 0) return; - foreach (var kvp in userMap) { - int index = GetNickIndex(user.Nick, kvp.Value); + foreach (var chans in userMap) { + int index = GetNickIndex(user.Nick, chans.Value); if (index >= 0) { - string prefix = GetPrefix(kvp.Value[index]); - kvp.Value[index] = prefix + newNick; + string prefix = GetPrefix(chans.Value[index]); + chans.Value[index] = prefix + newNick; } else { // should never happen, but just in case. - bot.connection.Sender.Names(kvp.Key); + bot.connection.Sender.Names(chans.Key); } } @@ -436,12 +436,13 @@ namespace MCGalaxy.Network { } List GetNicks(string channel) { - List chanNicks; - if (!userMap.TryGetValue(channel, out chanNicks)) { - chanNicks = new List(); - userMap[channel] = chanNicks; + foreach (var chan in userMap) { + if (chan.Key.CaselessEq(channel)) return chan.Value; } - return chanNicks; + + List nicks = new List(); + userMap[channel] = nicks; + return nicks; } void UpdateNick(string n, List chanNicks) { @@ -495,8 +496,8 @@ namespace MCGalaxy.Network { } bool VerifyNick(string channel, string userNick, ref string error, ref bool foundAtAll) { - List chanNicks = null; - if (!userMap.TryGetValue(channel, out chanNicks)) return false; + List chanNicks = GetNicks(channel); + if (chanNicks.Count == 0) return false; int index = GetNickIndex(userNick, chanNicks); if (index == -1) return false; @@ -513,7 +514,8 @@ namespace MCGalaxy.Network { return true; } else { foreach (string chan in bot.opchannels) { - if (!userMap.TryGetValue(chan, out chanNicks)) continue; + chanNicks = GetNicks(chan); + if (chanNicks.Count == 0) continue; index = GetNickIndex(userNick, chanNicks); if (index != -1) return true;