fixed a serious potential bug with swapping plugins to debug mode, leaving stale function pointers without plugin removal
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 RootConsoleMenu::RootConsoleMenu()
22 m_pCommands = sm_trie_create();
25 RootConsoleMenu::~RootConsoleMenu()
27 sm_trie_destroy(m_pCommands);
29 List<ConsoleEntry *>::iterator iter;
30 for (iter=m_Menu.begin(); iter!=m_Menu.end(); iter++)
37 void RootConsoleMenu::OnSourceModStartup(bool late)
39 ConCommandBaseMgr::OneTimeInit(this);
40 AddRootConsoleCommand("version", "Display version information", this);
41 AddRootConsoleCommand("credits", "Display credits listing", this);
44 void RootConsoleMenu::OnSourceModShutdown()
46 RemoveRootConsoleCommand("credits", this);
47 RemoveRootConsoleCommand("version", this);
50 bool RootConsoleMenu::RegisterConCommandBase(ConCommandBase *pCommand)
52 META_REGCVAR(pCommand);
57 void RootConsoleMenu::ConsolePrint(const char *fmt, ...)
63 size_t len = vsnprintf(buffer, sizeof(buffer), fmt, ap);
66 if (len >= sizeof(buffer) - 1)
75 META_CONPRINT(buffer);
78 bool RootConsoleMenu::AddRootConsoleCommand(const char *cmd, const char *text, IRootConsoleCommand *pHandler)
80 if (sm_trie_retrieve(m_pCommands, cmd, NULL))
85 sm_trie_insert(m_pCommands, cmd, pHandler);
87 /* Sort this into the menu */
88 List<ConsoleEntry *>::iterator iter = m_Menu.begin();
90 bool inserted = false;
91 while (iter != m_Menu.end())
94 if (strcmp(cmd, pEntry->command.c_str()) < 0)
96 ConsoleEntry *pNew = new ConsoleEntry;
97 pNew->command.assign(cmd);
98 pNew->description.assign(text);
99 m_Menu.insert(iter, pNew);
108 ConsoleEntry *pNew = new ConsoleEntry;
109 pNew->command.assign(cmd);
110 pNew->description.assign(text);
111 m_Menu.push_back(pNew);
117 bool RootConsoleMenu::RemoveRootConsoleCommand(const char *cmd, IRootConsoleCommand *pHandler)
120 IRootConsoleCommand *object;
121 if (sm_trie_retrieve(m_pCommands, cmd, (void **)&object))
123 if (object != pHandler)
131 sm_trie_delete(m_pCommands, cmd);
133 List<ConsoleEntry *>::iterator iter;
134 ConsoleEntry *pEntry;
135 for (iter=m_Menu.begin(); iter!=m_Menu.end(); iter++)
138 if (pEntry->command.compare(cmd) == 0)
149 void RootConsoleMenu::DrawGenericOption(const char *cmd, const char *text)
152 size_t len, cmdlen = strlen(cmd);
154 len = snprintf(buffer, sizeof(buffer), " %s", cmd);
157 size_t num = 16 - cmdlen;
158 for (size_t i = 0; i < num; i++)
162 len += snprintf(&buffer[len], sizeof(buffer) - len, " - %s", text);
163 ConsolePrint("%s", buffer);
167 void RootConsoleMenu::GotRootCmd()
169 unsigned int argnum = GetArgumentCount();
173 const char *cmd = GetArgument(1);
174 IRootConsoleCommand *pHandler;
175 if (sm_trie_retrieve(m_pCommands, cmd, (void **)&pHandler))
177 pHandler->OnRootConsoleCommand(cmd, argnum);
182 ConsolePrint("SourceMod Menu:");
183 ConsolePrint("Usage: sm <command> [arguments]");
185 List<ConsoleEntry *>::iterator iter;
186 ConsoleEntry *pEntry;
187 for (iter=m_Menu.begin(); iter!=m_Menu.end(); iter++)
190 DrawGenericOption(pEntry->command.c_str(), pEntry->description.c_str());
194 const char *RootConsoleMenu::GetArgument(unsigned int argno)
196 return engine->Cmd_Argv(argno);
199 const char *RootConsoleMenu::GetArguments()
201 return engine->Cmd_Args();
204 unsigned int RootConsoleMenu::GetArgumentCount()
206 return engine->Cmd_Argc();
209 void RootConsoleMenu::OnRootConsoleCommand(const char *cmd, unsigned int argcount)
211 if (strcmp(cmd, "credits") == 0)
213 ConsolePrint(" SourceMod was developed by AlliedModders, LLC.");
214 ConsolePrint(" Development would not have been possible without the following people:");
215 ConsolePrint(" David \"BAILOPAN\" Anderson, lead developer");
216 ConsolePrint(" Borja \"faluco\" Ferrer, Core developer");
217 ConsolePrint(" Scott \"Damaged Soul\" Ehlert, SourceMM developer");
218 ConsolePrint(" Pavol \"PM OnoTo\" Marko, SourceHook developer");
219 ConsolePrint(" Special thanks to Viper of GameConnect");
220 ConsolePrint(" Special thanks to Mani of Mani-Admin-Plugin");
221 ConsolePrint(" http://www.sourcemod.net/");
222 } else if (strcmp(cmd, "version") == 0) {
223 ConsolePrint(" SourceMod Version Information:");
224 ConsolePrint(" SourceMod Version: %s", SOURCEMOD_VERSION);
225 ConsolePrint(" JIT Version: %s, %s", g_pVM->GetVMName(), g_pVM->GetVersionString());
226 ConsolePrint(" JIT Settings: %s", g_pVM->GetCPUOptimizations());
227 ConsolePrint(" http://www.sourcemod.net/");
231 CON_COMMAND(sm, "SourceMod Menu")
233 g_RootMenu.GotRootCmd();