1 /* ======== SourceMM ========
2 * Copyright (C) 2004-2005 Metamod:Source Development Team
3 * No warranties of any kind
7 * Author(s): David "BAILOPAN" Anderson
8 * ============================
11 #include "concommands.h"
15 * @brief Console Command Implementations
16 * @file concommands.cpp
19 SMConVarAccessor g_SMConVarAccessor;
21 bool SMConVarAccessor::RegisterConCommandBase(ConCommandBase *pCommand)
23 // Add the FCVAR_GAMEDLL flag
24 // => No crash on exit!
25 pCommand->AddFlags(FCVAR_GAMEDLL);
26 pCommand->SetNext( NULL );
27 g_Engine.icvar->RegisterConCommandBase(pCommand);
32 ConVar metamod_version("metamod_version", SOURCEMM_VERSION, FCVAR_REPLICATED | FCVAR_SPONLY, "Metamod:Source Version");
34 CON_COMMAND(meta, "Metamod:Source Menu")
36 IVEngineServer *e = g_Engine.engine;
38 int args = e->Cmd_Argc();
42 const char *command = e->Cmd_Argv(1);
43 if (strcmp(command, "credits") == 0)
45 Msg("Metamod:Source was developed by:\n");
46 Msg(" SourceHook: Pavol \"PM OnoTo\" Marko\n");
47 Msg(" GameDLL/Plugins: David \"BAILOPAN\" Anderson\n");
48 Msg(" GameDLL: Scott \"Damaged Soul\" Ehlert\n");
49 Msg("For more information, see the official website\n");
50 Msg("http://www.sourcemm.net/\n\n");
53 } else if (strcmp(command, "version") == 0) {
54 Msg("Metamod:Source version %s\n", SOURCEMM_VERSION);
55 Msg("Compiled on: %s\n", SOURCEMM_DATE);
56 Msg("Plugin interface version: %d:%d\n", PLAPI_VERSION, PLAPI_MIN_VERSION);
57 Msg("http://www.sourcemm.net/\n\n");
60 } else if (strcmp(command, "game") == 0) {
61 Msg("GameDLL Information\n");
62 Msg(" Mod path: %s\n", g_ModPath.c_str());
63 Msg(" Dll path: %s\n", g_BinPath.c_str());
66 } else if (strcmp(command, "refresh") == 0) {
68 #if defined WIN32 || defined _WIN32
69 snprintf(full_path, sizeof(full_path)-1, "%s\\%s", g_ModPath.c_str(), "metaplugins.ini");
71 snprintf(full_path, sizeof(full_path)-1, "%s/%s", g_ModPath.c_str(), "metaplugins.ini");
73 LoadPluginsFromFile(full_path);
76 } else if (strcmp(command, "list") == 0) {
77 SourceMM::CPluginManager::CPlugin *pl;
79 const char *status="";
80 const char *version=NULL;
81 const char *name=NULL;
82 const char *author=NULL;
84 Msg("-Id- %-16.15s %-8.7s %-12.11s %-8.7s\n", "Name", "Version", "Author", "Status");
85 for (i=g_PluginMngr._begin(); i!=g_PluginMngr._end(); i++)
90 if (pl->m_Status == Pl_Paused)
93 } else if (pl->m_Status == Pl_Running) {
95 } else if (pl->m_Status == Pl_Refused) {
97 } else if (pl->m_Status == Pl_Error) {
99 } else if (pl->m_Status == Pl_NotFound) {
105 version = pl->m_API->GetVersion();
106 author = pl->m_API->GetAuthor();
107 name = pl->m_API->GetName();
119 name = pl->m_File.c_str();
122 Msg("[%02d] %-16.15s %-8.7s %-12.11s %-8.7s\n", pl->m_Id, name, version, author, status);
128 } else if (strcmp(command, "info") == 0) {
131 int id = atoi(e->Cmd_Argv(2));
132 SourceMM::CPluginManager::CPlugin *pl = g_PluginMngr.FindById(id);
135 Msg("Plugin %d not found.\n", id);
141 Msg("Plugin %d is not loaded.\n", id);
143 if (pl->m_Status == Pl_Paused)
145 Msg("Plugin %d is paused.\n", id);
146 } else if (pl->m_Status == Pl_Running) {
147 Msg("Plugin %d is running.\n", id);
149 Msg(" Name: \"%s\" by %s\n", pl->m_API->GetName(), pl->m_API->GetAuthor());
150 Msg(" Version: %s\n", pl->m_API->GetVersion());
151 Msg(" Description: %s\n", pl->m_API->GetDescription());
152 Msg(" License: %s\n", pl->m_API->GetLicense());
153 Msg(" URL: %s\n", pl->m_API->GetURL());
154 Msg(" Details: API %03d, Date: %s\n", pl->m_API->GetApiVersion(), pl->m_API->GetDate());
156 Msg("File: %s\n\n", pl->m_File.c_str());
160 Msg("Usage: meta info <id>\n");
164 } else if (strcmp(command, "pause") == 0) {
167 int id = atoi(e->Cmd_Argv(2));
171 if (!g_PluginMngr.Pause(id, error, sizeof(error)-1))
173 Msg("Pause failed: %s\n", error);
177 Msg("Plugin %d has been paused.\n", id);
181 Msg("Usage: meta pause <id>\n");
185 } else if (strcmp(command, "unpause") == 0) {
188 int id = atoi(e->Cmd_Argv(2));
191 if (!g_PluginMngr.Unpause(id, error, sizeof(error)-1))
193 Msg("Unpause failed: %s\n", error);
197 Msg("Plugin %d has been unpaused.\n", id);
201 Msg("Usage: meta unpause <id>\n");
205 } else if (strcmp(command, "load") == 0) {
208 const char *file = e->Cmd_Argv(2);
211 if (file[0] == '/' || strcmp(&(file[1]), ":\\") == 0)
213 snprintf(full_path, sizeof(full_path)-1, "%s", file);
215 const char *ext = UTIL_GetExtension(file);
216 #if defined WIN32 || defined _WIN32
217 ext = ext ? "" : ".dll";
218 snprintf(full_path, sizeof(full_path)-1, "%s\\%s%s", g_ModPath.c_str(), file, ext);
220 ext = ext ? "" : "_i486.so";
221 snprintf(full_path, sizeof(full_path)-1, "%s/%s%s", g_ModPath.c_str(), file, ext);
227 SourceMM::CPluginManager::CPlugin *pl;
229 PluginId id = g_PluginMngr.Load(full_path, Pl_Console, already, error, sizeof(error)-1);
230 pl = g_PluginMngr.FindById(id);
231 if (!pl || id < Pl_MinId || (pl->m_Status < Pl_Paused))
233 Msg("Failed to load plugin %s (%s).\n", file, error);
239 Msg("Plugin \"%s\" loaded with id %d.\n", pl->m_API->GetName(), pl->m_Id);
241 Msg("Plugin \"%s\" is already loaded as %d.\n", pl->m_API->GetName(), pl->m_Id);
246 Msg("Usage: meta load <path>\n");
250 } else if (strcmp(command, "unload") == 0) {
253 int id = atoi(e->Cmd_Argv(2));
256 if (!g_PluginMngr.Unload(id, false, error, sizeof(error)-1))
258 Msg("Unload failed: %s\n", error);
262 Msg("Plugin %d unloaded.\n", id);
266 Msg("Usage: meta unload <id>\n");
270 } else if (strcmp(command, "force_unload") == 0) {
273 int id = atoi(e->Cmd_Argv(2));
276 if (!g_PluginMngr.Unload(id, false, error, sizeof(error)-1))
278 Msg("Force unload failed: %s\n", error);
282 Msg("Plugin %d force unloaded.\n", id);
286 Msg("Usage: meta force_unload <id>\n");
290 } else if (strcmp(command, "clear") == 0) {
291 if (!g_PluginMngr.UnloadAll())
293 Msg("One or more plugins resisted removal (cleaned anyway).\n");
297 Msg("All plugins unloaded.\n");
300 } else if (strcmp(command, "retry") == 0) {
303 int id = atoi(e->Cmd_Argv(2));
306 if (!g_PluginMngr.Retry(id, error, sizeof(error)-1))
308 Msg("Error reloading plugin: %s\n", error);
312 Msg("Plugin %d successfully reloaded.\n", id);
316 Msg("Usage: meta retry <id>\n");
323 Msg("Metamod:Source Menu\n");
324 Msg("usage: meta <command> [arguments]\n");
325 Msg(" clear - Unload all plugins forcefully\n");
326 Msg(" credits - About Metamod:Source\n");
327 Msg(" force_unload - Forcefully unload a plugin\n");
328 Msg(" game - Information about GameDLL\n");
329 Msg(" info - Information about a plugin\n");
330 Msg(" list - List plugins\n");
331 Msg(" load - Load a plugin\n");
332 Msg(" pause - Pause a running plugin\n");
333 Msg(" refresh - Reparse plugins file\n");
334 Msg(" retry - Attempt to reload a plugin\n");
335 Msg(" unload - Unload a loaded plugin\n");
336 Msg(" unpause - Unpause a paused plugin\n");
337 Msg(" version - Version information\n");