diff --git a/MCGalaxy/Chat/Chat.cs b/MCGalaxy/Chat/Chat.cs index 1e4380bd8..790b5c954 100644 --- a/MCGalaxy/Chat/Chat.cs +++ b/MCGalaxy/Chat/Chat.cs @@ -123,7 +123,7 @@ namespace MCGalaxy { Player[] players = PlayerInfo.Online.Items; ChatMessageFilter scopeFilter = scopeFilters[(int)scope]; - OnChatSysEvent.Call(scope, ref msg, arg, ref filter, irc); + OnChatSysEvent.Call(scope, msg, arg, ref filter, irc); foreach (Player pl in players) { if (!scopeFilter(pl, arg)) continue; if (filter != null && !filter(pl, arg)) continue; @@ -157,7 +157,7 @@ namespace MCGalaxy { ChatMessageFilter scopeFilter = scopeFilters[(int)scope]; if (source == null) source = ConsolePlayer.Instance; - OnChatFromEvent.Call(scope, source, ref msg, arg, ref filter, irc); + OnChatFromEvent.Call(scope, source, msg, arg, ref filter, irc); foreach (Player pl in players) { if (!scopeFilter(pl, arg)) continue; if (filter != null && !filter(pl, arg)) continue; @@ -184,7 +184,7 @@ namespace MCGalaxy { ChatMessageFilter scopeFilter = scopeFilters[(int)scope]; if (source == null) source = ConsolePlayer.Instance; - OnChatEvent.Call(scope, source, ref msg, arg, ref filter, irc); + OnChatEvent.Call(scope, source, msg, arg, ref filter, irc); foreach (Player pl in players) { if (!NotIgnoring(pl, source)) continue; // Always show message to self too (unless ignoring self) diff --git a/MCGalaxy/Commands/Fun/CmdTeam.cs b/MCGalaxy/Commands/Fun/CmdTeam.cs index 15999bd11..f6f6197b2 100644 --- a/MCGalaxy/Commands/Fun/CmdTeam.cs +++ b/MCGalaxy/Commands/Fun/CmdTeam.cs @@ -128,7 +128,7 @@ namespace MCGalaxy.Commands.Fun { p.SetPrefix(); Team.Add(team); Team.SaveList(); - Chat.MessageFrom(p, "λNICK %S created the &a" + args[1] + " %Steam"); + Chat.MessageFrom(p, "λNICK %Screated the &a" + args[1] + " %Steam"); } void HandleJoin(Player p, string[] args) { diff --git a/MCGalaxy/Commands/Information/CmdTop.cs b/MCGalaxy/Commands/Information/CmdTop.cs index 5715de4fe..20df113c6 100644 --- a/MCGalaxy/Commands/Information/CmdTop.cs +++ b/MCGalaxy/Commands/Information/CmdTop.cs @@ -39,7 +39,7 @@ namespace MCGalaxy.Commands.Info { TopStat stat = FindTopStat(args[1]); if (stat == null) { - Player.Message(p, "/Top: Unrecognised type \"{0}\".", args[1]); return; + Player.Message(p, "&cUnrecognised type \"{0}\".", args[1]); return; } if (args.Length > 2) { diff --git a/MCGalaxy/Commands/Information/CmdViewRanks.cs b/MCGalaxy/Commands/Information/CmdViewRanks.cs index 4611815f5..5f688042b 100644 --- a/MCGalaxy/Commands/Information/CmdViewRanks.cs +++ b/MCGalaxy/Commands/Information/CmdViewRanks.cs @@ -50,8 +50,8 @@ namespace MCGalaxy.Commands.Info { } public override void Help(Player p) { - Player.Message(p, "/viewranks [rank] - Shows all players who have [rank]"); - Player.Message(p, "/viewranks banned - Shows all players who are banned."); + Player.Message(p, "%T/viewranks [rank] %H- Shows all players who have [rank]"); + Player.Message(p, "%T/viewranks banned %H- Shows all players who are banned"); Player.Message(p, "Available ranks: " + Group.GroupList.Join(g => g.ColoredName)); } } diff --git a/MCGalaxy/Commands/Moderation/CmdBan.cs b/MCGalaxy/Commands/Moderation/CmdBan.cs index 21cf3fe55..1d30305a4 100644 --- a/MCGalaxy/Commands/Moderation/CmdBan.cs +++ b/MCGalaxy/Commands/Moderation/CmdBan.cs @@ -38,8 +38,7 @@ namespace MCGalaxy.Commands.Moderation { reason = ModActionCmd.ExpandReason(p, reason); if (reason == null) return; - Player who = PlayerInfo.FindExact(target); - Group group = who != null ? who.group : Group.GroupIn(target); + Group group = PlayerInfo.GetGroup(target); if (!CheckPerms(target, group, p)) return; ModAction action = new ModAction(target, p, ModActionType.Ban, reason); diff --git a/MCGalaxy/Commands/Moderation/CmdBanip.cs b/MCGalaxy/Commands/Moderation/CmdBanip.cs index fd47c46d5..4b4154546 100644 --- a/MCGalaxy/Commands/Moderation/CmdBanip.cs +++ b/MCGalaxy/Commands/Moderation/CmdBanip.cs @@ -58,7 +58,7 @@ namespace MCGalaxy.Commands.Moderation { if (accounts == null || accounts.Count == 0) return true; foreach (string name in accounts) { - Group grp = Group.GroupIn(name); + Group grp = PlayerInfo.GetGroup(name); if (grp == null || grp.Permission < p.Rank) continue; Player.Message(p, "You can only IP ban IPs used by players with a lower rank."); diff --git a/MCGalaxy/Commands/Moderation/CmdReview.cs b/MCGalaxy/Commands/Moderation/CmdReview.cs index 684b177dc..a37c51621 100644 --- a/MCGalaxy/Commands/Moderation/CmdReview.cs +++ b/MCGalaxy/Commands/Moderation/CmdReview.cs @@ -95,7 +95,7 @@ namespace MCGalaxy.Commands.Moderation { Player.Message(p, "&9Players in the review queue:"); int pos = 1; foreach (string name in Server.reviewlist) { - Group grp = Group.GroupIn(name); + Group grp = PlayerInfo.GetGroup(name); Player.Message(p, "&a" + pos + ". &f" + name + "&a - Current Rank: " + grp.ColoredName); pos++; } diff --git a/MCGalaxy/Commands/Moderation/CmdSetRank.cs b/MCGalaxy/Commands/Moderation/CmdSetRank.cs index 2da1a76be..2b27d05c1 100644 --- a/MCGalaxy/Commands/Moderation/CmdSetRank.cs +++ b/MCGalaxy/Commands/Moderation/CmdSetRank.cs @@ -34,43 +34,44 @@ namespace MCGalaxy.Commands.Moderation { public override void Use(Player p, string message) { string[] args = message.SplitSpaces(3); if (args.Length < 2) { Help(p); return; } - string rankName = null, name = null; + string rankName, target; string reason = args.Length > 2 ? args[2] : null; if (args[0].CaselessEq("+up")) { rankName = args[0]; - name = ModActionCmd.FindName(p, "promote", "Promote", "", args[1], ref reason); + target = ModActionCmd.FindName(p, "promote", "Promote", "", args[1], ref reason); } else if (args[0].CaselessEq("-down")) { rankName = args[0]; - name = ModActionCmd.FindName(p, "demote", "Demote", "", args[1], ref reason); + target = ModActionCmd.FindName(p, "demote", "Demote", "", args[1], ref reason); } else { rankName = args[1]; - name = ModActionCmd.FindName(p, "rank", "Rank", " " + rankName, args[0], ref reason); + target = ModActionCmd.FindName(p, "rank", "Rank", " " + rankName, args[0], ref reason); } - if (name == null) return; - Player who = PlayerInfo.FindExact(name); - if (p == who && who != null) { Player.Message(p, "Cannot change your own rank."); return; } + if (target == null) return; + if (p != null && p.name.CaselessEq(target)) { + Player.Message(p, "Cannot change your own rank."); return; + } - Group curRank = who != null ? who.group : PlayerInfo.GetGroup(name); + Group curRank = PlayerInfo.GetGroup(target); Group newRank = TargetRank(p, rankName, curRank); if (newRank == null) return; if (curRank == newRank) { Player.Message(p, "{0} %Sis already ranked {1}", - PlayerInfo.GetColoredName(p, name), curRank.ColoredName); + PlayerInfo.GetColoredName(p, target), curRank.ColoredName); return; } - if (!CanChangeRank(name, curRank, newRank, who, p, ref reason)) return; + if (!CanChangeRank(target, curRank, newRank, p, ref reason)) return; - ModAction action = new ModAction(name, p, ModActionType.Rank, reason); + ModAction action = new ModAction(target, p, ModActionType.Rank, reason); action.targetGroup = curRank; action.Metadata = newRank; OnModActionEvent.Call(action); } internal static bool CanChangeRank(string name, Group curRank, Group newRank, - Player who, Player p, ref string reason) { + Player p, ref string reason) { Group banned = Group.BannedRank; if (reason == null) { reason = newRank.Permission >= curRank.Permission ? diff --git a/MCGalaxy/Commands/Moderation/CmdTempBan.cs b/MCGalaxy/Commands/Moderation/CmdTempBan.cs index 285f1ad76..2e47ab623 100644 --- a/MCGalaxy/Commands/Moderation/CmdTempBan.cs +++ b/MCGalaxy/Commands/Moderation/CmdTempBan.cs @@ -34,9 +34,8 @@ namespace MCGalaxy.Commands.Moderation { args.Length == 1 ? "" : " " + args[1], args[0], ref reason); if (target == null) return; - Player who = PlayerInfo.FindExact(target); - Group grp = who == null ? PlayerInfo.GetGroup(target) : who.group; + Group grp = PlayerInfo.GetGroup(target); if (p != null && grp.Permission >= p.Rank) { MessageTooHighRank(p, "temp ban", false); return; } diff --git a/MCGalaxy/Commands/Moderation/CmdTempRank.cs b/MCGalaxy/Commands/Moderation/CmdTempRank.cs index 1890cd8da..b49e3d4ba 100644 --- a/MCGalaxy/Commands/Moderation/CmdTempRank.cs +++ b/MCGalaxy/Commands/Moderation/CmdTempRank.cs @@ -46,7 +46,6 @@ namespace MCGalaxy.Commands.Moderation { static void Assign(Player p, string[] args) { string target = PlayerInfo.FindMatchesPreferOnline(p, args[0]); if (target == null) return; - Player who = PlayerInfo.FindExact(target); Group newRank = Matcher.FindRanks(p, args[1]); if (newRank == null) return; @@ -57,12 +56,13 @@ namespace MCGalaxy.Commands.Moderation { Player.Message(p, "&cThe player already has a temporary rank assigned!"); return; } - if (p != null && who != null && p == who) { + if (p != null && p.name.CaselessEq(target)) { Player.Message(p, "&cYou cannot assign yourself a temporary rank."); return; } - Group curRank = who != null ? who.group : Group.GroupIn(target); + + Group curRank = PlayerInfo.GetGroup(target); string reason = args.Length > 3 ? args[3] : "assigning temp rank"; - if (!CmdSetRank.CanChangeRank(target, curRank, newRank, who, p, ref reason)) return; + if (!CmdSetRank.CanChangeRank(target, curRank, newRank, p, ref reason)) return; ModAction action = new ModAction(target, p, ModActionType.Rank, reason, duration); action.targetGroup = curRank; @@ -79,14 +79,13 @@ namespace MCGalaxy.Commands.Moderation { } string[] parts = line.SplitSpaces(); - Player who = PlayerInfo.FindExact(target); - Group curRank = who != null ? who.group : Group.GroupIn(target); + Group curRank = PlayerInfo.GetGroup(target); Group oldRank = Group.Find(parts[4 - 1]); // -1 because data, not whole line if (oldRank == null) return; string reason = "temp rank unassigned"; - if (!CmdSetRank.CanChangeRank(target, curRank, oldRank, who, p, ref reason)) return; + if (!CmdSetRank.CanChangeRank(target, curRank, oldRank, p, ref reason)) return; ModAction action = new ModAction(target, p, ModActionType.Rank, reason); action.Metadata = oldRank; diff --git a/MCGalaxy/Commands/Moderation/CmdUndoPlayer.cs b/MCGalaxy/Commands/Moderation/CmdUndoPlayer.cs index ff033ce6c..4757f6b1d 100644 --- a/MCGalaxy/Commands/Moderation/CmdUndoPlayer.cs +++ b/MCGalaxy/Commands/Moderation/CmdUndoPlayer.cs @@ -108,7 +108,7 @@ namespace MCGalaxy.Commands.Moderation { names[i] = PlayerInfo.FindOfflineNameMatches(p, parts[i]); if (names[i] == null) return null; - Group grp = Group.GroupIn(names[i]); + Group grp = PlayerInfo.GetGroup(names[i]); bool canUndo = p == null || grp.Permission < p.Rank || p.name.CaselessEq(names[i]); if (!canUndo) { MessageTooHighRank(p, "undo", false); return null; diff --git a/MCGalaxy/Commands/building/CmdBrush.cs b/MCGalaxy/Commands/building/CmdBrush.cs index b9d36064b..dceb9a374 100644 --- a/MCGalaxy/Commands/building/CmdBrush.cs +++ b/MCGalaxy/Commands/building/CmdBrush.cs @@ -37,10 +37,10 @@ namespace MCGalaxy.Commands.Building { BrushFactory brush = BrushFactory.Find(args[0]); if (args[0].CaselessEq("list")) { - Player.Message(p, "%HAvailable brushes: %S" + BrushFactory.Available); + List(p); } else if (brush == null) { Player.Message(p, "No brush found with name \"{0}\".", args[0]); - Player.Message(p, "Available brushes: " + BrushFactory.Available); + List(p); } else { Player.Message(p, "Set your brush to: " + brush.Name); p.BrushName = brush.Name; @@ -48,21 +48,25 @@ namespace MCGalaxy.Commands.Building { } } + internal static void List(Player p) { + Player.Message(p, "%HAvailable brushes: &f" + BrushFactory.Brushes.Join(b => b.Name)); + } + public override void Help(Player p) { Player.Message(p, "%T/Brush [name] "); Player.Message(p, "%HSets your current brush to the brush with that name."); Player.Message(p, "%T/Help Brush [name]"); Player.Message(p, "%HOutputs the help for the brush with that name."); - Player.Message(p, "%HAvailable brushes: %S" + BrushFactory.Available); + List(p); Player.Message(p, "%H- If \"skip\" is used for a block name, " + "existing blocks in the map will not be replaced by this block."); } - + public override void Help(Player p, string message) { BrushFactory brush = BrushFactory.Find(message); if (brush == null) { Player.Message(p, "No brush found with name \"{0}\".", message); - Player.Message(p, "%HAvailable brushes: %S" + BrushFactory.Available); + List(p); } else { Player.MessageLines(p, brush.Help); } diff --git a/MCGalaxy/Commands/building/CmdReplaceBrush.cs b/MCGalaxy/Commands/building/CmdReplaceBrush.cs index 962c394c2..d76812d20 100644 --- a/MCGalaxy/Commands/building/CmdReplaceBrush.cs +++ b/MCGalaxy/Commands/building/CmdReplaceBrush.cs @@ -45,7 +45,7 @@ namespace MCGalaxy.Commands.Building { BrushFactory factory = BrushFactory.Find(args[1]); if (factory == null) { Player.Message(p, "No brush found with name \"{0}\".", args[1]); - Player.Message(p, "Available brushes: " + BrushFactory.Available); + CmdBrush.List(p); return null; } diff --git a/MCGalaxy/Commands/building/CmdTransform.cs b/MCGalaxy/Commands/building/CmdTransform.cs index d561d5167..3de6463d1 100644 --- a/MCGalaxy/Commands/building/CmdTransform.cs +++ b/MCGalaxy/Commands/building/CmdTransform.cs @@ -37,10 +37,10 @@ namespace MCGalaxy.Commands.Building { TransformFactory transform = TransformFactory.Find(args[0]); if (args[0].CaselessEq("list")) { - Player.Message(p, "%HAvailable transforms: %S" + TransformFactory.Available); + List(p); } else if (transform == null) { Player.Message(p, "No transform found with name \"{0}\".", args[0]); - Player.Message(p, "Available transforms: " + TransformFactory.Available); + List(p); } else { Player.Message(p, "Set your transform to: " + transform.Name); Transform instance = transform.Construct(p, args.Length == 1 ? "" : args[1]); @@ -49,19 +49,23 @@ namespace MCGalaxy.Commands.Building { } } + static void List(Player p) { + Player.Message(p, "%HAvailable transforms: &f" + TransformFactory.Transforms.Join(t => t.Name)); + } + public override void Help(Player p) { Player.Message(p, "%T/Transform [name] "); Player.Message(p, "%HSets your current transform to the transform with that name."); Player.Message(p, "%T/Help Transform [name]"); Player.Message(p, "%HOutputs the help for the transform with that name."); - Player.Message(p, "%HAvailable transforms: %S" + TransformFactory.Available); + List(p); } public override void Help(Player p, string message) { TransformFactory transform = TransformFactory.Find(message); if (transform == null) { Player.Message(p, "No transform found with name \"{0}\".", message); - Player.Message(p, "%HAvailable transforms: %S" + TransformFactory.Available); + List(p); } else { Player.MessageLines(p, transform.Help); } diff --git a/MCGalaxy/CorePlugin/ChatHandler.cs b/MCGalaxy/CorePlugin/ChatHandler.cs index 526677040..7259be7cc 100644 --- a/MCGalaxy/CorePlugin/ChatHandler.cs +++ b/MCGalaxy/CorePlugin/ChatHandler.cs @@ -22,7 +22,7 @@ namespace MCGalaxy.Core { internal static class ChatHandler { - internal static void HandleOnChat(ChatScope scope, Player source, ref string msg, + internal static void HandleOnChat(ChatScope scope, Player source, string msg, object arg, ref ChatMessageFilter filter, bool irc) { msg = msg.Replace("λFULL", source.name).Replace("λNICK", source.name); LogType logType = LogType.PlayerChat; diff --git a/MCGalaxy/CorePlugin/ModActionHandler.cs b/MCGalaxy/CorePlugin/ModActionHandler.cs index 3118b1180..e4ef539b9 100644 --- a/MCGalaxy/CorePlugin/ModActionHandler.cs +++ b/MCGalaxy/CorePlugin/ModActionHandler.cs @@ -146,7 +146,7 @@ namespace MCGalaxy.Core { static void LogIPAction(ModAction e, string type) { LevelPermission perm = CommandExtraPerms.MinPerm("WhoIs"); Chat.Message(ChatScope.BelowRank, e.FormatMessage("An IP", type), perm, null, true); - Chat.Message(ChatScope.AboveEqRank, e.FormatMessage(e.TargetName, type), perm, null, true); + Chat.Message(ChatScope.AboveEqRank, e.FormatMessage("An IP", type), perm, null, true); } static void DoBanIP(ModAction e) { diff --git a/MCGalaxy/Database/PlayerData.cs b/MCGalaxy/Database/PlayerData.cs index 001f0e9db..26fbd6343 100644 --- a/MCGalaxy/Database/PlayerData.cs +++ b/MCGalaxy/Database/PlayerData.cs @@ -88,7 +88,7 @@ namespace MCGalaxy.DB { p.TotalDeleted = data.TotalDeleted; p.TimesDied = data.Deaths; - p.TotalMessagesSent = data.Messages; + p.TotalMessagesSent = data.Messages; p.money = data.Money; p.TimesBeenKicked = data.Kicks; } diff --git a/MCGalaxy/Database/Stats/OfflineStat.cs b/MCGalaxy/Database/Stats/OfflineStat.cs index 6da98e351..8bdb58bdd 100644 --- a/MCGalaxy/Database/Stats/OfflineStat.cs +++ b/MCGalaxy/Database/Stats/OfflineStat.cs @@ -44,7 +44,7 @@ namespace MCGalaxy.DB { string color = data.Color.Length == 0 ? group.Color : data.Color; string prefix = data.Title.Length == 0 ? "" : color + "[" + data.TitleColor + data.Title + color + "] "; string fullName = prefix + color + data.Name.RemoveLastPlus(); - OnlineStat.CoreLine(p, fullName, data.Name, group); + OnlineStat.CoreLine(p, fullName, data.Name, group, data.Messages); } static void BlocksModifiedLine(Player p, PlayerData who) { diff --git a/MCGalaxy/Database/Stats/OnlineStat.cs b/MCGalaxy/Database/Stats/OnlineStat.cs index 401eb4594..ff839e85c 100644 --- a/MCGalaxy/Database/Stats/OnlineStat.cs +++ b/MCGalaxy/Database/Stats/OnlineStat.cs @@ -46,12 +46,12 @@ namespace MCGalaxy.DB { static void OnlineCoreLine(Player p, Player who) { string prefix = who.title.Length == 0 ? "" : who.color + "[" + who.titlecolor + who.title + who.color + "] "; string fullName = prefix + who.ColoredName; - CoreLine(p, fullName, who.name, who.group); + CoreLine(p, fullName, who.name, who.group, who.TotalMessagesSent); } - internal static void CoreLine(Player p, string fullName, string name, Group grp) { - Player.Message(p, fullName + " %S(" + name + ") has:"); - Player.Message(p, " Rank of " + grp.ColoredName); + internal static void CoreLine(Player p, string fullName, string name, Group grp, int messages) { + Player.Message(p, "{0} %S({1}) has:", fullName, name); + Player.Message(p, " Rank of {0}%S, wrote &a{1} %Smessages", grp.ColoredName, messages); } internal static void MiscLine(Player p, string name, int deaths, int money) { diff --git a/MCGalaxy/Drawing/BrushFactories/BrushFactory.cs b/MCGalaxy/Drawing/BrushFactories/BrushFactory.cs index ee0672995..8466572f9 100644 --- a/MCGalaxy/Drawing/BrushFactories/BrushFactory.cs +++ b/MCGalaxy/Drawing/BrushFactories/BrushFactory.cs @@ -41,8 +41,6 @@ namespace MCGalaxy.Drawing.Brushes { new RandomBrushFactory(), new CloudyBrushFactory(), }; - public static string Available { get { return Brushes.Join(b => b.Name); } } - public static BrushFactory Find(string name) { foreach (BrushFactory entry in Brushes) { if (entry.Name.CaselessEq(name)) return entry; diff --git a/MCGalaxy/Drawing/TransformFactories/TransformFactory.cs b/MCGalaxy/Drawing/TransformFactories/TransformFactory.cs index a8bb83bb4..1c07ee11c 100644 --- a/MCGalaxy/Drawing/TransformFactories/TransformFactory.cs +++ b/MCGalaxy/Drawing/TransformFactories/TransformFactory.cs @@ -1,50 +1,48 @@ -/* - 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 MCGalaxy.Commands; -using MCGalaxy.Drawing.Ops; - -namespace MCGalaxy.Drawing.Transforms { - public abstract class TransformFactory { - - /// Human friendly name of this transform. - public abstract string Name { get; } - - /// Description of the transform, in addition to its syntax. - public abstract string[] Help { get; } - - /// Creates a transform from the given arguments, - /// returning null if invalid arguments are specified. - public abstract Transform Construct(Player p, string message); - - public static List Transforms = new List() { - new NoTransformFactory(), new ScaleTransformFactory(), - new RotateTransformFactory(), - }; - - public static string Available { get { return Transforms.Join(b => b.Name); } } - - public static TransformFactory Find(string name) { - foreach (TransformFactory entry in Transforms) { - if (entry.Name.CaselessEq(name)) return entry; - } - return null; - } - } -} +/* + 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 MCGalaxy.Commands; +using MCGalaxy.Drawing.Ops; + +namespace MCGalaxy.Drawing.Transforms { + public abstract class TransformFactory { + + /// Human friendly name of this transform. + public abstract string Name { get; } + + /// Description of the transform, in addition to its syntax. + public abstract string[] Help { get; } + + /// Creates a transform from the given arguments, + /// returning null if invalid arguments are specified. + public abstract Transform Construct(Player p, string message); + + public static List Transforms = new List() { + new NoTransformFactory(), new ScaleTransformFactory(), + new RotateTransformFactory(), + }; + + public static TransformFactory Find(string name) { + foreach (TransformFactory entry in Transforms) { + if (entry.Name.CaselessEq(name)) return entry; + } + return null; + } + } +} diff --git a/MCGalaxy/Events/ModActionEvent.cs b/MCGalaxy/Events/ModActionEvent.cs index cd07c369a..fc8662959 100644 --- a/MCGalaxy/Events/ModActionEvent.cs +++ b/MCGalaxy/Events/ModActionEvent.cs @@ -35,8 +35,7 @@ namespace MCGalaxy.Events { public Group TargetGroup { get { if (targetGroup != null) return targetGroup; - Player who = PlayerInfo.FindExact(Target); - targetGroup = who != null ? who.group : Group.GroupIn(Target); + targetGroup = PlayerInfo.GetGroup(Target); return targetGroup; } } diff --git a/MCGalaxy/Events/ServerEvents.cs b/MCGalaxy/Events/ServerEvents.cs index e17d63c30..2f45217b2 100644 --- a/MCGalaxy/Events/ServerEvents.cs +++ b/MCGalaxy/Events/ServerEvents.cs @@ -43,43 +43,43 @@ namespace MCGalaxy.Events.ServerEvents { } } - public delegate void OnChatSys(ChatScope scope, ref string msg, object arg, + public delegate void OnChatSys(ChatScope scope, string msg, object arg, ref ChatMessageFilter filter, bool irc); public sealed class OnChatSysEvent : IEvent { - public static void Call(ChatScope scope, ref string msg, object arg, + public static void Call(ChatScope scope, string msg, object arg, ref ChatMessageFilter filter, bool irc) { IEvent[] items = handlers.Items; for (int i = 0; i < items.Length; i++) { - try { items[i].method(scope, ref msg, arg, ref filter, irc); } + try { items[i].method(scope, msg, arg, ref filter, irc); } catch (Exception ex) { LogHandlerException(ex, items[i]); } } } } - public delegate void OnChatFrom(ChatScope scope, Player source, ref string msg, + public delegate void OnChatFrom(ChatScope scope, Player source, string msg, object arg, ref ChatMessageFilter filter, bool irc); public sealed class OnChatFromEvent : IEvent { - public static void Call(ChatScope scope,Player source, ref string msg, + public static void Call(ChatScope scope,Player source, string msg, object arg, ref ChatMessageFilter filter, bool irc) { IEvent[] items = handlers.Items; for (int i = 0; i < items.Length; i++) { - try { items[i].method(scope, source, ref msg, arg, ref filter, irc); } + try { items[i].method(scope, source, msg, arg, ref filter, irc); } catch (Exception ex) { LogHandlerException(ex, items[i]); } } } } - public delegate void OnChat(ChatScope scope, Player source, ref string msg, + public delegate void OnChat(ChatScope scope, Player source, string msg, object arg, ref ChatMessageFilter filter, bool irc); public sealed class OnChatEvent : IEvent { - public static void Call(ChatScope scope, Player source, ref string msg, + public static void Call(ChatScope scope, Player source, string msg, object arg, ref ChatMessageFilter filter, bool irc) { IEvent[] items = handlers.Items; for (int i = 0; i < items.Length; i++) { - try { items[i].method(scope, source, ref msg, arg, ref filter, irc); } + try { items[i].method(scope, source, msg, arg, ref filter, irc); } catch (Exception ex) { LogHandlerException(ex, items[i]); } } } diff --git a/MCGalaxy/Network/IRCPlugin/IRCBot.cs b/MCGalaxy/Network/IRCPlugin/IRCBot.cs index 030da8d94..1ad45c7d4 100644 --- a/MCGalaxy/Network/IRCPlugin/IRCBot.cs +++ b/MCGalaxy/Network/IRCPlugin/IRCBot.cs @@ -50,11 +50,9 @@ namespace MCGalaxy { /// Sends an IRC message to either the normal or operator IRC channel. - public void Say(string message, bool opchat = false) { + public void Say(string message, bool opchat) { string[] chans = opchat ? opchannels : channels; - foreach (string chan in chans) { - Message(chan, message); - } + foreach (string chan in chans) { Message(chan, message); } } /// Sends an IRC private message to the given user. diff --git a/MCGalaxy/Network/IRCPlugin/IRCHandlers.cs b/MCGalaxy/Network/IRCPlugin/IRCHandlers.cs index 9931bd1fa..3cf8920dc 100644 --- a/MCGalaxy/Network/IRCPlugin/IRCHandlers.cs +++ b/MCGalaxy/Network/IRCPlugin/IRCHandlers.cs @@ -19,6 +19,7 @@ using System; using System.Collections.Generic; using MCGalaxy.Commands; using MCGalaxy.Events; +using MCGalaxy.Events.GroupEvents; using MCGalaxy.Events.PlayerEvents; using MCGalaxy.Events.ServerEvents; using MCGalaxy.DB; @@ -30,7 +31,12 @@ namespace MCGalaxy.Network { public sealed class IRCHandlers { readonly IRCBot bot; - public IRCHandlers(IRCBot bot) { this.bot = bot; } + readonly Player ircGuest = new Player("IRC"); + + public IRCHandlers(IRCBot bot) { + this.bot = bot; + ircGuest.group = Group.GuestRank; + } volatile bool hookedEvents = false; Dictionary> userMap = new Dictionary>(); @@ -52,6 +58,7 @@ namespace MCGalaxy.Network { OnPlayerActionEvent.Register(HandlePlayerAction, Priority.Low); OnShuttingDownEvent.Register(HandleShutdown, Priority.Low); + OnGroupLoadEvent.Register(HandleGroupLoad, Priority.Low); OnChatEvent.Register(HandleChat, Priority.Low); OnChatSysEvent.Register(HandleChatSys, Priority.Low); @@ -83,6 +90,7 @@ namespace MCGalaxy.Network { OnPlayerActionEvent.Unregister(HandlePlayerAction); OnShuttingDownEvent.Unregister(HandleShutdown); + OnGroupLoadEvent.Unregister(HandleGroupLoad); OnChatEvent.Unregister(HandleChat); OnChatSysEvent.Unregister(HandleChatSys); @@ -107,40 +115,45 @@ namespace MCGalaxy.Network { } + string Unescape(Player p, string msg) { + string full = ServerConfig.IRCShowPlayerTitles ? p.FullName : p.group.Prefix + p.ColoredName; + return msg.Replace("λFULL", full).Replace("λNICK", p.ColoredName); + } + void HandlePlayerAction(Player p, PlayerAction action, string message, bool stealth) { if (!p.level.SeesServerWideChat || action != PlayerAction.Me) return; bot.Say("*" + p.DisplayName + " " + message, stealth); } + + bool ToPublicChannel(ChatScope scope, object arg, ChatMessageFilter filter) { + return Chat.scopeFilters[(int)scope](ircGuest, arg) + && (filter == null || filter(ircGuest, arg)); + } - void HandleChatSys(ChatScope scope, ref string msg, object arg, + void HandleChatSys(ChatScope scope, string msg, object arg, ref ChatMessageFilter filter, bool irc) { if (!irc) return; - // TODO: Check filter - bot.Say(msg); + bot.Say(msg, !ToPublicChannel(scope, arg, filter)); } - void HandleChatFrom(ChatScope scope, Player source, ref string msg, + void HandleChatFrom(ChatScope scope, Player source, string msg, object arg, ref ChatMessageFilter filter, bool irc) { if (!irc) return; - // TODO: Check filter - string full = ServerConfig.IRCShowPlayerTitles ? source.FullName : source.group.Prefix + source.ColoredName; - msg = msg.Replace("λFULL", full).Replace("λNICK", source.ColoredName); - bot.Say(msg); + bot.Say(Unescape(source, msg), !ToPublicChannel(scope, arg, filter)); } - void HandleChat(ChatScope scope, Player source, ref string msg, + void HandleChat(ChatScope scope, Player source, string msg, object arg, ref ChatMessageFilter filter, bool irc) { if (!irc) return; - // TODO: Check filter - string full = ServerConfig.IRCShowPlayerTitles ? source.FullName : source.group.Prefix + source.ColoredName; - msg = msg.Replace("λFULL", full).Replace("λNICK", source.ColoredName); - bot.Say(msg); + bot.Say(Unescape(source, msg), !ToPublicChannel(scope, arg, filter)); } void HandleShutdown(bool restarting, string message) { bot.Disconnect(restarting ? "Server is restarting." : "Server is shutting down."); } + void HandleGroupLoad() { ircGuest.group = Group.GuestRank; } + void Listener_OnAction(UserInfo user, string channel, string description) { MessageInGame(user.Nick, string.Format("%I(IRC) * {0} {1}", user.Nick, description)); diff --git a/MCGalaxy/Player/PlayerInfo.cs b/MCGalaxy/Player/PlayerInfo.cs index 64bc2e1dc..73011d6ce 100644 --- a/MCGalaxy/Player/PlayerInfo.cs +++ b/MCGalaxy/Player/PlayerInfo.cs @@ -26,14 +26,16 @@ namespace MCGalaxy { /// Note this field is highly volatile, you should cache references to the items array. public static VolatileArray Online = new VolatileArray(true); - public static Group GetGroup(string name) { return Group.GroupIn(name); } - - public static string GetColor(string name) { return GetGroup(name).Color; } + public static Group GetGroup(string name) { + Player target = FindExact(name); + return target != null ? target.group : Group.GroupIn(name); + } public static string GetColoredName(Player p, string name) { Player target = FindExact(name); - return target != null && Entities.CanSee(p, target) ? - target.ColoredName : GetColor(name) + name.RemoveLastPlus(); // TODO: select color from database? + // TODO: select color from database? + return target != null && Entities.CanSee(p, target) ? target.ColoredName + : Group.GroupIn(name).Color + name.RemoveLastPlus(); } public static int NonHiddenCount() {