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