Executable memory is now provided by MM:S's allocator, this should reduce virtual memory usage.
3 * =============================================================================
5 * Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved.
6 * =============================================================================
8 * This program is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU General Public License, version 3.0, as published by the
10 * Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 * You should have received a copy of the GNU General Public License along with
18 * this program. If not, see <http://www.gnu.org/licenses/>.
20 * As a special exception, AlliedModders LLC gives you permission to link the
21 * code of this program (as well as its derivative works) to "Half-Life 2," the
22 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
23 * by the Valve Corporation. You must obey the GNU General Public License in
24 * all respects for all other code used. Additionally, AlliedModders LLC grants
25 * this exception to all derivative works. AlliedModders LLC defines further
26 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
27 * or <http://www.sourcemod.net/license.php>.
32 #include "sm_srvcmds.h"
33 #include "sm_version.h"
34 #include "sm_stringutil.h"
35 #include "HandleSys.h"
36 #include "CoreConfig.h"
37 #include "ConVarManager.h"
40 RootConsoleMenu g_RootMenu;
42 ConVar sourcemod_version("sourcemod_version", SVN_FULL_VERSION, FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY, "SourceMod Version");
44 RootConsoleMenu::RootConsoleMenu()
46 m_pCommands = sm_trie_create();
47 m_CfgExecDone = false;
50 RootConsoleMenu::~RootConsoleMenu()
52 sm_trie_destroy(m_pCommands);
54 List<ConsoleEntry *>::iterator iter;
55 for (iter=m_Menu.begin(); iter!=m_Menu.end(); iter++)
62 extern void _IntExt_OnHostnameChanged(ConVar *var, const char *pOldValue, float flOldValue);
64 class DetectHostNameChanges : public IConVarChangeListener
67 void OnConVarChanged(ConVar *pConVar, const char *oldValue, float flOldValue)
69 _IntExt_OnHostnameChanged(pConVar, oldValue, flOldValue);
71 } s_HostnameChangeDetector;
73 void RootConsoleMenu::OnSourceModStartup(bool late)
75 #if defined ORANGEBOX_BUILD
78 CONVAR_REGISTER(this);
79 AddRootConsoleCommand("version", "Display version information", this);
80 AddRootConsoleCommand("credits", "Display credits listing", this);
83 void RootConsoleMenu::OnSourceModAllInitialized()
85 g_ConVarManager.AddConVarChangeListener("hostname", &s_HostnameChangeDetector);
86 g_ShareSys.AddInterface(NULL, this);
89 void RootConsoleMenu::OnSourceModShutdown()
91 g_ConVarManager.RemoveConVarChangeListener("hostname", &s_HostnameChangeDetector);
92 RemoveRootConsoleCommand("credits", this);
93 RemoveRootConsoleCommand("version", this);
96 bool RootConsoleMenu::RegisterConCommandBase(ConCommandBase *pCommand)
98 META_REGCVAR(pCommand);
100 /* Override values of convars created by SourceMod convar manager if specified on command line */
101 const char *cmdLineValue = icvar->GetCommandLineValue(pCommand->GetName());
102 if (cmdLineValue && !pCommand->IsCommand())
104 static_cast<ConVar *>(pCommand)->SetValue(cmdLineValue);
110 void RootConsoleMenu::ConsolePrint(const char *fmt, ...)
116 size_t len = vsnprintf(buffer, sizeof(buffer), fmt, ap);
119 if (len >= sizeof(buffer) - 1)
124 buffer[len++] = '\n';
128 META_CONPRINT(buffer);
131 bool RootConsoleMenu::AddRootConsoleCommand(const char *cmd, const char *text, IRootConsoleCommand *pHandler)
133 if (sm_trie_retrieve(m_pCommands, cmd, NULL))
138 sm_trie_insert(m_pCommands, cmd, pHandler);
140 /* Sort this into the menu */
141 List<ConsoleEntry *>::iterator iter = m_Menu.begin();
142 ConsoleEntry *pEntry;
143 bool inserted = false;
144 while (iter != m_Menu.end())
147 if (strcmp(cmd, pEntry->command.c_str()) < 0)
149 ConsoleEntry *pNew = new ConsoleEntry;
150 pNew->command.assign(cmd);
151 pNew->description.assign(text);
152 m_Menu.insert(iter, pNew);
161 ConsoleEntry *pNew = new ConsoleEntry;
162 pNew->command.assign(cmd);
163 pNew->description.assign(text);
164 m_Menu.push_back(pNew);
170 bool RootConsoleMenu::RemoveRootConsoleCommand(const char *cmd, IRootConsoleCommand *pHandler)
173 IRootConsoleCommand *object;
174 if (sm_trie_retrieve(m_pCommands, cmd, (void **)&object))
176 if (object != pHandler)
184 sm_trie_delete(m_pCommands, cmd);
186 List<ConsoleEntry *>::iterator iter;
187 ConsoleEntry *pEntry;
188 for (iter=m_Menu.begin(); iter!=m_Menu.end(); iter++)
191 if (pEntry->command.compare(cmd) == 0)
202 void RootConsoleMenu::DrawGenericOption(const char *cmd, const char *text)
205 size_t len, cmdlen = strlen(cmd);
207 len = UTIL_Format(buffer, sizeof(buffer), " %s", cmd);
210 size_t num = 16 - cmdlen;
211 for (size_t i = 0; i < num; i++)
215 len += snprintf(&buffer[len], sizeof(buffer) - len, " - %s", text);
216 ConsolePrint("%s", buffer);
220 const char *RootConsoleMenu::GetInterfaceName()
222 return SMINTERFACE_ROOTCONSOLE_NAME;
225 unsigned int RootConsoleMenu::GetInterfaceVersion()
227 return SMINTERFACE_ROOTCONSOLE_VERSION;
230 extern void _IntExt_EnableYams();
232 void RootConsoleMenu::GotRootCmd(const CCommand &cmd)
234 unsigned int argnum = cmd.ArgC();
238 const char *cmdname = cmd.Arg(1);
239 if (strcmp(cmdname, "text") == 0)
241 _IntExt_EnableYams();
244 else if (strcmp(cmdname, "internal") == 0)
248 const char *arg = cmd.Arg(2);
249 if (strcmp(arg, "1") == 0)
251 SM_ConfigsExecuted_Global();
253 else if (strcmp(arg, "2") == 0)
257 SM_ConfigsExecuted_Plugin(atoi(cmd.Arg(3)));
264 IRootConsoleCommand *pHandler;
265 if (sm_trie_retrieve(m_pCommands, cmdname, (void **)&pHandler))
267 pHandler->OnRootConsoleCommand(cmdname, cmd);
272 ConsolePrint("SourceMod Menu:");
273 ConsolePrint("Usage: sm <command> [arguments]");
275 List<ConsoleEntry *>::iterator iter;
276 ConsoleEntry *pEntry;
277 for (iter=m_Menu.begin(); iter!=m_Menu.end(); iter++)
280 DrawGenericOption(pEntry->command.c_str(), pEntry->description.c_str());
284 void RootConsoleMenu::OnRootConsoleCommand(const char *cmdname, const CCommand &command)
286 if (strcmp(cmdname, "credits") == 0)
288 ConsolePrint(" SourceMod was developed by AlliedModders, LLC.");
289 ConsolePrint(" Development would not have been possible without the following people:");
290 ConsolePrint(" David \"BAILOPAN\" Anderson, lead developer");
291 ConsolePrint(" Borja \"faluco\" Ferrer, Core developer");
292 ConsolePrint(" Scott \"Damaged Soul\" Ehlert, Core developer");
293 ConsolePrint(" Pavol \"PM OnoTo\" Marko, SourceHook developer");
294 ConsolePrint(" Special thanks to Viper of GameConnect");
295 ConsolePrint(" Special thanks to Mani of Mani-Admin-Plugin");
296 ConsolePrint(" http://www.sourcemod.net/");
297 } else if (strcmp(cmdname, "version") == 0) {
298 ConsolePrint(" SourceMod Version Information:");
299 ConsolePrint(" SourceMod Version: %s", SVN_FULL_VERSION);
300 ConsolePrint(" JIT Version: %s, %s", g_pVM->GetVMName(), g_pVM->GetVersionString());
301 ConsolePrint(" JIT Settings: %s", g_pVM->GetCPUOptimizations());
302 ConsolePrint(" http://www.sourcemod.net/");
306 CON_COMMAND(sm, "SourceMod Menu")
308 #if !defined ORANGEBOX_BUILD
311 g_RootMenu.GotRootCmd(args);
314 FILE *g_pHndlLog = NULL;
316 void write_handles_to_log(const char *fmt, ...)
321 vfprintf(g_pHndlLog, fmt, ap);
322 fprintf(g_pHndlLog, "\n");
326 void write_handles_to_game(const char *fmt, ...)
333 len = UTIL_FormatArgs(buffer, sizeof(buffer)-2, fmt, ap);
337 buffer[len+1] = '\0';
339 engine->LogPrint(buffer);
342 CON_COMMAND(sm_dump_handles, "Dumps Handle usage to a file for finding Handle leaks")
344 #if !defined ORANGEBOX_BUILD
349 g_RootMenu.ConsolePrint("Usage: sm_dump_handles <file> or <log> for game logs");
353 if (strcmp(args.Arg(1), "log") != 0)
355 const char *arg = args.Arg(1);
356 FILE *fp = fopen(arg, "wt");
359 g_RootMenu.ConsolePrint("Could not find file \"%s\"", arg);
364 g_HandleSys.Dump(write_handles_to_log);
371 g_HandleSys.Dump(write_handles_to_game);