added sourcemod's VDF file. yay
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"
39 RootConsoleMenu g_RootMenu;
41 ConVar sourcemod_version("sourcemod_version", SVN_FULL_VERSION, FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY, "SourceMod Version");
43 RootConsoleMenu::RootConsoleMenu()
45 m_pCommands = sm_trie_create();
46 m_CfgExecDone = false;
49 RootConsoleMenu::~RootConsoleMenu()
51 sm_trie_destroy(m_pCommands);
53 List<ConsoleEntry *>::iterator iter;
54 for (iter=m_Menu.begin(); iter!=m_Menu.end(); iter++)
61 extern void _IntExt_OnHostnameChanged(ConVar *var, const char *pOldValue, float flOldValue);
63 class DetectHostNameChanges : public IConVarChangeListener
66 void OnConVarChanged(ConVar *pConVar, const char *oldValue, float flOldValue)
68 _IntExt_OnHostnameChanged(pConVar, oldValue, flOldValue);
70 } s_HostnameChangeDetector;
72 void RootConsoleMenu::OnSourceModStartup(bool late)
74 #if defined ORANGEBOX_BUILD
77 CONVAR_REGISTER(this);
78 AddRootConsoleCommand("version", "Display version information", this);
79 AddRootConsoleCommand("credits", "Display credits listing", this);
82 void RootConsoleMenu::OnSourceModAllInitialized()
84 g_ConVarManager.AddConVarChangeListener("hostname", &s_HostnameChangeDetector);
87 void RootConsoleMenu::OnSourceModShutdown()
89 g_ConVarManager.RemoveConVarChangeListener("hostname", &s_HostnameChangeDetector);
90 RemoveRootConsoleCommand("credits", this);
91 RemoveRootConsoleCommand("version", this);
94 bool RootConsoleMenu::RegisterConCommandBase(ConCommandBase *pCommand)
96 META_REGCVAR(pCommand);
98 /* Override values of convars created by SourceMod convar manager if specified on command line */
99 const char *cmdLineValue = icvar->GetCommandLineValue(pCommand->GetName());
100 if (cmdLineValue && !pCommand->IsCommand())
102 static_cast<ConVar *>(pCommand)->SetValue(cmdLineValue);
108 void RootConsoleMenu::ConsolePrint(const char *fmt, ...)
114 size_t len = vsnprintf(buffer, sizeof(buffer), fmt, ap);
117 if (len >= sizeof(buffer) - 1)
122 buffer[len++] = '\n';
126 META_CONPRINT(buffer);
129 bool RootConsoleMenu::AddRootConsoleCommand(const char *cmd, const char *text, IRootConsoleCommand *pHandler)
131 if (sm_trie_retrieve(m_pCommands, cmd, NULL))
136 sm_trie_insert(m_pCommands, cmd, pHandler);
138 /* Sort this into the menu */
139 List<ConsoleEntry *>::iterator iter = m_Menu.begin();
140 ConsoleEntry *pEntry;
141 bool inserted = false;
142 while (iter != m_Menu.end())
145 if (strcmp(cmd, pEntry->command.c_str()) < 0)
147 ConsoleEntry *pNew = new ConsoleEntry;
148 pNew->command.assign(cmd);
149 pNew->description.assign(text);
150 m_Menu.insert(iter, pNew);
159 ConsoleEntry *pNew = new ConsoleEntry;
160 pNew->command.assign(cmd);
161 pNew->description.assign(text);
162 m_Menu.push_back(pNew);
168 bool RootConsoleMenu::RemoveRootConsoleCommand(const char *cmd, IRootConsoleCommand *pHandler)
171 IRootConsoleCommand *object;
172 if (sm_trie_retrieve(m_pCommands, cmd, (void **)&object))
174 if (object != pHandler)
182 sm_trie_delete(m_pCommands, cmd);
184 List<ConsoleEntry *>::iterator iter;
185 ConsoleEntry *pEntry;
186 for (iter=m_Menu.begin(); iter!=m_Menu.end(); iter++)
189 if (pEntry->command.compare(cmd) == 0)
200 void RootConsoleMenu::DrawGenericOption(const char *cmd, const char *text)
203 size_t len, cmdlen = strlen(cmd);
205 len = UTIL_Format(buffer, sizeof(buffer), " %s", cmd);
208 size_t num = 16 - cmdlen;
209 for (size_t i = 0; i < num; i++)
213 len += snprintf(&buffer[len], sizeof(buffer) - len, " - %s", text);
214 ConsolePrint("%s", buffer);
218 extern void _IntExt_EnableYams();
220 void RootConsoleMenu::GotRootCmd(const CCommand &cmd)
222 unsigned int argnum = cmd.ArgC();
226 const char *cmdname = cmd.Arg(1);
227 if (strcmp(cmdname, "text") == 0)
229 _IntExt_EnableYams();
232 else if (strcmp(cmdname, "internal") == 0)
236 const char *arg = cmd.Arg(2);
237 if (strcmp(arg, "1") == 0)
239 SM_ConfigsExecuted_Global();
241 else if (strcmp(arg, "2") == 0)
245 SM_ConfigsExecuted_Plugin(atoi(cmd.Arg(3)));
252 IRootConsoleCommand *pHandler;
253 if (sm_trie_retrieve(m_pCommands, cmdname, (void **)&pHandler))
255 pHandler->OnRootConsoleCommand(cmdname, cmd);
260 ConsolePrint("SourceMod Menu:");
261 ConsolePrint("Usage: sm <command> [arguments]");
263 List<ConsoleEntry *>::iterator iter;
264 ConsoleEntry *pEntry;
265 for (iter=m_Menu.begin(); iter!=m_Menu.end(); iter++)
268 DrawGenericOption(pEntry->command.c_str(), pEntry->description.c_str());
272 void RootConsoleMenu::OnRootConsoleCommand(const char *cmdname, const CCommand &command)
274 if (strcmp(cmdname, "credits") == 0)
276 ConsolePrint(" SourceMod was developed by AlliedModders, LLC.");
277 ConsolePrint(" Development would not have been possible without the following people:");
278 ConsolePrint(" David \"BAILOPAN\" Anderson, lead developer");
279 ConsolePrint(" Borja \"faluco\" Ferrer, Core developer");
280 ConsolePrint(" Scott \"Damaged Soul\" Ehlert, Core developer");
281 ConsolePrint(" Pavol \"PM OnoTo\" Marko, SourceHook developer");
282 ConsolePrint(" Special thanks to Viper of GameConnect");
283 ConsolePrint(" Special thanks to Mani of Mani-Admin-Plugin");
284 ConsolePrint(" http://www.sourcemod.net/");
285 } else if (strcmp(cmdname, "version") == 0) {
286 ConsolePrint(" SourceMod Version Information:");
287 ConsolePrint(" SourceMod Version: %s", SVN_FULL_VERSION);
288 ConsolePrint(" JIT Version: %s, %s", g_pVM->GetVMName(), g_pVM->GetVersionString());
289 ConsolePrint(" JIT Settings: %s", g_pVM->GetCPUOptimizations());
290 ConsolePrint(" http://www.sourcemod.net/");
294 CON_COMMAND(sm, "SourceMod Menu")
296 #if !defined ORANGEBOX_BUILD
299 g_RootMenu.GotRootCmd(args);
302 FILE *g_pHndlLog = NULL;
304 void write_handles_to_log(const char *fmt, ...)
309 vfprintf(g_pHndlLog, fmt, ap);
310 fprintf(g_pHndlLog, "\n");
314 void write_handles_to_game(const char *fmt, ...)
321 len = UTIL_FormatArgs(buffer, sizeof(buffer)-2, fmt, ap);
325 buffer[len+1] = '\0';
327 engine->LogPrint(buffer);
330 CON_COMMAND(sm_dump_handles, "Dumps Handle usage to a file for finding Handle leaks")
332 #if !defined ORANGEBOX_BUILD
337 g_RootMenu.ConsolePrint("Usage: sm_dump_handles <file> or <log> for game logs");
341 if (strcmp(args.Arg(1), "log") != 0)
343 const char *arg = args.Arg(1);
344 FILE *fp = fopen(arg, "wt");
347 g_RootMenu.ConsolePrint("Could not find file \"%s\"", arg);
352 g_HandleSys.Dump(write_handles_to_log);
359 g_HandleSys.Dump(write_handles_to_game);