sourcemm/concommands.cpp
author David Anderson <dvander@alliedmods.net>
Fri Jun 01 17:28:11 2007 +0000 (2007-06-01)
changeset 340 a8b4a311a1e0
parent 303 a199e9b6c67c
child 345 600e30820ea7
permissions -rw-r--r--
added ServerGameClients info output to the "meta game" command
     1 /* ======== SourceMM ========
     2  * Copyright (C) 2004-2007 Metamod:Source Development Team
     3  * No warranties of any kind
     4  *
     5  * License: zlib/libpng
     6  *
     7  * Author(s): David "BAILOPAN" Anderson
     8  * ============================
     9  */
    10 
    11 #include <ctype.h>
    12 #include "CSmmAPI.h"
    13 #include "concommands.h"
    14 #include "CPlugin.h"
    15 #include "sh_string.h"
    16 #include "sh_list.h"
    17 
    18 /**
    19  * @brief Console Command Implementations
    20  * @file concommands.cpp
    21  */
    22 
    23 CAlwaysRegisterableCommand g_EternalCommand;
    24 SMConVarAccessor g_SMConVarAccessor;
    25 
    26 bool SMConVarAccessor::RegisterConCommandBase(ConCommandBase *pCommand)
    27 {
    28 	// Add the FCVAR_GAMEDLL flag 
    29 	// => No crash on exit!
    30 	// UPDATE: Do _not_ add the FCVAR_GAMEDLL flag here, as it
    31 	// causes the command to be unusable on listenservers until you load a map
    32 	// We will set the FCVAR_GAMEDLL flag on all commands we have registered once we are being unloaded
    33 	//pCommand->AddFlags(FCVAR_GAMEDLL);
    34 	m_RegisteredCommands.push_back(pCommand);
    35 
    36 	pCommand->SetNext( NULL );
    37 	g_Engine.icvar->RegisterConCommandBase(pCommand);
    38 
    39 	return true;
    40 }
    41 
    42 bool SMConVarAccessor::Register(ConCommandBase *pCommand)
    43 {
    44 	//simple, don't mark as part of sourcemm!
    45 	pCommand->SetNext( NULL );
    46 	g_Engine.icvar->RegisterConCommandBase(pCommand);
    47 
    48 	return true;
    49 }
    50 
    51 void SMConVarAccessor::MarkCommandsAsGameDLL()
    52 {
    53 	for (SourceHook::List<ConCommandBase*>::iterator iter = m_RegisteredCommands.begin();
    54 		iter != m_RegisteredCommands.end(); ++iter)
    55 	{
    56 		(*iter)->AddFlags(FCVAR_GAMEDLL);
    57 	}
    58 }
    59 
    60 void SMConVarAccessor::Unregister(ConCommandBase *pCommand)
    61 {
    62 	ICvar *cv = g_Engine.icvar;
    63 	ConCommandBase *ptr = cv->GetCommands();
    64 
    65 	if (ptr == pCommand)
    66 	{
    67 		//first in list
    68 		g_EternalCommand.BringToFront();
    69 		g_EternalCommand.SetNext(const_cast<ConCommandBase *>(pCommand->GetNext()));
    70 	} else {
    71 		//find us and unregister us
    72 		ConCommandBase *pPrev = NULL;
    73 		while (ptr)
    74 		{
    75 			if (ptr == pCommand)
    76 				break;
    77 			pPrev = ptr;
    78 			ptr = const_cast<ConCommandBase *>(ptr->GetNext());
    79 		}
    80 		if (pPrev && ptr == pCommand)
    81 		{
    82 			pPrev->SetNext(const_cast<ConCommandBase *>(pCommand->GetNext()));
    83 		}
    84 	}
    85 }
    86 
    87 void SMConVarAccessor::UnregisterGameDLLCommands()
    88 {
    89 	ConCommandBase *begin = g_Engine.icvar->GetCommands();
    90 	ConCommandBase *iter = begin;
    91 	ConCommandBase *prev = NULL;
    92 	while (iter)
    93 	{
    94 		// watch out for the ETERNAL COMMAND!
    95 		if (iter != &g_EternalCommand && iter->IsBitSet(FCVAR_GAMEDLL))
    96 		{
    97 			// Remove it!
    98 			if (iter == begin)
    99 			{
   100 				g_EternalCommand.BringToFront();
   101 				iter = const_cast<ConCommandBase*>(iter->GetNext());
   102 				g_EternalCommand.SetNext(iter);
   103 				prev = &g_EternalCommand;
   104 				continue;
   105 			}
   106 			else
   107 			{
   108 				iter = const_cast<ConCommandBase*>(iter->GetNext());
   109 				prev->SetNext(iter);
   110 				continue;
   111 			}
   112 		}
   113 		prev = iter;
   114 		iter = const_cast<ConCommandBase*>(iter->GetNext());
   115 	}
   116 }
   117 
   118 ConVar metamod_version("metamod_version", SOURCEMM_VERSION, FCVAR_REPLICATED | FCVAR_SPONLY | FCVAR_NOTIFY, "Metamod:Source Version");
   119 #if defined WIN32 || defined _WIN32
   120 ConVar mm_pluginsfile("mm_pluginsfile", "addons\\metamod\\metaplugins.ini", FCVAR_SPONLY, "Metamod:Source Plugins File");
   121 #else
   122 ConVar mm_pluginsfile("mm_pluginsfile", "addons/metamod/metaplugins.ini", FCVAR_SPONLY, "Metamod:Source Plugins File");
   123 #endif
   124 
   125 CON_COMMAND(meta, "Metamod:Source Menu")
   126 {
   127 	IVEngineServer *e = g_Engine.engine;
   128 
   129 	int args = e->Cmd_Argc();
   130 
   131 	if (args >= 2)
   132 	{
   133 		const char *command = e->Cmd_Argv(1);
   134 		if (strcmp(command, "credits") == 0)
   135 		{
   136 			CONMSG("Metamod:Source was developed by:\n");
   137 			CONMSG("  SourceHook: Pavol \"PM OnoTo\" Marko\n");
   138 			CONMSG("  GameDLL/Plugins: David \"BAILOPAN\" Anderson\n");
   139 			CONMSG("  GameDLL: Scott \"Damaged Soul\" Ehlert\n");
   140 			CONMSG("For more information, see the official website\n");
   141 			CONMSG("http://www.sourcemm.net/\n");
   142 			
   143 			return;
   144 		} else if (strcmp(command, "version") == 0) {
   145 			CONMSG("Metamod:Source version %s\n", SOURCEMM_VERSION);
   146 			CONMSG("Compiled on: %s\n", SOURCEMM_DATE);
   147 			CONMSG("Plugin interface version: %d:%d\n", PLAPI_VERSION, PLAPI_MIN_VERSION);
   148 			CONMSG("SourceHook version: %d:%d\n", g_SourceHook.GetIfaceVersion(), g_SourceHook.GetImplVersion());
   149 			CONMSG("http://www.sourcemm.net/\n");
   150 
   151 			return;
   152 		} else if (strcmp(command, "game") == 0) {
   153 			CONMSG("GameDLL Information\n");
   154 			CONMSG("  Description: %s\n", g_GameDll.pGameDLL->GetGameDescription());
   155 			CONMSG("  Mod Path: %s\n", g_ModPath.c_str());
   156 			CONMSG("  DLL Path: %s\n", g_BinPath.c_str());
   157 			CONMSG("  Interface: ServerGameDLL%03d, ServerGameClients%03d\n", g_GameDllVersion, g_GameClientsVersion);
   158 
   159 			// Display user messages
   160 			if (g_SmmAPI.MsgCacheSuccessful())
   161 			{
   162 				const char *msgname;
   163 				int msgsize;
   164 				int msgcount = g_SmmAPI.GetUserMessageCount();
   165 
   166 				if (msgcount > 0)
   167 				{
   168 					CONMSG("  User Messages:  %-32.31s  %-5s  %-5s\n", "Name", "Index", "Size");
   169 
   170 					for (int i = 0; i < msgcount; i++)
   171 					{
   172 						msgname = g_SmmAPI.GetUserMessage(i, &msgsize);
   173 
   174 						CONMSG("                  %-32.31s  %-5d  %-5d\n", msgname, i, msgsize); 
   175 					}
   176 
   177 					CONMSG("  %d user message%s in total\n", msgcount, (msgcount > 1) ? "s" : "");
   178 				} else {
   179 					CONMSG("  User Messages: None\n");
   180 				}
   181 			} else {
   182 				CONMSG("  User Messages: Failed to get list of user messages\n");
   183 			}
   184 
   185 			return;
   186 		} else if (strcmp(command, "refresh") == 0) {
   187 			char full_path[255];
   188 			g_SmmAPI.PathFormat(full_path, sizeof(full_path), "%s/%s", g_ModPath.c_str(), GetPluginsFile());
   189 
   190 			LoadPluginsFromFile(full_path);
   191 
   192 			return;
   193 		} else if (strcmp(command, "list") == 0) {
   194 			SourceMM::CPluginManager::CPlugin *pl;
   195 			PluginIter i;
   196 			const char *status="";
   197 			const char *version=NULL;
   198 			const char *name=NULL;
   199 			const char *author=NULL;
   200 
   201 			CONMSG("-Id- %-20.19s  %-10.9s  %-20.19s %-8.7s\n", "Name", "Version", "Author", "Status");
   202 			for (i=g_PluginMngr._begin(); i!=g_PluginMngr._end(); i++)
   203 			{
   204 				pl = (*i);
   205 				if (!pl)
   206 					break;
   207 				if (pl->m_Status == Pl_Paused)
   208 				{
   209 					status = "PAUSE";
   210 				} else if (pl->m_Status == Pl_Running) {
   211 					if (pl->m_API && pl->m_API->QueryRunning(NULL, 0))
   212 						status = "RUN";
   213 					else
   214 						status = "STOPPED";
   215 				} else if (pl->m_Status == Pl_Refused) {
   216 					status = "FAIL";
   217 				} else if (pl->m_Status == Pl_Error) {
   218 					status = "ERROR";
   219 				} else if (pl->m_Status == Pl_NotFound) {
   220 					status = "NOFILE";
   221 				}
   222 
   223 				if (pl->m_API)
   224 				{
   225 					version = pl->m_API->GetVersion();
   226 					author = pl->m_API->GetAuthor();
   227 					name = pl->m_API->GetName();
   228 				} else {
   229 					version = "-";
   230 					author = "-";
   231 					name = "-";
   232 				}
   233 
   234 				if (!version)
   235 					version = "-";
   236 				if (!author)
   237 					author = "-";
   238 				if (!name)
   239 					name = pl->m_File.c_str();
   240 
   241 
   242 				CONMSG("[%02d] %-20.19s  %-10.9s  %-20.19s %-8.7s\n", pl->m_Id, name, version, author, status);
   243 			}
   244 
   245 			//CONMSG("\n");
   246 
   247 			return;
   248 		} else if (strcmp(command, "cmds") == 0) {
   249 			if (args >= 3)
   250 			{
   251 				int id = atoi(e->Cmd_Argv(2));
   252 				SourceMM::CPluginManager::CPlugin *pl = g_PluginMngr.FindById(id);
   253 
   254 				if (!pl)
   255 				{
   256 					CONMSG("Plugin %d not found.\n", id);
   257 					return;
   258 				}
   259 
   260 				if (!pl->m_API)
   261 				{
   262 					CONMSG("Plugin %d is not loaded.\n", id);
   263 				} else {
   264 					CONMSG("Console commands for %s:\n", pl->m_API->GetName());
   265 					SourceHook::List<ConCommandBase *>::iterator ci;
   266 					size_t count = 0;
   267 
   268 					for (ci=pl->m_Cmds.begin(); ci!=pl->m_Cmds.end(); ci++)
   269 					{
   270 						count++;
   271 						CONMSG(" [%5d] %-s\n", count, (*ci)->GetName());
   272 					}
   273 				}
   274 			} else {
   275 				CONMSG("Usage: meta cmds <id>\n");
   276 			}
   277 
   278 			return;
   279 		} else if (strcmp(command, "cvars") == 0) {
   280 			if (args >= 3)
   281 			{
   282 				int id = atoi(e->Cmd_Argv(2));
   283 				SourceMM::CPluginManager::CPlugin *pl = g_PluginMngr.FindById(id);
   284 
   285 				if (!pl)
   286 				{
   287 					CONMSG("Plugin %d not found.\n", id);
   288 					return;
   289 				}
   290 
   291 				if (!pl->m_API)
   292 				{
   293 					CONMSG("Plugin %d is not loaded.\n", id);
   294 				} else {
   295 					CONMSG("Registered cvars for %s:\n", pl->m_API->GetName());
   296 					SourceHook::List<ConCommandBase *>::iterator ci;
   297 					size_t count = 0;
   298 
   299 					for (ci=pl->m_Cvars.begin(); ci!=pl->m_Cvars.end(); ci++)
   300 					{
   301 						count++;
   302 						CONMSG(" [%5d] %-s\n", count, (*ci)->GetName());
   303 					}
   304 				}
   305 			} else {
   306 				CONMSG("Usage: meta cvars <id>\n");
   307 			}
   308 
   309 			return;
   310 		} else if (strcmp(command, "info") == 0) {
   311 			if (args >= 3)
   312 			{
   313 				int id = atoi(e->Cmd_Argv(2));
   314 				SourceMM::CPluginManager::CPlugin *pl = g_PluginMngr.FindById(id);
   315 				if (!pl)
   316 				{
   317 					CONMSG("Plugin %d not found.\n", id);
   318 					return;
   319 				}
   320 
   321 				if (!pl->m_API)
   322 				{
   323 					CONMSG("Plugin %d is not loaded.\n", id);
   324 				} else {
   325 					if (pl->m_Status == Pl_Paused)
   326 					{
   327 						CONMSG("Plugin %d is paused.\n", id);
   328 					} else if (pl->m_Status == Pl_Running) {
   329 						char run_msg[255];
   330 						bool run = false;
   331 						if (pl->m_API && pl->m_API->QueryRunning(run_msg, sizeof(run_msg)-1))
   332 							run = true;
   333 						if (run)
   334 						{
   335 							CONMSG("Plugin %d is running.\n", id);
   336 						} else {
   337 							CONMSG("Plugin %d is stopped: %s\n", id, run_msg);
   338 						}
   339 					}
   340 					CONMSG("  Name: \"%s\" by %s\n", pl->m_API->GetName(), pl->m_API->GetAuthor());
   341 					CONMSG("  Version: %s\n", pl->m_API->GetVersion());
   342 					CONMSG("  Description: %s\n", pl->m_API->GetDescription());
   343 					CONMSG("  License: %s\n", pl->m_API->GetLicense());
   344 					CONMSG("  URL: %s\n", pl->m_API->GetURL());
   345 					CONMSG("  Details: API %03d, Date: %s\n", pl->m_API->GetApiVersion(), pl->m_API->GetDate());
   346 				}
   347 				CONMSG("File: %s\n\n", pl->m_File.c_str());
   348 
   349 				return;
   350 			} else {
   351 				CONMSG("Usage: meta info <id>\n");
   352 
   353 				return;
   354 			}
   355 		} else if (strcmp(command, "pause") == 0) {
   356 			if (args >= 3)
   357 			{
   358 				int id = atoi(e->Cmd_Argv(2));
   359 
   360 				char error[255];
   361 
   362 				if (!g_PluginMngr.Pause(id, error, sizeof(error)))
   363 				{
   364 					CONMSG("Pause failed: %s\n", error);
   365 					return;
   366 				}
   367 				
   368 				CONMSG("Plugin %d has been paused.\n", id);
   369 
   370 				return;
   371 			} else {
   372 				CONMSG("Usage: meta pause <id>\n");
   373 
   374 				return;
   375 			}
   376 		} else if (strcmp(command, "unpause") == 0) {
   377 			if (args >= 3)
   378 			{
   379 				int id = atoi(e->Cmd_Argv(2));
   380 				char error[255];
   381 
   382 				if (!g_PluginMngr.Unpause(id, error, sizeof(error)))
   383 				{
   384 					CONMSG("Unpause failed: %s\n", error);
   385 					return;
   386 				}
   387 
   388 				CONMSG("Plugin %d has been unpaused.\n", id);
   389 
   390 				return;
   391 			} else {
   392 				CONMSG("Usage: meta unpause <id>\n");
   393 
   394 				return;
   395 			}
   396 		} else if (strcmp(command, "load") == 0) {
   397 			if (args >= 3)
   398 			{
   399 				const char *file = e->Cmd_Argv(2);
   400 				char full_path[255];
   401 
   402 				const char *alias = g_PluginMngr.LookupAlias(file);
   403 				if (alias)
   404 				{
   405 					file = alias;
   406 				}
   407 
   408 				if (file[0] == '/' || strcmp(&(file[1]), ":\\") == 0)
   409 				{
   410 					g_SmmAPI.PathFormat(full_path, sizeof(full_path), "%s", file);
   411 				} else {
   412 					const char *ext = UTIL_GetExtension(file);
   413 #if defined WIN32 || defined _WIN32
   414 					ext = ext ? "" : ".dll";
   415 #else
   416 					ext = ext ? "" : "_i486.so";
   417 #endif
   418 					g_SmmAPI.PathFormat(full_path, sizeof(full_path), "%s/%s%s", g_ModPath.c_str(), file, ext);
   419 				}
   420 
   421 				char error[255]={0};
   422 				bool already;
   423 				SourceMM::CPluginManager::CPlugin *pl;
   424 
   425 				PluginId id = g_PluginMngr.Load(full_path, Pl_Console, already, error, sizeof(error));
   426 				pl = g_PluginMngr.FindById(id);
   427 				if (!pl || id < Pl_MinId || (pl->m_Status < Pl_Paused))
   428 				{
   429 					CONMSG("Failed to load plugin %s (%s).\n", file, error);
   430 					return;
   431 				}
   432 
   433 				if (!already)
   434 				{
   435 					CONMSG("Plugin \"%s\" loaded with id %d.\n", pl->m_API->GetName(), pl->m_Id);
   436 				} else {
   437 					CONMSG("Plugin \"%s\" is already loaded as %d.\n", pl->m_API->GetName(), pl->m_Id);
   438 				}
   439 				
   440 				return;
   441 			} else {
   442 				CONMSG("Usage: meta load <path>\n");
   443 
   444 				return;
   445 			}
   446 		} else if ( (strcmp(command, "alias") == 0) ||
   447 					(strcmp(command, "aliases") == 0) ) {
   448 			if (args >= 4)
   449 			{
   450 				const char *alias = e->Cmd_Argv(2);
   451 				const char *value = e->Cmd_Argv(3);
   452 
   453 				g_PluginMngr.SetAlias(alias, value);
   454 				if (value[0] == '\0')
   455 				{
   456 					CONMSG("Deleted alias: %s.\n", alias);
   457 				} else {
   458 					CONMSG("Set alias \"%s\" to: %s\n", alias, value);
   459 				}
   460 			} else if (args >= 3) {
   461 				const char *alias = e->Cmd_Argv(2);
   462 				const char *value = g_PluginMngr.LookupAlias(alias);
   463 				if (value)
   464 				{
   465 					CONMSG("Alias \"%s\" is set to: %s\n", alias, value);
   466 				} else {
   467 					CONMSG("Alias \"%s\" was not found.\n", alias);
   468 				}
   469 			} else {
   470 				SourceHook::List<SourceMM::CNameAlias *>::iterator iter, end;
   471 				SourceMM::CNameAlias *p;
   472 
   473 				iter = g_PluginMngr._alias_begin();
   474 				end = g_PluginMngr._alias_end();
   475 				size_t total = 0;
   476 				if (iter != end)
   477 				{
   478 					CONMSG("%-10.9s %s\n", "Alias", "File");
   479 					CONMSG(" --- \n");
   480 					for (; iter!=end; iter++)
   481 					{
   482 						p = (*iter);
   483 						CONMSG("%-10.9s %s\n", p->alias.c_str(), p->value.c_str());
   484 						total++;
   485 					}
   486 					CONMSG(" --- \n");
   487 					CONMSG("%d aliases total.\n", total);
   488 				} else {
   489 					CONMSG("No aliases found.\n");
   490 				}
   491 			}
   492 			return;
   493 		} else if (strcmp(command, "unload") == 0) {
   494 			if (args >= 3)
   495 			{
   496 				const char *file = e->Cmd_Argv(2);
   497 				int id = atoi(file);
   498 				char error[255]={0};
   499 
   500 				if (id == 0 && isalpha(file[0]))
   501 				{
   502 					char full_path[255];
   503 					const char *alias = g_PluginMngr.LookupAlias(file);
   504 
   505 					if (alias)
   506 					{
   507 						file = alias;
   508 					}
   509 
   510 					/* first check if it's a known filename */
   511 					if (file[0] == '/' || strcmp(&(file[1]), ":\\") == 0)
   512 					{
   513 						g_SmmAPI.PathFormat(full_path, sizeof(full_path), "%s", file);
   514 					} else {
   515 						const char *ext = UTIL_GetExtension(file);
   516 #if defined WIN32 || defined _WIN32
   517 						ext = ext ? "" : ".dll";
   518 #else
   519 						ext = ext ? "" : "_i486.so";
   520 #endif
   521 						g_SmmAPI.PathFormat(full_path, sizeof(full_path), "%s/%s%s", g_ModPath.c_str(), file, ext);
   522 					}
   523 
   524 					SourceHook::List<SourceMM::CPluginManager::CPlugin *>::iterator iter, end;
   525 					SourceMM::CPluginManager::CPlugin *pl;
   526 					iter = g_PluginMngr._begin();
   527 					end = g_PluginMngr._end();
   528 					for (; iter!=end; iter++)
   529 					{
   530 						pl = (*iter);
   531 						if (strcmp(pl->m_File.c_str(), full_path) == 0)
   532 						{
   533 							id = pl->m_Id;
   534 							break;
   535 						}
   536 					}
   537 					if (id == 0)
   538 					{
   539 						CONMSG("Plugin \"%s\" not found.\n", full_path);
   540 						return;
   541 					}
   542 				}
   543 
   544 				if (!g_PluginMngr.Unload(id, false, error, sizeof(error)))
   545 				{
   546 					CONMSG("Unload failed: %s\n", error);
   547 					return;
   548 				}
   549 
   550 				CONMSG("Plugin %d unloaded.\n", id);
   551 			} else {
   552 				CONMSG("Usage: meta unload <id>\n");
   553 			}
   554 			return;
   555 		} else if (strcmp(command, "force_unload") == 0) {
   556 			if (args >= 3)
   557 			{
   558 				int id = atoi(e->Cmd_Argv(2));
   559 				char error[255]={0};
   560 
   561 				if (!g_PluginMngr.Unload(id, false, error, sizeof(error)))
   562 				{
   563 					CONMSG("Force unload failed: %s\n", error);
   564 					return;
   565 				}
   566 
   567 				CONMSG("Plugin %d force unloaded.\n", id);
   568 
   569 				return;
   570 			} else {
   571 				CONMSG("Usage: meta force_unload <id>\n");
   572 
   573 				return;
   574 			}
   575 		} else if (strcmp(command, "clear") == 0) {
   576 			if (!g_PluginMngr.UnloadAll())
   577 			{
   578 				CONMSG("One or more plugins resisted removal (cleaned anyway).\n");
   579 				return;
   580 			} 
   581 
   582 			CONMSG("All plugins unloaded.\n");
   583 
   584 			return;
   585 		} else if (strcmp(command, "retry") == 0) {
   586 			if (args >= 3)
   587 			{
   588 				int id = atoi(e->Cmd_Argv(2));
   589 				char error[255];
   590 
   591 				if (!g_PluginMngr.Retry(id, error, sizeof(error)))
   592 				{
   593 					CONMSG("Error reloading plugin: %s\n", error);
   594 					return;
   595 				}
   596 
   597 				CONMSG("Plugin %d successfully reloaded.\n", id);
   598 
   599 				return;
   600 			} else {
   601 				CONMSG("Usage: meta retry <id>\n");
   602 
   603 				return;
   604 			}
   605 		}
   606 	}
   607 
   608 	CONMSG("Metamod:Source Menu\n");
   609 	CONMSG("usage: meta <command> [arguments]\n");
   610 	CONMSG("  alias        - List or set an alias\n");
   611 	CONMSG("  clear        - Unload all plugins forcefully\n");
   612 	CONMSG("  cmds         - Show plugin commands\n");
   613 	CONMSG("  cvars        - Show plugin cvars\n");
   614 	CONMSG("  credits      - About Metamod:Source\n");
   615 	CONMSG("  force_unload - Forcefully unload a plugin\n");
   616 	CONMSG("  game         - Information about GameDLL\n");
   617 	CONMSG("  info         - Information about a plugin\n");
   618 	CONMSG("  list         - List plugins\n");
   619 	CONMSG("  load         - Load a plugin\n");
   620 	CONMSG("  pause        - Pause a running plugin\n");
   621 	CONMSG("  refresh      - Reparse plugins file\n");
   622 	CONMSG("  retry        - Attempt to reload a plugin\n");
   623 	CONMSG("  unload       - Unload a loaded plugin\n");
   624 	CONMSG("  unpause      - Unpause a paused plugin\n");
   625 	CONMSG("  version      - Version information\n");
   626 }
   627 
   628 CAlwaysRegisterableCommand::CAlwaysRegisterableCommand()
   629 {
   630 	Create("", NULL, FCVAR_UNREGISTERED|FCVAR_GAMEDLL);
   631 	m_pICvar = NULL;
   632 }
   633 
   634 bool CAlwaysRegisterableCommand::IsRegistered( void ) const
   635 {
   636 	return false;
   637 }
   638 
   639 void CAlwaysRegisterableCommand::BringToFront()
   640 {
   641 	if (!m_pICvar)
   642 		m_pICvar = g_Engine.icvar;
   643 
   644 	// First, let's try to find us!
   645 	ConCommandBase *pPtr = m_pICvar->GetCommands();
   646 
   647 	if (pPtr == this)
   648 	{
   649 		// We are already at the beginning; Nothing to do
   650 		return;
   651 	}
   652 
   653 	while (pPtr)
   654 	{
   655 		if (pPtr == this && pPtr->IsCommand() && stricmp(GetName(), pPtr->GetName()) == 0)
   656 			break;
   657 		ConCommandBase *pPrev = NULL;
   658 		while (pPtr)
   659 		{
   660 			if (pPtr == this)
   661 				break;
   662 			pPrev = pPtr;
   663 			pPtr = const_cast<ConCommandBase*>(pPtr->GetNext());
   664 		}
   665 		if (pPrev && pPtr == this)
   666 		{
   667 			pPrev->SetNext(m_pNext);		// Remove us from the list
   668 		}
   669 		// Now, register us
   670 		SetNext(NULL);
   671 		m_pICvar->RegisterConCommandBase(this);
   672 	}
   673 }
   674 
   675 void ClientCommand_handler(edict_t *client)
   676 {
   677 	IVEngineServer *e = g_Engine.engine;
   678 	const char *cmd = e->Cmd_Argv(0);
   679 
   680 	if (strcmp(cmd, "meta") == 0)
   681 	{
   682 		int args = e->Cmd_Argc();
   683 		if (args == 2)
   684 		{
   685 			const char *subcmd = e->Cmd_Argv(1);
   686 
   687 			if (strcmp(subcmd, "credits") == 0)
   688 			{
   689 				CLIENT_CONMSG(client, "Metamod:Source was developed by:\n");
   690 				CLIENT_CONMSG(client, "  SourceHook: Pavol \"PM OnoTo\" Marko\n");
   691 				CLIENT_CONMSG(client, "  GameDLL/Plugins: David \"BAILOPAN\" Anderson\n");
   692 				CLIENT_CONMSG(client, "  GameDLL: Scott \"Damaged Soul\" Ehlert\n");
   693 				CLIENT_CONMSG(client, "For more information, see the official website\n");
   694 				CLIENT_CONMSG(client, "http://www.sourcemm.net/\n");
   695 
   696 				RETURN_META(MRES_SUPERCEDE);
   697 			} else if(strcmp(subcmd, "version") == 0) {
   698 				CLIENT_CONMSG(client, "Metamod:Source version %s\n", SOURCEMM_VERSION);
   699 				CLIENT_CONMSG(client, "Compiled on: %s\n", SOURCEMM_DATE);
   700 				CLIENT_CONMSG(client, "Plugin interface version: %d:%d\n", PLAPI_VERSION, PLAPI_MIN_VERSION);
   701 				CLIENT_CONMSG(client, "SourceHook version: %d:%d\n", g_SourceHook.GetIfaceVersion(), g_SourceHook.GetImplVersion());
   702 				CLIENT_CONMSG(client, "http://www.sourcemm.net/\n");
   703 
   704 				RETURN_META(MRES_SUPERCEDE);
   705 			} else if(strcmp(subcmd, "list") == 0) {
   706 				SourceMM::CPluginManager::CPlugin *pl;
   707 				Pl_Status st;
   708 				PluginIter i;
   709 				const char *version = NULL;
   710 				const char *name = NULL;
   711 				const char *author = NULL;
   712 				const char *status = NULL;
   713 
   714 				CLIENT_CONMSG(client, "-Id- %-20.19s  %-10.9s  %-20.19s  %6s\n", "Name", "Version", "Author", "Status");
   715 
   716 				for (i=g_PluginMngr._begin(); i!=g_PluginMngr._end(); i++)
   717 				{
   718 					pl = (*i);
   719 					if (!pl)
   720 						break;
   721 					
   722 					st = pl->m_Status;
   723 
   724 					/* Only show plugins that are running or paused */
   725 					if (pl->m_API && (st == Pl_Running || st == Pl_Paused))
   726 					{
   727 						version = pl->m_API->GetVersion();
   728 						author = pl->m_API->GetAuthor();
   729 						name = pl->m_API->GetName();
   730 
   731 						if (st == Pl_Running && pl->m_API->QueryRunning(NULL, 0))
   732 						{
   733 							status = "RUN";
   734 						} else {
   735 							status = "PAUSE";
   736 						}
   737 
   738 						if (!version || !author || !name)
   739 							break;
   740 
   741 						CLIENT_CONMSG(client, "[%02d] %-20.19s  %-10.9s  %-20.19s  %6s\n", pl->m_Id, name, version, author, status);
   742 					}
   743 				}
   744 
   745 				RETURN_META(MRES_SUPERCEDE);
   746 			}
   747 		}
   748 
   749 		CLIENT_CONMSG(client, "Metamod:Source Menu\n");
   750 		CLIENT_CONMSG(client, "usage: meta <command>\n");
   751 		CLIENT_CONMSG(client, "  credits - About Metamod:Source\n");
   752 		CLIENT_CONMSG(client, "  list    - List plugins\n");
   753 		CLIENT_CONMSG(client, "  version - Version information\n");
   754 
   755 		RETURN_META(MRES_SUPERCEDE);
   756 	}
   757 
   758 	RETURN_META(MRES_IGNORED);
   759 }
   760 
   761 const char *GetPluginsFile()
   762 {
   763 	return mm_pluginsfile.GetString();
   764 }