Exposed extensions list to clients (bug 5221, r=asherkin).
authorRyan Stecker <voidedweasel@gmail.com>
Sun May 27 01:51:08 2012 +0100 (2012-05-27)
changeset 3511c9fd86b6bec3
parent 3510 c72cfe0c6a57
child 3512 688718339deb
Exposed extensions list to clients (bug 5221, r=asherkin).
core/ExtensionSys.cpp
core/ExtensionSys.h
core/PlayerManager.cpp
     1.1 --- a/core/ExtensionSys.cpp	Sun May 27 01:51:06 2012 +0100
     1.2 +++ b/core/ExtensionSys.cpp	Sun May 27 01:51:08 2012 +0100
     1.3 @@ -37,6 +37,7 @@
     1.4  #include "sourcemm_api.h"
     1.5  #include "sm_srvcmds.h"
     1.6  #include "sm_stringutil.h"
     1.7 +#include "PlayerManager.h"
     1.8  
     1.9  CExtensionManager g_Extensions;
    1.10  IdentityType_t g_ExtType;
    1.11 @@ -1284,6 +1285,94 @@
    1.12  	g_RootMenu.DrawGenericOption("unload", "Unload an extension");
    1.13  }
    1.14  
    1.15 +void CExtensionManager::ListExtensionsToClient(CPlayer *player, const CCommand &args)
    1.16 +{
    1.17 +	char buffer[256];
    1.18 +	int numExtensions = m_Libs.size();
    1.19 +	edict_t *edict = player->GetEdict();
    1.20 +	unsigned int id = 0;
    1.21 +	unsigned int start = 0;
    1.22 +
    1.23 +	if (!numExtensions)
    1.24 +	{
    1.25 +		ClientConsolePrint(edict, "[SM] No extensions found.");
    1.26 +		return;
    1.27 +	}
    1.28 +
    1.29 +	if (args.ArgC() > 2)
    1.30 +	{
    1.31 +		start = atoi(args.Arg(2));
    1.32 +	}
    1.33 +
    1.34 +	CExtension *ext;
    1.35 +	SourceHook::List<CExtension *>::iterator iter;
    1.36 +
    1.37 +	for (iter = m_Libs.begin();
    1.38 +		 iter != m_Libs.end();
    1.39 +		 iter++)
    1.40 +	{
    1.41 +		ext = (*iter);
    1.42 +
    1.43 +		char error[255];
    1.44 +		if (!ext->IsRunning(error, sizeof(error)))
    1.45 +		{
    1.46 +			continue;
    1.47 +		}
    1.48 +
    1.49 +		id++;
    1.50 +		if (id < start)
    1.51 +		{
    1.52 +			continue;
    1.53 +		}
    1.54 +
    1.55 +		if (id - start > 10)
    1.56 +		{
    1.57 +			break;
    1.58 +		}
    1.59 +
    1.60 +		IExtensionInterface *api = ext->GetAPI();
    1.61 +
    1.62 +		const char *name = api->GetExtensionName();
    1.63 +		const char *version = api->GetExtensionVerString();
    1.64 +		const char *author = api->GetExtensionAuthor();
    1.65 +		const char *description = api->GetExtensionDescription();
    1.66 +
    1.67 +		size_t len = UTIL_Format(buffer, sizeof(buffer), " \"%s\"", name);
    1.68 +
    1.69 +		if (version != NULL && IS_STR_FILLED(version))
    1.70 +		{
    1.71 +			len += UTIL_Format(&buffer[len], sizeof(buffer)-len, " (%s)", version);
    1.72 +		}
    1.73 +
    1.74 +		if (author != NULL && IS_STR_FILLED(author))
    1.75 +		{
    1.76 +			len += UTIL_Format(&buffer[len], sizeof(buffer)-len, " by %s", author);
    1.77 +		}
    1.78 +
    1.79 +		if (description != NULL && IS_STR_FILLED(description))
    1.80 +		{
    1.81 +			len += UTIL_Format(&buffer[len], sizeof(buffer)-len, ": %s", description);
    1.82 +		}
    1.83 +
    1.84 +
    1.85 +		ClientConsolePrint(edict, "%s", buffer);
    1.86 +	}
    1.87 +
    1.88 +	while (iter != m_Libs.end())
    1.89 +	{
    1.90 +		char error[255];
    1.91 +		if ((*iter)->IsRunning(error, sizeof(error)))
    1.92 +		{
    1.93 +			break;
    1.94 +		}
    1.95 +	}
    1.96 +
    1.97 +	if (iter != m_Libs.end())
    1.98 +	{
    1.99 +		ClientConsolePrint(edict, "To see more, type \"sm exts %d\"", id);
   1.100 +	}
   1.101 +}
   1.102 +
   1.103  CExtension *CExtensionManager::GetExtensionFromIdent(IdentityToken_t *ptr)
   1.104  {
   1.105  	if (ptr->type == g_ExtType)
     2.1 --- a/core/ExtensionSys.h	Sun May 27 01:51:06 2012 +0100
     2.2 +++ b/core/ExtensionSys.h	Sun May 27 01:51:08 2012 +0100
     2.3 @@ -45,6 +45,8 @@
     2.4  #include "PluginSys.h"
     2.5  #include "NativeOwner.h"
     2.6  
     2.7 +class CPlayer;
     2.8 +
     2.9  using namespace SourceMod;
    2.10  using namespace SourceHook;
    2.11  
    2.12 @@ -176,6 +178,8 @@
    2.13  	void CallOnCoreMapStart(edict_t *pEdictList, int edictCount, int clientMax);
    2.14  	void AddRawDependency(IExtension *ext, IdentityToken_t *other, void *iface);
    2.15  public:
    2.16 +	void ListExtensionsToClient(CPlayer *player, const CCommand &args);
    2.17 +public:
    2.18  	CExtension *GetExtensionFromIdent(IdentityToken_t *ptr);
    2.19  	void Shutdown();
    2.20  	CNativeOwner *GetNativeOwner(IExtension *pExt)
     3.1 --- a/core/PlayerManager.cpp	Sun May 27 01:51:06 2012 +0100
     3.2 +++ b/core/PlayerManager.cpp	Sun May 27 01:51:08 2012 +0100
     3.3 @@ -770,6 +770,11 @@
     3.4  			g_PluginSys.ListPluginsToClient(pPlayer, args);
     3.5  			RETURN_META(MRES_SUPERCEDE);
     3.6  		}
     3.7 +		else if (args.ArgC() > 1 && strcmp(args.Arg(1), "exts") == 0)
     3.8 +		{
     3.9 +			g_Extensions.ListExtensionsToClient(pPlayer, args);
    3.10 +			RETURN_META(MRES_SUPERCEDE);
    3.11 +		}
    3.12  		else if (args.ArgC() > 1 && strcmp(args.Arg(1), "credits") == 0)
    3.13  		{
    3.14  			ClientConsolePrint(pEntity,