From 38a8e8ac8074da8b537e21e2080d19111cb128ed Mon Sep 17 00:00:00 2001 From: David Anderson Date: Thu, 13 Sep 2007 17:21:41 +0000 Subject: [PATCH] added amb919 - GetExtensionFileStatus() --HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401425 --- core/smn_core.cpp | 30 ++++++++++++++++++++++++++++++ plugins/include/sourcemod.inc | 14 ++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/core/smn_core.cpp b/core/smn_core.cpp index 766fc197..ce51b9fc 100644 --- a/core/smn_core.cpp +++ b/core/smn_core.cpp @@ -41,6 +41,7 @@ #include "TimerSys.h" #include "ForwardSys.h" #include "Logger.h" +#include "ExtensionSys.h" #if defined PLATFORM_WINDOWS #include @@ -549,6 +550,33 @@ static cell_t LogToFileEx(IPluginContext *pContext, const cell_t *params) return 1; } +static cell_t GetExtensionFileStatus(IPluginContext *pContext, const cell_t *params) +{ + char *str; + pContext->LocalToString(params[1], &str); + + IExtension *pExtension = g_Extensions.FindExtensionByFile(str); + + if (!pExtension) + { + return -2; + } + + if (!pExtension->IsLoaded()) + { + return -1; + } + + char *error; + pContext->LocalToString(params[2], &error); + if (!pExtension->IsRunning(error, params[3])) + { + return 0; + } + + return 1; +} + REGISTER_NATIVES(coreNatives) { {"AutoExecConfig", AutoExecConfig}, @@ -570,5 +598,7 @@ REGISTER_NATIVES(coreNatives) {"LogAction", sm_LogAction}, {"LogToFile", LogToFile}, {"LogToFileEx", LogToFileEx}, + {"GetExtensionFileStatus", GetExtensionFileStatus}, {NULL, NULL}, }; + diff --git a/plugins/include/sourcemod.inc b/plugins/include/sourcemod.inc index 9496a6ca..193a4f57 100644 --- a/plugins/include/sourcemod.inc +++ b/plugins/include/sourcemod.inc @@ -452,6 +452,19 @@ native RegPluginLibrary(const String:name[]); */ native bool:LibraryExists(const String:name[]); +/** + * Returns the status of an extension, by filename. + * + * @param name Extension name (like "sdktools.ext"). + * @param error Optional error message buffer. + * @param maxlength Length of optional error message buffer. + * @return -2 if the extension was not found. + * -1 if the extension was found but failed to load. + * 0 if the extension loaded but reported an error. + * 1 if the extension is running without error. + */ +native GetExtensionFileStatus(const String:name[], String:error[]="", maxlength=0); + /** * Called after a library (plugin) is added that the * current plugin references optionally. @@ -470,3 +483,4 @@ forward OnLibraryRemoved(const String:name[]); #include #include +