From 643c39690f9343569a9f664f22a863eccbb11741 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Sun, 1 Feb 2009 02:33:31 -0500 Subject: [PATCH] Added client "sm", "sm credits", and "sm plugins" commands (bug 3570, r=ds,pred). --- core/PlayerManager.cpp | 55 +++++++++++++++++++++++++++++ core/PlayerManager.h | 2 ++ core/PluginSys.cpp | 80 ++++++++++++++++++++++++++++++++++++++++++ core/PluginSys.h | 4 +++ 4 files changed, 141 insertions(+) diff --git a/core/PlayerManager.cpp b/core/PlayerManager.cpp index eae89dd80..0e63d4d3c 100644 --- a/core/PlayerManager.cpp +++ b/core/PlayerManager.cpp @@ -47,6 +47,7 @@ #include #include "GameConfigs.h" #include "ExtensionSys.h" +#include "sm_version.h" PlayerManager g_Players; bool g_OnMapStarted = false; @@ -632,6 +633,27 @@ void PlayerManager::OnClientDisconnect_Post(edict_t *pEntity) } } +void ClientConsolePrint(edict_t *e, const char *fmt, ...) +{ + char buffer[512]; + + va_list ap; + va_start(ap, fmt); + size_t len = vsnprintf(buffer, sizeof(buffer), fmt, ap); + va_end(ap); + + if (len >= sizeof(buffer) - 1) + { + buffer[510] = '\n'; + buffer[511] = '\0'; + } else { + buffer[len++] = '\n'; + buffer[len] = '\0'; + } + + engine->ClientPrintf(e, buffer); +} + #if SOURCE_ENGINE >= SE_ORANGEBOX void PlayerManager::OnClientCommand(edict_t *pEntity, const CCommand &args) { @@ -649,6 +671,39 @@ void PlayerManager::OnClientCommand(edict_t *pEntity) return; } + if (strcmp(args.Arg(0), "sm") == 0) + { + if (args.ArgC() > 1 && strcmp(args.Arg(1), "plugins") == 0) + { + g_PluginSys.ListPluginsToClient(pPlayer, args); + RETURN_META(MRES_SUPERCEDE); + } + else if (args.ArgC() > 1 && strcmp(args.Arg(1), "credits") == 0) + { + ClientConsolePrint(pEntity, + "SourceMod would not be possible without:"); + ClientConsolePrint(pEntity, + " David \"BAILOPAN\" Anderson, Borja \"faluco\" Ferrer"); + ClientConsolePrint(pEntity, + " Scott \"Damaged Soul\" Ehlert, Matt \"pRED\" Woodrow"); + ClientConsolePrint(pEntity, + " Michael \"ferret\" McKoy, Pavol \"PM OnoTo\" Marko"); + ClientConsolePrint(pEntity, + "SourceMod is open source under the GNU General Public License."); + RETURN_META(MRES_SUPERCEDE); + } + + ClientConsolePrint(pEntity, + "SourceMod %s, by AlliedModders LLC", SVN_FULL_VERSION); + ClientConsolePrint(pEntity, + "To see running plugins, type \"sm plugins\""); + ClientConsolePrint(pEntity, + "To see credits, type \"sm credits\""); + ClientConsolePrint(pEntity, + "Visit http://www.sourcemod.net/"); + RETURN_META(MRES_SUPERCEDE); + } + g_HL2.PushCommandStack(&args); int argcount = args.ArgC() - 1; diff --git a/core/PlayerManager.h b/core/PlayerManager.h index 2c33ec0d3..5d568a701 100644 --- a/core/PlayerManager.h +++ b/core/PlayerManager.h @@ -210,6 +210,8 @@ void CmdMaxplayersCallback(const CCommand &command); void CmdMaxplayersCallback(); #endif +extern void ClientConsolePrint(edict_t *e, const char *fmt, ...); + extern PlayerManager g_Players; extern bool g_OnMapStarted; extern const unsigned int *g_NumPlayersToAuth; diff --git a/core/PluginSys.cpp b/core/PluginSys.cpp index 091a71c8f..86f6774ef 100644 --- a/core/PluginSys.cpp +++ b/core/PluginSys.cpp @@ -2624,3 +2624,83 @@ void CPluginManager::SyncMaxClients(int max_clients) (*iter)->SyncMaxClients(max_clients); } } + +void CPluginManager::ListPluginsToClient(CPlayer *player, const CCommand &args) +{ + char buffer[256]; + unsigned int id = 0; + int plnum = GetPluginCount(); + edict_t *e = player->GetEdict(); + unsigned int start = 0; + + if (!plnum) + { + ClientConsolePrint(e, "[SM] No plugins found."); + return; + } + + if (args.ArgC() > 2) + { + start = atoi(args.Arg(2)); + } + + CPlugin *pl; + SourceHook::List::iterator iter; + SourceHook::List m_FailList; + + for (iter = m_plugins.begin(); + iter != m_plugins.end(); + iter++) + { + pl = (*iter); + + if (pl->GetStatus() != Plugin_Running) + { + continue; + } + + /* Count valid plugins */ + id++; + if (id < start) + { + continue; + } + + if (id - start > 10) + { + break; + } + + size_t len; + const sm_plugininfo_t *info = pl->GetPublicInfo(); + len = UTIL_Format(buffer, sizeof(buffer), " \"%s\"", (IS_STR_FILLED(info->name)) ? info->name : pl->GetFilename()); + if (IS_STR_FILLED(info->version)) + { + len += UTIL_Format(&buffer[len], sizeof(buffer)-len, " (%s)", info->version); + } + if (IS_STR_FILLED(info->author)) + { + UTIL_Format(&buffer[len], sizeof(buffer)-len, " by %s", info->author); + } + else + { + UTIL_Format(&buffer[len], sizeof(buffer)-len, " %s", pl->m_filename); + } + ClientConsolePrint(e, "%s", buffer); + } + + /* See if we can get more plugins */ + while (iter != m_plugins.end()) + { + if ((*iter)->GetStatus() == Plugin_Running) + { + break; + } + } + + /* Do we actually have more plugins? */ + if (iter != m_plugins.end()) + { + ClientConsolePrint(e, "To see more, type \"sm plugins %d\"", id + 1); + } +} diff --git a/core/PluginSys.h b/core/PluginSys.h index 68d27e1e1..d40cff174 100644 --- a/core/PluginSys.h +++ b/core/PluginSys.h @@ -58,6 +58,8 @@ #include "NativeOwner.h" #include "ShareSys.h" +class CPlayer; + using namespace SourceHook; /** @@ -397,6 +399,8 @@ public: CPlugin *FindPluginByConsoleArg(const char *arg); void SyncMaxClients(int max_clients); + + void ListPluginsToClient(CPlayer *player, const CCommand &args); private: LoadRes _LoadPlugin(CPlugin **pPlugin, const char *path, bool debug, PluginType type, char error[], size_t maxlength);