1 #include "sm_srvcmds.h"
2 #include "sm_version.h"
3 #include "sm_stringutil.h"
5 RootConsoleMenu g_RootMenu;
7 RootConsoleMenu::RootConsoleMenu()
9 m_pCommands = sm_trie_create();
12 RootConsoleMenu::~RootConsoleMenu()
14 sm_trie_destroy(m_pCommands);
16 List<ConsoleEntry *>::iterator iter;
17 for (iter=m_Menu.begin(); iter!=m_Menu.end(); iter++)
24 void RootConsoleMenu::OnSourceModStartup(bool late)
26 ConCommandBaseMgr::OneTimeInit(this);
27 AddRootConsoleCommand("version", "Display version information", this);
28 AddRootConsoleCommand("credits", "Display credits listing", this);
31 void RootConsoleMenu::OnSourceModShutdown()
33 RemoveRootConsoleCommand("credits", this);
34 RemoveRootConsoleCommand("version", this);
37 bool RootConsoleMenu::RegisterConCommandBase(ConCommandBase *pCommand)
39 META_REGCVAR(pCommand);
44 void RootConsoleMenu::ConsolePrint(const char *fmt, ...)
50 size_t len = vsnprintf(buffer, sizeof(buffer), fmt, ap);
53 if (len >= sizeof(buffer) - 1)
62 META_CONPRINT(buffer);
65 bool RootConsoleMenu::AddRootConsoleCommand(const char *cmd, const char *text, IRootConsoleCommand *pHandler)
67 if (sm_trie_retrieve(m_pCommands, cmd, NULL))
72 sm_trie_insert(m_pCommands, cmd, pHandler);
74 /* Sort this into the menu */
75 List<ConsoleEntry *>::iterator iter = m_Menu.begin();
77 bool inserted = false;
78 while (iter != m_Menu.end())
81 if (strcmp(cmd, pEntry->command.c_str()) < 0)
83 ConsoleEntry *pNew = new ConsoleEntry;
84 pNew->command.assign(cmd);
85 pNew->description.assign(text);
86 m_Menu.insert(iter, pNew);
95 ConsoleEntry *pNew = new ConsoleEntry;
96 pNew->command.assign(cmd);
97 pNew->description.assign(text);
98 m_Menu.push_back(pNew);
104 bool RootConsoleMenu::RemoveRootConsoleCommand(const char *cmd, IRootConsoleCommand *pHandler)
107 IRootConsoleCommand *object;
108 if (sm_trie_retrieve(m_pCommands, cmd, (void **)&object))
110 if (object != pHandler)
118 sm_trie_delete(m_pCommands, cmd);
120 List<ConsoleEntry *>::iterator iter;
121 ConsoleEntry *pEntry;
122 for (iter=m_Menu.begin(); iter!=m_Menu.end(); iter++)
125 if (pEntry->command.compare(cmd) == 0)
136 void RootConsoleMenu::DrawGenericOption(const char *cmd, const char *text)
139 size_t len, cmdlen = strlen(cmd);
141 len = snprintf(buffer, sizeof(buffer), " %s", cmd);
144 size_t num = 16 - cmdlen;
145 for (size_t i = 0; i < num; i++)
149 len += snprintf(&buffer[len], sizeof(buffer) - len, " - %s", text);
150 ConsolePrint("%s", buffer);
154 void RootConsoleMenu::GotRootCmd()
156 unsigned int argnum = GetArgumentCount();
160 const char *cmd = GetArgument(1);
161 IRootConsoleCommand *pHandler;
162 if (sm_trie_retrieve(m_pCommands, cmd, (void **)&pHandler))
164 pHandler->OnRootConsoleCommand(cmd, argnum);
169 ConsolePrint("SourceMod Menu:");
170 ConsolePrint("Usage: sm <command> [arguments]");
172 List<ConsoleEntry *>::iterator iter;
173 ConsoleEntry *pEntry;
174 for (iter=m_Menu.begin(); iter!=m_Menu.end(); iter++)
177 DrawGenericOption(pEntry->command.c_str(), pEntry->description.c_str());
181 const char *RootConsoleMenu::GetArgument(unsigned int argno)
183 return engine->Cmd_Argv(argno);
186 const char *RootConsoleMenu::GetArguments()
188 return engine->Cmd_Args();
191 unsigned int RootConsoleMenu::GetArgumentCount()
193 return engine->Cmd_Argc();
196 void RootConsoleMenu::OnRootConsoleCommand(const char *cmd, unsigned int argcount)
198 if (strcmp(cmd, "credits") == 0)
200 ConsolePrint(" SourceMod was developed by AlliedModders, LLC.");
201 ConsolePrint(" Development would not have been possible without the following people:");
202 ConsolePrint(" David \"BAILOPAN\" Anderson, lead developer");
203 ConsolePrint(" Borja \"faluco\" Ferrer, Core developer");
204 ConsolePrint(" Scott \"Damaged Soul\" Ehlert, SourceMM developer");
205 ConsolePrint(" Pavol \"PM OnoTo\" Marko, SourceHook developer");
206 ConsolePrint(" Special thanks to Viper of GameConnect");
207 ConsolePrint(" Special thanks to Mani of Mani-Admin-Plugin");
208 ConsolePrint(" http://www.sourcemod.net/");
209 } else if (strcmp(cmd, "version") == 0) {
210 ConsolePrint(" SourceMod Version Information:");
211 ConsolePrint(" SourceMod Version: %s", SOURCEMOD_VERSION);
212 ConsolePrint(" JIT Version: %s, %s", g_pVM->GetVMName(), g_pVM->GetVersionString());
213 ConsolePrint(" JIT Settings: %s", g_pVM->GetCPUOptimizations());
214 ConsolePrint(" http://www.sourcemod.net/");
218 CON_COMMAND(sm, "SourceMod Menu")
220 g_RootMenu.GotRootCmd();