commit 3e9031650176a5edbb7dc0e3d3e90347ee462768 Author: Philipp Date: Sat Dec 6 20:03:07 2025 +0100 Initial commit diff --git a/README.md b/README.md new file mode 100644 index 0000000..8404c90 --- /dev/null +++ b/README.md @@ -0,0 +1,10 @@ +# discord-sdr +A simple SourceMod plugin to print SDR connect info to chat and send it via a webhook to discord + +Requires [SteamPawn](https://github.com/nosoop/SM-SteamPawn) to be installed on the server. +Requires [Discord](https://gitlab.com/Zipcore/Discord/) to be installed on the server. + +sm_sdr - Returns the SDR connect info to the chat if it is available, including password. + +See the configs to setup discord webhooks. + diff --git a/configs/discord.cfg b/configs/discord.cfg new file mode 100644 index 0000000..4c20345 --- /dev/null +++ b/configs/discord.cfg @@ -0,0 +1,7 @@ +"Discord" +{ + "sdrinfo" + { + "url" "https://discordapp.com/api/webhooks/268689253305810944/hJW0vmftQIXaMcfVLdxQ5CXvEIfM0GN0lDmuRunNLPjy_NFi441rPk6KIZKfnFcqFZ-w/slack" + } +} diff --git a/configs/discord_sdrinfo.cfg b/configs/discord_sdrinfo.cfg new file mode 100644 index 0000000..3637801 --- /dev/null +++ b/configs/discord_sdrinfo.cfg @@ -0,0 +1,7 @@ +// Discord/Slack attachment color. + +// Config key from configs/discord.cfg. +// - +// Default: "sdrinfo" +discord_sdrinfo_webhook "sdrinfo" + diff --git a/discord_sdr.sp b/discord_sdr.sp new file mode 100644 index 0000000..744a908 --- /dev/null +++ b/discord_sdr.sp @@ -0,0 +1,107 @@ +#include +#include +#include +#include +#include + +#pragma newdecls required +#pragma semicolon 1 + +char sPublicIP[64]; +int PublicSDRIP[4]; +bool SDR_IP_Set = false; +ConVar g_cWebhook = null; + +#define MSG_SDR "The SDR IP for {SERVER_NAME} is: `{SDR_INFO}` You can use `connect {SDR_INFO}` in the console!" + +public Plugin myinfo = +{ + name = "List SDR Info", + author = "Spaenny", + description = "Adds a command to list SDR info and post to Discord.", + version = "1.0.0", + url = "https://spaenny.tf" +}; + +public void OnPluginStart() +{ + RegConsoleCmd("sm_sdr", Command_SDR, "List SDR Info"); + + g_cWebhook = CreateConVar("discord_sdrinfo_webhook", "sdrinfo", "Config key from configs/discord.cfg."); + + AutoExecConfig(true, "discord_sdrinfo"); +} + +public void OnConfigsExecuted() +{ + int decSDRIP = SteamPawn_GetSDRFakeIP(); + if (decSDRIP == 0) + { + LogMessage("SDR IP is not set"); + return; + } + + SDR_IP_Set = true; + + PublicSDRIP[0] = (decSDRIP >> 24) & 0xFF; + PublicSDRIP[1] = (decSDRIP >> 16) & 0xFF; + PublicSDRIP[2] = (decSDRIP >> 8) & 0xFF; + PublicSDRIP[3] = decSDRIP & 0xFF; + + int SDRPort = SteamPawn_GetSDRFakePort(0); + Format(sPublicIP, sizeof(sPublicIP), "%u.%u.%u.%u:%d", + PublicSDRIP[0], PublicSDRIP[1], PublicSDRIP[2], PublicSDRIP[3], SDRPort); + + // Build the Discord message + char sMSG[512]; + Format(sMSG, sizeof(sMSG), "%s", MSG_SDR); + + // Replace SDR IP + ReplaceString(sMSG, sizeof(sMSG), "{SDR_INFO}", sPublicIP); + + // Replace Server Name + char sServerName[128]; + GetConVarString(FindConVar("hostname"), sServerName, sizeof(sServerName)); + ReplaceString(sMSG, sizeof(sMSG), "{SERVER_NAME}", sServerName); + + LogMessage("SDR IP: %s", sPublicIP); + SendMessage(sMSG); +} + +public Action Command_SDR(int client, int args) +{ + if (!SDR_IP_Set) + { + PrintToChat(client, "SDR does not seem to be on for this server."); + return Plugin_Handled; + } + + PrintToChat(client, "SDR IP: %s", sPublicIP); + + char password[64]; + ConVar cv = FindConVar("sv_password"); + if (cv != null) + { + cv.GetString(password, sizeof(password)); + } + else + { + password[0] = '\0'; + } + + PrintToChat(client, "Connect Command: connect %s; password %s", sPublicIP, password); + + return Plugin_Handled; +} + +// Helper function: send a message to Discord +void SendMessage(const char[] sMessage) +{ + if (g_cWebhook != null) + { + char sWebhook[64]; + g_cWebhook.GetString(sWebhook, sizeof(sWebhook)); + Discord_SendMessage(sWebhook, sMessage); + } +} +