Initial commit
This commit is contained in:
commit
3e90316501
4 changed files with 131 additions and 0 deletions
10
README.md
Normal file
10
README.md
Normal file
|
|
@ -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.
|
||||||
|
|
||||||
7
configs/discord.cfg
Normal file
7
configs/discord.cfg
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
"Discord"
|
||||||
|
{
|
||||||
|
"sdrinfo"
|
||||||
|
{
|
||||||
|
"url" "https://discordapp.com/api/webhooks/268689253305810944/hJW0vmftQIXaMcfVLdxQ5CXvEIfM0GN0lDmuRunNLPjy_NFi441rPk6KIZKfnFcqFZ-w/slack"
|
||||||
|
}
|
||||||
|
}
|
||||||
7
configs/discord_sdrinfo.cfg
Normal file
7
configs/discord_sdrinfo.cfg
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
// Discord/Slack attachment color.
|
||||||
|
|
||||||
|
// Config key from configs/discord.cfg.
|
||||||
|
// -
|
||||||
|
// Default: "sdrinfo"
|
||||||
|
discord_sdrinfo_webhook "sdrinfo"
|
||||||
|
|
||||||
107
discord_sdr.sp
Normal file
107
discord_sdr.sp
Normal file
|
|
@ -0,0 +1,107 @@
|
||||||
|
#include <sdkhooks>
|
||||||
|
#include <sdktools>
|
||||||
|
#include <sourcemod>
|
||||||
|
#include <steampawn>
|
||||||
|
#include <discord>
|
||||||
|
|
||||||
|
#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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue