2 * ===============================================================
3 * SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved.
4 * ===============================================================
6 * This file is not open source and may not be copied without explicit
7 * written permission of AlliedModders LLC. This file may not be redistributed
8 * in whole or significant part.
9 * For information, see LICENSE.txt or http://www.sourcemod.net/license.php
14 #include "sm_srvcmds.h"
15 #include "sm_version.h"
16 #include "sm_stringutil.h"
18 RootConsoleMenu g_RootMenu;
20 ConVar sourcemod_version("sourcemod_version", SVN_FULL_VERSION, FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY, "SourceMod Version");
22 RootConsoleMenu::RootConsoleMenu()
24 m_pCommands = sm_trie_create();
27 RootConsoleMenu::~RootConsoleMenu()
29 sm_trie_destroy(m_pCommands);
31 List<ConsoleEntry *>::iterator iter;
32 for (iter=m_Menu.begin(); iter!=m_Menu.end(); iter++)
39 void RootConsoleMenu::OnSourceModStartup(bool late)
41 ConCommandBaseMgr::OneTimeInit(this);
42 AddRootConsoleCommand("version", "Display version information", this);
43 AddRootConsoleCommand("credits", "Display credits listing", this);
46 void RootConsoleMenu::OnSourceModShutdown()
48 RemoveRootConsoleCommand("credits", this);
49 RemoveRootConsoleCommand("version", this);
52 bool RootConsoleMenu::RegisterConCommandBase(ConCommandBase *pCommand)
54 META_REGCVAR(pCommand);
59 void RootConsoleMenu::ConsolePrint(const char *fmt, ...)
65 size_t len = vsnprintf(buffer, sizeof(buffer), fmt, ap);
68 if (len >= sizeof(buffer) - 1)
77 META_CONPRINT(buffer);
80 bool RootConsoleMenu::AddRootConsoleCommand(const char *cmd, const char *text, IRootConsoleCommand *pHandler)
82 if (sm_trie_retrieve(m_pCommands, cmd, NULL))
87 sm_trie_insert(m_pCommands, cmd, pHandler);
89 /* Sort this into the menu */
90 List<ConsoleEntry *>::iterator iter = m_Menu.begin();
92 bool inserted = false;
93 while (iter != m_Menu.end())
96 if (strcmp(cmd, pEntry->command.c_str()) < 0)
98 ConsoleEntry *pNew = new ConsoleEntry;
99 pNew->command.assign(cmd);
100 pNew->description.assign(text);
101 m_Menu.insert(iter, pNew);
110 ConsoleEntry *pNew = new ConsoleEntry;
111 pNew->command.assign(cmd);
112 pNew->description.assign(text);
113 m_Menu.push_back(pNew);
119 bool RootConsoleMenu::RemoveRootConsoleCommand(const char *cmd, IRootConsoleCommand *pHandler)
122 IRootConsoleCommand *object;
123 if (sm_trie_retrieve(m_pCommands, cmd, (void **)&object))
125 if (object != pHandler)
133 sm_trie_delete(m_pCommands, cmd);
135 List<ConsoleEntry *>::iterator iter;
136 ConsoleEntry *pEntry;
137 for (iter=m_Menu.begin(); iter!=m_Menu.end(); iter++)
140 if (pEntry->command.compare(cmd) == 0)
151 void RootConsoleMenu::DrawGenericOption(const char *cmd, const char *text)
154 size_t len, cmdlen = strlen(cmd);
156 len = snprintf(buffer, sizeof(buffer), " %s", cmd);
159 size_t num = 16 - cmdlen;
160 for (size_t i = 0; i < num; i++)
164 len += snprintf(&buffer[len], sizeof(buffer) - len, " - %s", text);
165 ConsolePrint("%s", buffer);
169 void RootConsoleMenu::GotRootCmd()
171 unsigned int argnum = GetArgumentCount();
175 const char *cmd = GetArgument(1);
176 IRootConsoleCommand *pHandler;
177 if (sm_trie_retrieve(m_pCommands, cmd, (void **)&pHandler))
179 pHandler->OnRootConsoleCommand(cmd, argnum);
184 ConsolePrint("SourceMod Menu:");
185 ConsolePrint("Usage: sm <command> [arguments]");
187 List<ConsoleEntry *>::iterator iter;
188 ConsoleEntry *pEntry;
189 for (iter=m_Menu.begin(); iter!=m_Menu.end(); iter++)
192 DrawGenericOption(pEntry->command.c_str(), pEntry->description.c_str());
196 const char *RootConsoleMenu::GetArgument(unsigned int argno)
198 return engine->Cmd_Argv(argno);
201 const char *RootConsoleMenu::GetArguments()
203 return engine->Cmd_Args();
206 unsigned int RootConsoleMenu::GetArgumentCount()
208 return engine->Cmd_Argc();
211 void RootConsoleMenu::OnRootConsoleCommand(const char *cmd, unsigned int argcount)
213 if (strcmp(cmd, "credits") == 0)
215 ConsolePrint(" SourceMod was developed by AlliedModders, LLC.");
216 ConsolePrint(" Development would not have been possible without the following people:");
217 ConsolePrint(" David \"BAILOPAN\" Anderson, lead developer");
218 ConsolePrint(" Borja \"faluco\" Ferrer, Core developer");
219 ConsolePrint(" Scott \"Damaged Soul\" Ehlert, SourceMM developer");
220 ConsolePrint(" Pavol \"PM OnoTo\" Marko, SourceHook developer");
221 ConsolePrint(" Special thanks to Viper of GameConnect");
222 ConsolePrint(" Special thanks to Mani of Mani-Admin-Plugin");
223 ConsolePrint(" http://www.sourcemod.net/");
224 } else if (strcmp(cmd, "version") == 0) {
225 ConsolePrint(" SourceMod Version Information:");
226 ConsolePrint(" SourceMod Version: %s", SVN_FULL_VERSION);
227 ConsolePrint(" JIT Version: %s, %s", g_pVM->GetVMName(), g_pVM->GetVersionString());
228 ConsolePrint(" JIT Settings: %s", g_pVM->GetCPUOptimizations());
229 ConsolePrint(" http://www.sourcemod.net/");
233 CON_COMMAND(sm, "SourceMod Menu")
235 g_RootMenu.GotRootCmd();