public void SendRoleQuery(string steamID) { if (!syncedPlayers.ContainsKey(steamID)) { return; } NetworkSystem.QueueMessage("rolequery " + steamID + " " + syncedPlayers[steamID]); }
public void SendRoleQuery(Player player) { if (player.UserIdType != UserIdType.STEAM || !syncedPlayers.ContainsKey(player.UserId)) { return; } NetworkSystem.QueueMessage("rolequery " + player.GetParsedUserID() + " " + syncedPlayers[player.UserId]); }
public void QueueMessage(string[] channelAliases, string message) { foreach (string channel in channelAliases) { if (Config.GetDict("aliases").ContainsKey(channel)) { NetworkSystem.QueueMessage(channel + message); } } }
public bool SendString(IEnumerable <string> channelAliases, string message) { foreach (string channel in channelAliases) { if (Config.GetDict("aliases").ContainsKey(channel)) { NetworkSystem.QueueMessage(Config.GetDict("aliases")[channel] + message); } } return(true); }
public bool SendStringByID(ulong channelID, string message) { MessageWrapper wrapper = new MessageWrapper { ChatMessage = new ChatMessage { ChannelID = channelID, Content = message } }; NetworkSystem.QueueMessage(wrapper); return(true); }
public void SendRoleQuery(Player player) { if (player.UserIDType != UserIdType.STEAM || !syncedPlayers.ContainsKey(player.UserID)) { return; } MessageWrapper message = new MessageWrapper { RoleQuery = new RoleQuery { SteamID = player.UserID, DiscordID = syncedPlayers[player.UserID] } }; NetworkSystem.QueueMessage(message); }
public bool SendString(IEnumerable <string> channelAliases, string message) { foreach (string channel in channelAliases) { if (Config.GetDict("aliases").ContainsKey(channel)) { MessageWrapper wrapper = new MessageWrapper { ChatMessage = new ChatMessage { ChannelID = Config.GetDict("aliases")[channel], Content = message } }; NetworkSystem.QueueMessage(wrapper); } } return(true); }
public BotListener(SCPDiscord plugin) { this.plugin = plugin; while (!plugin.shutdown) { //Listen for connections if (NetworkSystem.IsConnected()) { try { //Discord messages can be up to 2000 chars long, UTF8 chars can be up to 4 bytes long. byte[] data = new byte[1000]; int dataLength = NetworkSystem.Receive(data); string incomingData = Encoding.UTF8.GetString(data, 0, dataLength); List <string> messages = new List <string>(incomingData.Split('\n')); //If several messages come in at the same time, process all of them while (messages.Count > 0) { if (messages[0].Length == 0) { messages.RemoveAt(0); continue; } plugin.Debug("Incoming command from discord: " + messages[0]); string[] words = messages[0].Split(' '); if (words[0] == "command") { string channel = words[1]; string discordTag = words[2].Replace('_', ' '); string command = words[3]; string[] arguments = new string[0]; if (words.Length >= 5) { arguments = words.Skip(4).ToArray(); } string response; Dictionary <string, string> variables; switch (command) { case "ban": //Check if the command has enough arguments if (arguments.Length >= 2) { BanCommand(channel, arguments[0], arguments[1], MergeString(arguments.Skip(2).ToArray()), discordTag); } else { variables = new Dictionary <string, string> { { "command", messages[0] } }; plugin.SendMessageByID(channel, "botresponses.missingarguments", variables); } break; case "kick": //Check if the command has enough arguments if (arguments.Length >= 1) { KickCommand(channel, arguments[0], MergeString(arguments.Skip(1).ToArray()), discordTag); } else { variables = new Dictionary <string, string> { { "command", messages[0] } }; plugin.SendMessageByID(channel, "botresponses.missingarguments", variables); } break; case "kickall": KickallCommand(channel, MergeString(arguments), discordTag); break; case "unban": //Check if the command has enough arguments if (arguments.Length >= 1) { UnbanCommand(channel, arguments[0]); } else { variables = new Dictionary <string, string> { { "command", messages[0] } }; plugin.SendMessageByID(channel, "botresponses.missingarguments", variables); } break; case "list": var message = "```md\n# Players online (" + (plugin.Server.NumPlayers - 1) + "):\n"; foreach (Player player in plugin.Server.GetPlayers()) { message += player.Name.PadRight(35) + "<" + player.UserId + ">" + "\n"; } message += "```"; NetworkSystem.QueueMessage(channel + message); break; case "exit": plugin.SendMessageByID(channel, "botresponses.exit"); break; case "help": plugin.SendMessageByID(channel, "botresponses.help"); break; case "hidetag": case "showtag": if (plugin.PluginManager.GetEnabledPlugin("karlofduty.toggletag") != null) { if (arguments.Length > 0) { command = "console_" + command; response = plugin.ConsoleCommand(plugin.PluginManager.Server, command, arguments); variables = new Dictionary <string, string> { { "feedback", response } }; plugin.SendMessageByID(channel, "botresponses.consolecommandfeedback", variables); } else { variables = new Dictionary <string, string> { { "command", command } }; plugin.SendMessageByID(channel, "botresponses.missingarguments", variables); } } else { plugin.SendMessageByID(channel, "botresponses.toggletag.notinstalled"); } break; case "vs_enable": case "vs_disable": case "vs_whitelist": case "vs_reload": if (plugin.PluginManager.GetEnabledPlugin("karlofduty.vpnshield") != null) { response = plugin.ConsoleCommand(plugin.PluginManager.Server, command, arguments); variables = new Dictionary <string, string> { { "feedback", response } }; plugin.SendMessageByID(channel, "botresponses.consolecommandfeedback", variables); } else { plugin.SendMessageByID(channel, "botresponses.vpnshield.notinstalled"); } break; case "scperms_reload": case "scperms_giverank": case "scperms_removerank": case "scperms_verbose": case "scperms_debug": case "scpermissions_reload": case "scpermissions_giverank": case "scpermissions_removerank": case "scpermissions_verbose": case "scpermissions_debug": if (plugin.PluginManager.GetEnabledPlugin("karlofduty.scpermissions") != null) { response = plugin.ConsoleCommand(plugin.PluginManager.Server, command, arguments); variables = new Dictionary <string, string> { { "feedback", response } }; plugin.SendMessageByID(channel, "botresponses.consolecommandfeedback", variables); } else { plugin.SendMessageByID(channel, "botresponses.scpermissions.notinstalled"); } break; case "syncrole": NetworkSystem.QueueMessage(channel + plugin.roleSync.AddPlayer(arguments[0], arguments[1])); break; case "unsyncrole": NetworkSystem.QueueMessage(channel + plugin.roleSync.RemovePlayer(arguments[0])); break; default: response = plugin.ConsoleCommand(plugin.PluginManager.Server, command, arguments); variables = new Dictionary <string, string> { { "feedback", response } }; plugin.SendMessageByID(channel, "botresponses.consolecommandfeedback", variables); break; } } else if (words[0] == "roleresponse") { plugin.roleSync.ReceiveQueryResponse(words[1] + "@steam", MergeString(words.Skip(2).ToArray())); } plugin.Verbose("From discord: " + messages[0]); messages.RemoveAt(0); } } catch (Exception ex) { plugin.Error("BotListener Error: " + ex); } } Thread.Sleep(1000); } }
public bool SendStringByID(string channelID, string message) { NetworkSystem.QueueMessage(channelID + message); return(true); }