sourcemm/concommands.cpp
author David Anderson <dvander@alliedmods.net>
Thu May 25 04:49:47 2006 +0000 (2006-05-25)
changeset 205 08964c08d894
parent 194 86c91d09179f
child 207 5c09084ad251
permissions -rw-r--r--
added alias ability
fixed gamedll version finding fall through
     1 /* ======== SourceMM ========
     2 * Copyright (C) 2004-2006 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("  Mod path: %s\n", g_ModPath.c_str());
   155 			CONMSG("  Dll path: %s\n", g_BinPath.c_str());
   156 
   157 			return;
   158 		} else if (strcmp(command, "refresh") == 0) {
   159 			char full_path[255];
   160 			g_SmmAPI.PathFormat(full_path, sizeof(full_path) - 1, "%s/%s", g_ModPath.c_str(), GetPluginsFile());
   161 
   162 			LoadPluginsFromFile(full_path);
   163 
   164 			return;
   165 		} else if (strcmp(command, "list") == 0) {
   166 			SourceMM::CPluginManager::CPlugin *pl;
   167 			PluginIter i;
   168 			const char *status="";
   169 			const char *version=NULL;
   170 			const char *name=NULL;
   171 			const char *author=NULL;
   172 
   173 			CONMSG("-Id- %-20.19s  %-10.9s  %-16.15s %-8.7s\n", "Name", "Version", "Author", "Status");
   174 			for (i=g_PluginMngr._begin(); i!=g_PluginMngr._end(); i++)
   175 			{
   176 				pl = (*i);
   177 				if (!pl)
   178 					break;
   179 				if (pl->m_Status == Pl_Paused)
   180 				{
   181 					status = "PAUSE";
   182 				} else if (pl->m_Status == Pl_Running) {
   183 					if (pl->m_API && pl->m_API->QueryRunning(NULL, 0))
   184 						status = "RUN";
   185 					else
   186 						status = "STOPPED";
   187 				} else if (pl->m_Status == Pl_Refused) {
   188 					status = "FAIL";
   189 				} else if (pl->m_Status == Pl_Error) {
   190 					status = "ERROR";
   191 				} else if (pl->m_Status == Pl_NotFound) {
   192 					status = "NOFILE";
   193 				}
   194 
   195 				if (pl->m_API)
   196 				{
   197 					version = pl->m_API->GetVersion();
   198 					author = pl->m_API->GetAuthor();
   199 					name = pl->m_API->GetName();
   200 				} else {
   201 					version = "-";
   202 					author = "-";
   203 					name = "-";
   204 				}
   205 
   206 				if (!version)
   207 					version = "-";
   208 				if (!author)
   209 					author = "-";
   210 				if (!name)
   211 					name = pl->m_File.c_str();
   212 
   213 
   214 				CONMSG("[%02d] %-20.19s  %-10.9s  %-16.15s %-8.7s\n", pl->m_Id, name, version, author, status);
   215 			}
   216 
   217 			//CONMSG("\n");
   218 
   219 			return;
   220 		} else if (strcmp(command, "cmds") == 0) {
   221 			if (args >= 3)
   222 			{
   223 				int id = atoi(e->Cmd_Argv(2));
   224 				SourceMM::CPluginManager::CPlugin *pl = g_PluginMngr.FindById(id);
   225 
   226 				if (!pl)
   227 				{
   228 					CONMSG("Plugin %d not found.\n", id);
   229 					return;
   230 				}
   231 
   232 				if (!pl->m_API)
   233 				{
   234 					CONMSG("Plugin %d is not loaded.\n", id);
   235 				} else {
   236 					CONMSG("Console commands for %s:\n", pl->m_API->GetName());
   237 					SourceHook::List<ConCommandBase *>::iterator ci;
   238 					size_t count = 0;
   239 
   240 					for (ci=pl->m_Cmds.begin(); ci!=pl->m_Cmds.end(); ci++)
   241 					{
   242 						count++;
   243 						CONMSG(" [%5d] %-s\n", count, (*ci)->GetName());
   244 					}
   245 				}
   246 			} else {
   247 				CONMSG("Usage: meta cmds <id>\n");
   248 			}
   249 
   250 			return;
   251 		} else if (strcmp(command, "cvars") == 0) {
   252 			if (args >= 3)
   253 			{
   254 				int id = atoi(e->Cmd_Argv(2));
   255 				SourceMM::CPluginManager::CPlugin *pl = g_PluginMngr.FindById(id);
   256 
   257 				if (!pl)
   258 				{
   259 					CONMSG("Plugin %d not found.\n", id);
   260 					return;
   261 				}
   262 
   263 				if (!pl->m_API)
   264 				{
   265 					CONMSG("Plugin %d is not loaded.\n", id);
   266 				} else {
   267 					CONMSG("Registered cvars for %s:\n", pl->m_API->GetName());
   268 					SourceHook::List<ConCommandBase *>::iterator ci;
   269 					size_t count = 0;
   270 
   271 					for (ci=pl->m_Cvars.begin(); ci!=pl->m_Cvars.end(); ci++)
   272 					{
   273 						count++;
   274 						CONMSG(" [%5d] %-s\n", count, (*ci)->GetName());
   275 					}
   276 				}
   277 			} else {
   278 				CONMSG("Usage: meta cvars <id>\n");
   279 			}
   280 
   281 			return;
   282 		} else if (strcmp(command, "info") == 0) {
   283 			if (args >= 3)
   284 			{
   285 				int id = atoi(e->Cmd_Argv(2));
   286 				SourceMM::CPluginManager::CPlugin *pl = g_PluginMngr.FindById(id);
   287 				if (!pl)
   288 				{
   289 					CONMSG("Plugin %d not found.\n", id);
   290 					return;
   291 				}
   292 
   293 				if (!pl->m_API)
   294 				{
   295 					CONMSG("Plugin %d is not loaded.\n", id);
   296 				} else {
   297 					if (pl->m_Status == Pl_Paused)
   298 					{
   299 						CONMSG("Plugin %d is paused.\n", id);
   300 					} else if (pl->m_Status == Pl_Running) {
   301 						char run_msg[255];
   302 						bool run = false;
   303 						if (pl->m_API && pl->m_API->QueryRunning(run_msg, sizeof(run_msg)-1))
   304 							run = true;
   305 						if (run)
   306 						{
   307 							CONMSG("Plugin %d is running.\n", id);
   308 						} else {
   309 							CONMSG("Plugin %d is stopped: %s\n", id, run_msg);
   310 						}
   311 					}
   312 					CONMSG("  Name: \"%s\" by %s\n", pl->m_API->GetName(), pl->m_API->GetAuthor());
   313 					CONMSG("  Version: %s\n", pl->m_API->GetVersion());
   314 					CONMSG("  Description: %s\n", pl->m_API->GetDescription());
   315 					CONMSG("  License: %s\n", pl->m_API->GetLicense());
   316 					CONMSG("  URL: %s\n", pl->m_API->GetURL());
   317 					CONMSG("  Details: API %03d, Date: %s\n", pl->m_API->GetApiVersion(), pl->m_API->GetDate());
   318 				}
   319 				CONMSG("File: %s\n\n", pl->m_File.c_str());
   320 
   321 				return;
   322 			} else {
   323 				CONMSG("Usage: meta info <id>\n");
   324 
   325 				return;
   326 			}
   327 		} else if (strcmp(command, "pause") == 0) {
   328 			if (args >= 3)
   329 			{
   330 				int id = atoi(e->Cmd_Argv(2));
   331 
   332 				char error[255];
   333 
   334 				if (!g_PluginMngr.Pause(id, error, sizeof(error)-1))
   335 				{
   336 					CONMSG("Pause failed: %s\n", error);
   337 					return;
   338 				}
   339 				
   340 				CONMSG("Plugin %d has been paused.\n", id);
   341 
   342 				return;
   343 			} else {
   344 				CONMSG("Usage: meta pause <id>\n");
   345 
   346 				return;
   347 			}
   348 		} else if (strcmp(command, "unpause") == 0) {
   349 			if (args >= 3)
   350 			{
   351 				int id = atoi(e->Cmd_Argv(2));
   352 				char error[255];
   353 
   354 				if (!g_PluginMngr.Unpause(id, error, sizeof(error)-1))
   355 				{
   356 					CONMSG("Unpause failed: %s\n", error);
   357 					return;
   358 				}
   359 
   360 				CONMSG("Plugin %d has been unpaused.\n", id);
   361 
   362 				return;
   363 			} else {
   364 				CONMSG("Usage: meta unpause <id>\n");
   365 
   366 				return;
   367 			}
   368 		} else if (strcmp(command, "load") == 0) {
   369 			if (args >= 3)
   370 			{
   371 				const char *file = e->Cmd_Argv(2);
   372 				char full_path[255];
   373 
   374 				const char *alias = g_PluginMngr.LookupAlias(file);
   375 				if (alias)
   376 				{
   377 					file = alias;
   378 				}
   379 
   380 				if (file[0] == '/' || strcmp(&(file[1]), ":\\") == 0)
   381 				{
   382 					g_SmmAPI.PathFormat(full_path, sizeof(full_path)-1, "%s", file);
   383 					snprintf(full_path, sizeof(full_path)-1, "%s", file);
   384 				} else {
   385 					const char *ext = UTIL_GetExtension(file);
   386 #if defined WIN32 || defined _WIN32
   387 					ext = ext ? "" : ".dll";
   388 #else
   389 					ext = ext ? "" : "_i486.so";
   390 #endif
   391 					g_SmmAPI.PathFormat(full_path, sizeof(full_path)-1, "%s/%s%s", g_ModPath.c_str(), file, ext);
   392 				}
   393 
   394 				char error[255]={0};
   395 				bool already;
   396 				SourceMM::CPluginManager::CPlugin *pl;
   397 
   398 				PluginId id = g_PluginMngr.Load(full_path, Pl_Console, already, error, sizeof(error)-1);
   399 				pl = g_PluginMngr.FindById(id);
   400 				if (!pl || id < Pl_MinId || (pl->m_Status < Pl_Paused))
   401 				{
   402 					CONMSG("Failed to load plugin %s (%s).\n", file, error);
   403 					return;
   404 				}
   405 
   406 				if (!already)
   407 				{
   408 					CONMSG("Plugin \"%s\" loaded with id %d.\n", pl->m_API->GetName(), pl->m_Id);
   409 				} else {
   410 					CONMSG("Plugin \"%s\" is already loaded as %d.\n", pl->m_API->GetName(), pl->m_Id);
   411 				}
   412 				
   413 				return;
   414 			} else {
   415 				CONMSG("Usage: meta load <path>\n");
   416 
   417 				return;
   418 			}
   419 		} else if ( (strcmp(command, "alias") == 0) ||
   420 					(strcmp(command, "aliases") == 0) ) {
   421 			if (args >= 4)
   422 			{
   423 				const char *alias = e->Cmd_Argv(2);
   424 				const char *value = e->Cmd_Argv(3);
   425 
   426 				g_PluginMngr.SetAlias(alias, value);
   427 				if (value[0] == '\0')
   428 				{
   429 					CONMSG("Deleted alias: %s.\n", alias);
   430 				} else {
   431 					CONMSG("Set alias \"%s\" to: %s\n", alias, value);
   432 				}
   433 			} else if (args >= 3) {
   434 				const char *alias = e->Cmd_Argv(2);
   435 				const char *value = g_PluginMngr.LookupAlias(alias);
   436 				if (value)
   437 				{
   438 					CONMSG("Alias \"%s\" is set to: %s\n", alias, value);
   439 				} else {
   440 					CONMSG("Alias \"%s\" was not found.\n", alias);
   441 				}
   442 			} else {
   443 				SourceHook::List<SourceMM::CNameAlias *>::iterator iter, end;
   444 				SourceMM::CNameAlias *p;
   445 
   446 				iter = g_PluginMngr._alias_begin();
   447 				end = g_PluginMngr._alias_end();
   448 				size_t total = 0;
   449 				if (iter != end)
   450 				{
   451 					CONMSG("%-10.9s %s\n", "Alias", "File");
   452 					CONMSG(" --- \n");
   453 					for (; iter!=end; iter++)
   454 					{
   455 						p = (*iter);
   456 						CONMSG("%-10.9s %s\n", p->alias.c_str(), p->value.c_str());
   457 						total++;
   458 					}
   459 					CONMSG(" --- \n");
   460 					CONMSG("%d aliases total.\n", total);
   461 				} else {
   462 					CONMSG("No aliases found.\n");
   463 				}
   464 			}
   465 			return;
   466 		} else if (strcmp(command, "unload") == 0) {
   467 			if (args >= 3)
   468 			{
   469 				const char *file = e->Cmd_Argv(2);
   470 				int id = atoi(file);
   471 				char error[255]={0};
   472 
   473 				if (id == 0 && isalpha(file[0]))
   474 				{
   475 					char full_path[255];
   476 					const char *alias = g_PluginMngr.LookupAlias(file);
   477 
   478 					if (alias)
   479 					{
   480 						file = alias;
   481 					}
   482 
   483 					/* first check if it's a known filename */
   484 					if (file[0] == '/' || strcmp(&(file[1]), ":\\") == 0)
   485 					{
   486 						g_SmmAPI.PathFormat(full_path, sizeof(full_path)-1, "%s", file);
   487 						snprintf(full_path, sizeof(full_path)-1, "%s", file);
   488 					} else {
   489 						const char *ext = UTIL_GetExtension(file);
   490 #if defined WIN32 || defined _WIN32
   491 						ext = ext ? "" : ".dll";
   492 #else
   493 						ext = ext ? "" : "_i486.so";
   494 #endif
   495 						g_SmmAPI.PathFormat(full_path, sizeof(full_path)-1, "%s/%s%s", g_ModPath.c_str(), file, ext);
   496 					}
   497 
   498 					SourceHook::List<SourceMM::CPluginManager::CPlugin *>::iterator iter, end;
   499 					SourceMM::CPluginManager::CPlugin *pl;
   500 					iter = g_PluginMngr._begin();
   501 					end = g_PluginMngr._end();
   502 					for (; iter!=end; iter++)
   503 					{
   504 						pl = (*iter);
   505 						if (strcmp(pl->m_File.c_str(), full_path) == 0)
   506 						{
   507 							id = pl->m_Id;
   508 							break;
   509 						}
   510 					}
   511 					if (id == 0)
   512 					{
   513 						CONMSG("Plugin \"%s\" not found.\n", full_path);
   514 						return;
   515 					}
   516 				}
   517 
   518 				if (!g_PluginMngr.Unload(id, false, error, sizeof(error)-1))
   519 				{
   520 					CONMSG("Unload failed: %s\n", error);
   521 					return;
   522 				}
   523 
   524 				CONMSG("Plugin %d unloaded.\n", id);
   525 			} else {
   526 				CONMSG("Usage: meta unload <id>\n");
   527 			}
   528 			return;
   529 		} else if (strcmp(command, "force_unload") == 0) {
   530 			if (args >= 3)
   531 			{
   532 				int id = atoi(e->Cmd_Argv(2));
   533 				char error[255]={0};
   534 
   535 				if (!g_PluginMngr.Unload(id, false, error, sizeof(error)-1))
   536 				{
   537 					CONMSG("Force unload failed: %s\n", error);
   538 					return;
   539 				}
   540 
   541 				CONMSG("Plugin %d force unloaded.\n", id);
   542 
   543 				return;
   544 			} else {
   545 				CONMSG("Usage: meta force_unload <id>\n");
   546 
   547 				return;
   548 			}
   549 		} else if (strcmp(command, "clear") == 0) {
   550 			if (!g_PluginMngr.UnloadAll())
   551 			{
   552 				CONMSG("One or more plugins resisted removal (cleaned anyway).\n");
   553 				return;
   554 			} 
   555 
   556 			CONMSG("All plugins unloaded.\n");
   557 
   558 			return;
   559 		} else if (strcmp(command, "retry") == 0) {
   560 			if (args >= 3)
   561 			{
   562 				int id = atoi(e->Cmd_Argv(2));
   563 				char error[255];
   564 
   565 				if (!g_PluginMngr.Retry(id, error, sizeof(error)-1))
   566 				{
   567 					CONMSG("Error reloading plugin: %s\n", error);
   568 					return;
   569 				}
   570 
   571 				CONMSG("Plugin %d successfully reloaded.\n", id);
   572 
   573 				return;
   574 			} else {
   575 				CONMSG("Usage: meta retry <id>\n");
   576 
   577 				return;
   578 			}
   579 		}
   580 	}
   581 
   582 	CONMSG("Metamod:Source Menu\n");
   583 	CONMSG("usage: meta <command> [arguments]\n");
   584 	CONMSG("  alias        - list or set an alias\n");
   585 	CONMSG("  clear        - Unload all plugins forcefully\n");
   586 	CONMSG("  cmds         - Show plugin commands\n");
   587 	CONMSG("  cvars        - Show plugin cvars\n");
   588 	CONMSG("  credits      - About Metamod:Source\n");
   589 	CONMSG("  force_unload - Forcefully unload a plugin\n");
   590 	CONMSG("  game         - Information about GameDLL\n");
   591 	CONMSG("  info         - Information about a plugin\n");
   592 	CONMSG("  list         - List plugins\n");
   593 	CONMSG("  load         - Load a plugin\n");
   594 	CONMSG("  pause        - Pause a running plugin\n");
   595 	CONMSG("  refresh      - Reparse plugins file\n");
   596 	CONMSG("  retry        - Attempt to reload a plugin\n");
   597 	CONMSG("  unload       - Unload a loaded plugin\n");
   598 	CONMSG("  unpause      - Unpause a paused plugin\n");
   599 	CONMSG("  version      - Version information\n");
   600 }
   601 
   602 CAlwaysRegisterableCommand::CAlwaysRegisterableCommand()
   603 {
   604 	Create("", NULL, FCVAR_UNREGISTERED|FCVAR_GAMEDLL);
   605 	m_pICvar = NULL;
   606 }
   607 
   608 bool CAlwaysRegisterableCommand::IsRegistered( void ) const
   609 {
   610 	return false;
   611 }
   612 
   613 void CAlwaysRegisterableCommand::BringToFront()
   614 {
   615 	if (!m_pICvar)
   616 		m_pICvar = g_Engine.icvar;
   617 
   618 	// First, let's try to find us!
   619 	ConCommandBase *pPtr = m_pICvar->GetCommands();
   620 
   621 	if (pPtr == this)
   622 	{
   623 		// We are already at the beginning; Nothing to do
   624 		return;
   625 	}
   626 
   627 	while (pPtr)
   628 	{
   629 		if (pPtr == this && pPtr->IsCommand() && stricmp(GetName(), pPtr->GetName()) == 0)
   630 			break;
   631 		ConCommandBase *pPrev = NULL;
   632 		while (pPtr)
   633 		{
   634 			if (pPtr == this)
   635 				break;
   636 			pPrev = pPtr;
   637 			pPtr = const_cast<ConCommandBase*>(pPtr->GetNext());
   638 		}
   639 		if (pPrev && pPtr == this)
   640 		{
   641 			pPrev->SetNext(m_pNext);		// Remove us from the list
   642 		}
   643 		// Now, register us
   644 		SetNext(NULL);
   645 		m_pICvar->RegisterConCommandBase(this);
   646 	}
   647 }
   648 
   649 void ClientCommand_handler(edict_t *client)
   650 {
   651 	IVEngineServer *e = g_Engine.engine;
   652 	const char *cmd = e->Cmd_Argv(0);
   653 
   654 	if (strcmp(cmd, "meta") == 0)
   655 	{
   656 		int args = e->Cmd_Argc();
   657 		if (args == 2)
   658 		{
   659 			const char *subcmd = e->Cmd_Argv(1);
   660 
   661 			if (strcmp(subcmd, "credits") == 0)
   662 			{
   663 				CLIENT_CONMSG(client, "Metamod:Source was developed by:\n");
   664 				CLIENT_CONMSG(client, "  SourceHook: Pavol \"PM OnoTo\" Marko\n");
   665 				CLIENT_CONMSG(client, "  GameDLL/Plugins: David \"BAILOPAN\" Anderson\n");
   666 				CLIENT_CONMSG(client, "  GameDLL: Scott \"Damaged Soul\" Ehlert\n");
   667 				CLIENT_CONMSG(client, "For more information, see the official website\n");
   668 				CLIENT_CONMSG(client, "http://www.sourcemm.net/\n");
   669 			}
   670 			else if(strcmp(subcmd, "version") == 0)
   671 			{
   672 				CLIENT_CONMSG(client, "Metamod:Source version %s\n", SOURCEMM_VERSION);
   673 				CLIENT_CONMSG(client, "Compiled on: %s\n", SOURCEMM_DATE);
   674 				CLIENT_CONMSG(client, "Plugin interface version: %d:%d\n", PLAPI_VERSION, PLAPI_MIN_VERSION);
   675 				CLIENT_CONMSG(client, "SourceHook version: %d:%d\n", g_SourceHook.GetIfaceVersion(), g_SourceHook.GetImplVersion());
   676 				CLIENT_CONMSG(client, "http://www.sourcemm.net/\n");
   677 			}
   678 			else if(strcmp(subcmd, "list") == 0)
   679 			{
   680 				SourceMM::CPluginManager::CPlugin *pl;
   681 				PluginIter i;
   682 				const char *version=NULL;
   683 				const char *name=NULL;
   684 				const char *author=NULL;
   685 
   686 				CLIENT_CONMSG(client, "-Id- %-20.19s  %-10.9s  %-16.15s\n", "Name", "Version", "Author");
   687 
   688 				for (i=g_PluginMngr._begin(); i!=g_PluginMngr._end(); i++)
   689 				{
   690 					pl = (*i);
   691 					if (!pl)
   692 						break;
   693 
   694 					// Should paused plugins really show up in the list too?
   695 					if (pl->m_API && (pl->m_Status == Pl_Running || pl->m_Status == Pl_Paused))
   696 					{
   697 						version = pl->m_API->GetVersion();
   698 						author = pl->m_API->GetAuthor();
   699 						name = pl->m_API->GetName();
   700 
   701 						if (!version || !author || !name)
   702 							break;
   703 
   704 						CLIENT_CONMSG(client, "[%02d] %-20.19s  %-10.9s  %-16.15s\n", pl->m_Id, name, version, author);
   705 					}
   706 				}
   707 			}
   708 		}
   709 		else
   710 		{
   711 			CLIENT_CONMSG(client, "Metamod:Source Menu\n");
   712 			CLIENT_CONMSG(client, "usage: meta <command>\n");
   713 			CLIENT_CONMSG(client, "  credits - About Metamod:Source\n");
   714 			CLIENT_CONMSG(client, "  list    - List plugins\n");
   715 			CLIENT_CONMSG(client, "  version - Version information\n");
   716 		}
   717 
   718 		RETURN_META(MRES_SUPERCEDE);
   719 	}
   720 
   721 	RETURN_META(MRES_IGNORED);
   722 }
   723 
   724 const char *GetPluginsFile()
   725 {
   726 	return mm_pluginsfile.GetString();
   727 }