├── .vscode └── tasks.json ├── README.md ├── plugins └── .gitignore ├── scripting └── auto_cmd_on_update.sp └── translations └── acou.phrases.txt /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0.0", 3 | "options": 4 | { 5 | "env": 6 | { 7 | "sm_path": "/home/dev/sourcemod/scripting" 8 | } 9 | }, 10 | "tasks": 11 | [ 12 | { 13 | "label": "sourcepawn", 14 | "type": "shell", 15 | "command": "$sm_path/spcomp64 ${file} -D ${workspaceFolder}/plugins -i ${workspaceFolder}/scripting/include -i $sm_path/include" 16 | } 17 | ] 18 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Auto Command On Update 2 | ## Description 3 | A SourceMod plugin that executes a console command on SRCDS servers when a game update is detected. This plugins relies on a forward call in SteamWork's Update Check plugin [here](https://github.com/KyleSanderson/SteamWorks/blob/master/Pawn/UpdateCheck.sp). Therefore, you will need the plugin and SteamWorks for this plugin to operate. 4 | 5 | Additionally, a warning timer is supported. 6 | 7 | This works great for servers that automatically check for SteamCMD updates on startup. This would essentially enable automatic game updating for your game servers. 8 | 9 | ## Requirements 10 | * [SteamWorks](https://forums.alliedmods.net/showthread.php?t=229556) 11 | * [SteamWorks - Update Check](https://github.com/KyleSanderson/SteamWorks/blob/master/Pawn/UpdateCheck.sp) 12 | 13 | For compiling the plugin, you need SteamWork's include file (`SteamWorks.inc`) alongside [MultiColors](https://forums.alliedmods.net/showthread.php?t=247770). 14 | 15 | ## ConVars 16 | * `sm_acou_command` - The command to execute when a game update is detected (Default - `quit`). 17 | * `sm_acou_warn_time` - Warning time in seconds before command is executed when an update is detected (Default - `10`). 18 | * `sm_acou_version` - The plugin's current version. 19 | 20 | ## Commands 21 | * `sm_acou_print_version` - Prints the current plugin's version to the server console. 22 | * `sm_acou_test` - Executes the command when an update is detected and includes the warning time. 23 | 24 | **Note** - Both commands require the `root` flag. 25 | 26 | ## Installation 27 | 1. Compile plugin with `spcomp(64)` or `compile` executable within SourceMod's `scripting/` directory. 28 | 1. Copy `auto_cmd_on_update.smx` file into `sourcemod/plugins` directory. 29 | 1. Copy `translations/acou.phrases.txt` file into `sourcemod/` directory. 30 | 31 | ## Credits 32 | * [Christian Deacon](https://github.com/gamemann) -------------------------------------------------------------------------------- /plugins/.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore everything in this directory 2 | * 3 | # Except this file 4 | !.gitignore -------------------------------------------------------------------------------- /scripting/auto_cmd_on_update.sp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include 5 | 6 | #define PLUGIN_VERSION "1.0.0" 7 | 8 | ConVar g_cvCommand = null; 9 | ConVar g_cvWarnTime = null; 10 | ConVar g_cvVersion = null; 11 | 12 | int g_iCountDown = 0; 13 | 14 | public Plugin myinfo = 15 | { 16 | name = "Auto Command On Update", 17 | author = "Christian Deacon", 18 | description = "Executes a command when a game update is detected.", 19 | version = PLUGIN_VERSION, 20 | url = "moddingcommunity.com" 21 | }; 22 | 23 | public void OnPluginStart() 24 | { 25 | g_cvCommand = CreateConVar("sm_acou_command", "quit", "The command to execute when a game update is detected."); 26 | g_cvWarnTime = CreateConVar("sm_acou_warn_time", "10", "Warning time in seconds before command is executed when an update is detected."); 27 | g_cvVersion = CreateConVar("sm_acou_version", PLUGIN_VERSION, "Current version of plugin."); 28 | 29 | RegAdminCmd("sm_acou_print_version", Command_Version, ADMFLAG_ROOT); 30 | RegAdminCmd("sm_acou_test", Command_Test, ADMFLAG_ROOT); 31 | 32 | LoadTranslations("acou.phrases"); 33 | 34 | AutoExecConfig(true, "acou.plugin"); 35 | } 36 | 37 | public Action Command_Version(int iClient, int iArgs) 38 | { 39 | // Retrieve version from CVAR. 40 | char sVersion[MAX_NAME_LENGTH]; 41 | GetConVarString(g_cvVersion, sVersion, sizeof(sVersion)); 42 | 43 | PrintToServer("[ACOU] Version %s", sVersion); 44 | 45 | return Plugin_Handled; 46 | } 47 | 48 | public Action Command_Test(int iClient, int iArgs) 49 | { 50 | CReplyToCommand(iClient, "%t%t", "Tag", "TestReply"); 51 | 52 | UpdateDetected(); 53 | 54 | return Plugin_Handled; 55 | } 56 | 57 | public Action SteamWorks_RestartRequested() 58 | { 59 | UpdateDetected(); 60 | } 61 | 62 | public Action Timer_Warning(Handle hTimer) 63 | { 64 | // Check if we should execute the command and stop this timer. 65 | if (g_iCountDown >= g_cvWarnTime.IntValue) 66 | { 67 | ExecCmd(); 68 | 69 | return Plugin_Stop; 70 | } 71 | 72 | CPrintToChatAll("%t%t", "Tag", "WarnMsg", (g_cvWarnTime.IntValue - g_iCountDown)); 73 | 74 | g_iCountDown++; 75 | 76 | return Plugin_Continue; 77 | } 78 | 79 | stock void UpdateDetected() 80 | { 81 | // Check if we have warning time. 82 | if (g_cvWarnTime.IntValue > 0) 83 | { 84 | CreateTimer(1.0, Timer_Warning, _, TIMER_REPEAT | TIMER_FLAG_NO_MAPCHANGE); 85 | } 86 | else 87 | { 88 | ExecCmd(); 89 | } 90 | } 91 | 92 | stock void ExecCmd() 93 | { 94 | char sCmd[256]; 95 | GetConVarString(g_cvCommand, sCmd, sizeof(sCmd)); 96 | 97 | ServerCommand(sCmd); 98 | } -------------------------------------------------------------------------------- /translations/acou.phrases.txt: -------------------------------------------------------------------------------- 1 | "Phrases" 2 | { 3 | "Tag" 4 | { 5 | "en" "{lightgreen}[ACOU]" 6 | } 7 | 8 | "WarnMsg" 9 | { 10 | "#format" "{1:d}" 11 | "en" "{default} Game update detected. Restarting server in {lightgreen}{1} {default}seconds!" 12 | } 13 | 14 | "TestReply" 15 | { 16 | "en" "{default} Testing Auto Command On Update..." 17 | } 18 | } --------------------------------------------------------------------------------