public static void MessageFrom(ChatScope scope, Player source, string msg, object arg, ChatMessageFilter filter, bool irc = false) { Player[] players = PlayerInfo.Online.Items; ChatMessageFilter scopeFilter = scopeFilters[(int)scope]; 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; } if (Ignoring(pl, source)) { continue; } pl.Message(UnescapeMessage(pl, source, msg)); } }
public void Reset() { Scope = ChatScope.Global; ClientIndex = 0; Message = string.Empty; Name = string.Empty; }
void HandleChatFrom(ChatScope scope, Player source, string msg, object arg, ref ChatMessageFilter filter, bool relay) { if (relay) { MessageToRelay(scope, Unescape(source, msg), arg, filter); } }
void HandleChatSys(ChatScope scope, string msg, object arg, ref ChatMessageFilter filter, bool relay) { if (relay) { MessageToRelay(scope, msg, arg, filter); } }
void HandleChatSys(ChatScope scope, string msg, object arg, ref ChatMessageFilter filter, bool irc) { if (irc) { MessageToIRC(scope, msg, arg, filter); } }
void HandleChat(ChatScope scope, Player source, string msg, object arg, ref ChatMessageFilter filter, bool irc) { if (irc) { MessageToIRC(scope, Unescape(source, msg), arg, filter); } }
public void Read(NetBuffer buffer) { Scope = (ChatScope)buffer.ReadByte(); Message = buffer.ReadString(); Name = buffer.ReadString(); ClientIndex = buffer.ReadInt32(); SupporterLevel = buffer.ReadInt32(); }
public static void Call(ChatScope scope, string msg, object arg, ref ChatMessageFilter filter, bool relay) { IEvent <OnChatSys>[] items = handlers.Items; for (int i = 0; i < items.Length; i++) { try { items[i].method(scope, msg, arg, ref filter, relay); } catch (Exception ex) { LogHandlerException(ex, items[i]); } } }
void OnChat(ChatScope scope, Player source, string msg, object arg, ref ChatMessageFilter filter, bool relay) { if (!relay) { return; } msg = PrepareMessage(msg); MessageToRelay(scope, Unescape(source, msg), arg, filter); }
void OnChatSys(ChatScope scope, string msg, object arg, ref ChatMessageFilter filter, bool relay) { if (!relay) { return; } msg = PrepareMessage(msg); MessageToRelay(scope, msg, arg, filter); }
/// <summary> Sends a chat message from the given player (e.g. regular player chat or /me) </summary> /// <remarks> Chat messages will increase player's total messages sent in /info, /// and count towards triggering automute for chat spamming </remarks> /// <remarks> Only players not ignoring the given player will see this message. </remarks> public static void MessageChat(ChatScope scope, Player source, string msg, object arg, ChatMessageFilter filter, bool relay = false) { Player[] players = PlayerInfo.Online.Items; ChatMessageFilter scopeFilter = scopeFilters[(int)scope]; bool counted = false; // Filter out bad words if (Server.Config.ProfanityFiltering) { msg = ProfanityFilter.Parse(msg); } OnChatEvent.Call(scope, source, msg, arg, ref filter, relay); foreach (Player pl in players) { if (Ignoring(pl, source)) { continue; } // Always show message to self too (unless ignoring self) if (pl != source) { if (!scopeFilter(pl, arg)) { continue; } if (filter != null && !filter(pl, arg)) { continue; } if (!counted) { source.TotalMessagesSent++; counted = true; } } else { // don't send PM back to self if (scope == ChatScope.PM) { continue; } } pl.Message(UnescapeMessage(pl, source, msg)); } source.CheckForMessageSpam(); }
void MessageToRelay(ChatScope scope, string msg, object arg, ChatMessageFilter filter) { ChatMessageFilter scopeFilter = Chat.scopeFilters[(int)scope]; fakeGuest.group = Group.DefaultRank; if (scopeFilter(fakeGuest, arg) && (filter == null || filter(fakeGuest, arg))) { SendPublicMessage(msg); return; } fakeStaff.group = GetControllerRank(); if (scopeFilter(fakeStaff, arg) && (filter == null || filter(fakeStaff, arg))) { SendStaffMessage(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; if (scope == ChatScope.Perms) { logType = LogType.StaffChat; } else if (scope == ChatScope.Chatroom || scope == ChatScope.AllChatrooms) { logType = LogType.ChatroomChat; } else if (scope == ChatScope.Rank) { logType = LogType.RankChat; } if (scope != ChatScope.PM) { Logger.Log(logType, msg); } Player[] players = PlayerInfo.Online.Items; ChatMessageFilter scopeFilter = Chat.scopeFilters[(int)scope]; foreach (Player pl in players) { if (pl == source || Chat.Ignoring(pl, source)) { continue; } if (!scopeFilter(pl, arg)) { continue; } if (filter != null && !filter(pl, arg)) { continue; } source.TotalMessagesSent++; break; } }
public static void Message(ChatScope scope, string msg, object arg, ChatMessageFilter filter, bool relay = false) { Player[] players = PlayerInfo.Online.Items; ChatMessageFilter scopeFilter = scopeFilters[(int)scope]; OnChatSysEvent.Call(scope, msg, arg, ref filter, relay); foreach (Player pl in players) { if (!scopeFilter(pl, arg)) { continue; } if (filter != null && !filter(pl, arg)) { continue; } pl.Message(msg); } }
void MessageToIRC(ChatScope scope, string msg, object arg, ChatMessageFilter filter) { ChatMessageFilter scopeFilter = Chat.scopeFilters[(int)scope]; if (scopeFilter(ircDefault, arg) && (filter == null || filter(ircDefault, arg))) { bot.Say(msg, false); } else { ircOp.group = Group.Find(Server.Config.IRCControllerRank); if (ircOp.group == null) { ircOp.group = Group.NobodyRank; } if (scopeFilter(ircOp, arg) && (filter == null || filter(ircOp, arg))) { bot.Say(msg, true); } } }
public static void MessageChat(ChatScope scope, Player source, string msg, object arg, ChatMessageFilter filter, bool irc = false) { Player[] players = PlayerInfo.Online.Items; ChatMessageFilter scopeFilter = scopeFilters[(int)scope]; OnChatEvent.Call(scope, source, msg, arg, ref filter, irc); foreach (Player pl in players) { if (Ignoring(pl, source)) { continue; } // Always show message to self too (unless ignoring self) if (pl != source) { if (!scopeFilter(pl, arg)) { continue; } if (filter != null && !filter(pl, arg)) { continue; } } else { // don't send PM back to self if (scope == ChatScope.PM) { continue; } } pl.Message(UnescapeMessage(pl, source, msg)); } source.CheckForMessageSpam(); }
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; if (scope == ChatScope.Perms) { logType = LogType.StaffChat; } else if (scope == ChatScope.Chatroom || scope == ChatScope.AllChatrooms) { logType = LogType.ChatroomChat; } else if (scope == ChatScope.Rank) { logType = LogType.RankChat; } if (scope != ChatScope.PM) { Logger.Log(logType, msg); } }
private void InGameCommand(String msg, ChatScope scope, int team, int squad, String name) { if (EnableLoggingOnlyMode) { ConsoleDebug("EnableLoggingOnlyMode enabled, commands disabled"); return; } if (!EnableInGameCommands) { ConsoleDebug("EnableInGameCommands is False, commands disabled"); return; } CPrivileges p = this.GetAccountPrivileges(name); if (p == null || !p.CanMovePlayers) { List<String> m = new List<String>(); m.Add("You are not authorized to use @mb commands! Check your Procon account settings."); SayLines(m, name); return; } Match mbCmd = Regex.Match(msg, @"^\s*[@!#]mb\s+([\w]+)\s+(.*)$", RegexOptions.IgnoreCase); Match mbSubCmd = Regex.Match(msg, @"^\s*[@!#]mb\s+(sub|unsub)", RegexOptions.IgnoreCase); Match mbHelp = Regex.Match(msg, @"^\s*[@!#]mb\s+help\s*$", RegexOptions.IgnoreCase); Match mbHelpCmd = Regex.Match(msg, @"^\s*[@!#]mb\s+help\s+(add|del|list|new|sub|unsub)", RegexOptions.IgnoreCase); List<String> lines = null; PlayerModel player = null; int dispersalGroup = 0; String nameMatch = String.Empty; List<String> list = null; if (mbHelp.Success) { lines = new List<String>(); lines.Add("Type '@mb help' and one of the following:"); lines.Add("add, delete, list, new, subscribe, unsubscribe"); SayLines(lines, name); return; } if (mbHelpCmd.Success) { lines = new List<String>(); String which = mbHelpCmd.Groups[1].Value; switch (which.ToLower()) { case "add": lines.Add("Add names to a matching name in the disperse, friends, or white list"); lines.Add("Example: @mb add friends Match Adam"); break; case "del": lines.Add("Delete player names from the disperse, friends, or white list"); lines.Add("Example: @mb del friends Adam Eve"); break; case "list": lines.Add("List the disperse, friends or white list"); lines.Add("Example: @mb list friends"); break; case "new": lines.Add("Create a new entry in the disperse, friends, or white list"); lines.Add("Example: @mb new disperse 2 Name1 Name2 Name3"); break; case "sub": lines.Add("Subscribe to all balancer chat messages"); break; case "unsub": lines.Add("Unsubscribe from all balancer chat messages"); break; default: break; } SayLines(lines, name); return; } if (mbSubCmd.Success) { lines = new List<String>(); String which = mbSubCmd.Groups[1].Value; switch (which.ToLower()) { case "sub": player = GetPlayer(name); if (player != null) { player.Subscribed = true; lines.Add("You will see all balancer chat messages"); } break; case "unsub": player = GetPlayer(name); if (player != null) { player.Subscribed = false; lines.Add("You will no longer see all balancer chat messages"); } break; default: break; } SayLines(lines, name); return; } if (mbCmd.Success) { lines = new List<String>(); String which = mbCmd.Groups[1].Value; String tmp = mbCmd.Groups[2].Value; IGCommand cmd = IGCommand.None; if (Regex.Match(which, @"^add", RegexOptions.IgnoreCase).Success) { cmd = IGCommand.Add; } else if (Regex.Match(which, @"^del", RegexOptions.IgnoreCase).Success) { cmd = IGCommand.Delete; } else if (Regex.Match(which, @"^list", RegexOptions.IgnoreCase).Success) { cmd = IGCommand.List; } else if (Regex.Match(which, @"^new", RegexOptions.IgnoreCase).Success) { cmd = IGCommand.New; } else { lines.Add("Unknown command: " + which + ", try @mb help"); SayLines(lines, name); return; } String[] args = Regex.Split(tmp, @"\s+"); if (args.Length == 0) { lines.Add("No list (disperse, friends) specified, try @mb help"); SayLines(lines, name); return; } else if (cmd != IGCommand.List && args.Length < 2) { lines.Add("The command is incomplete: " + msg + ", try @mb help"); SayLines(lines, name); } // args[0] should be the name of the list String listName = String.Empty; if (Regex.Match(args[0], @"^di?s?p?e?r?s?e?", RegexOptions.IgnoreCase).Success) { listName = "Dispersal"; } else if (Regex.Match(args[0], @"^fr?i?e?n?d?s?", RegexOptions.IgnoreCase).Success) { listName = "Friends"; } else if (Regex.Match(args[0], @"^wh?i?t?e?l?i?s?t?", RegexOptions.IgnoreCase).Success) { listName = "Whitelist"; } else { lines.Add("Unknown list name: " + args[0] + ", try @mb help"); SayLines(lines, name); return; } int i = 1; if (listName == "Dispersal" && args.Length >= 3) { // args[1] may be a dispersal group if (args[1] == "1") { dispersalGroup = 1; ++i; } else if (args[1] == "2") { dispersalGroup = 2; ++i; } } // Next arg may be the match string for add if (cmd == IGCommand.Add && listName == "Friends" && i < args.Length) { nameMatch = args[i]; ++i; } // The rest of the args are the name operands List<String> names = new List<String>(); while (i < args.Length) { names.Add(args[i]); ++i; } // Execute the command switch (cmd) { case IGCommand.Add: if (listName == "Dispersal") { if (dispersalGroup != 0) { bool found = false; int groupId = 0; String[] copy = (String[])DisperseEvenlyList.Clone(); list = new List<String>(); list.AddRange(DisperseEvenlyList); for (int n = 0; n < copy.Length; ++n) { if (Regex.Match(copy[n], @"^[1234]\s+").Success) { // It's a group List<String> tokens = new List<String>(Regex.Split(copy[n], @"\s+")); if (tokens.Count > 0 && Int32.TryParse(tokens[0], out groupId) && groupId == dispersalGroup) { found = true; foreach (String nm in names) { copy[n] = copy[n] + " " + nm; } break; } } } if (found) { list.Clear(); list.AddRange(copy); lines.Add("Added " + names.Count + " names to Dispersal Group " + groupId); } else { lines.Add("Can't find Dispersal Group " + groupId + ", add failed!"); SayLines(lines, name); return; } } else { foreach (String nm in names) { player = GetPlayer(nm); if (player != null && IsDispersal(player, true)) { lines.Add("Duplicate name ^b" + nm + "^n, add failed!"); SayLines(lines, name); return; } list.Add(nm); } lines.Add("Added " + names.Count + " names to Disperse Evenly List"); } ForceSetPluginVariable("1 - Settings|Disperse Evenly List", list.ToArray()); } else if (listName == "Friends") { bool found = false; String[] copy = fSettingFriendsList.ToArray(); list = new List<String>(); list.AddRange(fSettingFriendsList); for (int n = 0; n < copy.Length; ++n) { // Find a line in the list that contains the nameMatch string List<String> tokens = new List<String>(Regex.Split(copy[n], @"\s+")); if (tokens.Contains(nameMatch)) { found = true; foreach (String nm in names) { copy[n] = copy[n] + " " + nm; } break; } } if (found) { list.Clear(); list.AddRange(copy); lines.Add("Added " + names.Count + " names to Friends List"); } else { lines.Add("Can't find friend " + nameMatch + " in Friends List, add failed!"); SayLines(lines, name); return; } ForceSetPluginVariable("1 - Settings|Friends List", list.ToArray()); } else if (listName == "Whitelist") { String[] copy = fSettingWhitelist.ToArray(); list = new List<String>(); list.AddRange(fSettingWhitelist); // Check for duplication foreach (String nm in names) { for (int n = 0; n < copy.Length; ++n) { // Find matches List<String> tokens = new List<String>(Regex.Split(copy[n], @"\s+")); if (tokens.Contains(nm)) { lines.Add("Duplicate name ^b" + nm + "^n, add failed!"); SayLines(lines, name); return; } } // ok to add list.Add(nm); } lines.Add("Added " + names.Count + " names to Whitelist"); ForceSetPluginVariable("1 - Settings|Whitelist", list.ToArray()); } break; case IGCommand.Delete: if (listName == "Dispersal") { if (dispersalGroup != 0) { bool found = false; String remove = String.Empty; int groupId = 0; String[] copy = (String[])DisperseEvenlyList.Clone(); list = new List<String>(); list.AddRange(DisperseEvenlyList); for (int n = 0; n < copy.Length; ++n) { if (Regex.Match(copy[n], @"^[1234]\s+").Success) { // It's a group List<String> tokens = new List<String>(Regex.Split(copy[n], @"\s+")); if (tokens.Count > 0 && Int32.TryParse(tokens[0], out groupId) && groupId == dispersalGroup) { found = true; foreach (String nm in names) { if (tokens.Contains(nm)) { tokens.Remove(nm); } } if (tokens.Count > 1) { copy[n] = String.Join(" ", tokens.ToArray()); } else { // Remove the whole item remove = copy[n]; } break; } } } if (found) { list.Clear(); list.AddRange(copy); if (!String.IsNullOrEmpty(remove)) { list.Remove(remove); } lines.Add("Deleted " + names.Count + " names from Dispersal Group " + groupId); } else { lines.Add("Can't find Dispersal Group " + groupId + ", delete failed!"); SayLines(lines, name); return; } } else { foreach (String nm in names) { player = GetPlayer(nm); if (player != null && !IsDispersal(player, true)) { lines.Add("Can't find name ^b" + nm + "^n, delete failed!"); SayLines(lines, name); return; } list.Remove(nm); } lines.Add("Deleted " + names.Count + " names from Disperse Evenly List"); } ForceSetPluginVariable("1 - Settings|Disperse Evenly List", list.ToArray()); } else if (listName == "Friends") { bool found = false; String remove = String.Empty; String[] copy = fSettingFriendsList.ToArray(); list = new List<String>(); list.AddRange(fSettingFriendsList); for (int n = 0; n < copy.Length; ++n) { // Find a token in the line that contains a match List<String> tokens = new List<String>(Regex.Split(copy[n], @"\s+")); foreach (String nm in names) { if (tokens.Contains(nm)) { found = true; tokens.Remove(nm); } } if (tokens.Count > 1) { copy[n] = String.Join(" ", tokens.ToArray()); } else { // Remove the whole item remove = copy[n]; } } if (found) { list.Clear(); list.AddRange(copy); if (!String.IsNullOrEmpty(remove)) list.Remove(remove); lines.Add("Deleted " + names.Count + " names from Friends List"); } else { lines.Add("Can't find any matching friends in Friends List, delete failed!"); SayLines(lines, name); return; } ForceSetPluginVariable("1 - Settings|Friends List", list.ToArray()); } else if (listName == "Whitelist") { bool found = false; String[] copy = fSettingWhitelist.ToArray(); list = new List<String>(); list.AddRange(fSettingWhitelist); // Check for match foreach (String nm in names) { for (int n = 0; n < copy.Length; ++n) { // Find matches List<String> tokens = new List<String>(Regex.Split(copy[n], @"\s+")); if (tokens.Contains(nm)) { list.Remove(copy[n]); found = true; } } } if (found) { lines.Add("Deleted " + names.Count + " names from Whitelist"); } else { lines.Add("Can't find any matching names in Whitelist, delete failed!"); } ForceSetPluginVariable("1 - Settings|Whitelist", list.ToArray()); } break; case IGCommand.List: String buffer = String.Empty; bool first = true; if (listName == "Dispersal") { for (int j = 1; j <= 4; ++j) { if (fDispersalGroups[j].Count > 0) { String dg = j.ToString() + " " + String.Join(" ", fDispersalGroups[j].ToArray()); if (first) { buffer = dg; first = false; } else { buffer = buffer + "; " + dg; } } } foreach (String item in fSettingDisperseEvenlyList) { if (first) { buffer = item; first = false; } else { buffer = buffer + "; " + item; } } lines.Add(buffer); } else if (listName == "Friends") { foreach (String item in fSettingFriendsList) { if (first) { buffer = item; first = false; } else { buffer = buffer + "; " + item; } } lines.Add(buffer); } else if (listName == "Whitelist") { foreach (String item in fSettingWhitelist) { if (first) { buffer = item; first = false; } else { buffer = buffer + "; " + item; } } lines.Add(buffer); } break; case IGCommand.New: if (listName == "Dispersal") { if (dispersalGroup != 0) { int groupId = 0; String[] copy = (String[])DisperseEvenlyList.Clone(); list = new List<String>(); list.AddRange(DisperseEvenlyList); for (int n = 0; n < copy.Length; ++n) { if (Regex.Match(copy[n], @"^[1234]\s+").Success) { // It's a group List<String> tokens = new List<String>(Regex.Split(copy[n], @"\s+")); if (tokens.Count > 0 && Int32.TryParse(tokens[0], out groupId) && groupId == dispersalGroup) { lines.Add("Dispersal Group " + groupId + " already exists, new failed!"); SayLines(lines, name); return; } } } list.Add(groupId + " " + String.Join(" ", names.ToArray())); lines.Add("Created Dispersal Group " + groupId + " with " + names.Count + " names in Disperse Evenly List"); } else { foreach (String nm in names) { player = GetPlayer(nm); if (player != null && IsDispersal(player, true)) { lines.Add("Duplicate name ^b" + nm + "^n, new failed!"); SayLines(lines, name); return; } list.Add(nm); } lines.Add("Created " + names.Count + " new names in Disperse Evenly List"); } ForceSetPluginVariable("1 - Settings|Disperse Evenly List", list.ToArray()); } else if (listName == "Friends") { if (names.Count < 2) { lines.Add("New friends must have at least 2 names, new failed!"); SayLines(lines, name); return; } bool found = false; String[] copy = fSettingFriendsList.ToArray(); list = new List<String>(); list.AddRange(fSettingFriendsList); for (int n = 0; n < copy.Length; ++n) { // Find a line in the list that contains the nameMatch string List<String> tokens = new List<String>(Regex.Split(copy[n], @"\s+")); foreach (String nm in names) { if (tokens.Contains(nm)) { found = true; break; } } if (found) break; } if (!found) { list.Add(String.Join(" ", names.ToArray())); lines.Add("Created " + names.Count + " new names in Friends List"); } else { lines.Add("Duplicate names in Friends List, new failed!"); SayLines(lines, name); return; } ForceSetPluginVariable("1 - Settings|Friends List", list.ToArray()); } else if (listName == "Whitelist") { String[] copy = fSettingWhitelist.ToArray(); list = new List<String>(); list.AddRange(fSettingWhitelist); // Check for duplication foreach (String nm in names) { for (int n = 0; n < copy.Length; ++n) { // Find matches List<String> tokens = new List<String>(Regex.Split(copy[n], @"\s+")); if (tokens.Contains(nm)) { lines.Add("Duplicate name ^b" + nm + "^n, new failed!"); SayLines(lines, name); return; } } // ok to add list.Add(nm); } lines.Add("Created " + names.Count + " new names in Whitelist"); ForceSetPluginVariable("1 - Settings|Whitelist", list.ToArray()); } break; default: break; } // Send the results SayLines(lines, name); return; } // Unknown command lines = new List<String>(); lines.Add("Unknown command: " + msg); SayLines(lines, name); }