Trigger build for hl2sdk-l4d changes.
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"
29 #include <versionlib.h>
31 #include "metamod_util.h"
32 #include "metamod_console.h"
33 #include "metamod_plugins.h"
35 using namespace SourceMM;
36 using namespace SourceHook;
39 * @brief Console Command Implementations
40 * @file concommands.cpp
43 #define CONMSG g_Metamod.ConPrintf
44 #define CLIENT_CONMSG g_Metamod.ClientConPrintf
46 bool Command_Meta(IMetamodSourceCommandInfo *info)
48 unsigned int args = info->GetArgCount();
50 if (mm_IsVspBridged() && !mm_IsVspLoadComplete())
52 CONMSG("You must change the map to activate Metamod:Source.\n");
58 const char *command = info->GetArg(1);
59 if (strcmp(command, "credits") == 0)
61 CONMSG("Metamod:Source was developed by:\n");
62 CONMSG(" SourceHook: Pavol \"PM OnoTo\" Marko\n");
63 CONMSG(" GameDLL/Plugins: David \"BAILOPAN\" Anderson\n");
64 CONMSG(" GameDLL: Scott \"DS\" Ehlert\n");
65 CONMSG("For more information, see the official website\n");
66 CONMSG("http://www.metamodsource.net/\n");
70 else if (strcmp(command, "version") == 0)
72 CONMSG("Metamod:Source version %s\n", METAMOD_VERSION);
73 CONMSG("Build ID: %s\n", METAMOD_BUILD_ID);
75 if (g_Metamod.IsLoadedAsGameDLL())
77 CONMSG("Loaded As: GameDLL (gameinfo.txt)\n");
81 CONMSG("Loaded As: Valve Server Plugin\n");
84 CONMSG("Compiled on: %s\n", SOURCEMM_DATE);
85 CONMSG("Plugin interface version: %d:%d\n", METAMOD_PLAPI_VERSION, PLAPI_MIN_VERSION);
86 CONMSG("SourceHook version: %d:%d\n", g_SHPtr->GetIfaceVersion(), g_SHPtr->GetImplVersion());
87 CONMSG("http://www.metamodsource.net/\n");
91 else if (strcmp(command, "game") == 0)
93 CONMSG("GameDLL Information\n");
94 CONMSG(" Description: %s\n", provider->GetGameDescription());
95 CONMSG(" Mod Path: %s\n", g_Metamod.GetBaseDir());
96 CONMSG(" DLL Path: %s\n", g_Metamod.GetGameBinaryPath());
97 CONMSG(" Interface: ServerGameDLL%03d\n", g_Metamod.GetGameDLLVersion());
100 int engine = g_Metamod.GetSourceEngineBuild();
101 if (engine == SOURCE_ENGINE_ORIGINAL)
103 CONMSG(" Engine: Original (pre-Episode 1)\n");
105 else if (engine == SOURCE_ENGINE_EPISODEONE)
107 CONMSG(" Engine: Episode 1 (2004)\n");
109 else if (engine == SOURCE_ENGINE_ORANGEBOX)
111 CONMSG(" Engine: Episode 2 (Orange Box, 2007)\n");
115 #if SOURCE_ENGINE == SE_BLOODYGOODTIME
116 CONMSG(" Engine: Bloody Good Time (2010)\n");
117 #elif SOURCE_ENGINE == SE_ALIENSWARM
118 CONMSG(" Engine: Alien Swarm (2010)\n");
119 #elif SOURCE_ENGINE == SE_LEFT4DEAD2
120 CONMSG(" Engine: Left 4 Dead 2 (2009)\n");
121 #elif SOURCE_ENGINE == SE_NUCLEARDAWN
122 CONMSG(" Engine: Nuclear Dawn (2011)\n");
123 #elif SOURCE_ENGINE == SE_CONTAGION
124 CONMSG(" Engine: Contagion (2013)\n");
125 #elif SOURCE_ENGINE == SE_LEFT4DEAD
126 CONMSG(" Engine: Left 4 Dead (2008)\n");
127 #elif SOURCE_ENGINE == SE_ORANGEBOX
128 CONMSG(" Engine: Episode 2 (Orange Box, 2007)\n");
129 #elif SOURCE_ENGINE == SE_CSS
130 CONMSG(" Engine: Counter-Strike: Source (Valve Orange Box)\n");
131 #elif SOURCE_ENGINE == SE_HL2DM
132 CONMSG(" Engine: Half-Life 2 Deathmatch (Valve Orange Box)\n");
133 #elif SOURCE_ENGINE == SE_DODS
134 CONMSG(" Engine: Day of Defeat: Source (Valve Orange Box)\n");
135 #elif SOURCE_ENGINE == SE_SDK2013
136 CONMSG(" Engine: Source SDK 2013 (2013)\n");
137 #elif SOURCE_ENGINE == SE_TF2
138 CONMSG(" Engine: Team Fortress 2 (Valve Orange Box)\n");
139 #elif SOURCE_ENGINE == SE_DARKMESSIAH
140 CONMSG(" Engine: Dark Messiah (2006)\n");
141 #elif SOURCE_ENGINE == SE_EYE
142 CONMSG(" Engine: E.Y.E. Divine Cybermancy (2011)\n");
143 #elif SOURCE_ENGINE == SE_PORTAL2
144 CONMSG(" Engine: Portal 2 (2011)\n");
145 #elif SOURCE_ENGINE == SE_BLADE
146 CONMSG(" Engine: Blade Symphony (2013)\n");
147 #elif SOURCE_ENGINE == SE_INSURGENCY
148 CONMSG(" Engine: Insurgency (2013)\n");
149 #elif SOURCE_ENGINE == SE_CSGO
150 CONMSG(" Engine: Counter-Strike: Global Offensive (2012)\n");
151 #elif SOURCE_ENGINE == SE_DOTA
152 CONMSG(" Engine: Dota 2 (2013)\n");
154 #error "SOURCE_ENGINE not defined to a known value"
157 // Display user messages
160 int messages = g_Metamod.GetUserMessageCount();
164 CONMSG(" User Messages: %-32.31s %-5s %-5s\n", "Name", "Index", "Size");
166 for (int i = 0; i < messages; i++)
168 msgname = g_Metamod.GetUserMessage(i, &msgsize);
170 CONMSG(" %-32.31s %-5d %-5d\n", msgname, i, msgsize);
173 CONMSG(" %d user message%s in total\n", messages, (messages > 1) ? "s" : "");
177 CONMSG(" User Messages: None\n");
182 else if (strcmp(command, "refresh") == 0)
184 char filepath[PATH_SIZE], vdfpath[PATH_SIZE];
185 g_Metamod.PathFormat(filepath,
188 g_Metamod.GetBaseDir(),
189 g_Metamod.GetPluginsFile());
190 g_Metamod.PathFormat(vdfpath,
193 g_Metamod.GetBaseDir(),
194 g_Metamod.GetVDFDir());
196 mm_LoadPlugins(filepath, vdfpath);
200 else if (strcmp(command, "list") == 0)
202 CPluginManager::CPlugin *pl;
208 int plnum = g_PluginMngr.GetPluginCount();
212 CONMSG("No plugins loaded.\n");
215 CONMSG("Listing %d plugin%s:\n", plnum, (plnum > 1) ? "s" : "");
218 for (i = g_PluginMngr._begin(); i != g_PluginMngr._end(); i++)
228 if (pl->m_Status != Pl_Running)
230 len += UTIL_Format(buffer, sizeof(buffer), " [%02d] <%s>", pl->m_Id, g_PluginMngr.GetStatusText(pl));
232 len += UTIL_Format(buffer, sizeof(buffer), " [%02d]", pl->m_Id);
235 if ((plapi = pl->m_API))
237 plname = IS_STR_FILLED(plapi->GetName()) ? plapi->GetName() : pl->m_File.c_str();
238 len += UTIL_Format(&buffer[len], sizeof(buffer)-len, " %s", plname);
240 if (IS_STR_FILLED(plapi->GetVersion()))
242 len += UTIL_Format(&buffer[len], sizeof(buffer)-len, " (%s)", plapi->GetVersion());
244 if (IS_STR_FILLED(plapi->GetAuthor()))
246 UTIL_Format(&buffer[len], sizeof(buffer)-len, " by %s", plapi->GetAuthor());
250 CONMSG("%s\n", buffer);
255 else if (strcmp(command, "cmds") == 0)
259 int id = atoi(info->GetArg(2));
260 CPluginManager::CPlugin *pl = g_PluginMngr.FindById(id);
264 CONMSG("Plugin %d not found.\n", id);
270 CONMSG("Plugin %d is not loaded.\n", id);
274 CONMSG("Console commands for %s:\n", pl->m_API->GetName());
275 List<ConCommandBase *>::iterator ci;
278 for (ci=pl->m_Cmds.begin(); ci!=pl->m_Cmds.end(); ci++)
281 CONMSG(" [%5d] %-s\n", count, (*ci)->GetName());
287 CONMSG("Usage: meta cmds <id>\n");
292 else if (strcmp(command, "cvars") == 0)
296 int id = atoi(info->GetArg(2));
297 CPluginManager::CPlugin *pl = g_PluginMngr.FindById(id);
301 CONMSG("Plugin %d not found.\n", id);
307 CONMSG("Plugin %d is not loaded.\n", id);
311 CONMSG("Registered cvars for %s:\n", pl->m_API->GetName());
312 List<ConCommandBase *>::iterator ci;
315 for (ci=pl->m_Cvars.begin(); ci!=pl->m_Cvars.end(); ci++)
318 CONMSG(" [%5d] %-s\n", count, (*ci)->GetName());
324 CONMSG("Usage: meta cvars <id>\n");
329 else if (strcmp(command, "info") == 0)
333 int id = atoi(info->GetArg(2));
334 CPluginManager::CPlugin *pl = g_PluginMngr.FindById(id);
337 CONMSG("Plugin %d not found.\n", id);
343 CONMSG("Plugin %d is not loaded.\n", id);
347 if (pl->m_Status == Pl_Paused)
349 CONMSG("Plugin %d is paused.\n", id);
351 else if (pl->m_Status == Pl_Running)
355 if (pl->m_API && pl->m_API->QueryRunning(run_msg, sizeof(run_msg)-1))
361 CONMSG("Plugin %d is running.\n", id);
365 CONMSG("Plugin %d is stopped: %s\n", id, run_msg);
368 CONMSG(" Name: \"%s\" by %s\n", pl->m_API->GetName(), pl->m_API->GetAuthor());
369 CONMSG(" Version: %s\n", pl->m_API->GetVersion());
370 CONMSG(" Description: %s\n", pl->m_API->GetDescription());
371 CONMSG(" License: %s\n", pl->m_API->GetLicense());
372 CONMSG(" URL: %s\n", pl->m_API->GetURL());
373 CONMSG(" Details: API %03d, Date: %s\n", pl->m_API->GetApiVersion(), pl->m_API->GetDate());
375 CONMSG("File: %s\n\n", pl->m_File.c_str());
381 CONMSG("Usage: meta info <id>\n");
386 else if (strcmp(command, "pause") == 0)
390 int id = atoi(info->GetArg(2));
394 if (!g_PluginMngr.Pause(id, error, sizeof(error)))
396 CONMSG("Pause failed: %s\n", error);
400 CONMSG("Plugin %d has been paused.\n", id);
406 CONMSG("Usage: meta pause <id>\n");
411 else if (strcmp(command, "unpause") == 0)
415 int id = atoi(info->GetArg(2));
418 if (!g_PluginMngr.Unpause(id, error, sizeof(error)))
420 CONMSG("Unpause failed: %s\n", error);
424 CONMSG("Plugin %d has been unpaused.\n", id);
430 CONMSG("Usage: meta unpause <id>\n");
435 else if (strcmp(command, "load") == 0)
439 const char *file = info->GetArg(2);
442 const char *alias = g_PluginMngr.LookupAlias(file);
448 g_Metamod.GetFullPluginPath(file, full_path, sizeof(full_path));
452 CPluginManager::CPlugin *pl;
454 // If we've recently tried to unload plugins, they might still
455 // be in the unload queue. Force them out now. This is not
456 // lowered to CPluginManager because it's not strictly safe
458 g_SourceHook.ResolvePendingUnloads(true);
460 PluginId id = g_PluginMngr.Load(full_path, Pl_Console, already, error, sizeof(error));
461 pl = g_PluginMngr.FindById(id);
462 if (!pl || id < Pl_MinId || (pl->m_Status < Pl_Paused))
464 CONMSG("Failed to load plugin %s (%s).\n", file, error);
470 CONMSG("Plugin \"%s\" loaded with id %d.\n", pl->m_API->GetName(), pl->m_Id);
472 CONMSG("Plugin \"%s\" is already loaded as %d.\n", pl->m_API->GetName(), pl->m_Id);
479 CONMSG("Usage: meta load <path>\n");
484 else if ( (strcmp(command, "alias") == 0) ||
485 (strcmp(command, "aliases") == 0) )
489 const char *alias = info->GetArg(2);
490 const char *value = info->GetArg(3);
492 g_PluginMngr.SetAlias(alias, value);
493 if (value == NULL || value[0] == '\0')
495 CONMSG("Deleted alias: %s.\n", alias);
497 CONMSG("Set alias \"%s\" to: %s\n", alias, value);
502 const char *alias = info->GetArg(2);
503 const char *value = g_PluginMngr.LookupAlias(alias);
506 CONMSG("Alias \"%s\" is set to: %s\n", alias, value);
508 CONMSG("Alias \"%s\" was not found.\n", alias);
513 List<CNameAlias *>::iterator iter, end;
516 iter = g_PluginMngr._alias_begin();
517 end = g_PluginMngr._alias_end();
521 CONMSG("%-10.9s %s\n", "Alias", "File");
523 for (; iter!=end; iter++)
526 CONMSG("%-10.9s %s\n", p->alias.c_str(), p->value.c_str());
530 CONMSG("%d aliases total.\n", total);
534 CONMSG("No aliases found.\n");
539 else if (strcmp(command, "unload") == 0)
543 const char *file = info->GetArg(2);
547 if (id == 0 && isalpha(file[0]))
550 const char *alias = g_PluginMngr.LookupAlias(file);
557 g_Metamod.GetFullPluginPath(file, full_path, sizeof(full_path));
559 List<CPluginManager::CPlugin *>::iterator iter, end;
560 CPluginManager::CPlugin *pl;
561 iter = g_PluginMngr._begin();
562 end = g_PluginMngr._end();
563 for (; iter!=end; iter++)
566 if (strcmp(pl->m_File.c_str(), full_path) == 0)
574 CONMSG("Plugin \"%s\" not found.\n", full_path);
579 if (!g_PluginMngr.Unload(id, false, error, sizeof(error)))
581 CONMSG("Unload failed: %s\n", error);
585 CONMSG("Plugin %d unloaded.\n", id);
589 CONMSG("Usage: meta unload <id>\n");
593 else if (strcmp(command, "force_unload") == 0)
597 int id = atoi(info->GetArg(2));
600 if (!g_PluginMngr.Unload(id, false, error, sizeof(error)))
602 CONMSG("Force unload failed: %s\n", error);
606 CONMSG("Plugin %d force unloaded.\n", id);
612 CONMSG("Usage: meta force_unload <id>\n");
617 else if (strcmp(command, "clear") == 0)
619 if (!g_PluginMngr.UnloadAll())
621 CONMSG("One or more plugins resisted removal (cleaned anyway).\n");
625 CONMSG("All plugins unloaded.\n");
629 else if (strcmp(command, "retry") == 0)
633 int id = atoi(info->GetArg(2));
636 if (!g_PluginMngr.Retry(id, error, sizeof(error)))
638 CONMSG("Error reloading plugin: %s\n", error);
642 CONMSG("Plugin %d successfully reloaded.\n", id);
648 CONMSG("Usage: meta retry <id>\n");
655 CONMSG("Metamod:Source Menu\n");
656 CONMSG("usage: meta <command> [arguments]\n");
657 CONMSG(" alias - List or set an alias\n");
658 CONMSG(" clear - Unload all plugins forcefully\n");
659 CONMSG(" cmds - Show plugin commands\n");
660 CONMSG(" cvars - Show plugin cvars\n");
661 CONMSG(" credits - About Metamod:Source\n");
662 CONMSG(" force_unload - Forcefully unload a plugin\n");
663 CONMSG(" game - Information about GameDLL\n");
664 CONMSG(" info - Information about a plugin\n");
665 CONMSG(" list - List plugins\n");
666 CONMSG(" load - Load a plugin\n");
667 CONMSG(" pause - Pause a running plugin\n");
668 CONMSG(" refresh - Reparse plugin files\n");
669 CONMSG(" retry - Attempt to reload a plugin\n");
670 CONMSG(" unload - Unload a loaded plugin\n");
671 CONMSG(" unpause - Unpause a paused plugin\n");
672 CONMSG(" version - Version information\n");
677 #if SOURCE_ENGINE == SE_DOTA
678 bool Command_ClientMeta(int client, IMetamodSourceCommandInfo *info)
680 bool Command_ClientMeta(edict_t *client, IMetamodSourceCommandInfo *info)
683 const char *cmd = info->GetArg(0);
685 if (strcmp(cmd, "meta") == 0)
687 unsigned int args = info->GetArgCount();
690 const char *subcmd = info->GetArg(1);
692 if (strcmp(subcmd, "credits") == 0)
694 CLIENT_CONMSG(client, "Metamod:Source was developed by:\n");
695 CLIENT_CONMSG(client, " SourceHook: Pavol \"PM OnoTo\" Marko\n");
696 CLIENT_CONMSG(client, " GameDLL/Plugins: David \"BAILOPAN\" Anderson\n");
697 CLIENT_CONMSG(client, " GameDLL: Scott \"DS\" Ehlert\n");
698 CLIENT_CONMSG(client, "For more information, see the official website\n");
699 CLIENT_CONMSG(client, "http://www.metamodsource.net/\n");
703 else if(strcmp(subcmd, "version") == 0)
705 CLIENT_CONMSG(client, "Metamod:Source version %s\n", METAMOD_VERSION);
706 CLIENT_CONMSG(client, "Compiled on: %s\n", SOURCEMM_DATE);
707 CLIENT_CONMSG(client, "Plugin interface version: %d:%d\n", METAMOD_PLAPI_VERSION, PLAPI_MIN_VERSION);
708 CLIENT_CONMSG(client, "SourceHook version: %d:%d\n", g_SHPtr->GetIfaceVersion(), g_SHPtr->GetImplVersion());
709 CLIENT_CONMSG(client, "http://www.metamodsource.net/\n");
713 else if(strcmp(subcmd, "list") == 0)
715 CPluginManager::CPlugin *pl;
723 for (i = g_PluginMngr._begin(); i != g_PluginMngr._end(); i++, len=0)
726 if (pl && pl->m_Status == Pl_Running)
729 if (!plapi || !plapi->QueryRunning(NULL, 0))
735 len += UTIL_Format(buffer, sizeof(buffer), " [%02d]", plnum);
737 plname = IS_STR_FILLED(plapi->GetName()) ? plapi->GetName() : pl->m_File.c_str();
738 len += UTIL_Format(&buffer[len], sizeof(buffer)-len, " %s", plname);
740 if (IS_STR_FILLED(plapi->GetVersion()))
742 len += UTIL_Format(&buffer[len], sizeof(buffer)-len, " (%s)", plapi->GetVersion());
744 if (IS_STR_FILLED(plapi->GetAuthor()))
746 UTIL_Format(&buffer[len], sizeof(buffer)-len, " by %s", plapi->GetAuthor());
749 CLIENT_CONMSG(client, "%s\n", buffer);
755 CLIENT_CONMSG(client, "No active plugins loaded.\n");
762 CLIENT_CONMSG(client, "Metamod:Source Menu\n");
763 CLIENT_CONMSG(client, "usage: meta <command>\n");
764 CLIENT_CONMSG(client, " credits - About Metamod:Source\n");
765 CLIENT_CONMSG(client, " list - List plugins\n");
766 CLIENT_CONMSG(client, " version - Version information\n");