Updated makefiles to link against binaries at l4d directory instead of l4d_demo
3 * =============================================================================
5 * Copyright (C) 2004-2008 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 void RootConsoleMenu::OnSourceModStartup(bool late)
64 #if SOURCE_ENGINE >= SE_ORANGEBOX
67 CONVAR_REGISTER(this);
68 AddRootConsoleCommand("version", "Display version information", this);
69 AddRootConsoleCommand("credits", "Display credits listing", this);
72 void RootConsoleMenu::OnSourceModAllInitialized()
74 g_ShareSys.AddInterface(NULL, this);
77 void RootConsoleMenu::OnSourceModShutdown()
79 RemoveRootConsoleCommand("credits", this);
80 RemoveRootConsoleCommand("version", this);
83 bool RootConsoleMenu::RegisterConCommandBase(ConCommandBase *pCommand)
85 META_REGCVAR(pCommand);
87 /* Override values of convars created by SourceMod convar manager if specified on command line */
88 const char *cmdLineValue = icvar->GetCommandLineValue(pCommand->GetName());
89 if (cmdLineValue && !pCommand->IsCommand())
91 static_cast<ConVar *>(pCommand)->SetValue(cmdLineValue);
97 void RootConsoleMenu::ConsolePrint(const char *fmt, ...)
103 size_t len = vsnprintf(buffer, sizeof(buffer), fmt, ap);
106 if (len >= sizeof(buffer) - 1)
111 buffer[len++] = '\n';
115 META_CONPRINT(buffer);
118 bool RootConsoleMenu::AddRootConsoleCommand(const char *cmd, const char *text, IRootConsoleCommand *pHandler)
120 if (sm_trie_retrieve(m_pCommands, cmd, NULL))
125 sm_trie_insert(m_pCommands, cmd, pHandler);
127 /* Sort this into the menu */
128 List<ConsoleEntry *>::iterator iter = m_Menu.begin();
129 ConsoleEntry *pEntry;
130 bool inserted = false;
131 while (iter != m_Menu.end())
134 if (strcmp(cmd, pEntry->command.c_str()) < 0)
136 ConsoleEntry *pNew = new ConsoleEntry;
137 pNew->command.assign(cmd);
138 pNew->description.assign(text);
139 m_Menu.insert(iter, pNew);
148 ConsoleEntry *pNew = new ConsoleEntry;
149 pNew->command.assign(cmd);
150 pNew->description.assign(text);
151 m_Menu.push_back(pNew);
157 bool RootConsoleMenu::RemoveRootConsoleCommand(const char *cmd, IRootConsoleCommand *pHandler)
160 IRootConsoleCommand *object;
161 if (sm_trie_retrieve(m_pCommands, cmd, (void **)&object))
163 if (object != pHandler)
171 sm_trie_delete(m_pCommands, cmd);
173 List<ConsoleEntry *>::iterator iter;
174 ConsoleEntry *pEntry;
175 for (iter=m_Menu.begin(); iter!=m_Menu.end(); iter++)
178 if (pEntry->command.compare(cmd) == 0)
189 void RootConsoleMenu::DrawGenericOption(const char *cmd, const char *text)
192 size_t len, cmdlen = strlen(cmd);
194 len = UTIL_Format(buffer, sizeof(buffer), " %s", cmd);
197 size_t num = 16 - cmdlen;
198 for (size_t i = 0; i < num; i++)
202 len += snprintf(&buffer[len], sizeof(buffer) - len, " - %s", text);
203 ConsolePrint("%s", buffer);
207 const char *RootConsoleMenu::GetInterfaceName()
209 return SMINTERFACE_ROOTCONSOLE_NAME;
212 unsigned int RootConsoleMenu::GetInterfaceVersion()
214 return SMINTERFACE_ROOTCONSOLE_VERSION;
217 void RootConsoleMenu::GotRootCmd(const CCommand &cmd)
219 unsigned int argnum = cmd.ArgC();
223 const char *cmdname = cmd.Arg(1);
224 if (strcmp(cmdname, "internal") == 0)
228 const char *arg = cmd.Arg(2);
229 if (strcmp(arg, "1") == 0)
231 SM_ConfigsExecuted_Global();
233 else if (strcmp(arg, "2") == 0)
237 SM_ConfigsExecuted_Plugin(atoi(cmd.Arg(3)));
244 IRootConsoleCommand *pHandler;
245 if (sm_trie_retrieve(m_pCommands, cmdname, (void **)&pHandler))
247 pHandler->OnRootConsoleCommand(cmdname, cmd);
252 ConsolePrint("SourceMod Menu:");
253 ConsolePrint("Usage: sm <command> [arguments]");
255 List<ConsoleEntry *>::iterator iter;
256 ConsoleEntry *pEntry;
257 for (iter=m_Menu.begin(); iter!=m_Menu.end(); iter++)
260 DrawGenericOption(pEntry->command.c_str(), pEntry->description.c_str());
264 void RootConsoleMenu::OnRootConsoleCommand(const char *cmdname, const CCommand &command)
266 if (strcmp(cmdname, "credits") == 0)
268 ConsolePrint(" SourceMod was developed by AlliedModders, LLC.");
269 ConsolePrint(" Development would not have been possible without the following people:");
270 ConsolePrint(" David \"BAILOPAN\" Anderson, lead developer");
271 ConsolePrint(" Borja \"faluco\" Ferrer, core developer");
272 ConsolePrint(" Scott \"Damaged Soul\" Ehlert, core developer");
273 ConsolePrint(" Matt \"pRED\" Woodrow, core developer");
274 ConsolePrint(" Michael \"ferret\" McKoy, plugin developer");
275 ConsolePrint(" Pavol \"PM OnoTo\" Marko, SourceHook developer");
276 ConsolePrint(" Special thanks to Viper of GameConnect");
277 ConsolePrint(" Special thanks to Mani of Mani-Admin-Plugin");
278 ConsolePrint(" http://www.sourcemod.net/");
280 else if (strcmp(cmdname, "version") == 0)
282 ConsolePrint(" SourceMod Version Information:");
283 ConsolePrint(" SourceMod Version: %s", SVN_FULL_VERSION);
284 ConsolePrint(" SourcePawn Engine: %s (build %s)", g_pSourcePawn2->GetEngineName(), g_pSourcePawn2->GetVersionString());
285 ConsolePrint(" SourcePawn API: v1 = %d, v2 = %d", g_pSourcePawn->GetEngineAPIVersion(), g_pSourcePawn2->GetAPIVersion());
286 ConsolePrint(" Compiled on: %s %s", __DATE__, __TIME__);
287 ConsolePrint(" Build ID: %s", SM_BUILD_UNIQUEID);
288 ConsolePrint(" http://www.sourcemod.net/");
292 CON_COMMAND(sm, "SourceMod Menu")
294 #if SOURCE_ENGINE == SE_EPISODEONE
297 g_RootMenu.GotRootCmd(args);
300 FILE *g_pHndlLog = NULL;
302 void write_handles_to_log(const char *fmt, ...)
307 vfprintf(g_pHndlLog, fmt, ap);
308 fprintf(g_pHndlLog, "\n");
312 void write_handles_to_game(const char *fmt, ...)
319 len = UTIL_FormatArgs(buffer, sizeof(buffer)-2, fmt, ap);
323 buffer[len+1] = '\0';
325 engine->LogPrint(buffer);
328 CON_COMMAND(sm_dump_handles, "Dumps Handle usage to a file for finding Handle leaks")
330 #if SOURCE_ENGINE == SE_EPISODEONE
335 g_RootMenu.ConsolePrint("Usage: sm_dump_handles <file> or <log> for game logs");
339 if (strcmp(args.Arg(1), "log") != 0)
341 const char *arg = args.Arg(1);
342 FILE *fp = fopen(arg, "wt");
345 g_RootMenu.ConsolePrint("Could not find file \"%s\"", arg);
350 g_HandleSys.Dump(write_handles_to_log);
357 g_HandleSys.Dump(write_handles_to_game);