diff --git a/Commands/Command.All.cs b/Commands/Command.All.cs index f20c7b53d..ffaea90df 100644 --- a/Commands/Command.All.cs +++ b/Commands/Command.All.cs @@ -132,6 +132,7 @@ namespace MCGalaxy all.Add(new CmdInfected()); all.Add(new CmdInfo()); all.Add(new CmdInvincible()); + all.Add(new CmdIrcControllers()); all.Add(new CmdJail()); all.Add(new CmdJoker()); all.Add(new CmdKick()); diff --git a/Commands/Moderation/CmdIrcControllers.cs b/Commands/Moderation/CmdIrcControllers.cs new file mode 100644 index 000000000..e04bdeabc --- /dev/null +++ b/Commands/Moderation/CmdIrcControllers.cs @@ -0,0 +1,74 @@ +/* + Copyright 2015 MCGalaxy + + 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 System.Collections.Generic; + +namespace MCGalaxy.Commands { + + public sealed class CmdIrcControllers : Command { + + public override string name { get { return "irccontrollers"; } } + public override string shortcut { get { return "ircctrl"; } } + public override string type { get { return CommandTypes.Moderation; } } + public override bool museumUsable { get { return true; } } + public override LevelPermission defaultRank { get { return LevelPermission.Admin; } } + public CmdIrcControllers() { } + + public override void Use(Player p, string message) { + if (message == "") { Help(p); return; } + string[] parts = message.Split(' '); + + switch (parts[0].ToLower()) { + case "reload": + Server.ircControllers = PlayerList.Load("IRC_Controllers.txt", null); + Player.SendMessage(p, "IRC Controllers reloaded!"); + break; + case "add": + if (parts.Length < 2) { Player.SendMessage(p, "You need to provide a name to add."); return; } + if (Server.ircControllers.Contains(parts[1])) { + Player.SendMessage(p, parts[1] + " is already an IRC controller."); return; + } + + Server.ircControllers.Add(parts[1]); + Server.ircControllers.Save("IRC_Controllers.txt", true); + Player.SendMessage(p, parts[1] + " added to the IRC controller list."); + break; + case "remove": + if (parts.Length < 2) { Player.SendMessage(p, "You need to provide a name to remove."); return; } + if (!Server.ircControllers.Contains(parts[1])) { + Player.SendMessage(p, parts[1] + " is not an IRC controller."); return; + } + + Server.ircControllers.Remove(parts[1]); + Server.ircControllers.Save("IRC_Controllers.txt", true); + Player.SendMessage(p, parts[1] + " removed from the IRC controller list."); + break; + case "list": + List players = Server.ircControllers.All(); + string names = String.Join(", ", players); + Player.SendMessage(p, "IRC controllers list:"); + Player.SendMessage(p, names); + break; + } + } + + public override void Help(Player p) { + Player.SendMessage(p, "/ircctrl [name]"); + } + } +} diff --git a/Commands/Moderation/CmdReloadControllers.cs b/Commands/Moderation/CmdReloadControllers.cs deleted file mode 100644 index aaa6e8d9a..000000000 --- a/Commands/Moderation/CmdReloadControllers.cs +++ /dev/null @@ -1,39 +0,0 @@ -/* - Copyright 2010 MCSharp team (Modified for use with MCZall/MCLawl/MCGalaxy) - - 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. -*/ -namespace MCGalaxy.Commands -{ - public sealed class CmdReloadControllers : Command - { - public override string name { get { return "reloadcontrollers"; } } - public override string shortcut { get { return "rlctl"; } } - public override string type { get { return CommandTypes.Moderation; } } - public override bool museumUsable { get { return true; } } - public override LevelPermission defaultRank { get { return LevelPermission.Operator; } } - public CmdReloadControllers() { } - - public override void Use(Player p, string message) - { - Server.ircControllers = PlayerList.Load("IRC_Controllers.txt", null); - Player.SendMessage(p, "IRC Controllers reloaded!"); - } - public override void Help(Player p) - { - Player.SendMessage(p, "/reloadcontrollers - Reloads IRC Controllers."); - } - } -} diff --git a/Commands/Moderation/CmdWhitelist.cs b/Commands/Moderation/CmdWhitelist.cs index b24629d44..fa07841f0 100644 --- a/Commands/Moderation/CmdWhitelist.cs +++ b/Commands/Moderation/CmdWhitelist.cs @@ -46,7 +46,7 @@ namespace MCGalaxy.Commands } Server.whiteList.Add(player); Chat.GlobalMessageOps(p.color + p.prefix + p.name + Server.DefaultColor + " added &f" + player + Server.DefaultColor + " to the whitelist."); - Server.whiteList.Save("whitelist.txt"); + Server.whiteList.Save("whitelist.txt", true); Server.s.Log("WHITELIST: Added " + player); break; case "del": @@ -57,7 +57,7 @@ namespace MCGalaxy.Commands } Server.whiteList.Remove(player); Chat.GlobalMessageOps(p.color + p.prefix + p.name + Server.DefaultColor + " removed &f" + player + Server.DefaultColor + " from the whitelist."); - Server.whiteList.Save("whitelist.txt"); + Server.whiteList.Save("whitelist.txt", true); Server.s.Log("WHITELIST: Removed " + player); break; case "list": diff --git a/IRC/ForgeBot.cs b/IRC/ForgeBot.cs index 39173d96d..3512bf0ae 100644 --- a/IRC/ForgeBot.cs +++ b/IRC/ForgeBot.cs @@ -42,7 +42,10 @@ namespace MCGalaxy { this.channel = channel.Trim(); this.opchannel = opchannel.Trim(); this.nick = nick.Replace(" ", ""); this.server = server; banCmd = new List(); banCmd.Add("resetbot"); + banCmd.Add("resetirc"); banCmd.Add("oprules"); + banCmd.Add("irccontrollers"); + banCmd.Add("ircctrl"); if (Server.irc) { @@ -167,7 +170,7 @@ namespace MCGalaxy { void Listener_OnPrivate(UserInfo user, string message) { message = Colors.IrcToMinecraftColors(message); message = CP437Reader.ConvertToRaw(message); - string[] parts = message.Split(trimChars, 3); + string[] parts = message.Split(trimChars, 2); string ircCmd = parts[0].ToLower(); if (ircCmd == ".who" || ircCmd == ".players") { try { @@ -179,14 +182,14 @@ namespace MCGalaxy { } if (!Server.ircControllers.Contains(user.Nick)) { Pm(user.Nick, "You are not an IRC controller!"); return; } - if (message.Split(' ')[0] == "resetbot" || banCmd.Contains(message.Split(' ')[0])) { Pm(user.Nick, "You cannot use this command from IRC!"); return; } + if (banCmd.Contains(ircCmd)) { Pm(user.Nick, "You cannot use this command from IRC!"); return; } if (Player.CommandHasBadColourCodes(null, message)) { Pm(user.Nick, "Your command had invalid color codes!"); return; } - Command cmd = Command.all.Find(message.Split(' ')[0]); + Command cmd = Command.all.Find(ircCmd); if (cmd != null) { Server.s.Log("IRC Command: /" + message); usedCmd = user.Nick; - try { cmd.Use(new Player("IRC"), message.Split(' ').Length > 1 ? message.Substring(message.IndexOf(' ')).Trim() : ""); } + try { cmd.Use(new Player("IRC"), parts.Length > 1 ? parts[1] : ""); } catch { Pm(user.Nick, "Failed command!"); } usedCmd = ""; } @@ -195,8 +198,8 @@ namespace MCGalaxy { } void Listener_OnPublic(UserInfo user, string channel, string message) { - message = Colors.IrcToMinecraftColors(message); - message = CP437Reader.ConvertToRaw(message); + message = Colors.IrcToMinecraftColors(message); + message = CP437Reader.ConvertToRaw(message); string[] parts = message.Split(trimChars, 3); string ircCmd = parts[0].ToLower(); if (ircCmd == ".who" || ircCmd == ".players") { @@ -223,7 +226,7 @@ namespace MCGalaxy { Server.IRC.Say("You must be at least a half-op on the channel to use commands from IRC."); return; } - string cmdName = parts.Length >= 2 ? parts[1] : ""; + string cmdName = parts.Length >= 2 ? parts[1].ToLower() : ""; if (banCmd.Contains(cmdName)) { Server.IRC.Say("You are not allowed to use this command from IRC."); return; } diff --git a/MCGalaxy_.csproj b/MCGalaxy_.csproj index 468feae30..322c652de 100644 --- a/MCGalaxy_.csproj +++ b/MCGalaxy_.csproj @@ -246,6 +246,7 @@ + @@ -269,7 +270,6 @@ - diff --git a/Player/PlayerList.cs b/Player/PlayerList.cs index f6206c7eb..a586022fd 100644 --- a/Player/PlayerList.cs +++ b/Player/PlayerList.cs @@ -1,62 +1,79 @@ /* - Copyright 2010 MCSharp team (Modified for use with MCZall/MCLawl/MCGalaxy) - - 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. -*/ + Copyright 2010 MCSharp team (Modified for use with MCZall/MCLawl/MCGalaxy) + + 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.IO; using System.Collections.Generic; -namespace MCGalaxy -{ - public sealed class PlayerList - { - //public string name; + +namespace MCGalaxy { + + public sealed class PlayerList { + public Group group; List players = new List(); + readonly object locker = new object(); public PlayerList() { } - public void Add(string p) { players.Add(p.ToLower()); } - public bool Remove(string p) - { - return players.Remove(p.ToLower()); + + public void Add(string p) { + lock (locker) + players.Add(p.ToLower()); } - public bool Contains(string p) { return players.Contains(p.ToLower()); } - public List All() { return new List(players); } - public void Save(string path) { Save(path, true); } - public void Save() { - Save(group.fileName); + + public bool Remove(string p) { + lock (locker) + return players.Remove(p.ToLower()); } - public void Save(string path, bool console) - { - StreamWriter file = File.CreateText("ranks/" + path); - players.ForEach(delegate(string p) { file.WriteLine(p); }); - file.Close(); if (console) { Server.s.Log("SAVED: " + path); } + + public bool Contains(string p) { + lock (locker) + return players.Contains(p.ToLower()); } - public static PlayerList Load(string path, Group groupName) - { - if (!Directory.Exists("ranks")) { Directory.CreateDirectory("ranks"); } + + public List All() { + lock (locker) + return new List(players); + } + + public void Save() { Save(group.fileName, true); } + + public void Save(string path, bool console) { + using (StreamWriter w = File.CreateText("ranks/" + path)) { + lock (locker) { + foreach (string p in players) + w.WriteLine(p); + } + } + if (console) + Server.s.Log("SAVED: " + path); + } + + public static PlayerList Load(string path, Group groupName) { + if (!Directory.Exists("ranks")) + Directory.CreateDirectory("ranks"); path = "ranks/" + path; PlayerList list = new PlayerList(); list.group = groupName; - if (File.Exists(path)) - { + + if (File.Exists(path)) { foreach (string line in File.ReadAllLines(path)) { list.Add(line); } - } - else - { + } else { File.Create(path).Close(); Server.s.Log("CREATED NEW: " + path); - } return list; + } + return list; } } } \ No newline at end of file