2006-12-16 03:16:21 +01:00
|
|
|
#include "sm_srvcmds.h"
|
2007-01-05 14:23:25 +01:00
|
|
|
#include "sm_version.h"
|
2007-01-07 02:30:28 +01:00
|
|
|
#include "sm_stringutil.h"
|
2006-12-16 03:16:21 +01:00
|
|
|
|
2007-01-17 07:49:59 +01:00
|
|
|
RootConsoleMenu g_RootMenu;
|
2006-12-16 03:16:21 +01:00
|
|
|
|
2007-01-17 07:49:59 +01:00
|
|
|
RootConsoleMenu::RootConsoleMenu()
|
2006-12-16 03:16:21 +01:00
|
|
|
{
|
2007-01-17 07:49:59 +01:00
|
|
|
m_pCommands = sm_trie_create();
|
2006-12-16 03:16:21 +01:00
|
|
|
}
|
|
|
|
|
2007-01-17 07:49:59 +01:00
|
|
|
RootConsoleMenu::~RootConsoleMenu()
|
|
|
|
{
|
|
|
|
sm_trie_destroy(m_pCommands);
|
|
|
|
|
|
|
|
List<ConsoleEntry *>::iterator iter;
|
|
|
|
for (iter=m_Menu.begin(); iter!=m_Menu.end(); iter++)
|
|
|
|
{
|
|
|
|
delete (*iter);
|
|
|
|
}
|
|
|
|
m_Menu.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void RootConsoleMenu::OnSourceModStartup(bool late)
|
|
|
|
{
|
|
|
|
ConCommandBaseMgr::OneTimeInit(this);
|
|
|
|
AddRootConsoleCommand("version", "Display version information", this);
|
|
|
|
AddRootConsoleCommand("credits", "Display credits listing", this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RootConsoleMenu::OnSourceModShutdown()
|
|
|
|
{
|
|
|
|
RemoveRootConsoleCommand("credits", this);
|
|
|
|
RemoveRootConsoleCommand("version", this);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RootConsoleMenu::RegisterConCommandBase(ConCommandBase *pCommand)
|
2006-12-16 03:16:21 +01:00
|
|
|
{
|
|
|
|
META_REGCVAR(pCommand);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2007-01-17 07:49:59 +01:00
|
|
|
void RootConsoleMenu::ConsolePrint(const char *fmt, ...)
|
2006-12-16 03:16:21 +01:00
|
|
|
{
|
2007-01-17 07:49:59 +01:00
|
|
|
char buffer[512];
|
2006-12-16 03:16:21 +01:00
|
|
|
|
2007-01-17 07:49:59 +01:00
|
|
|
va_list ap;
|
|
|
|
va_start(ap, fmt);
|
|
|
|
size_t len = vsnprintf(buffer, sizeof(buffer), fmt, ap);
|
|
|
|
va_end(ap);
|
2006-12-16 03:16:21 +01:00
|
|
|
|
2007-01-19 06:33:04 +01:00
|
|
|
if (len >= sizeof(buffer) - 1)
|
2007-01-17 07:49:59 +01:00
|
|
|
{
|
|
|
|
buffer[510] = '\n';
|
|
|
|
buffer[511] = '\0';
|
|
|
|
} else {
|
|
|
|
buffer[len++] = '\n';
|
|
|
|
buffer[len] = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
META_CONPRINT(buffer);
|
|
|
|
}
|
2006-12-16 03:16:21 +01:00
|
|
|
|
2007-01-17 07:49:59 +01:00
|
|
|
bool RootConsoleMenu::AddRootConsoleCommand(const char *cmd, const char *text, IRootConsoleCommand *pHandler)
|
|
|
|
{
|
|
|
|
if (sm_trie_retrieve(m_pCommands, cmd, NULL))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2006-12-16 03:16:21 +01:00
|
|
|
|
2007-01-17 07:49:59 +01:00
|
|
|
sm_trie_insert(m_pCommands, cmd, pHandler);
|
2006-12-16 03:16:21 +01:00
|
|
|
|
2007-01-17 07:49:59 +01:00
|
|
|
/* Sort this into the menu */
|
|
|
|
List<ConsoleEntry *>::iterator iter = m_Menu.begin();
|
|
|
|
ConsoleEntry *pEntry;
|
|
|
|
bool inserted = false;
|
|
|
|
while (iter != m_Menu.end())
|
|
|
|
{
|
|
|
|
pEntry = (*iter);
|
|
|
|
if (strcmp(cmd, pEntry->command.c_str()) < 0)
|
|
|
|
{
|
|
|
|
ConsoleEntry *pNew = new ConsoleEntry;
|
|
|
|
pNew->command.assign(cmd);
|
|
|
|
pNew->description.assign(text);
|
|
|
|
m_Menu.insert(iter, pNew);
|
|
|
|
inserted = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
iter++;
|
|
|
|
}
|
2006-12-16 03:16:21 +01:00
|
|
|
|
2007-01-17 07:49:59 +01:00
|
|
|
if (!inserted)
|
|
|
|
{
|
|
|
|
ConsoleEntry *pNew = new ConsoleEntry;
|
|
|
|
pNew->command.assign(cmd);
|
|
|
|
pNew->description.assign(text);
|
|
|
|
m_Menu.push_back(pNew);
|
|
|
|
}
|
2006-12-16 03:16:21 +01:00
|
|
|
|
2007-01-17 07:49:59 +01:00
|
|
|
return true;
|
|
|
|
}
|
2006-12-16 03:16:21 +01:00
|
|
|
|
2007-01-17 07:49:59 +01:00
|
|
|
bool RootConsoleMenu::RemoveRootConsoleCommand(const char *cmd, IRootConsoleCommand *pHandler)
|
|
|
|
{
|
|
|
|
/* Sanity tests */
|
|
|
|
IRootConsoleCommand *object;
|
|
|
|
if (sm_trie_retrieve(m_pCommands, cmd, (void **)&object))
|
|
|
|
{
|
|
|
|
if (object != pHandler)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2006-12-16 03:16:21 +01:00
|
|
|
|
2007-01-17 07:49:59 +01:00
|
|
|
sm_trie_delete(m_pCommands, cmd);
|
2006-12-16 03:16:21 +01:00
|
|
|
|
2007-01-17 07:49:59 +01:00
|
|
|
List<ConsoleEntry *>::iterator iter;
|
|
|
|
ConsoleEntry *pEntry;
|
|
|
|
for (iter=m_Menu.begin(); iter!=m_Menu.end(); iter++)
|
|
|
|
{
|
|
|
|
pEntry = (*iter);
|
|
|
|
if (pEntry->command.compare(cmd) == 0)
|
|
|
|
{
|
|
|
|
delete pEntry;
|
|
|
|
m_Menu.erase(iter);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2006-12-17 21:33:31 +01:00
|
|
|
|
2007-01-17 07:49:59 +01:00
|
|
|
return true;
|
|
|
|
}
|
2006-12-16 03:16:21 +01:00
|
|
|
|
2007-01-17 19:22:00 +01:00
|
|
|
void RootConsoleMenu::DrawGenericOption(const char *cmd, const char *text)
|
|
|
|
{
|
|
|
|
char buffer[255];
|
|
|
|
size_t len, cmdlen = strlen(cmd);
|
|
|
|
|
|
|
|
len = snprintf(buffer, sizeof(buffer), " %s", cmd);
|
|
|
|
if (cmdlen < 16)
|
|
|
|
{
|
|
|
|
size_t num = 16 - cmdlen;
|
|
|
|
for (size_t i = 0; i < num; i++)
|
|
|
|
{
|
|
|
|
buffer[len++] = ' ';
|
|
|
|
}
|
|
|
|
len += snprintf(&buffer[len], sizeof(buffer) - len, " - %s", text);
|
|
|
|
ConsolePrint("%s", buffer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-17 07:49:59 +01:00
|
|
|
void RootConsoleMenu::GotRootCmd()
|
|
|
|
{
|
|
|
|
unsigned int argnum = GetArgumentCount();
|
2006-12-16 03:16:21 +01:00
|
|
|
|
2007-01-17 07:49:59 +01:00
|
|
|
if (argnum >= 2)
|
|
|
|
{
|
|
|
|
const char *cmd = GetArgument(1);
|
|
|
|
IRootConsoleCommand *pHandler;
|
|
|
|
if (sm_trie_retrieve(m_pCommands, cmd, (void **)&pHandler))
|
|
|
|
{
|
|
|
|
pHandler->OnRootConsoleCommand(cmd, argnum);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2007-01-15 01:56:39 +01:00
|
|
|
|
2007-01-17 07:49:59 +01:00
|
|
|
ConsolePrint("SourceMod Menu:");
|
|
|
|
ConsolePrint("Usage: sm <command> [arguments]");
|
2007-01-15 01:56:39 +01:00
|
|
|
|
2007-01-17 07:49:59 +01:00
|
|
|
List<ConsoleEntry *>::iterator iter;
|
|
|
|
ConsoleEntry *pEntry;
|
|
|
|
for (iter=m_Menu.begin(); iter!=m_Menu.end(); iter++)
|
|
|
|
{
|
|
|
|
pEntry = (*iter);
|
2007-01-17 19:22:00 +01:00
|
|
|
DrawGenericOption(pEntry->command.c_str(), pEntry->description.c_str());
|
2007-01-17 07:49:59 +01:00
|
|
|
}
|
|
|
|
}
|
2007-01-15 01:56:39 +01:00
|
|
|
|
2007-01-17 07:49:59 +01:00
|
|
|
const char *RootConsoleMenu::GetArgument(unsigned int argno)
|
|
|
|
{
|
|
|
|
return engine->Cmd_Argv(argno);
|
|
|
|
}
|
2007-01-15 01:56:39 +01:00
|
|
|
|
2007-01-17 07:49:59 +01:00
|
|
|
const char *RootConsoleMenu::GetArguments()
|
|
|
|
{
|
|
|
|
return engine->Cmd_Args();
|
|
|
|
}
|
2007-01-15 01:56:39 +01:00
|
|
|
|
2007-01-17 07:49:59 +01:00
|
|
|
unsigned int RootConsoleMenu::GetArgumentCount()
|
|
|
|
{
|
|
|
|
return engine->Cmd_Argc();
|
|
|
|
}
|
2007-01-05 14:23:25 +01:00
|
|
|
|
2007-01-17 07:49:59 +01:00
|
|
|
void RootConsoleMenu::OnRootConsoleCommand(const char *cmd, unsigned int argcount)
|
|
|
|
{
|
|
|
|
if (strcmp(cmd, "credits") == 0)
|
|
|
|
{
|
|
|
|
ConsolePrint(" SourceMod was developed by AlliedModders, LLC.");
|
|
|
|
ConsolePrint(" Development would not have been possible without the following people:");
|
|
|
|
ConsolePrint(" David \"BAILOPAN\" Anderson, lead developer");
|
|
|
|
ConsolePrint(" Borja \"faluco\" Ferrer, Core developer");
|
|
|
|
ConsolePrint(" Scott \"Damaged Soul\" Ehlert, SourceMM developer");
|
|
|
|
ConsolePrint(" Pavol \"PM OnoTo\" Marko, SourceHook developer");
|
|
|
|
ConsolePrint(" Special thanks to Viper of GameConnect");
|
|
|
|
ConsolePrint(" Special thanks to Mani of Mani-Admin-Plugin");
|
|
|
|
ConsolePrint(" http://www.sourcemod.net/");
|
|
|
|
} else if (strcmp(cmd, "version") == 0) {
|
|
|
|
ConsolePrint(" SourceMod Version Information:");
|
|
|
|
ConsolePrint(" SourceMod Version: %s", SOURCEMOD_VERSION);
|
|
|
|
ConsolePrint(" JIT Version: %s, %s", g_pVM->GetVMName(), g_pVM->GetVersionString());
|
|
|
|
ConsolePrint(" JIT Settings: %s", g_pVM->GetCPUOptimizations());
|
|
|
|
ConsolePrint(" http://www.sourcemod.net/");
|
2006-12-16 03:16:21 +01:00
|
|
|
}
|
2007-01-17 07:49:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
CON_COMMAND(sm, "SourceMod Menu")
|
|
|
|
{
|
|
|
|
g_RootMenu.GotRootCmd();
|
2007-01-11 02:13:34 +01:00
|
|
|
}
|