now messages show on IRC (still a bit broken though)

This commit is contained in:
UnknownShadow200 2018-06-11 15:43:08 +10:00
parent b5e327eded
commit 046b478a93
12 changed files with 102 additions and 102 deletions

View File

@ -106,10 +106,8 @@ namespace MCGalaxy {
public static void MessageAll(string msg) { Message(ChatScope.All, msg, null, null); }
public static void MessageGlobal(string msg) { Message(ChatScope.Global, msg, null, null); }
public static void MessageOps(string msg) { MessageAboveOrSameRank(OpchatPerm, msg); }
public static void MessageAboveOrSameRank(LevelPermission rank, string msg) {
Message(ChatScope.AboveEqRank, msg, rank, null);
public static void MessageOps(string msg) {
Message(ChatScope.AboveEqRank, msg, OpchatPerm, null);
}
public static void MessageGlobal(string message, object a0) {

View File

@ -33,9 +33,9 @@ namespace MCGalaxy.Commands.Chatting {
if (args[1] == "loving" || args[1] == "creepy" || args[1] == "friendly" || args[1] == "deadly")
hugType = args[1];
}
if (hugType == null) { TryMessageAction(p, args[0], "{0} %Shugged {1}", false); return; }
if (hugType == null) { TryMessageAction(p, args[0], "λNICK %Shugged λTARGET", false); return; }
TryMessageAction(p, args[0], "{0} %Sgave {1} %Sa " + hugType + " hug", false);
TryMessageAction(p, args[0], "λNICK %Sgave λTARGET %Sa " + hugType + " hug", false);
if (hugType == "deadly") {
if (!CheckExtraPerm(p, 1)) return;
Player target = PlayerInfo.FindMatches(p, args[0]);

View File

@ -19,26 +19,25 @@ namespace MCGalaxy.Commands.Chatting {
public abstract class MessageCmd : Command {
public override string type { get { return CommandTypes.Chat; } }
protected bool TryMessageAction(Player p, string name, string message, bool messageWho) {
protected bool TryMessageAction(Player p, string name, string msg, bool messageWho) {
if (name.Length == 0) { Help(p); return false; }
Player target = PlayerInfo.FindMatches(p, name);
if (target == null) return false;
string giver = (p == null) ? "(console)" : p.ColoredName;
string reciever = p == target ? "themselves" : target.ColoredName;
if (!TryMessage(p, string.Format(message, giver, reciever))) return false;
if (!TryMessage(p, msg.Replace("λTARGET", reciever))) return false;
if (messageWho && p != target && Chat.NotIgnoring(target, p)) {
Player.Message(target, string.Format(message, giver, "you"));
string giver = (p == null) ? "(console)" : p.ColoredName;
msg = msg.Replace("λNICK", giver);
Player.Message(target, msg.Replace("λTARGET", "you"));
}
return true;
}
protected bool TryMessage(Player p, string message) { return TryMessage(p, message, name); }
protected static bool TryMessage(Player p, string message, string cmd) {
if (!CanSpeak(p, cmd)) return false;
Chat.MessageFrom(p, message, null);
protected bool TryMessage(Player p, string msg) {
if (!CanSpeak(p, name)) return false;
Chat.MessageFrom(p, msg, null);
p.CheckForMessageSpam();
return true;
@ -61,7 +60,7 @@ namespace MCGalaxy.Commands.Chatting {
public override string name { get { return "High5"; } }
public override void Use(Player p, string message) {
TryMessageAction(p, message, "{0} %Sjust highfived {1}", true);
TryMessageAction(p, message, "λNICK %Sjust highfived λTARGET", true);
}
public override void Help(Player p) {

View File

@ -44,7 +44,7 @@ namespace MCGalaxy.Commands.Moderation {
perms.Allowed.Add(grp.Permission);
}
UpdatePermissions(block, p, " can now be used by " + grp.ColoredName);
UpdatePermissions(block, p, " %Scan now be used by " + grp.ColoredName);
} else if (args.Length == 2 && args[1][0] == '-') {
Group grp = GetGroup(p, args[1].Substring(1));
if (grp == null) return;
@ -60,14 +60,14 @@ namespace MCGalaxy.Commands.Moderation {
perms.Disallowed.Add(grp.Permission);
}
UpdatePermissions(block, p, " is no longer usable by " + grp.ColoredName);
UpdatePermissions(block, p, " %Sis no longer usable by " + grp.ColoredName);
} else if (args.Length == 2) {
Group grp = GetGroup(p, args[1]);
if (grp == null) return;
BlockPerms perms = BlockPerms.List[block];
perms.MinRank = grp.Permission;
UpdatePermissions(block, p, "'s permission was set to " + grp.ColoredName);
UpdatePermissions(block, p, "%S's permission was set to " + grp.ColoredName);
}
}
@ -89,7 +89,7 @@ namespace MCGalaxy.Commands.Moderation {
}
string name = Block.GetName(p, block);
Chat.MessageGlobal("&d{0}%S{1}", name, message);
Chat.MessageAll("&d" + name + message);
if (Player.IsSuper(p)) Player.Message(p, name + message);
}

View File

@ -45,7 +45,7 @@ namespace MCGalaxy.Commands.Moderation {
perms.Allowed.Add(grp.Permission);
}
UpdatePermissions(cmd, p, " can now be used by " + grp.ColoredName);
UpdatePermissions(cmd, p, " %Scan now be used by " + grp.ColoredName);
} else if (args.Length == 2 && args[1][0] == '-') {
Group grp = GetGroup(p, args[1].Substring(1));
if (grp == null) return;
@ -61,14 +61,14 @@ namespace MCGalaxy.Commands.Moderation {
perms.Disallowed.Add(grp.Permission);
}
UpdatePermissions(cmd, p, " is no longer usable by " + grp.ColoredName);
UpdatePermissions(cmd, p, " %Sis no longer usable by " + grp.ColoredName);
} else if (args.Length == 2) {
Group grp = GetGroup(p, args[1]);
if (grp == null) return;
CommandPerms perms = CommandPerms.Find(cmd.name);
perms.MinRank = grp.Permission;
UpdatePermissions(cmd, p, "'s permission was set to " + grp.ColoredName);
UpdatePermissions(cmd, p, "%S's permission was set to " + grp.ColoredName);
} else {
int otherPermIndex = 0;
if (!CommandParser.GetInt(p, args[2], "Extra permission number", ref otherPermIndex)) return;
@ -86,10 +86,8 @@ namespace MCGalaxy.Commands.Moderation {
perms.MinRank = grp.Permission;
CommandExtraPerms.Save();
string permName = "extra permission " + otherPermIndex;
Chat.MessageGlobal("&d{0}%S's {1} was set to {2}", cmd.name, permName, grp.ColoredName);
if (Player.IsSuper(p))
Player.Message(p, "{0}'s {1} was set to {2}", cmd.name, permName, grp.ColoredName);
string msg = "extra permission " + otherPermIndex;
Announce(p, cmd.name + "%S's " + msg + " was set to " + grp.ColoredName);
}
}
@ -103,13 +101,15 @@ namespace MCGalaxy.Commands.Moderation {
return grp;
}
static void UpdatePermissions(Command cmd, Player p, string message) {
static void UpdatePermissions(Command cmd, Player p, string msg) {
CommandPerms.Save();
CommandPerms.Load();
Announce(p, cmd.name + msg);
}
Chat.MessageGlobal("&d{0}%S{1}", cmd.name, message);
if (Player.IsSuper(p))
Player.Message(p, cmd.name + message);
static void Announce(Player p, string msg) {
Chat.MessageAll("&d" + msg);
if (Player.IsSuper(p)) Player.Message(p, msg);
}
public override void Help(Player p) {

View File

@ -166,8 +166,9 @@ namespace MCGalaxy.Commands.Moderation {
File.WriteAllLines("extra/reported/" + target + ".txt", reports.ToArray());
Player.Message(p, "&aReport sent! It should be viewed when a {0}&a+ is online", checkRankName);
string opsMsg = p.ColoredName + " %Smade a report, view it with %T/Report check " + target;
Chat.MessageAboveOrSameRank(checkRank, opsMsg);
string opsMsg = "λNICK %Smade a report, view it with %T/Report check " + target;
Chat.MessageFrom(ChatScope.AboveEqRank, p, opsMsg,
checkRank, null, true);
}
public override void Help(Player p) {

View File

@ -1,4 +1,4 @@
/*
/*
Written by BeMacized
Assisted by RedNoodle
@ -72,22 +72,18 @@ namespace MCGalaxy.Commands.Moderation {
}
Server.reviewlist.Add(p.name);
int pos = Server.reviewlist.IndexOf(p.name);
if (pos > 1) { Player.Message(p, "You entered the &creview %Squeue. You have &c" + pos + " %Speople in front of you in the queue"); }
if (pos == 1) { Player.Message(p, "You entered the &creview %Squeue. There is &c1 %Sperson in front of you in the queue"); }
if (pos == 0) { Player.Message(p, "You entered the &creview %Squeue. You are &cfirst %Sin line!"); }
int pos = Server.reviewlist.IndexOf(p.name) + 1;
Player.Message(p, "You entered the &creview %Squeue at &aposition #" + pos);
string msg = opsOn ?
"The Online staff have been notified. Someone should be with you shortly." :
"The online staff have been notified. Someone should be with you shortly." :
"There are currently no staff online. Staff will be notified when they join the server.";
Player.Message(p, msg);
string start = pos > 0 ? "There are now &c" + (pos + 1) + " %Speople" : "There is now &c1 %Sperson";
Chat.MessageAboveOrSameRank(nextPerm, p.ColoredName + " %Sis requesting a review!");
Chat.MessageAboveOrSameRank(nextPerm, start + " waiting for a &creview!");
Chat.MessageFrom(ChatScope.AboveEqRank, p,
"λNICK %Srequested a review! &c(Total " + pos + " waiting)", nextPerm, null, true);
p.NextReviewTime = DateTime.UtcNow.AddSeconds(ServerConfig.ReviewCooldown);
OnPlayerActionEvent.Call(p, PlayerAction.Review, null, true);
}
void HandleView(Player p) {
@ -109,17 +105,12 @@ namespace MCGalaxy.Commands.Moderation {
void HandleLeave(Player p) {
if (p == null) { Player.Message(p, "Console cannot leave the review queue."); return; }
bool inQueue = false;
foreach (string who in Server.reviewlist) {
inQueue |= who.CaselessEq(p.name);
}
if (!inQueue) {
Player.Message(p, "You aren't in the review queue so you cannot leave it."); return;
}
Server.reviewlist.Remove(p.name);
MessageReviewPosChanged();
if (Server.reviewlist.CaselessRemove(p.name)) {
AnnounceQueueChanged();
Player.Message(p, "You have left the review queue!");
} else {
Player.Message(p, "You weren't in the review queue to begin with.");
}
}
void HandleNext(Player p) {
@ -131,21 +122,17 @@ namespace MCGalaxy.Commands.Moderation {
string user = Server.reviewlist[0];
Player who = PlayerInfo.FindExact(user);
Server.reviewlist.RemoveAt(0);
if (who == null) {
Player.Message(p, "Player " + user + " doesn't exist or is offline, and was removed from the review queue");
Server.reviewlist.Remove(user);
return;
} else if (who == p) {
Player.Message(p, "Cannot teleport to yourself. You have been removed from the review queue.");
Server.reviewlist.Remove(user);
Player.Message(p, "Player " + user + " is offline, and was removed from the review queue");
return;
}
Server.reviewlist.Remove(user);
Command.Find("TP").Use(p, who.name);
Player.Message(p, "You have been teleported to " + user);
Player.Message(who, "Your review request has been answered by " + p.name + ".");
MessageReviewPosChanged();
Player.Message(who, "Your review request has been answered by " + p.ColoredName + ".");
AnnounceQueueChanged();
}
void HandleClear(Player p) {
@ -154,13 +141,14 @@ namespace MCGalaxy.Commands.Moderation {
Player.Message(p, "The review queue has been cleared");
}
static void MessageReviewPosChanged() {
int count = 0;
static void AnnounceQueueChanged() {
int pos = 1;
foreach (string name in Server.reviewlist) {
Player who = PlayerInfo.FindExact(name);
if (who == null) continue;
Player.Message(who, "The review queue has changed. You now have " + count + " players in front of you.");
count++;
Player.Message(who, "The review queue has changed. You are now at &aposition #" + pos);
pos++;
}
}

View File

@ -19,7 +19,7 @@ using System;
using BlockID = System.UInt16;
namespace MCGalaxy.Events.PlayerEvents {
public enum PlayerAction { Me, Review, Referee, UnReferee };
public enum PlayerAction { Me, Referee, UnReferee };
public delegate void OnPlayerChat(Player p, string message);
/// <summary> Called whenever a player chats on the server. </summary>

View File

@ -50,10 +50,13 @@ namespace MCGalaxy.Network {
if (hookedEvents) return;
hookedEvents = true;
OnPlayerChatEvent.Register(HandleChat, Priority.Low);
OnPlayerActionEvent.Register(HandlePlayerAction, Priority.Low);
OnShuttingDownEvent.Register(HandleShutdown, Priority.Low);
OnChatEvent.Register(HandleChat, Priority.Low);
OnChatSysEvent.Register(HandleChatSys, Priority.Low);
OnChatFromEvent.Register(HandleChatFrom, Priority.Low);
// Regster events for incoming
bot.connection.Listener.OnNick += Listener_OnNick;
bot.connection.Listener.OnRegistered += Listener_OnRegistered;
@ -78,10 +81,13 @@ namespace MCGalaxy.Network {
hookedEvents = false;
userMap.Clear();
OnPlayerChatEvent.Unregister(HandleChat);
OnPlayerActionEvent.Unregister(HandlePlayerAction);
OnShuttingDownEvent.Unregister(HandleShutdown);
OnChatEvent.Unregister(HandleChat);
OnChatSysEvent.Unregister(HandleChatSys);
OnChatFromEvent.Unregister(HandleChatFrom);
// Regster events for incoming
bot.connection.Listener.OnNick -= Listener_OnNick;
bot.connection.Listener.OnRegistered -= Listener_OnRegistered;
@ -102,25 +108,33 @@ namespace MCGalaxy.Network {
void HandlePlayerAction(Player p, PlayerAction action, string message, bool stealth) {
if (!p.level.SeesServerWideChat) return;
string msg = null;
if (p.muted || (Server.chatmod && !p.voice)) return;
if (action == PlayerAction.Me)
msg = "*" + p.DisplayName + " " + message;
else if (action == PlayerAction.Review)
msg = p.ColoredName + " %Sis requesting a review.";
if (msg != null) bot.Say(msg, stealth);
if (!p.level.SeesServerWideChat || action != PlayerAction.Me) return;
bot.Say("*" + p.DisplayName + " " + message, stealth);
}
static char[] trimChars = new char[] { ' ' };
void HandleChat(Player p, string message) {
if (p.cancelchat || !p.level.SeesServerWideChat) return;
if (message.Trim(trimChars).Length == 0) return;
void HandleChatSys(ChatScope scope, ref string msg, object arg,
ref ChatMessageFilter filter, bool irc) {
if (!irc) return;
// TODO: Check filter
bot.Say(msg);
}
string name = ServerConfig.IRCShowPlayerTitles ? p.FullName : p.group.Prefix + p.ColoredName;
bot.Say(name + "%S: " + message, p.opchat);
void HandleChatFrom(ChatScope scope, Player source, ref 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);
}
void HandleChat(ChatScope scope, Player source, ref 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);
}
void HandleShutdown(bool restarting, string message) {