Cleanup /ignore and related code

This commit is contained in:
UnknownShadow200 2017-09-01 15:27:23 +10:00
parent a933a360f8
commit 6cc8366f8b
14 changed files with 131 additions and 103 deletions

View File

@ -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 {
/// <summary> Sends a message to all players who are on the given level,
/// are not in a chatroom, and are not ignoring all chat. </summary>
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);
}
/// <summary> Sends a message to all players who are have the permission to read opchat. </summary>
@ -140,7 +140,7 @@ namespace MCGalaxy {
/// <summary> 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. </summary>
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);
}
/// <summary> Sends a message to everyone, regardless of their level, chatroom or ignoring all chat. </summary>
@ -171,9 +171,9 @@ namespace MCGalaxy {
/// <summary> Returns true if the target player can see chat messags by source. </summary>
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);
}

View File

@ -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);

View File

@ -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) {

View File

@ -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) {

View File

@ -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;
}

View File

@ -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);
}
}

View File

@ -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));
}

View File

@ -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;

View File

@ -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;

View File

@ -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);
}

View File

@ -603,6 +603,7 @@
<Compile Include="Player\Player.Handlers.cs" />
<Compile Include="Player\Player.Login.cs" />
<Compile Include="Player\PlayerActions.cs" />
<Compile Include="Player\PlayerIgnores.cs" />
<Compile Include="Player\PlayerInfo.cs" />
<Compile Include="Player\PlayerPhysics.cs" />
<Compile Include="Player\SpamChecker.cs" />

View File

@ -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<PendingItem> pendingNames = new List<PendingItem>();
internal static object pendingLock = new object();
internal static object pendingLock = new object();
public static List<Player> connections = new List<Player>(ServerConfig.MaxPlayers);
public List<string> listignored = new List<string>();
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;

View File

@ -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);

View File

@ -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<string> Names = new List<string>();
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.");
}
}
}