From 7af40128a3f4387be2eabfa7718eef274c70ff5b Mon Sep 17 00:00:00 2001 From: David Anderson Date: Sun, 17 Dec 2006 09:59:01 +0000 Subject: [PATCH] Clarified states a little Fixed include order and double include prevention --HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40228 --- core/interfaces/IPluginSys.h | 2 ++ core/sm_srvcmds.cpp | 29 ++++++++++++++++------------- core/sm_srvcmds.h | 11 ++++++++--- 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/core/interfaces/IPluginSys.h b/core/interfaces/IPluginSys.h index fabf86c1..037cc33b 100644 --- a/core/interfaces/IPluginSys.h +++ b/core/interfaces/IPluginSys.h @@ -28,6 +28,8 @@ namespace SourceMod /** * @brief Describes the usability status of a plugin. + * Note: The status "Loaded" and "Created" are only reachable + * during map load. */ enum PluginStatus { diff --git a/core/sm_srvcmds.cpp b/core/sm_srvcmds.cpp index 451b34d0..8148c8f5 100644 --- a/core/sm_srvcmds.cpp +++ b/core/sm_srvcmds.cpp @@ -29,11 +29,11 @@ inline const char *StatusToStr(PluginStatus st) case Plugin_BadLoad: return "Bad Load"; default: + assert(false); return "-"; } } -#define IS_STR_FILLED(var) (var[0] != '\0') CON_COMMAND(sm, "SourceMod Menu") { int argnum = engine->Cmd_Argc(); @@ -69,12 +69,12 @@ CON_COMMAND(sm, "SourceMod Menu") const sm_plugininfo_t *info = pl->GetPublicInfo(); len += snprintf(&buffer[len], sizeof(buffer)-len, " %02d <%s>", id, StatusToStr(pl->GetStatus())); - len += snprintf(&buffer[len], sizeof(buffer)-len, " \"%s\"", (IS_STR_FILLED(info->name)) ? info->name : pl->GetFilename()); - if (IS_STR_FILLED(info->version)) + len += snprintf(&buffer[len], sizeof(buffer)-len, " \"%s\"", (info->name) ? info->name : iter->GetPlugin()->GetFilename()); + if (info->version) { len += snprintf(&buffer[len], sizeof(buffer)-len, " (%s)", info->version); } - if (IS_STR_FILLED(info->author)) + if (info->author) { snprintf(&buffer[len], sizeof(buffer)-len, " by %s", info->author); } @@ -102,6 +102,7 @@ CON_COMMAND(sm, "SourceMod Menu") } return; + } else if (!strcmp("unload", cmd2)) { if (argnum < 4) { @@ -109,6 +110,7 @@ CON_COMMAND(sm, "SourceMod Menu") return; } + IPlugin *pl = NULL; int id = 1; int num = atoi(engine->Cmd_Argv(3)); if (num < 1 || num > (int)g_PluginSys.GetPluginCount()) @@ -119,11 +121,11 @@ CON_COMMAND(sm, "SourceMod Menu") IPluginIterator *iter = g_PluginSys.GetPluginIterator(); for (; iter->MorePlugins() && idNextPlugin(), id++) {} - IPlugin *pl = iter->GetPlugin(); + pl = iter->GetPlugin(); char name[64]; const sm_plugininfo_t *info = pl->GetPublicInfo(); - strcpy(name, (IS_STR_FILLED(info->name)) ? info->name : pl->GetFilename()); + strcpy(name, (info->name) ? info->name : pl->GetFilename()); if (g_PluginSys.UnloadPlugin(pl)) { @@ -134,6 +136,7 @@ CON_COMMAND(sm, "SourceMod Menu") iter->Release(); return; + } else if (!strcmp("info", cmd2)) { if (argnum < 4) { @@ -141,6 +144,7 @@ CON_COMMAND(sm, "SourceMod Menu") return; } + IPlugin *pl = NULL; int id = 1; int num = atoi(engine->Cmd_Argv(3)); if (num < 1 || num > (int)g_PluginSys.GetPluginCount()) @@ -151,28 +155,27 @@ CON_COMMAND(sm, "SourceMod Menu") IPluginIterator *iter = g_PluginSys.GetPluginIterator(); for (; iter->MorePlugins() && idNextPlugin(), id++) {} - - IPlugin *pl = iter->GetPlugin(); + pl = iter->GetPlugin(); const sm_plugininfo_t *info = pl->GetPublicInfo(); META_CONPRINTF(" Filename: %s\n", pl->GetFilename()); - if (IS_STR_FILLED(info->name)) + if (info->name) { META_CONPRINTF(" Title: %s\n", info->name); } - if (IS_STR_FILLED(info->author)) + if (info->author) { META_CONPRINTF(" Author: %s\n", info->author); } - if (IS_STR_FILLED(info->version)) + if (info->version) { META_CONPRINTF(" Version: %s\n", info->version); } - if (IS_STR_FILLED(info->description)) + if (info->description) { META_CONPRINTF(" Description: %s\n", info->description); } - if (IS_STR_FILLED(info->url)) + if (info->url) { META_CONPRINTF(" URL: %s\n", info->url); } diff --git a/core/sm_srvcmds.h b/core/sm_srvcmds.h index 62670c3e..aa4ac340 100644 --- a/core/sm_srvcmds.h +++ b/core/sm_srvcmds.h @@ -1,7 +1,10 @@ -#include "sourcemm_api.h" -#include +#ifndef _INCLUDE_SOURCEMOD_SERVERCOMMANDS_H_ +#define _INCLUDE_SOURCEMOD_SERVERCOMMANDS_H_ + #include "sourcemod.h" #include "PluginSys.h" +#include "sourcemm_api.h" +#include using namespace SourceMod; @@ -13,4 +16,6 @@ public: // IConCommandBaseAccessor virtual bool RegisterConCommandBase(ConCommandBase *pCommand); public: // SMGlobalClass virtual void OnSourceModStartup(bool late); -}; \ No newline at end of file +}; + +#endif //_INCLUDE_SOURCEMOD_SERVERCOMMANDS_H_