Now messages appropriately go to IRC opchannel, some other minor code cleanup

This commit is contained in:
UnknownShadow200 2018-06-11 23:21:12 +10:00
parent 8c6a18a096
commit 52d882cbc3
26 changed files with 151 additions and 137 deletions

View File

@ -123,7 +123,7 @@ namespace MCGalaxy {
Player[] players = PlayerInfo.Online.Items; Player[] players = PlayerInfo.Online.Items;
ChatMessageFilter scopeFilter = scopeFilters[(int)scope]; 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) { foreach (Player pl in players) {
if (!scopeFilter(pl, arg)) continue; if (!scopeFilter(pl, arg)) continue;
if (filter != null && !filter(pl, arg)) continue; if (filter != null && !filter(pl, arg)) continue;
@ -157,7 +157,7 @@ namespace MCGalaxy {
ChatMessageFilter scopeFilter = scopeFilters[(int)scope]; ChatMessageFilter scopeFilter = scopeFilters[(int)scope];
if (source == null) source = ConsolePlayer.Instance; 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) { foreach (Player pl in players) {
if (!scopeFilter(pl, arg)) continue; if (!scopeFilter(pl, arg)) continue;
if (filter != null && !filter(pl, arg)) continue; if (filter != null && !filter(pl, arg)) continue;
@ -184,7 +184,7 @@ namespace MCGalaxy {
ChatMessageFilter scopeFilter = scopeFilters[(int)scope]; ChatMessageFilter scopeFilter = scopeFilters[(int)scope];
if (source == null) source = ConsolePlayer.Instance; 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) { foreach (Player pl in players) {
if (!NotIgnoring(pl, source)) continue; if (!NotIgnoring(pl, source)) continue;
// Always show message to self too (unless ignoring self) // Always show message to self too (unless ignoring self)

View File

@ -128,7 +128,7 @@ namespace MCGalaxy.Commands.Fun {
p.SetPrefix(); p.SetPrefix();
Team.Add(team); Team.Add(team);
Team.SaveList(); 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) { void HandleJoin(Player p, string[] args) {

View File

@ -39,7 +39,7 @@ namespace MCGalaxy.Commands.Info {
TopStat stat = FindTopStat(args[1]); TopStat stat = FindTopStat(args[1]);
if (stat == null) { 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) { if (args.Length > 2) {

View File

@ -50,8 +50,8 @@ namespace MCGalaxy.Commands.Info {
} }
public override void Help(Player p) { public override void Help(Player p) {
Player.Message(p, "/viewranks [rank] - Shows all players who have [rank]"); Player.Message(p, "%T/viewranks [rank] %H- Shows all players who have [rank]");
Player.Message(p, "/viewranks banned - Shows all players who are banned."); Player.Message(p, "%T/viewranks banned %H- Shows all players who are banned");
Player.Message(p, "Available ranks: " + Group.GroupList.Join(g => g.ColoredName)); Player.Message(p, "Available ranks: " + Group.GroupList.Join(g => g.ColoredName));
} }
} }

View File

@ -38,8 +38,7 @@ namespace MCGalaxy.Commands.Moderation {
reason = ModActionCmd.ExpandReason(p, reason); reason = ModActionCmd.ExpandReason(p, reason);
if (reason == null) return; if (reason == null) return;
Player who = PlayerInfo.FindExact(target); Group group = PlayerInfo.GetGroup(target);
Group group = who != null ? who.group : Group.GroupIn(target);
if (!CheckPerms(target, group, p)) return; if (!CheckPerms(target, group, p)) return;
ModAction action = new ModAction(target, p, ModActionType.Ban, reason); ModAction action = new ModAction(target, p, ModActionType.Ban, reason);

View File

@ -58,7 +58,7 @@ namespace MCGalaxy.Commands.Moderation {
if (accounts == null || accounts.Count == 0) return true; if (accounts == null || accounts.Count == 0) return true;
foreach (string name in accounts) { foreach (string name in accounts) {
Group grp = Group.GroupIn(name); Group grp = PlayerInfo.GetGroup(name);
if (grp == null || grp.Permission < p.Rank) continue; if (grp == null || grp.Permission < p.Rank) continue;
Player.Message(p, "You can only IP ban IPs used by players with a lower rank."); Player.Message(p, "You can only IP ban IPs used by players with a lower rank.");

View File

@ -95,7 +95,7 @@ namespace MCGalaxy.Commands.Moderation {
Player.Message(p, "&9Players in the review queue:"); Player.Message(p, "&9Players in the review queue:");
int pos = 1; int pos = 1;
foreach (string name in Server.reviewlist) { 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); Player.Message(p, "&a" + pos + ". &f" + name + "&a - Current Rank: " + grp.ColoredName);
pos++; pos++;
} }

View File

@ -34,43 +34,44 @@ namespace MCGalaxy.Commands.Moderation {
public override void Use(Player p, string message) { public override void Use(Player p, string message) {
string[] args = message.SplitSpaces(3); string[] args = message.SplitSpaces(3);
if (args.Length < 2) { Help(p); return; } if (args.Length < 2) { Help(p); return; }
string rankName = null, name = null; string rankName, target;
string reason = args.Length > 2 ? args[2] : null; string reason = args.Length > 2 ? args[2] : null;
if (args[0].CaselessEq("+up")) { if (args[0].CaselessEq("+up")) {
rankName = args[0]; 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")) { } else if (args[0].CaselessEq("-down")) {
rankName = args[0]; rankName = args[0];
name = ModActionCmd.FindName(p, "demote", "Demote", "", args[1], ref reason); target = ModActionCmd.FindName(p, "demote", "Demote", "", args[1], ref reason);
} else { } else {
rankName = args[1]; 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 (target == null) return;
if (p == who && who != null) { Player.Message(p, "Cannot change your own rank."); 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); Group newRank = TargetRank(p, rankName, curRank);
if (newRank == null) return; if (newRank == null) return;
if (curRank == newRank) { if (curRank == newRank) {
Player.Message(p, "{0} %Sis already ranked {1}", Player.Message(p, "{0} %Sis already ranked {1}",
PlayerInfo.GetColoredName(p, name), curRank.ColoredName); PlayerInfo.GetColoredName(p, target), curRank.ColoredName);
return; 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.targetGroup = curRank;
action.Metadata = newRank; action.Metadata = newRank;
OnModActionEvent.Call(action); OnModActionEvent.Call(action);
} }
internal static bool CanChangeRank(string name, Group curRank, Group newRank, 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; Group banned = Group.BannedRank;
if (reason == null) { if (reason == null) {
reason = newRank.Permission >= curRank.Permission ? reason = newRank.Permission >= curRank.Permission ?

View File

@ -34,9 +34,8 @@ namespace MCGalaxy.Commands.Moderation {
args.Length == 1 ? "" : " " + args[1], args.Length == 1 ? "" : " " + args[1],
args[0], ref reason); args[0], ref reason);
if (target == null) return; 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) { if (p != null && grp.Permission >= p.Rank) {
MessageTooHighRank(p, "temp ban", false); return; MessageTooHighRank(p, "temp ban", false); return;
} }

View File

@ -46,7 +46,6 @@ namespace MCGalaxy.Commands.Moderation {
static void Assign(Player p, string[] args) { static void Assign(Player p, string[] args) {
string target = PlayerInfo.FindMatchesPreferOnline(p, args[0]); string target = PlayerInfo.FindMatchesPreferOnline(p, args[0]);
if (target == null) return; if (target == null) return;
Player who = PlayerInfo.FindExact(target);
Group newRank = Matcher.FindRanks(p, args[1]); Group newRank = Matcher.FindRanks(p, args[1]);
if (newRank == null) return; if (newRank == null) return;
@ -57,12 +56,13 @@ namespace MCGalaxy.Commands.Moderation {
Player.Message(p, "&cThe player already has a temporary rank assigned!"); return; 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; 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"; 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); ModAction action = new ModAction(target, p, ModActionType.Rank, reason, duration);
action.targetGroup = curRank; action.targetGroup = curRank;
@ -79,14 +79,13 @@ namespace MCGalaxy.Commands.Moderation {
} }
string[] parts = line.SplitSpaces(); string[] parts = line.SplitSpaces();
Player who = PlayerInfo.FindExact(target); Group curRank = PlayerInfo.GetGroup(target);
Group curRank = who != null ? who.group : Group.GroupIn(target);
Group oldRank = Group.Find(parts[4 - 1]); // -1 because data, not whole line Group oldRank = Group.Find(parts[4 - 1]); // -1 because data, not whole line
if (oldRank == null) return; if (oldRank == null) return;
string reason = "temp rank unassigned"; 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); ModAction action = new ModAction(target, p, ModActionType.Rank, reason);
action.Metadata = oldRank; action.Metadata = oldRank;

View File

@ -108,7 +108,7 @@ namespace MCGalaxy.Commands.Moderation {
names[i] = PlayerInfo.FindOfflineNameMatches(p, parts[i]); names[i] = PlayerInfo.FindOfflineNameMatches(p, parts[i]);
if (names[i] == null) return null; 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]); bool canUndo = p == null || grp.Permission < p.Rank || p.name.CaselessEq(names[i]);
if (!canUndo) { if (!canUndo) {
MessageTooHighRank(p, "undo", false); return null; MessageTooHighRank(p, "undo", false); return null;

View File

@ -37,10 +37,10 @@ namespace MCGalaxy.Commands.Building {
BrushFactory brush = BrushFactory.Find(args[0]); BrushFactory brush = BrushFactory.Find(args[0]);
if (args[0].CaselessEq("list")) { if (args[0].CaselessEq("list")) {
Player.Message(p, "%HAvailable brushes: %S" + BrushFactory.Available); List(p);
} else if (brush == null) { } else if (brush == null) {
Player.Message(p, "No brush found with name \"{0}\".", args[0]); Player.Message(p, "No brush found with name \"{0}\".", args[0]);
Player.Message(p, "Available brushes: " + BrushFactory.Available); List(p);
} else { } else {
Player.Message(p, "Set your brush to: " + brush.Name); Player.Message(p, "Set your brush to: " + brush.Name);
p.BrushName = 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) { public override void Help(Player p) {
Player.Message(p, "%T/Brush [name] <default brush args>"); Player.Message(p, "%T/Brush [name] <default brush args>");
Player.Message(p, "%HSets your current brush to the brush with that name."); Player.Message(p, "%HSets your current brush to the brush with that name.");
Player.Message(p, "%T/Help Brush [name]"); Player.Message(p, "%T/Help Brush [name]");
Player.Message(p, "%HOutputs the help for the brush with that 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, " + Player.Message(p, "%H- If \"skip\" is used for a block name, " +
"existing blocks in the map will not be replaced by this block."); "existing blocks in the map will not be replaced by this block.");
} }
public override void Help(Player p, string message) { public override void Help(Player p, string message) {
BrushFactory brush = BrushFactory.Find(message); BrushFactory brush = BrushFactory.Find(message);
if (brush == null) { if (brush == null) {
Player.Message(p, "No brush found with name \"{0}\".", message); Player.Message(p, "No brush found with name \"{0}\".", message);
Player.Message(p, "%HAvailable brushes: %S" + BrushFactory.Available); List(p);
} else { } else {
Player.MessageLines(p, brush.Help); Player.MessageLines(p, brush.Help);
} }

View File

@ -45,7 +45,7 @@ namespace MCGalaxy.Commands.Building {
BrushFactory factory = BrushFactory.Find(args[1]); BrushFactory factory = BrushFactory.Find(args[1]);
if (factory == null) { if (factory == null) {
Player.Message(p, "No brush found with name \"{0}\".", args[1]); Player.Message(p, "No brush found with name \"{0}\".", args[1]);
Player.Message(p, "Available brushes: " + BrushFactory.Available); CmdBrush.List(p);
return null; return null;
} }

View File

@ -37,10 +37,10 @@ namespace MCGalaxy.Commands.Building {
TransformFactory transform = TransformFactory.Find(args[0]); TransformFactory transform = TransformFactory.Find(args[0]);
if (args[0].CaselessEq("list")) { if (args[0].CaselessEq("list")) {
Player.Message(p, "%HAvailable transforms: %S" + TransformFactory.Available); List(p);
} else if (transform == null) { } else if (transform == null) {
Player.Message(p, "No transform found with name \"{0}\".", args[0]); Player.Message(p, "No transform found with name \"{0}\".", args[0]);
Player.Message(p, "Available transforms: " + TransformFactory.Available); List(p);
} else { } else {
Player.Message(p, "Set your transform to: " + transform.Name); Player.Message(p, "Set your transform to: " + transform.Name);
Transform instance = transform.Construct(p, args.Length == 1 ? "" : args[1]); 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) { public override void Help(Player p) {
Player.Message(p, "%T/Transform [name] <transform args>"); Player.Message(p, "%T/Transform [name] <transform args>");
Player.Message(p, "%HSets your current transform to the transform with that name."); Player.Message(p, "%HSets your current transform to the transform with that name.");
Player.Message(p, "%T/Help Transform [name]"); Player.Message(p, "%T/Help Transform [name]");
Player.Message(p, "%HOutputs the help for the transform with that 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) { public override void Help(Player p, string message) {
TransformFactory transform = TransformFactory.Find(message); TransformFactory transform = TransformFactory.Find(message);
if (transform == null) { if (transform == null) {
Player.Message(p, "No transform found with name \"{0}\".", message); Player.Message(p, "No transform found with name \"{0}\".", message);
Player.Message(p, "%HAvailable transforms: %S" + TransformFactory.Available); List(p);
} else { } else {
Player.MessageLines(p, transform.Help); Player.MessageLines(p, transform.Help);
} }

View File

@ -22,7 +22,7 @@ namespace MCGalaxy.Core {
internal static class ChatHandler { 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) { object arg, ref ChatMessageFilter filter, bool irc) {
msg = msg.Replace("λFULL", source.name).Replace("λNICK", source.name); msg = msg.Replace("λFULL", source.name).Replace("λNICK", source.name);
LogType logType = LogType.PlayerChat; LogType logType = LogType.PlayerChat;

View File

@ -146,7 +146,7 @@ namespace MCGalaxy.Core {
static void LogIPAction(ModAction e, string type) { static void LogIPAction(ModAction e, string type) {
LevelPermission perm = CommandExtraPerms.MinPerm("WhoIs"); LevelPermission perm = CommandExtraPerms.MinPerm("WhoIs");
Chat.Message(ChatScope.BelowRank, e.FormatMessage("An IP", type), perm, null, true); 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) { static void DoBanIP(ModAction e) {

View File

@ -88,7 +88,7 @@ namespace MCGalaxy.DB {
p.TotalDeleted = data.TotalDeleted; p.TotalDeleted = data.TotalDeleted;
p.TimesDied = data.Deaths; p.TimesDied = data.Deaths;
p.TotalMessagesSent = data.Messages; p.TotalMessagesSent = data.Messages;
p.money = data.Money; p.money = data.Money;
p.TimesBeenKicked = data.Kicks; p.TimesBeenKicked = data.Kicks;
} }

View File

@ -44,7 +44,7 @@ namespace MCGalaxy.DB {
string color = data.Color.Length == 0 ? group.Color : data.Color; string color = data.Color.Length == 0 ? group.Color : data.Color;
string prefix = data.Title.Length == 0 ? "" : color + "[" + data.TitleColor + data.Title + color + "] "; string prefix = data.Title.Length == 0 ? "" : color + "[" + data.TitleColor + data.Title + color + "] ";
string fullName = prefix + color + data.Name.RemoveLastPlus(); 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) { static void BlocksModifiedLine(Player p, PlayerData who) {

View File

@ -46,12 +46,12 @@ namespace MCGalaxy.DB {
static void OnlineCoreLine(Player p, Player who) { static void OnlineCoreLine(Player p, Player who) {
string prefix = who.title.Length == 0 ? "" : who.color + "[" + who.titlecolor + who.title + who.color + "] "; string prefix = who.title.Length == 0 ? "" : who.color + "[" + who.titlecolor + who.title + who.color + "] ";
string fullName = prefix + who.ColoredName; 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) { internal static void CoreLine(Player p, string fullName, string name, Group grp, int messages) {
Player.Message(p, fullName + " %S(" + name + ") has:"); Player.Message(p, "{0} %S({1}) has:", fullName, name);
Player.Message(p, " Rank of " + grp.ColoredName); 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) { internal static void MiscLine(Player p, string name, int deaths, int money) {

View File

@ -41,8 +41,6 @@ namespace MCGalaxy.Drawing.Brushes {
new RandomBrushFactory(), new CloudyBrushFactory(), new RandomBrushFactory(), new CloudyBrushFactory(),
}; };
public static string Available { get { return Brushes.Join(b => b.Name); } }
public static BrushFactory Find(string name) { public static BrushFactory Find(string name) {
foreach (BrushFactory entry in Brushes) { foreach (BrushFactory entry in Brushes) {
if (entry.Name.CaselessEq(name)) return entry; if (entry.Name.CaselessEq(name)) return entry;

View File

@ -1,50 +1,48 @@
/* /*
Copyright 2015 MCGalaxy Copyright 2015 MCGalaxy
Dual-licensed under the Educational Community License, Version 2.0 and Dual-licensed under the Educational Community License, Version 2.0 and
the GNU General Public License, Version 3 (the "Licenses"); you may the GNU General Public License, Version 3 (the "Licenses"); you may
not use this file except in compliance with the Licenses. You may not use this file except in compliance with the Licenses. You may
obtain a copy of the Licenses at obtain a copy of the Licenses at
http://www.opensource.org/licenses/ecl2.php http://www.opensource.org/licenses/ecl2.php
http://www.gnu.org/licenses/gpl-3.0.html http://www.gnu.org/licenses/gpl-3.0.html
Unless required by applicable law or agreed to in writing, Unless required by applicable law or agreed to in writing,
software distributed under the Licenses are distributed on an "AS IS" software distributed under the Licenses are distributed on an "AS IS"
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
or implied. See the Licenses for the specific language governing or implied. See the Licenses for the specific language governing
permissions and limitations under the Licenses. permissions and limitations under the Licenses.
*/ */
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using MCGalaxy.Commands; using MCGalaxy.Commands;
using MCGalaxy.Drawing.Ops; using MCGalaxy.Drawing.Ops;
namespace MCGalaxy.Drawing.Transforms { namespace MCGalaxy.Drawing.Transforms {
public abstract class TransformFactory { public abstract class TransformFactory {
/// <summary> Human friendly name of this transform. </summary> /// <summary> Human friendly name of this transform. </summary>
public abstract string Name { get; } public abstract string Name { get; }
/// <summary> Description of the transform, in addition to its syntax. </summary> /// <summary> Description of the transform, in addition to its syntax. </summary>
public abstract string[] Help { get; } public abstract string[] Help { get; }
/// <summary> Creates a transform from the given arguments, /// <summary> Creates a transform from the given arguments,
/// returning null if invalid arguments are specified. </summary> /// returning null if invalid arguments are specified. </summary>
public abstract Transform Construct(Player p, string message); public abstract Transform Construct(Player p, string message);
public static List<TransformFactory> Transforms = new List<TransformFactory>() { public static List<TransformFactory> Transforms = new List<TransformFactory>() {
new NoTransformFactory(), new ScaleTransformFactory(), new NoTransformFactory(), new ScaleTransformFactory(),
new RotateTransformFactory(), new RotateTransformFactory(),
}; };
public static string Available { get { return Transforms.Join(b => b.Name); } } public static TransformFactory Find(string name) {
foreach (TransformFactory entry in Transforms) {
public static TransformFactory Find(string name) { if (entry.Name.CaselessEq(name)) return entry;
foreach (TransformFactory entry in Transforms) { }
if (entry.Name.CaselessEq(name)) return entry; return null;
} }
return null; }
} }
}
}

View File

@ -35,8 +35,7 @@ namespace MCGalaxy.Events {
public Group TargetGroup { public Group TargetGroup {
get { get {
if (targetGroup != null) return targetGroup; if (targetGroup != null) return targetGroup;
Player who = PlayerInfo.FindExact(Target); targetGroup = PlayerInfo.GetGroup(Target);
targetGroup = who != null ? who.group : Group.GroupIn(Target);
return targetGroup; return targetGroup;
} }
} }

View File

@ -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); ref ChatMessageFilter filter, bool irc);
public sealed class OnChatSysEvent : IEvent<OnChatSys> { public sealed class OnChatSysEvent : IEvent<OnChatSys> {
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) { ref ChatMessageFilter filter, bool irc) {
IEvent<OnChatSys>[] items = handlers.Items; IEvent<OnChatSys>[] items = handlers.Items;
for (int i = 0; i < items.Length; i++) { 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]); } 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); object arg, ref ChatMessageFilter filter, bool irc);
public sealed class OnChatFromEvent : IEvent<OnChatFrom> { public sealed class OnChatFromEvent : IEvent<OnChatFrom> {
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) { object arg, ref ChatMessageFilter filter, bool irc) {
IEvent<OnChatFrom>[] items = handlers.Items; IEvent<OnChatFrom>[] items = handlers.Items;
for (int i = 0; i < items.Length; i++) { 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]); } 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); object arg, ref ChatMessageFilter filter, bool irc);
public sealed class OnChatEvent : IEvent<OnChat> { public sealed class OnChatEvent : IEvent<OnChat> {
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) { object arg, ref ChatMessageFilter filter, bool irc) {
IEvent<OnChat>[] items = handlers.Items; IEvent<OnChat>[] items = handlers.Items;
for (int i = 0; i < items.Length; i++) { 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]); } catch (Exception ex) { LogHandlerException(ex, items[i]); }
} }
} }

View File

@ -50,11 +50,9 @@ namespace MCGalaxy {
/// <summary> Sends an IRC message to either the normal or operator IRC channel. </summary> /// <summary> Sends an IRC message to either the normal or operator IRC channel. </summary>
public void Say(string message, bool opchat = false) { public void Say(string message, bool opchat) {
string[] chans = opchat ? opchannels : channels; string[] chans = opchat ? opchannels : channels;
foreach (string chan in chans) { foreach (string chan in chans) { Message(chan, message); }
Message(chan, message);
}
} }
/// <summary> Sends an IRC private message to the given user. </summary> /// <summary> Sends an IRC private message to the given user. </summary>

View File

@ -19,6 +19,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using MCGalaxy.Commands; using MCGalaxy.Commands;
using MCGalaxy.Events; using MCGalaxy.Events;
using MCGalaxy.Events.GroupEvents;
using MCGalaxy.Events.PlayerEvents; using MCGalaxy.Events.PlayerEvents;
using MCGalaxy.Events.ServerEvents; using MCGalaxy.Events.ServerEvents;
using MCGalaxy.DB; using MCGalaxy.DB;
@ -30,7 +31,12 @@ namespace MCGalaxy.Network {
public sealed class IRCHandlers { public sealed class IRCHandlers {
readonly IRCBot bot; 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; volatile bool hookedEvents = false;
Dictionary<string, List<string>> userMap = new Dictionary<string, List<string>>(); Dictionary<string, List<string>> userMap = new Dictionary<string, List<string>>();
@ -52,6 +58,7 @@ namespace MCGalaxy.Network {
OnPlayerActionEvent.Register(HandlePlayerAction, Priority.Low); OnPlayerActionEvent.Register(HandlePlayerAction, Priority.Low);
OnShuttingDownEvent.Register(HandleShutdown, Priority.Low); OnShuttingDownEvent.Register(HandleShutdown, Priority.Low);
OnGroupLoadEvent.Register(HandleGroupLoad, Priority.Low);
OnChatEvent.Register(HandleChat, Priority.Low); OnChatEvent.Register(HandleChat, Priority.Low);
OnChatSysEvent.Register(HandleChatSys, Priority.Low); OnChatSysEvent.Register(HandleChatSys, Priority.Low);
@ -83,6 +90,7 @@ namespace MCGalaxy.Network {
OnPlayerActionEvent.Unregister(HandlePlayerAction); OnPlayerActionEvent.Unregister(HandlePlayerAction);
OnShuttingDownEvent.Unregister(HandleShutdown); OnShuttingDownEvent.Unregister(HandleShutdown);
OnGroupLoadEvent.Unregister(HandleGroupLoad);
OnChatEvent.Unregister(HandleChat); OnChatEvent.Unregister(HandleChat);
OnChatSysEvent.Unregister(HandleChatSys); 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) { void HandlePlayerAction(Player p, PlayerAction action, string message, bool stealth) {
if (!p.level.SeesServerWideChat || action != PlayerAction.Me) return; if (!p.level.SeesServerWideChat || action != PlayerAction.Me) return;
bot.Say("*" + p.DisplayName + " " + message, stealth); 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) { ref ChatMessageFilter filter, bool irc) {
if (!irc) return; if (!irc) return;
// TODO: Check filter bot.Say(msg, !ToPublicChannel(scope, arg, filter));
bot.Say(msg);
} }
void HandleChatFrom(ChatScope scope, Player source, ref string msg, void HandleChatFrom(ChatScope scope, Player source, string msg,
object arg, ref ChatMessageFilter filter, bool irc) { object arg, ref ChatMessageFilter filter, bool irc) {
if (!irc) return; if (!irc) return;
// TODO: Check filter bot.Say(Unescape(source, msg), !ToPublicChannel(scope, arg, filter));
string full = ServerConfig.IRCShowPlayerTitles ? source.FullName : source.group.Prefix + source.ColoredName;
msg = msg.Replace("λFULL", full).Replace("λNICK", source.ColoredName);
bot.Say(msg);
} }
void HandleChat(ChatScope scope, Player source, ref string msg, void HandleChat(ChatScope scope, Player source, string msg,
object arg, ref ChatMessageFilter filter, bool irc) { object arg, ref ChatMessageFilter filter, bool irc) {
if (!irc) return; if (!irc) return;
// TODO: Check filter bot.Say(Unescape(source, msg), !ToPublicChannel(scope, arg, filter));
string full = ServerConfig.IRCShowPlayerTitles ? source.FullName : source.group.Prefix + source.ColoredName;
msg = msg.Replace("λFULL", full).Replace("λNICK", source.ColoredName);
bot.Say(msg);
} }
void HandleShutdown(bool restarting, string message) { void HandleShutdown(bool restarting, string message) {
bot.Disconnect(restarting ? "Server is restarting." : "Server is shutting down."); 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) { void Listener_OnAction(UserInfo user, string channel, string description) {
MessageInGame(user.Nick, string.Format("%I(IRC) * {0} {1}", user.Nick, description)); MessageInGame(user.Nick, string.Format("%I(IRC) * {0} {1}", user.Nick, description));

View File

@ -26,14 +26,16 @@ namespace MCGalaxy {
/// <remarks> Note this field is highly volatile, you should cache references to the items array. </remarks> /// <remarks> Note this field is highly volatile, you should cache references to the items array. </remarks>
public static VolatileArray<Player> Online = new VolatileArray<Player>(true); public static VolatileArray<Player> Online = new VolatileArray<Player>(true);
public static Group GetGroup(string name) { return Group.GroupIn(name); } public static Group GetGroup(string name) {
Player target = FindExact(name);
public static string GetColor(string name) { return GetGroup(name).Color; } return target != null ? target.group : Group.GroupIn(name);
}
public static string GetColoredName(Player p, string name) { public static string GetColoredName(Player p, string name) {
Player target = FindExact(name); Player target = FindExact(name);
return target != null && Entities.CanSee(p, target) ? // TODO: select color from database?
target.ColoredName : GetColor(name) + name.RemoveLastPlus(); // TODO: select color from database? return target != null && Entities.CanSee(p, target) ? target.ColoredName
: Group.GroupIn(name).Color + name.RemoveLastPlus();
} }
public static int NonHiddenCount() { public static int NonHiddenCount() {