Added client "sm", "sm credits", and "sm plugins" commands (bug 3570, r=ds,pred).
This commit is contained in:
parent
6048144310
commit
643c39690f
@ -47,6 +47,7 @@
|
||||
#include <iclient.h>
|
||||
#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;
|
||||
|
@ -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;
|
||||
|
@ -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<CPlugin *>::iterator iter;
|
||||
SourceHook::List<CPlugin *> 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);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user