diff --git a/MCGalaxy/Chat/Chat.cs b/MCGalaxy/Chat/Chat.cs index 7043b17ed..df57699e0 100644 --- a/MCGalaxy/Chat/Chat.cs +++ b/MCGalaxy/Chat/Chat.cs @@ -43,9 +43,9 @@ namespace MCGalaxy { if (visibleOnly && !Entities.CanSee(p, source)) continue; if (!p.level.SeesServerWideChat || p.Chatroom != null) continue; - if (p.ignoreNicks && p.ignoreTitles) Player.Message(p, msg_NNNT); - else if (p.ignoreNicks) Player.Message(p, msg_NN); - else if (p.ignoreTitles) Player.Message(p, msg_NT); + if (p.Ignores.Nicks && p.Ignores.Titles) Player.Message(p, msg_NNNT); + else if (p.Ignores.Nicks) Player.Message(p, msg_NN); + else if (p.Ignores.Titles) Player.Message(p, msg_NT); else Player.Message(p, message); } } @@ -122,7 +122,7 @@ namespace MCGalaxy { /// Sends a message to all players who are on the given level, /// are not in a chatroom, and are not ignoring all chat. public static void MessageLevel(Level lvl, string message) { - MessageWhere(message, pl => !pl.ignoreAll && pl.level == lvl && pl.Chatroom == null); + MessageWhere(message, pl => !pl.Ignores.All && pl.level == lvl && pl.Chatroom == null); } /// Sends a message to all players who are have the permission to read opchat. @@ -140,7 +140,7 @@ namespace MCGalaxy { /// Sends a message to all players, who are not in a chatroom, are not ignoring all chat, /// and are not on a level that does not have isolated/level only chat. public static void MessageGlobal(string message) { - MessageWhere(message, pl => !pl.ignoreAll && pl.level.SeesServerWideChat && pl.Chatroom == null); + MessageWhere(message, pl => !pl.Ignores.All && pl.level.SeesServerWideChat && pl.Chatroom == null); } /// Sends a message to everyone, regardless of their level, chatroom or ignoring all chat. @@ -171,9 +171,9 @@ namespace MCGalaxy { /// Returns true if the target player can see chat messags by source. public static bool NotIgnoring(Player source, Player target) { - if (target.ignoreAll) return source == target; // don't ignore messages from self + if (target.Ignores.All) return source == target; // don't ignore messages from self - return source == null || !target.listignored.CaselessContains(source.name); + return source == null || !target.Ignores.Names.CaselessContains(source.name); } diff --git a/MCGalaxy/Chat/ChatModes.cs b/MCGalaxy/Chat/ChatModes.cs index 5a49755d2..e99cab211 100644 --- a/MCGalaxy/Chat/ChatModes.cs +++ b/MCGalaxy/Chat/ChatModes.cs @@ -94,10 +94,10 @@ namespace MCGalaxy { if (who == null) return; if (who == p) { Player.Message(p, "Trying to talk to yourself, huh?"); return; } - if (who.ignoreAll) { + if (who.Ignores.All) { DoFakePM(p, who, message); return; } - if (p != null && who.listignored.CaselessContains(p.name)) { + if (p != null && who.Ignores.Names.CaselessContains(p.name)) { DoFakePM(p, who, message); return; } DoPM(p, who, message); diff --git a/MCGalaxy/Commands/Chat/Cmd8Ball.cs b/MCGalaxy/Commands/Chat/Cmd8Ball.cs index 4a7b00f63..cdf436890 100644 --- a/MCGalaxy/Commands/Chat/Cmd8Ball.cs +++ b/MCGalaxy/Commands/Chat/Cmd8Ball.cs @@ -62,7 +62,7 @@ namespace MCGalaxy.Commands.Chatting { } static bool Sees8Ball(Player p) { - return !p.ignoreAll && !p.ignore8ball && p.level.SeesServerWideChat && p.Chatroom == null; + return !p.Ignores.All && !p.Ignores.EightBall && p.level.SeesServerWideChat && p.Chatroom == null; } public override void Help(Player p) { diff --git a/MCGalaxy/Commands/Chat/CmdIgnore.cs b/MCGalaxy/Commands/Chat/CmdIgnore.cs index 955d5edf5..071f4bcea 100644 --- a/MCGalaxy/Commands/Chat/CmdIgnore.cs +++ b/MCGalaxy/Commands/Chat/CmdIgnore.cs @@ -36,42 +36,29 @@ namespace MCGalaxy.Commands.Chatting { string action = args[0].ToLower(); if (action == "all") { - Toggle(p, ref p.ignoreAll, "{0} ignoring all chat"); return; + Toggle(p, ref p.Ignores.All, "{0} ignoring all chat"); return; } else if (action == "irc") { - Toggle(p, ref p.ignoreIRC, "{0} ignoring IRC chat"); return; + Toggle(p, ref p.Ignores.IRC, "{0} ignoring IRC chat"); return; } else if (action == "titles") { - Toggle(p, ref p.ignoreTitles, "{1}Player titles {0} show before names in chat"); return; + Toggle(p, ref p.Ignores.Titles, "{1}Player titles {0} show before names in chat"); return; } else if (action == "nicks") { - Toggle(p, ref p.ignoreNicks, "{1}Custom player nicks {0} show in chat"); return; + Toggle(p, ref p.Ignores.Nicks, "{1}Custom player nicks {0} show in chat"); return; } else if (action == "8ball") { - Toggle(p, ref p.ignore8ball, "{0} ignoring %T/8ball"); return; + Toggle(p, ref p.Ignores.EightBall, "{0} ignoring %T/8ball"); return; } else if (action == "drawoutput") { - Toggle(p, ref p.ignoreDrawOutput, "{0} ignoring draw command output"); return; + Toggle(p, ref p.Ignores.DrawOutput, "{0} ignoring draw command output"); return; } else if (action == "list") { - string names = p.listignored.Join(); - if (names.Length > 0) { - Player.Message(p, "&cCurrently ignoring the following players:"); - Player.Message(p, names); - } - - if (p.ignoreAll) Player.Message(p, "&cIgnoring all chat"); - if (p.ignoreIRC) Player.Message(p, "&cIgnoring IRC chat"); - if (p.ignore8ball) Player.Message(p, "&cIgnoring %T/8ball"); - - if (p.ignoreDrawOutput) Player.Message(p, "&cIgnoring draw command output."); - if (p.ignoreTitles) Player.Message(p, "&cPlayer titles do not show before names in chat."); - if (p.ignoreNicks) Player.Message(p, "&cCustom player nicks do not show in chat."); - return; + p.Ignores.Output(p); return; } string unignore = null; - for (int i = 0; i < p.listignored.Count; i++) { - if (!action.CaselessEq(p.listignored[i])) continue; - unignore = p.listignored[i]; break; + for (int i = 0; i < p.Ignores.Names.Count; i++) { + if (!action.CaselessEq(p.Ignores.Names[i])) continue; + unignore = p.Ignores.Names[i]; break; } if (unignore != null) { - p.listignored.Remove(unignore); + p.Ignores.Names.Remove(unignore); Player.Message(p, "&aNo longer ignoring {0}", unignore); } else { int matches = 0; @@ -83,14 +70,14 @@ namespace MCGalaxy.Commands.Chatting { } if (p == who) { Player.Message(p, "You cannot ignore yourself."); return; } - if (p.listignored.CaselessRemove(who.name)) { + if (p.Ignores.Names.CaselessRemove(who.name)) { Player.Message(p, "&aNo longer ignoring {0}", who.ColoredName); } else { - p.listignored.Add(who.name); + p.Ignores.Names.Add(who.name); Player.Message(p, "&cNow ignoring {0}", who.ColoredName); } } - SaveIgnores(p); + p.Ignores.Save(p); } static void Toggle(Player p, ref bool ignore, string format) { @@ -100,30 +87,7 @@ namespace MCGalaxy.Commands.Chatting { } else { Player.Message(p, format, ignore ? "no longer" : "now", ignore ? "&c" : "&a"); } - SaveIgnores(p); - } - static void SaveIgnores(Player p) { - string path = "ranks/ignore/" + p.name + ".txt"; - if (!Directory.Exists("ranks/ignore")) - Directory.CreateDirectory("ranks/ignore"); - - try { - using (StreamWriter w = new StreamWriter(path)) { - if (p.ignoreAll) w.WriteLine("&all"); - if (p.ignoreIRC) w.WriteLine("&irc"); - if (p.ignore8ball) w.WriteLine("&8ball"); - - if (p.ignoreDrawOutput) w.WriteLine("&drawoutput"); - if (p.ignoreTitles) w.WriteLine("&titles"); - if (p.ignoreNicks) w.WriteLine("&nicks"); - - foreach (string line in p.listignored) - w.WriteLine(line); - } - } catch (IOException ex) { - Logger.LogError(ex); - Logger.Log(LogType.Warning, "Failed to save ignored list for player: " + p.name); - } + p.Ignores.Save(p); } public override void Help(Player p) { diff --git a/MCGalaxy/Commands/Chat/MessageCmd.cs b/MCGalaxy/Commands/Chat/MessageCmd.cs index 72a76bc5d..d6d069c20 100644 --- a/MCGalaxy/Commands/Chat/MessageCmd.cs +++ b/MCGalaxy/Commands/Chat/MessageCmd.cs @@ -30,7 +30,7 @@ namespace MCGalaxy.Commands.Chatting { if (!TryMessage(p, string.Format(message, giver, who.ColoredName))) return false; string giverRaw = (p == null) ? "(console)" : p.name; - if (messageWho && !who.listignored.CaselessContains(giverRaw) && !who.ignoreAll) + if (messageWho && !who.Ignores.Names.CaselessContains(giverRaw) && !who.Ignores.All) Player.Message(who, string.Format(message, giver, "you")); return true; } diff --git a/MCGalaxy/Commands/building/CmdPlace.cs b/MCGalaxy/Commands/building/CmdPlace.cs index 15d30571c..a7181ac84 100644 --- a/MCGalaxy/Commands/building/CmdPlace.cs +++ b/MCGalaxy/Commands/building/CmdPlace.cs @@ -58,7 +58,7 @@ namespace MCGalaxy.Commands.Building { p.level.UpdateBlock(p, (ushort)x, (ushort)y, (ushort)z, block); string blockName = p.level.BlockName(block); - if (!p.ignoreDrawOutput) { + if (!p.Ignores.DrawOutput) { Player.Message(p, "{3} block was placed at ({0}, {1}, {2}).", x, y, z, blockName); } } diff --git a/MCGalaxy/Commands/building/CmdSPlace.cs b/MCGalaxy/Commands/building/CmdSPlace.cs index d58d89711..ca832695b 100644 --- a/MCGalaxy/Commands/building/CmdSPlace.cs +++ b/MCGalaxy/Commands/building/CmdSPlace.cs @@ -83,7 +83,7 @@ namespace MCGalaxy.Commands.Building { p.level.UpdateBlock(p, (ushort)m[0].X, (ushort)m[0].Y, (ushort)m[0].Z, held, BlockDBFlags.Drawn, true); } - if (!p.ignoreDrawOutput) { + if (!p.Ignores.DrawOutput) { Player.Message(p, "Placed {1} blocks {0} apart.", interval > 0 ? interval : distance, p.level.BlockName(held)); } diff --git a/MCGalaxy/Commands/other/CmdTpA.cs b/MCGalaxy/Commands/other/CmdTpA.cs index 9ff63a0f6..b92131186 100644 --- a/MCGalaxy/Commands/other/CmdTpA.cs +++ b/MCGalaxy/Commands/other/CmdTpA.cs @@ -44,7 +44,7 @@ namespace MCGalaxy.Commands.Misc { Player target = PlayerInfo.FindMatches(p, message); if (target == null) return; if (target == p) { Player.Message(p, "You cannot /tpa to yourself."); return; } - if (target.listignored.CaselessContains(p.name)) { ShowSentMessage(p, target); return; } + if (target.Ignores.Names.CaselessContains(p.name)) { ShowSentMessage(p, target); return; } if (target.name.CaselessEq(p.currentTpa)) { Player.Message(p, "You still have a pending teleport request with this player."); return; diff --git a/MCGalaxy/CorePlugin/ConnectHandler.cs b/MCGalaxy/CorePlugin/ConnectHandler.cs index 0ff259283..53e16557b 100644 --- a/MCGalaxy/CorePlugin/ConnectHandler.cs +++ b/MCGalaxy/CorePlugin/ConnectHandler.cs @@ -31,7 +31,7 @@ namespace MCGalaxy.Core { LoadReach(p); LoadWaypoints(p); - LoadIgnores(p); + p.Ignores.Load(p); CheckLoginJailed(p); } @@ -69,33 +69,6 @@ namespace MCGalaxy.Core { } } - static void LoadIgnores(Player p) { - string path = "ranks/ignore/" + p.name + ".txt"; - if (!File.Exists(path)) return; - - try { - string[] lines = File.ReadAllLines(path); - foreach (string line in lines) { - if (line == "&global") continue; // deprecated /ignore global - if (line == "&all") p.ignoreAll = true; - else if (line == "&irc") p.ignoreIRC = true; - else if (line == "&8ball") p.ignore8ball = true; - else if (line == "&drawoutput") p.ignoreDrawOutput = true; - else if (line == "&titles") p.ignoreTitles = true; - else if (line == "&nicks") p.ignoreNicks = true; - else p.listignored.Add(line); - } - } catch (IOException ex) { - Logger.LogError(ex); - Logger.Log(LogType.Warning, "Failed to load ignore list for: " + p.name); - } - - if (p.ignoreAll || p.ignoreIRC || p.ignore8ball || p.ignoreDrawOutput - || p.ignoreTitles || p.ignoreNicks || p.listignored.Count > 0) { - Player.Message(p, "&cType &a/ignore list &cto see who you are still ignoring"); - } - } - static void CheckLoginJailed(Player p) { string level = Server.jailed.FindData(p.name); if (level == null) return; diff --git a/MCGalaxy/Drawing/DrawOps/DrawOpPerformer.cs b/MCGalaxy/Drawing/DrawOps/DrawOpPerformer.cs index 07e0f9a31..1ab28b059 100644 --- a/MCGalaxy/Drawing/DrawOps/DrawOpPerformer.cs +++ b/MCGalaxy/Drawing/DrawOps/DrawOpPerformer.cs @@ -65,12 +65,12 @@ namespace MCGalaxy.Drawing.Ops { if (brush != null && affected != -1) { const string format = "{0}({1}): affecting up to {2} blocks"; - if (p == null || !p.ignoreDrawOutput) { + if (p == null || !p.Ignores.DrawOutput) { Player.Message(p, format, op.Name, brush.Name, affected); } } else if (affected != -1) { const string format = "{0}: affecting up to {1} blocks"; - if (p == null || !p.ignoreDrawOutput) { + if (p == null || !p.Ignores.DrawOutput) { Player.Message(p, format, op.Name, affected); } } @@ -191,7 +191,7 @@ namespace MCGalaxy.Drawing.Ops { // Potentially buffer the block change if (op.TotalModified == reloadThreshold) { - if (p == null || !p.ignoreDrawOutput) { + if (p == null || !p.Ignores.DrawOutput) { Player.Message(p, "Changed over {0} blocks, preparing to reload map..", reloadThreshold); } diff --git a/MCGalaxy/MCGalaxy_.csproj b/MCGalaxy/MCGalaxy_.csproj index 00ed026ec..98ae665ce 100644 --- a/MCGalaxy/MCGalaxy_.csproj +++ b/MCGalaxy/MCGalaxy_.csproj @@ -603,6 +603,7 @@ + diff --git a/MCGalaxy/Player/Player.Fields.cs b/MCGalaxy/Player/Player.Fields.cs index 2d9bf3781..e4ca4aa54 100644 --- a/MCGalaxy/Player/Player.Fields.cs +++ b/MCGalaxy/Player/Player.Fields.cs @@ -26,7 +26,7 @@ using MCGalaxy.Undo; namespace MCGalaxy { public enum VoteKickChoice { NotYetVoted, Yes, No } - + public partial class Player : IDisposable { internal class PendingItem { @@ -39,9 +39,9 @@ namespace MCGalaxy { } } internal static List pendingNames = new List(); - internal static object pendingLock = new object(); + internal static object pendingLock = new object(); public static List connections = new List(ServerConfig.MaxPlayers); - public List listignored = new List(); + public PlayerIgnores Ignores = new PlayerIgnores(); public static string lastMSG = ""; //TpA @@ -93,7 +93,6 @@ namespace MCGalaxy { public string ColoredName { get { return color + DisplayName; } } public bool deleteMode; - public bool ignorePermission; public bool ignoreGrief; public bool parseEmotes = ServerConfig.ParseEmotes; public bool opchat; @@ -101,8 +100,6 @@ namespace MCGalaxy { public bool onWhitelist; public bool whisper; public string whisperTo = ""; - public bool ignoreAll, ignoreGlobal, ignoreIRC, ignoreTitles, ignoreNicks, ignore8ball, ignoreDrawOutput; - string partialMessage = ""; public bool trainGrab; diff --git a/MCGalaxy/Player/Player.cs b/MCGalaxy/Player/Player.cs index 7cd933544..85cbf8340 100644 --- a/MCGalaxy/Player/Player.cs +++ b/MCGalaxy/Player/Player.cs @@ -188,7 +188,7 @@ namespace MCGalaxy { message = Colors.Escape(message); Player[] players = PlayerInfo.Online.Items; foreach (Player p in players) { - if (p.ignoreAll || p.ignoreIRC) continue; + if (p.Ignores.All || p.Ignores.IRC) continue; if (p.level.SeesServerWideChat && p.Chatroom == null) Player.Message(p, message); diff --git a/MCGalaxy/Player/PlayerIgnores.cs b/MCGalaxy/Player/PlayerIgnores.cs new file mode 100644 index 000000000..e9354398b --- /dev/null +++ b/MCGalaxy/Player/PlayerIgnores.cs @@ -0,0 +1,93 @@ +/* + 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; +using System.IO; + +namespace MCGalaxy { + + public class PlayerIgnores { + public List Names = new List(); + public bool All, Global, IRC, Titles, Nicks, EightBall, DrawOutput; + + public void Load(Player p) { + string path = "ranks/ignore/" + p.name + ".txt"; + if (!File.Exists(path)) return; + + try { + string[] lines = File.ReadAllLines(path); + foreach (string line in lines) { + if (line == "&global") continue; // deprecated /ignore global + if (line == "&all") All = true; + else if (line == "&irc") IRC = true; + else if (line == "&8ball") EightBall = true; + else if (line == "&drawoutput") DrawOutput = true; + else if (line == "&titles") Titles = true; + else if (line == "&nicks") Nicks = true; + else Names.Add(line); + } + } catch (IOException ex) { + Logger.LogError(ex); + Logger.Log(LogType.Warning, "Failed to load ignore list for: " + p.name); + } + + if (All || IRC || EightBall || DrawOutput || Titles || Nicks || Names.Count > 0) { + Player.Message(p, "&cType &a/ignore list &cto see who you are still ignoring"); + } + } + + public void Save(Player p) { + string path = "ranks/ignore/" + p.name + ".txt"; + if (!Directory.Exists("ranks/ignore")) + Directory.CreateDirectory("ranks/ignore"); + + try { + using (StreamWriter w = new StreamWriter(path)) { + if (All) w.WriteLine("&all"); + if (IRC) w.WriteLine("&irc"); + if (EightBall) w.WriteLine("&8ball"); + + if (DrawOutput) w.WriteLine("&drawoutput"); + if (Titles) w.WriteLine("&titles"); + if (Nicks) w.WriteLine("&nicks"); + + foreach (string line in Names) { w.WriteLine(line); } + } + } catch (IOException ex) { + Logger.LogError(ex); + Logger.Log(LogType.Warning, "Failed to save ignored list for player: " + p.name); + } + } + + public void Output(Player p) { + string names = Names.Join(); + if (names.Length > 0) { + Player.Message(p, "&cCurrently ignoring the following players:"); + Player.Message(p, names); + } + + if (All) Player.Message(p, "&cIgnoring all chat"); + if (IRC) Player.Message(p, "&cIgnoring IRC chat"); + if (EightBall) Player.Message(p, "&cIgnoring %T/8ball"); + + if (DrawOutput) Player.Message(p, "&cIgnoring draw command output."); + if (Titles) Player.Message(p, "&cPlayer titles do not show before names in chat."); + if (Nicks) Player.Message(p, "&cCustom player nicks do not show in chat."); + } + } +} \ No newline at end of file