Skip to content

Commit

Permalink
v1.1.1 - Optional Discord exclusion in compilation process, added tex…
Browse files Browse the repository at this point in the history
…t logging (requested by RGL)
  • Loading branch information
Shigbeard committed Nov 23, 2024
1 parent 361c92d commit 87aad32
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 15 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ jobs:
cd ./scripting
pwd
spcomp -i"./include/" demo_check.sp -o ../plugins/demo_check.smx
spcomp -i"./include/" NO_DISCORD=true demo_check.sp -o ../plugins/demo_check_no_discord.smx
ls -la
- name: Zip packages
Expand Down
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,16 @@ This plugin is used to check if players are recording demos or not.

All includes and extensions are bundled with this repository. Special thanks to [Dr. McKay](https://github.com/DoctorMcKay/sourcemod-plugins/blob/master/scripting/include/morecolors.inc) and [Sapphonie](https://github.com/sapphonie/StAC-tf2) from whom I shamelessly stole morecolors.inc and SteamWorks.inc/discord.inc (plus extensions) from.

Note: Don't like Discord? You can compile without Discord by passing `NO_DISCORD=true` to spcomp.

```bash
./spcomp64 -i"/path/to/sourcemod/scripting/include" -i"/path/to/demo_check/repo/clone/scripting/include" NO_DISCORD=true "/path/to/demo_check/repo/clone/scripting/demo_check.sp" -o "/path/to/demo_check/repo/clone/plugins/demo_check_no_demo.smx"
```

## Installation

1. Download the plugin from the [releases page](https://github.com/ozfortres/demo-check-plugin/releases).
2. Install the `plugins/demo_check.smx` file into your `tf/addons/sourcemod/plugins` directory.
2. Install the `plugins/demo_check.smx` file or the `plugins/demo_check_no_discord.smx` file into your `tf/addons/sourcemod/plugins` directory.
3. Install the `translations/demo_check.phrases.txt` file into your `tf/addons/sourcemod/translations` directory.
4. Restart your server.

Expand All @@ -20,12 +26,13 @@ The plugin has a few cvars that can be configured:
- `sm_democheck_enabled <0/1>` - Enable or disable the plugin. Default: `1`
- `sm_democheck_onreadyup <0/1>` - Performs an additional check at ready up. Requires SoapDM to be running. Default: `0`
- `sm_democheck_warn <0/1>` - Set the plugin into warning only mode. Default: `0`. If enabled, players will be warned if they are not recording demos, but will not be kicked.
- `sm_democheck_announce_textfile <0/1>` - Log kicks to a text file (democheck.log). Default: `0`

Additionally if your use case requires different languages or links to documentation, you can modify the `demo_check.phrases.txt` file in the `translations` directory. Currently only English is supported, and existing documentation links are for ozfortress.

We've also included Discord Webhook support! Starting from version 1.1.0, you can now configure the plugin to send a message to a Discord webhook when a player is kicked for not recording demos. To enable this feature, you will need to set the following cvars:

- `sm_democheck_announce_discord <0/1>` - Enable or disable the Discord webhook feature. Default: `0`
- `sm_democheck_announce_discord <0/1>` - Enable or disable the Discord webhook feature. Default: `0`. This Cvar and feature is not included when compiled with NO_DISCORD=true

Additionally, modify `/tf/addons/sourcemod/configs/discord.cfg` with the following:

Expand Down
Binary file modified plugins/demo_check.smx
Binary file not shown.
Binary file added plugins/demo_check_no_discord.smx
Binary file not shown.
48 changes: 35 additions & 13 deletions scripting/demo_check.sp
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,39 @@
* Plugin to check if a player is recording a demo.
*/

/**
* DEV NOTES
*
* https://sourcemod.dev/#/convars/function.QueryClientConVar
*
* ds_enable 0/1/2 - if set to one of these, boot with config on, warn with config off
* ds_enable 3 - if this is on, a ok
* ds_autodelete 1 instant boot with config on, prompt player to turn it off
*/

#include <sourcemod>
#include <sdktools>
#include <morecolors>
#include <SteamWorks>
#if !defined NO_DISCORD
#include <discord>
#endif

#define DEMOCHECK_TAG "{lime}[{red}Demo Check{lime}]{white} "

public Plugin:myinfo =
{
#if !defined NO_DISCORD
name = "Demo Check",
#else
name = "Demo Check (No Discord)",
#endif
author = "Shigbeard",
description = "Checks if a player is recording a demo",
version = "1.1.0",
version = "1.1.1",
url = "https://ozfortress.com/"
};

ConVar g_bDemoCheckEnabled;
ConVar g_bDemoCheckOnReadyUp; // Requires SoapDM
ConVar g_bDemoCheckWarn;
ConVar g_bDemoCheckAnnounce;
#if !defined NO_DISCORD
ConVar g_bDemoCheckAnnounceDiscord; // Requires Discord
ConVar g_HostName;
ConVar g_HostPort;
#endif
ConVar g_bDemoCheckAnnounceTextFile; // Dumps to a text file

public void OnPluginStart()
{
Expand All @@ -48,7 +47,12 @@ public void OnPluginStart()

g_bDemoCheckWarn = CreateConVar("sm_democheck_warn", "0", " Set the plugin into warning only mode.", FCVAR_NOTIFY, true, 0.0, true, 1.0);
g_bDemoCheckAnnounce = CreateConVar("sm_democheck_announce", "1", "Announce passed demo checks to chat", FCVAR_NOTIFY, true, 0.0, true, 1.0);
#if !defined NO_DISCORD
g_bDemoCheckAnnounceDiscord = CreateConVar("sm_democheck_announce_discord", "0", "Announce failed demo checks to discord", FCVAR_NOTIFY, true, 0.0, true, 1.0);
g_HostName = FindConVar("hostname");
g_HostPort = FindConVar("hostport");
#endif
g_bDemoCheckAnnounceTextFile = CreateConVar("sm_democheck_announce_textfile", "0", "Dump failed demo checks to a text file", FCVAR_NOTIFY, true, 0.0, true, 1.0);

RegServerCmd("sm_democheck", Cmd_DemoCheck_Console, "Check if a player is recording a demo", 0);
RegServerCmd("sm_democheck_enable", Cmd_DemoCheckEnable_Console, "Enable demo check", 0);
Expand All @@ -57,8 +61,6 @@ public void OnPluginStart()

HookConVarChange(g_bDemoCheckEnabled, OnDemoCheckEnabledChange)

g_HostName = FindConVar("hostname");
g_HostPort = FindConVar("hostport");
}

public void SOAP_StopDeathMatching()
Expand Down Expand Up @@ -265,6 +267,7 @@ public Action Timer_KickClient(Handle timer, int client)
{
return Plugin_Stop;
}
#if !defined NO_DISCORD
if (GetConVarBool(g_bDemoCheckAnnounceDiscord))
{
char sName[64];
Expand Down Expand Up @@ -302,6 +305,25 @@ public Action Timer_KickClient(Handle timer, int client)
Format(sMsg, sizeof(sMsg), "[Demo Check] %t", "discord_democheck", sName, sSteamID, sProfileURL, sServerName, sServerIP);
Discord_SendMessage("democheck", sMsg);
}
#endif
if (GetConVarBool(g_bDemoCheckAnnounceTextFile))
{
char sName[64];
char sSteamID[64];
char sProfileURL[64];
char sDateTime[64];
FormatTime(sDateTime, sizeof(sDateTime), "%Y-%m-%d %H:%M:%S");
GetClientName(client, sName, sizeof(sName));
GetClientAuthId(client, AuthId_Steam2, sSteamID, sizeof(sSteamID));
GetClientAuthId(client, AuthId_SteamID64, sProfileURL, sizeof(sProfileURL));
Format(sProfileURL, sizeof(sProfileURL), "https://steamcommunity.com/profiles/%s", sProfileURL);
GetClientName(client, sName, sizeof(sName));
char sMsg[512];
Format(sMsg, sizeof(sMsg), "[Demo Check] %t", sName, sSteamID, sProfileURL, sDateTime);
Handle file = OpenFile("democheck.log", "a");
WriteFileLine(file, sMsg);
CloseHandle(file);
}
KickClient(client, "[Demo Check] %t", "kicked");
return Plugin_Stop;
}
6 changes: 6 additions & 0 deletions translations/demo_check.phrases.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,10 @@
"#format" "{1:s},{2:s},{3:s},{4:s},{5:s}"
"en" "[{1} ({2})]({3}) failed the demo check at {4} - `{5}`"
}

"logs_democheck"
{
"#format" "{1:s},{2:s},{3:s},{4:s}"
"en" "{4} - {1} ({2}) [{3}] failed the demo check"
}
}

0 comments on commit 87aad32

Please sign in to comment.