Updated symstore logic.
2 * vim: set ts=4 sw=4 tw=99 noet :
3 * ======================================================
5 * Copyright (C) 2004-2010 AlliedModders LLC and authors.
7 * ======================================================
9 * This software is provided 'as-is', without any express or implied warranty.
10 * In no event will the authors be held liable for any damages arising from
11 * the use of this software.
13 * Permission is granted to anyone to use this software for any purpose,
14 * including commercial applications, and to alter it and redistribute it
15 * freely, subject to the following restrictions:
17 * 1. The origin of this software must not be misrepresented; you must not
18 * claim that you wrote the original software. If you use this software in a
19 * product, an acknowledgment in the product documentation would be
20 * appreciated but is not required.
21 * 2. Altered source versions must be plainly marked as such, and must not be
22 * misrepresented as being the original software.
23 * 3. This notice may not be removed or altered from any source distribution.
27 #include "metamod_oslink.h"
30 #include "metamod_util.h"
31 #include "metamod_console.h"
32 #include "metamod_plugins.h"
34 using namespace SourceMM;
35 using namespace SourceHook;
38 * @brief Console Command Implementations
39 * @file concommands.cpp
42 #define CONMSG g_Metamod.ConPrintf
43 #define CLIENT_CONMSG g_Metamod.ClientConPrintf
45 bool Command_Meta(IMetamodSourceCommandInfo *info)
47 unsigned int args = info->GetArgCount();
49 if (mm_IsVspBridged() && !mm_IsVspLoadComplete())
51 CONMSG("You must change the map to activate Metamod:Source.\n");
57 const char *command = info->GetArg(1);
58 if (strcmp(command, "credits") == 0)
60 CONMSG("Metamod:Source was developed by:\n");
61 CONMSG(" SourceHook: Pavol \"PM OnoTo\" Marko\n");
62 CONMSG(" GameDLL/Plugins: David \"BAILOPAN\" Anderson\n");
63 CONMSG(" GameDLL: Scott \"DS\" Ehlert\n");
64 CONMSG("For more information, see the official website\n");
65 CONMSG("http://www.metamodsource.net/\n");
69 else if (strcmp(command, "version") == 0)
71 CONMSG("Metamod:Source version %s\n", MMS_FULL_VERSION);
72 CONMSG("Build ID: %s\n", MMS_BUILD_UNIQUEID);
74 if (g_Metamod.IsLoadedAsGameDLL())
76 CONMSG("Loaded As: GameDLL (gameinfo.txt)\n");
80 CONMSG("Loaded As: Valve Server Plugin\n");
83 CONMSG("Compiled on: %s\n", SOURCEMM_DATE);
84 CONMSG("Plugin interface version: %d:%d\n", METAMOD_PLAPI_VERSION, PLAPI_MIN_VERSION);
85 CONMSG("SourceHook version: %d:%d\n", g_SHPtr->GetIfaceVersion(), g_SHPtr->GetImplVersion());
86 CONMSG("http://www.metamodsource.net/\n");
90 else if (strcmp(command, "game") == 0)
92 CONMSG("GameDLL Information\n");
93 CONMSG(" Description: %s\n", provider->GetGameDescription());
94 CONMSG(" Mod Path: %s\n", g_Metamod.GetBaseDir());
95 CONMSG(" DLL Path: %s\n", g_Metamod.GetGameBinaryPath());
96 CONMSG(" Interface: ServerGameDLL%03d\n", g_Metamod.GetGameDLLVersion());
99 int engine = g_Metamod.GetSourceEngineBuild();
100 if (engine == SOURCE_ENGINE_ORIGINAL)
102 CONMSG(" Engine: Original (pre-Episode 1)\n");
104 else if (engine == SOURCE_ENGINE_EPISODEONE)
106 CONMSG(" Engine: Episode 1 (2004)\n");
108 else if (engine == SOURCE_ENGINE_ORANGEBOX)
110 CONMSG(" Engine: Episode 2 (Orange Box, 2007)\n");
114 #if SOURCE_ENGINE == SE_BLOODYGOODTIME
115 CONMSG(" Engine: Bloody Good Time (2010)\n");
116 #elif SOURCE_ENGINE == SE_ALIENSWARM
117 CONMSG(" Engine: Alien Swarm (2010)\n");
118 #elif SOURCE_ENGINE == SE_LEFT4DEAD2
119 CONMSG(" Engine: Left 4 Dead 2 (2009)\n");
120 #elif SOURCE_ENGINE == SE_LEFT4DEAD
121 CONMSG(" Engine: Left 4 Dead (2008)\n");
122 #elif SOURCE_ENGINE == SE_ORANGEBOX
123 CONMSG(" Engine: Episode 2 (Orange Box, 2007)\n");
124 #elif SOURCE_ENGINE == SE_ORANGEBOXVALVE
125 CONMSG(" Engine: Episode 2 (Valve Orange Box, 2009)\n");
126 #elif SOURCE_ENGINE == SE_DARKMESSIAH
127 CONMSG(" Engine: Dark Messiah (2006)\n");
129 #error "SOURCE_ENGINE not defined to a known value"
132 // Display user messages
135 int messages = g_Metamod.GetUserMessageCount();
139 CONMSG(" User Messages: %-32.31s %-5s %-5s\n", "Name", "Index", "Size");
141 for (int i = 0; i < messages; i++)
143 msgname = g_Metamod.GetUserMessage(i, &msgsize);
145 CONMSG(" %-32.31s %-5d %-5d\n", msgname, i, msgsize);
148 CONMSG(" %d user message%s in total\n", messages, (messages > 1) ? "s" : "");
152 CONMSG(" User Messages: None\n");
157 else if (strcmp(command, "refresh") == 0)
159 char filepath[PATH_SIZE], vdfpath[PATH_SIZE];
160 g_Metamod.PathFormat(filepath,
163 g_Metamod.GetBaseDir(),
164 g_Metamod.GetPluginsFile());
165 g_Metamod.PathFormat(vdfpath,
168 g_Metamod.GetBaseDir(),
169 g_Metamod.GetVDFDir());
171 mm_LoadPlugins(filepath, vdfpath);
175 else if (strcmp(command, "list") == 0)
177 CPluginManager::CPlugin *pl;
183 int plnum = g_PluginMngr.GetPluginCount();
187 CONMSG("No plugins loaded.\n");
190 CONMSG("Listing %d plugin%s:\n", plnum, (plnum > 1) ? "s" : "");
193 for (i = g_PluginMngr._begin(); i != g_PluginMngr._end(); i++)
203 if (pl->m_Status != Pl_Running)
205 len += UTIL_Format(buffer, sizeof(buffer), " [%02d] <%s>", pl->m_Id, g_PluginMngr.GetStatusText(pl));
207 len += UTIL_Format(buffer, sizeof(buffer), " [%02d]", pl->m_Id);
210 if ((plapi = pl->m_API))
212 plname = IS_STR_FILLED(plapi->GetName()) ? plapi->GetName() : pl->m_File.c_str();
213 len += UTIL_Format(&buffer[len], sizeof(buffer)-len, " %s", plname);
215 if (IS_STR_FILLED(plapi->GetVersion()))
217 len += UTIL_Format(&buffer[len], sizeof(buffer)-len, " (%s)", plapi->GetVersion());
219 if (IS_STR_FILLED(plapi->GetAuthor()))
221 UTIL_Format(&buffer[len], sizeof(buffer)-len, " by %s", plapi->GetAuthor());
225 CONMSG("%s\n", buffer);
230 else if (strcmp(command, "cmds") == 0)
234 int id = atoi(info->GetArg(2));
235 CPluginManager::CPlugin *pl = g_PluginMngr.FindById(id);
239 CONMSG("Plugin %d not found.\n", id);
245 CONMSG("Plugin %d is not loaded.\n", id);
249 CONMSG("Console commands for %s:\n", pl->m_API->GetName());
250 List<ConCommandBase *>::iterator ci;
253 for (ci=pl->m_Cmds.begin(); ci!=pl->m_Cmds.end(); ci++)
256 CONMSG(" [%5d] %-s\n", count, (*ci)->GetName());
262 CONMSG("Usage: meta cmds <id>\n");
267 else if (strcmp(command, "cvars") == 0)
271 int id = atoi(info->GetArg(2));
272 CPluginManager::CPlugin *pl = g_PluginMngr.FindById(id);
276 CONMSG("Plugin %d not found.\n", id);
282 CONMSG("Plugin %d is not loaded.\n", id);
286 CONMSG("Registered cvars for %s:\n", pl->m_API->GetName());
287 List<ConCommandBase *>::iterator ci;
290 for (ci=pl->m_Cvars.begin(); ci!=pl->m_Cvars.end(); ci++)
293 CONMSG(" [%5d] %-s\n", count, (*ci)->GetName());
299 CONMSG("Usage: meta cvars <id>\n");
304 else if (strcmp(command, "info") == 0)
308 int id = atoi(info->GetArg(2));
309 CPluginManager::CPlugin *pl = g_PluginMngr.FindById(id);
312 CONMSG("Plugin %d not found.\n", id);
318 CONMSG("Plugin %d is not loaded.\n", id);
322 if (pl->m_Status == Pl_Paused)
324 CONMSG("Plugin %d is paused.\n", id);
326 else if (pl->m_Status == Pl_Running)
330 if (pl->m_API && pl->m_API->QueryRunning(run_msg, sizeof(run_msg)-1))
336 CONMSG("Plugin %d is running.\n", id);
340 CONMSG("Plugin %d is stopped: %s\n", id, run_msg);
343 CONMSG(" Name: \"%s\" by %s\n", pl->m_API->GetName(), pl->m_API->GetAuthor());
344 CONMSG(" Version: %s\n", pl->m_API->GetVersion());
345 CONMSG(" Description: %s\n", pl->m_API->GetDescription());
346 CONMSG(" License: %s\n", pl->m_API->GetLicense());
347 CONMSG(" URL: %s\n", pl->m_API->GetURL());
348 CONMSG(" Details: API %03d, Date: %s\n", pl->m_API->GetApiVersion(), pl->m_API->GetDate());
350 CONMSG("File: %s\n\n", pl->m_File.c_str());
356 CONMSG("Usage: meta info <id>\n");
361 else if (strcmp(command, "pause") == 0)
365 int id = atoi(info->GetArg(2));
369 if (!g_PluginMngr.Pause(id, error, sizeof(error)))
371 CONMSG("Pause failed: %s\n", error);
375 CONMSG("Plugin %d has been paused.\n", id);
381 CONMSG("Usage: meta pause <id>\n");
386 else if (strcmp(command, "unpause") == 0)
390 int id = atoi(info->GetArg(2));
393 if (!g_PluginMngr.Unpause(id, error, sizeof(error)))
395 CONMSG("Unpause failed: %s\n", error);
399 CONMSG("Plugin %d has been unpaused.\n", id);
405 CONMSG("Usage: meta unpause <id>\n");
410 else if (strcmp(command, "load") == 0)
414 const char *file = info->GetArg(2);
417 const char *alias = g_PluginMngr.LookupAlias(file);
423 g_Metamod.GetFullPluginPath(file, full_path, sizeof(full_path));
427 CPluginManager::CPlugin *pl;
429 PluginId id = g_PluginMngr.Load(full_path, Pl_Console, already, error, sizeof(error));
430 pl = g_PluginMngr.FindById(id);
431 if (!pl || id < Pl_MinId || (pl->m_Status < Pl_Paused))
433 CONMSG("Failed to load plugin %s (%s).\n", file, error);
439 CONMSG("Plugin \"%s\" loaded with id %d.\n", pl->m_API->GetName(), pl->m_Id);
441 CONMSG("Plugin \"%s\" is already loaded as %d.\n", pl->m_API->GetName(), pl->m_Id);
448 CONMSG("Usage: meta load <path>\n");
453 else if ( (strcmp(command, "alias") == 0) ||
454 (strcmp(command, "aliases") == 0) )
458 const char *alias = info->GetArg(2);
459 const char *value = info->GetArg(3);
461 g_PluginMngr.SetAlias(alias, value);
462 if (value == NULL || value[0] == '\0')
464 CONMSG("Deleted alias: %s.\n", alias);
466 CONMSG("Set alias \"%s\" to: %s\n", alias, value);
471 const char *alias = info->GetArg(2);
472 const char *value = g_PluginMngr.LookupAlias(alias);
475 CONMSG("Alias \"%s\" is set to: %s\n", alias, value);
477 CONMSG("Alias \"%s\" was not found.\n", alias);
482 List<CNameAlias *>::iterator iter, end;
485 iter = g_PluginMngr._alias_begin();
486 end = g_PluginMngr._alias_end();
490 CONMSG("%-10.9s %s\n", "Alias", "File");
492 for (; iter!=end; iter++)
495 CONMSG("%-10.9s %s\n", p->alias.c_str(), p->value.c_str());
499 CONMSG("%d aliases total.\n", total);
503 CONMSG("No aliases found.\n");
508 else if (strcmp(command, "unload") == 0)
512 const char *file = info->GetArg(2);
516 if (id == 0 && isalpha(file[0]))
519 const char *alias = g_PluginMngr.LookupAlias(file);
526 g_Metamod.GetFullPluginPath(file, full_path, sizeof(full_path));
528 List<CPluginManager::CPlugin *>::iterator iter, end;
529 CPluginManager::CPlugin *pl;
530 iter = g_PluginMngr._begin();
531 end = g_PluginMngr._end();
532 for (; iter!=end; iter++)
535 if (strcmp(pl->m_File.c_str(), full_path) == 0)
543 CONMSG("Plugin \"%s\" not found.\n", full_path);
548 if (!g_PluginMngr.Unload(id, false, error, sizeof(error)))
550 CONMSG("Unload failed: %s\n", error);
554 CONMSG("Plugin %d unloaded.\n", id);
558 CONMSG("Usage: meta unload <id>\n");
562 else if (strcmp(command, "force_unload") == 0)
566 int id = atoi(info->GetArg(2));
569 if (!g_PluginMngr.Unload(id, false, error, sizeof(error)))
571 CONMSG("Force unload failed: %s\n", error);
575 CONMSG("Plugin %d force unloaded.\n", id);
581 CONMSG("Usage: meta force_unload <id>\n");
586 else if (strcmp(command, "clear") == 0)
588 if (!g_PluginMngr.UnloadAll())
590 CONMSG("One or more plugins resisted removal (cleaned anyway).\n");
594 CONMSG("All plugins unloaded.\n");
598 else if (strcmp(command, "retry") == 0)
602 int id = atoi(info->GetArg(2));
605 if (!g_PluginMngr.Retry(id, error, sizeof(error)))
607 CONMSG("Error reloading plugin: %s\n", error);
611 CONMSG("Plugin %d successfully reloaded.\n", id);
617 CONMSG("Usage: meta retry <id>\n");
624 CONMSG("Metamod:Source Menu\n");
625 CONMSG("usage: meta <command> [arguments]\n");
626 CONMSG(" alias - List or set an alias\n");
627 CONMSG(" clear - Unload all plugins forcefully\n");
628 CONMSG(" cmds - Show plugin commands\n");
629 CONMSG(" cvars - Show plugin cvars\n");
630 CONMSG(" credits - About Metamod:Source\n");
631 CONMSG(" force_unload - Forcefully unload a plugin\n");
632 CONMSG(" game - Information about GameDLL\n");
633 CONMSG(" info - Information about a plugin\n");
634 CONMSG(" list - List plugins\n");
635 CONMSG(" load - Load a plugin\n");
636 CONMSG(" pause - Pause a running plugin\n");
637 CONMSG(" refresh - Reparse plugin files\n");
638 CONMSG(" retry - Attempt to reload a plugin\n");
639 CONMSG(" unload - Unload a loaded plugin\n");
640 CONMSG(" unpause - Unpause a paused plugin\n");
641 CONMSG(" version - Version information\n");
646 bool Command_ClientMeta(edict_t *client, IMetamodSourceCommandInfo *info)
648 const char *cmd = info->GetArg(0);
650 if (strcmp(cmd, "meta") == 0)
652 unsigned int args = info->GetArgCount();
655 const char *subcmd = info->GetArg(1);
657 if (strcmp(subcmd, "credits") == 0)
659 CLIENT_CONMSG(client, "Metamod:Source was developed by:\n");
660 CLIENT_CONMSG(client, " SourceHook: Pavol \"PM OnoTo\" Marko\n");
661 CLIENT_CONMSG(client, " GameDLL/Plugins: David \"BAILOPAN\" Anderson\n");
662 CLIENT_CONMSG(client, " GameDLL: Scott \"DS\" Ehlert\n");
663 CLIENT_CONMSG(client, "For more information, see the official website\n");
664 CLIENT_CONMSG(client, "http://www.metamodsource.net/\n");
668 else if(strcmp(subcmd, "version") == 0)
670 CLIENT_CONMSG(client, "Metamod:Source version %s\n", MMS_FULL_VERSION);
671 CLIENT_CONMSG(client, "Compiled on: %s\n", SOURCEMM_DATE);
672 CLIENT_CONMSG(client, "Plugin interface version: %d:%d\n", METAMOD_PLAPI_VERSION, PLAPI_MIN_VERSION);
673 CLIENT_CONMSG(client, "SourceHook version: %d:%d\n", g_SHPtr->GetIfaceVersion(), g_SHPtr->GetImplVersion());
674 CLIENT_CONMSG(client, "http://www.metamodsource.net/\n");
678 else if(strcmp(subcmd, "list") == 0)
680 CPluginManager::CPlugin *pl;
688 for (i = g_PluginMngr._begin(); i != g_PluginMngr._end(); i++, len=0)
691 if (pl && pl->m_Status == Pl_Running)
694 if (!plapi || !plapi->QueryRunning(NULL, 0))
700 len += UTIL_Format(buffer, sizeof(buffer), " [%02d]", plnum);
702 plname = IS_STR_FILLED(plapi->GetName()) ? plapi->GetName() : pl->m_File.c_str();
703 len += UTIL_Format(&buffer[len], sizeof(buffer)-len, " %s", plname);
705 if (IS_STR_FILLED(plapi->GetVersion()))
707 len += UTIL_Format(&buffer[len], sizeof(buffer)-len, " (%s)", plapi->GetVersion());
709 if (IS_STR_FILLED(plapi->GetAuthor()))
711 UTIL_Format(&buffer[len], sizeof(buffer)-len, " by %s", plapi->GetAuthor());
714 CLIENT_CONMSG(client, "%s\n", buffer);
720 CLIENT_CONMSG(client, "No active plugins loaded.\n");
727 CLIENT_CONMSG(client, "Metamod:Source Menu\n");
728 CLIENT_CONMSG(client, "usage: meta <command>\n");
729 CLIENT_CONMSG(client, " credits - About Metamod:Source\n");
730 CLIENT_CONMSG(client, " list - List plugins\n");
731 CLIENT_CONMSG(client, " version - Version information\n");