mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-25 06:04:46 -04:00
Now messages appropriately go to IRC opchannel, some other minor code cleanup
This commit is contained in:
parent
8c6a18a096
commit
52d882cbc3
@ -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)
|
||||
|
@ -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) {
|
||||
|
@ -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) {
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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.");
|
||||
|
@ -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++;
|
||||
}
|
||||
|
@ -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 ?
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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] <default brush args>");
|
||||
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);
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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] <transform args>");
|
||||
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);
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
|
@ -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 {
|
||||
|
||||
/// <summary> Human friendly name of this transform. </summary>
|
||||
public abstract string Name { get; }
|
||||
|
||||
/// <summary> Description of the transform, in addition to its syntax. </summary>
|
||||
public abstract string[] Help { get; }
|
||||
|
||||
/// <summary> Creates a transform from the given arguments,
|
||||
/// returning null if invalid arguments are specified. </summary>
|
||||
public abstract Transform Construct(Player p, string message);
|
||||
|
||||
public static List<TransformFactory> Transforms = new List<TransformFactory>() {
|
||||
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 {
|
||||
|
||||
/// <summary> Human friendly name of this transform. </summary>
|
||||
public abstract string Name { get; }
|
||||
|
||||
/// <summary> Description of the transform, in addition to its syntax. </summary>
|
||||
public abstract string[] Help { get; }
|
||||
|
||||
/// <summary> Creates a transform from the given arguments,
|
||||
/// returning null if invalid arguments are specified. </summary>
|
||||
public abstract Transform Construct(Player p, string message);
|
||||
|
||||
public static List<TransformFactory> Transforms = new List<TransformFactory>() {
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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<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) {
|
||||
IEvent<OnChatSys>[] 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<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) {
|
||||
IEvent<OnChatFrom>[] 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<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) {
|
||||
IEvent<OnChat>[] 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]); }
|
||||
}
|
||||
}
|
||||
|
@ -50,11 +50,9 @@ namespace MCGalaxy {
|
||||
|
||||
|
||||
/// <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;
|
||||
foreach (string chan in chans) {
|
||||
Message(chan, message);
|
||||
}
|
||||
foreach (string chan in chans) { Message(chan, message); }
|
||||
}
|
||||
|
||||
/// <summary> Sends an IRC private message to the given user. </summary>
|
||||
|
@ -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<string, List<string>> userMap = new Dictionary<string, List<string>>();
|
||||
@ -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));
|
||||
|
@ -26,14 +26,16 @@ namespace MCGalaxy {
|
||||
/// <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 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() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user