From dc06ac650169dc044bd4e388d11c89902c866f44 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Wed, 21 Feb 2007 22:05:25 +0000 Subject: [PATCH] added server command functions --HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40528 --- core/smn_console.cpp | 38 +++++++++++++++++++++++++++++++++++++ plugins/include/console.inc | 24 +++++++++++++++++++++++ 2 files changed, 62 insertions(+) diff --git a/core/smn_console.cpp b/core/smn_console.cpp index acc09148..e1277d71 100644 --- a/core/smn_console.cpp +++ b/core/smn_console.cpp @@ -477,6 +477,41 @@ static cell_t sm_PrintToConsole(IPluginContext *pCtx, const cell_t *params) return 1; } +static cell_t sm_ServerCommand(IPluginContext *pContext, const cell_t *params) +{ + char buffer[1024]; + size_t len = g_SourceMod.FormatString(buffer, sizeof(buffer)-2, pContext, params, 1); + + /* One byte for null terminator, one for newline */ + buffer[len++] = '\n'; + buffer[len] = '\0'; + + engine->ServerCommand(buffer); + + return 1; +} + +static cell_t sm_InsertServerCommand(IPluginContext *pContext, const cell_t *params) +{ + char buffer[1024]; + size_t len = g_SourceMod.FormatString(buffer, sizeof(buffer)-2, pContext, params, 1); + + /* One byte for null terminator, one for newline */ + buffer[len++] = '\n'; + buffer[len] = '\0'; + + engine->InsertServerCommand(buffer); + + return 1; +} + +static cell_t sm_ServerExecute(IPluginContext *pContext, const cell_t *params) +{ + engine->ServerExecute(); + + return 1; +} + REGISTER_NATIVES(consoleNatives) { {"CreateConVar", sm_CreateConVar}, @@ -505,5 +540,8 @@ REGISTER_NATIVES(consoleNatives) {"PrintToServer", sm_PrintToServer}, {"PrintToConsole", sm_PrintToConsole}, {"RegAdminCmd", sm_RegAdminCmd}, + {"ServerCommand", sm_ServerCommand}, + {"InsertServerCommand", sm_InsertServerCommand}, + {"ServerExecute", sm_ServerExecute}, {NULL, NULL} }; diff --git a/plugins/include/console.inc b/plugins/include/console.inc index 74e10906..9fa93148 100644 --- a/plugins/include/console.inc +++ b/plugins/include/console.inc @@ -52,6 +52,30 @@ #define FCVAR_NETWORKSYSTEM (1<<26) /**< Defined by the network system. */ #define FCVAR_VPHYSICS (1<<27) /**< Defined by vphysics. */ +/** + * Executes a server command as if it were on the server console (or RCON) + * + * @param format Formatting rules. + * @param ... Variable number of format parameters. + * @noreturn + */ +native ServerCommand(const String:format[], {Handle,Float,String,_}:...); + +/** + * Inserts a server command at the beginning of the server command buffer. + * + * @param format Formatting rules. + * @param ... Variable number of format parameters. + * @noreturn + */ +native InsertServerCommand(const String:format[], {Handle,Float,String,_}:...); + +/** + * Executes every command in the server's command buffer, rather than once per frame. + * + * @noreturn + */ +native ServerExecute(); /** * Sends a message to the server console.