mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-22 12:05:51 -04:00
For OnChatEvent etc events, pass message by ref to allow plugins to alter the message if they really want to
This commit is contained in:
parent
ffab090303
commit
be7765797c
@ -124,8 +124,9 @@ 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, msg, arg, ref filter, relay);
|
OnChatSysEvent.Call(scope, ref msg, arg, ref filter, relay);
|
||||||
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;
|
||||||
pl.Message(msg);
|
pl.Message(msg);
|
||||||
@ -160,8 +161,9 @@ namespace MCGalaxy {
|
|||||||
Player[] players = PlayerInfo.Online.Items;
|
Player[] players = PlayerInfo.Online.Items;
|
||||||
ChatMessageFilter scopeFilter = scopeFilters[(int)scope];
|
ChatMessageFilter scopeFilter = scopeFilters[(int)scope];
|
||||||
|
|
||||||
OnChatFromEvent.Call(scope, source, msg, arg, ref filter, relay);
|
OnChatFromEvent.Call(scope, source, ref msg, arg, ref filter, relay);
|
||||||
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;
|
||||||
|
|
||||||
@ -195,8 +197,9 @@ namespace MCGalaxy {
|
|||||||
// Filter out bad words
|
// Filter out bad words
|
||||||
if (Server.Config.ProfanityFiltering) msg = ProfanityFilter.Parse(msg);
|
if (Server.Config.ProfanityFiltering) msg = ProfanityFilter.Parse(msg);
|
||||||
|
|
||||||
OnChatEvent.Call(scope, source, msg, arg, ref filter, relay);
|
OnChatEvent.Call(scope, source, ref msg, arg, ref filter, relay);
|
||||||
foreach (Player pl in players) {
|
foreach (Player pl in players)
|
||||||
|
{
|
||||||
if (Ignoring(pl, source)) continue;
|
if (Ignoring(pl, source)) continue;
|
||||||
// Always show message to self too (unless ignoring self)
|
// Always show message to self too (unless ignoring self)
|
||||||
|
|
||||||
|
@ -43,7 +43,6 @@ namespace MCGalaxy.Commands.Moderation
|
|||||||
BlockID block;
|
BlockID block;
|
||||||
if (!CommandParser.GetBlockIfAllowed(p, args[0], "change permissions of", out block)) return;
|
if (!CommandParser.GetBlockIfAllowed(p, args[0], "change permissions of", out block)) return;
|
||||||
|
|
||||||
// TODO avoid showing message twice
|
|
||||||
if (canPlace) {
|
if (canPlace) {
|
||||||
BlockPerms perms = BlockPerms.GetPlace(block);
|
BlockPerms perms = BlockPerms.GetPlace(block);
|
||||||
placeMsg = SetPerms(p, args, data, perms, "block", "use", "usable");
|
placeMsg = SetPerms(p, args, data, perms, "block", "use", "usable");
|
||||||
|
@ -22,7 +22,7 @@ namespace MCGalaxy.Core {
|
|||||||
|
|
||||||
internal static class ChatHandler {
|
internal static class ChatHandler {
|
||||||
|
|
||||||
internal static void HandleOnChat(ChatScope scope, Player source, string msg,
|
internal static void HandleOnChat(ChatScope scope, Player source, ref 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;
|
||||||
|
@ -29,7 +29,8 @@ namespace MCGalaxy.Events.ServerEvents
|
|||||||
public static void Call(Heartbeat service, ref string name) {
|
public static void Call(Heartbeat service, ref string name) {
|
||||||
IEvent<OnSendingHeartbeat>[] items = handlers.Items;
|
IEvent<OnSendingHeartbeat>[] items = handlers.Items;
|
||||||
// Can't use CallCommon because we need to pass arguments by ref
|
// Can't use CallCommon because we need to pass arguments by ref
|
||||||
for (int i = 0; i < items.Length; i++) {
|
for (int i = 0; i < items.Length; i++)
|
||||||
|
{
|
||||||
try { items[i].method(service, ref name); }
|
try { items[i].method(service, ref name); }
|
||||||
catch (Exception ex) { LogHandlerException(ex, items[i]); }
|
catch (Exception ex) { LogHandlerException(ex, items[i]); }
|
||||||
}
|
}
|
||||||
@ -63,50 +64,54 @@ namespace MCGalaxy.Events.ServerEvents
|
|||||||
public static void Call(Socket s, ref bool cancel, ref bool announce) {
|
public static void Call(Socket s, ref bool cancel, ref bool announce) {
|
||||||
IEvent<OnConnectionReceived>[] items = handlers.Items;
|
IEvent<OnConnectionReceived>[] items = handlers.Items;
|
||||||
// Can't use CallCommon because we need to pass arguments by ref
|
// Can't use CallCommon because we need to pass arguments by ref
|
||||||
for (int i = 0; i < items.Length; i++) {
|
for (int i = 0; i < items.Length; i++)
|
||||||
|
{
|
||||||
try { items[i].method(s, ref cancel, ref announce); }
|
try { items[i].method(s, ref cancel, ref announce); }
|
||||||
catch (Exception ex) { LogHandlerException(ex, items[i]); }
|
catch (Exception ex) { LogHandlerException(ex, items[i]); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public delegate void OnChatSys(ChatScope scope, string msg, object arg,
|
public delegate void OnChatSys(ChatScope scope, ref string msg, object arg,
|
||||||
ref ChatMessageFilter filter, bool relay);
|
ref ChatMessageFilter filter, bool relay);
|
||||||
public sealed class OnChatSysEvent : IEvent<OnChatSys>
|
public sealed class OnChatSysEvent : IEvent<OnChatSys>
|
||||||
{
|
{
|
||||||
public static void Call(ChatScope scope, string msg, object arg,
|
public static void Call(ChatScope scope, ref string msg, object arg,
|
||||||
ref ChatMessageFilter filter, bool relay) {
|
ref ChatMessageFilter filter, bool relay) {
|
||||||
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, msg, arg, ref filter, relay); }
|
{
|
||||||
|
try { items[i].method(scope, ref msg, arg, ref filter, relay); }
|
||||||
catch (Exception ex) { LogHandlerException(ex, items[i]); }
|
catch (Exception ex) { LogHandlerException(ex, items[i]); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public delegate void OnChatFrom(ChatScope scope, Player source, string msg,
|
public delegate void OnChatFrom(ChatScope scope, Player source, ref string msg,
|
||||||
object arg, ref ChatMessageFilter filter, bool relay);
|
object arg, ref ChatMessageFilter filter, bool relay);
|
||||||
public sealed class OnChatFromEvent : IEvent<OnChatFrom>
|
public sealed class OnChatFromEvent : IEvent<OnChatFrom>
|
||||||
{
|
{
|
||||||
public static void Call(ChatScope scope,Player source, string msg,
|
public static void Call(ChatScope scope,Player source, ref string msg,
|
||||||
object arg, ref ChatMessageFilter filter, bool relay) {
|
object arg, ref ChatMessageFilter filter, bool relay) {
|
||||||
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, msg, arg, ref filter, relay); }
|
{
|
||||||
|
try { items[i].method(scope, source, ref msg, arg, ref filter, relay); }
|
||||||
catch (Exception ex) { LogHandlerException(ex, items[i]); }
|
catch (Exception ex) { LogHandlerException(ex, items[i]); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public delegate void OnChat(ChatScope scope, Player source, string msg,
|
public delegate void OnChat(ChatScope scope, Player source, ref string msg,
|
||||||
object arg, ref ChatMessageFilter filter, bool relay);
|
object arg, ref ChatMessageFilter filter, bool relay);
|
||||||
public sealed class OnChatEvent : IEvent<OnChat>
|
public sealed class OnChatEvent : IEvent<OnChat>
|
||||||
{
|
{
|
||||||
public static void Call(ChatScope scope, Player source, string msg,
|
public static void Call(ChatScope scope, Player source, ref string msg,
|
||||||
object arg, ref ChatMessageFilter filter, bool relay) {
|
object arg, ref ChatMessageFilter filter, bool relay) {
|
||||||
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, msg, arg, ref filter, relay); }
|
{
|
||||||
|
try { items[i].method(scope, source, ref msg, arg, ref filter, relay); }
|
||||||
catch (Exception ex) { LogHandlerException(ex, items[i]); }
|
catch (Exception ex) { LogHandlerException(ex, items[i]); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -321,7 +321,7 @@ namespace MCGalaxy.Modules.Relay
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnChatSys(ChatScope scope, string msg, object arg,
|
void OnChatSys(ChatScope scope, ref string msg, object arg,
|
||||||
ref ChatMessageFilter filter, bool relay) {
|
ref ChatMessageFilter filter, bool relay) {
|
||||||
if (!relay) return;
|
if (!relay) return;
|
||||||
|
|
||||||
@ -329,7 +329,7 @@ namespace MCGalaxy.Modules.Relay
|
|||||||
MessageToRelay(scope, msg, arg, filter);
|
MessageToRelay(scope, msg, arg, filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnChatFrom(ChatScope scope, Player source, string msg,
|
void OnChatFrom(ChatScope scope, Player source, ref string msg,
|
||||||
object arg, ref ChatMessageFilter filter, bool relay) {
|
object arg, ref ChatMessageFilter filter, bool relay) {
|
||||||
if (!relay) return;
|
if (!relay) return;
|
||||||
|
|
||||||
@ -337,7 +337,7 @@ namespace MCGalaxy.Modules.Relay
|
|||||||
MessageToRelay(scope, Unescape(source, msg), arg, filter);
|
MessageToRelay(scope, Unescape(source, msg), arg, filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnChat(ChatScope scope, Player source, string msg,
|
void OnChat(ChatScope scope, Player source, ref string msg,
|
||||||
object arg, ref ChatMessageFilter filter, bool relay) {
|
object arg, ref ChatMessageFilter filter, bool relay) {
|
||||||
if (!relay) return;
|
if (!relay) return;
|
||||||
|
|
||||||
|
@ -37,8 +37,8 @@ namespace MCGalaxy
|
|||||||
static SchedulerTask logTask;
|
static SchedulerTask logTask;
|
||||||
|
|
||||||
public static void Init() {
|
public static void Init() {
|
||||||
if (!Directory.Exists("logs")) Directory.CreateDirectory("logs");
|
Server.EnsureDirectoryExists("logs");
|
||||||
if (!Directory.Exists("logs/errors")) Directory.CreateDirectory("logs/errors");
|
Server.EnsureDirectoryExists("logs/errors");
|
||||||
UpdatePaths();
|
UpdatePaths();
|
||||||
Logger.LogHandler += LogMessage;
|
Logger.LogHandler += LogMessage;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user