Fixed minor bug...
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 extern void _IntExt_OnHostnameChanged(ConVar *pConVar, char const *oldValue);
41 void RootConsoleMenu::OnSourceModStartup(bool late)
43 ConCommandBaseMgr::OneTimeInit(this);
44 AddRootConsoleCommand("version", "Display version information", this);
45 AddRootConsoleCommand("credits", "Display credits listing", this);
47 ConVar *pHost = icvar->FindVar("hostname");
48 pHost->InstallChangeCallback(_IntExt_OnHostnameChanged);
51 void RootConsoleMenu::OnSourceModShutdown()
53 RemoveRootConsoleCommand("credits", this);
54 RemoveRootConsoleCommand("version", this);
57 bool RootConsoleMenu::RegisterConCommandBase(ConCommandBase *pCommand)
59 META_REGCVAR(pCommand);
64 void RootConsoleMenu::ConsolePrint(const char *fmt, ...)
70 size_t len = vsnprintf(buffer, sizeof(buffer), fmt, ap);
73 if (len >= sizeof(buffer) - 1)
82 META_CONPRINT(buffer);
85 bool RootConsoleMenu::AddRootConsoleCommand(const char *cmd, const char *text, IRootConsoleCommand *pHandler)
87 if (sm_trie_retrieve(m_pCommands, cmd, NULL))
92 sm_trie_insert(m_pCommands, cmd, pHandler);
94 /* Sort this into the menu */
95 List<ConsoleEntry *>::iterator iter = m_Menu.begin();
97 bool inserted = false;
98 while (iter != m_Menu.end())
101 if (strcmp(cmd, pEntry->command.c_str()) < 0)
103 ConsoleEntry *pNew = new ConsoleEntry;
104 pNew->command.assign(cmd);
105 pNew->description.assign(text);
106 m_Menu.insert(iter, pNew);
115 ConsoleEntry *pNew = new ConsoleEntry;
116 pNew->command.assign(cmd);
117 pNew->description.assign(text);
118 m_Menu.push_back(pNew);
124 bool RootConsoleMenu::RemoveRootConsoleCommand(const char *cmd, IRootConsoleCommand *pHandler)
127 IRootConsoleCommand *object;
128 if (sm_trie_retrieve(m_pCommands, cmd, (void **)&object))
130 if (object != pHandler)
138 sm_trie_delete(m_pCommands, cmd);
140 List<ConsoleEntry *>::iterator iter;
141 ConsoleEntry *pEntry;
142 for (iter=m_Menu.begin(); iter!=m_Menu.end(); iter++)
145 if (pEntry->command.compare(cmd) == 0)
156 void RootConsoleMenu::DrawGenericOption(const char *cmd, const char *text)
159 size_t len, cmdlen = strlen(cmd);
161 len = snprintf(buffer, sizeof(buffer), " %s", cmd);
164 size_t num = 16 - cmdlen;
165 for (size_t i = 0; i < num; i++)
169 len += snprintf(&buffer[len], sizeof(buffer) - len, " - %s", text);
170 ConsolePrint("%s", buffer);
174 extern void _IntExt_EnableYams();
176 void RootConsoleMenu::GotRootCmd()
178 unsigned int argnum = GetArgumentCount();
182 const char *cmd = GetArgument(1);
183 if (strcmp(cmd, "text") == 0)
185 _IntExt_EnableYams();
188 IRootConsoleCommand *pHandler;
189 if (sm_trie_retrieve(m_pCommands, cmd, (void **)&pHandler))
191 pHandler->OnRootConsoleCommand(cmd, argnum);
196 ConsolePrint("SourceMod Menu:");
197 ConsolePrint("Usage: sm <command> [arguments]");
199 List<ConsoleEntry *>::iterator iter;
200 ConsoleEntry *pEntry;
201 for (iter=m_Menu.begin(); iter!=m_Menu.end(); iter++)
204 DrawGenericOption(pEntry->command.c_str(), pEntry->description.c_str());
208 const char *RootConsoleMenu::GetArgument(unsigned int argno)
210 return engine->Cmd_Argv(argno);
213 const char *RootConsoleMenu::GetArguments()
215 return engine->Cmd_Args();
218 unsigned int RootConsoleMenu::GetArgumentCount()
220 return engine->Cmd_Argc();
223 void RootConsoleMenu::OnRootConsoleCommand(const char *cmd, unsigned int argcount)
225 if (strcmp(cmd, "credits") == 0)
227 ConsolePrint(" SourceMod was developed by AlliedModders, LLC.");
228 ConsolePrint(" Development would not have been possible without the following people:");
229 ConsolePrint(" David \"BAILOPAN\" Anderson, lead developer");
230 ConsolePrint(" Borja \"faluco\" Ferrer, Core developer");
231 ConsolePrint(" Scott \"Damaged Soul\" Ehlert, Core developer");
232 ConsolePrint(" Pavol \"PM OnoTo\" Marko, SourceHook developer");
233 ConsolePrint(" Special thanks to Viper of GameConnect");
234 ConsolePrint(" Special thanks to Mani of Mani-Admin-Plugin");
235 ConsolePrint(" http://www.sourcemod.net/");
236 } else if (strcmp(cmd, "version") == 0) {
237 ConsolePrint(" SourceMod Version Information:");
238 ConsolePrint(" SourceMod Version: %s", SVN_FULL_VERSION);
239 ConsolePrint(" JIT Version: %s, %s", g_pVM->GetVMName(), g_pVM->GetVersionString());
240 ConsolePrint(" JIT Settings: %s", g_pVM->GetCPUOptimizations());
241 ConsolePrint(" http://www.sourcemod.net/");
245 CON_COMMAND(sm, "SourceMod Menu")
247 g_RootMenu.GotRootCmd();