sourcemm/metamod_console.cpp
author David Anderson <dvander@alliedmods.net>
Sat Oct 06 16:47:58 2007 +0000 (2007-10-06)
changeset 376 f2d55f90f697
parent 371 751179604513
child 377 185f66cb03cd
permissions -rw-r--r--
added format/formatargs api
     1 /**
     2  * vim: set ts=4 :
     3  * ======================================================
     4  * Metamod:Source
     5  * Copyright (C) 2004-2007 AlliedModders LLC and authors.
     6  * All rights reserved.
     7  * ======================================================
     8  *
     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.
    12  * 
    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:
    16  *
    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.
    24  *
    25  * Version: $Id$
    26  */
    27 
    28 #if defined _DEBUG
    29 #define DEBUG2
    30 #undef _DEBUG
    31 #endif
    32 #include <ctype.h>
    33 #include "metamod.h"
    34 #include "metamod_util.h"
    35 #include "metamod_console.h"
    36 #include "metamod_plugins.h"
    37 #if defined DEBUG2
    38 #undef DEBUG2
    39 #define _DEBUG
    40 #endif
    41 
    42 using namespace SourceMM;
    43 using namespace SourceHook;
    44 
    45 /**
    46  * @brief Console Command Implementations
    47  * @file concommands.cpp
    48  */
    49 
    50 #define CONMSG			g_Metamod.ConPrintf
    51 #define CLIENT_CONMSG	g_Metamod.ClientConPrintf
    52 
    53 bool Command_Meta(IMetamodSourceCommandInfo *info)
    54 {
    55 	unsigned int args = info->GetArgCount();
    56 
    57 	if (args >= 1)
    58 	{
    59 		const char *command = info->GetArg(1);
    60 		if (strcmp(command, "credits") == 0)
    61 		{
    62 			CONMSG("Metamod:Source was developed by:\n");
    63 			CONMSG("  SourceHook: Pavol \"PM OnoTo\" Marko\n");
    64 			CONMSG("  GameDLL/Plugins: David \"BAILOPAN\" Anderson\n");
    65 			CONMSG("  GameDLL: Scott \"Damaged Soul\" Ehlert\n");
    66 			CONMSG("For more information, see the official website\n");
    67 			CONMSG("http://www.sourcemm.net/\n");
    68 			
    69 			return true;
    70 		}
    71 		else if (strcmp(command, "version") == 0)
    72 		{
    73 			CONMSG("Metamod:Source version %s\n", SOURCEMM_VERSION);
    74 			CONMSG("Compiled on: %s\n", SOURCEMM_DATE);
    75 			CONMSG("Plugin interface version: %d:%d\n", PLAPI_VERSION, PLAPI_MIN_VERSION);
    76 			CONMSG("SourceHook version: %d:%d\n", g_SourceHook.GetIfaceVersion(), g_SourceHook.GetImplVersion());
    77 			CONMSG("http://www.sourcemm.net/\n");
    78 
    79 			return true;
    80 		}
    81 		else if (strcmp(command, "game") == 0)
    82 		{
    83 			CONMSG("GameDLL Information\n");
    84 			CONMSG("  Description: %s\n", provider->GetGameDescription());
    85 			CONMSG("  Mod Path: %s\n", g_Metamod.GetBaseDir());
    86 			CONMSG("  DLL Path: %s\n", g_Metamod.GetGameBinaryPath());
    87 			CONMSG("  Interface: ServerGameDLL%03d\n", g_Metamod.GetGameDLLVersion());
    88 
    89 			// Display user messages
    90 			int messages = g_Metamod.GetUserMessageCount();
    91 			if (messages != -1)
    92 			{
    93 				const char *msgname;
    94 				int msgsize;
    95 
    96 				if (messages > 0)
    97 				{
    98 					CONMSG("  User Messages:  %-32.31s  %-5s  %-5s\n", "Name", "Index", "Size");
    99 
   100 					for (int i = 0; i < messages; i++)
   101 					{
   102 						msgname = g_Metamod.GetUserMessage(i, &msgsize);
   103 
   104 						CONMSG("                  %-32.31s  %-5d  %-5d\n", msgname, i, msgsize); 
   105 					}
   106 
   107 					CONMSG("  %d user message%s in total\n", messages, (messages > 1) ? "s" : "");
   108 				}
   109 				else
   110 				{
   111 					CONMSG("  User Messages: None\n");
   112 				}
   113 			}
   114 			else
   115 			{
   116 				CONMSG("  User Messages: Failed to get list of user messages\n");
   117 			}
   118 
   119 			return true;
   120 		}
   121 		else if (strcmp(command, "refresh") == 0)
   122 		{
   123 			char full_path[255];
   124 			g_Metamod.PathFormat(full_path,
   125 				sizeof(full_path),
   126 				"%s/%s",
   127 				g_Metamod.GetBaseDir(), 
   128 				g_Metamod.GetPluginsFile());
   129 
   130 			LoadPluginsFromFile(full_path);
   131 
   132 			return true;
   133 		}
   134 		else if (strcmp(command, "list") == 0)
   135 		{
   136 			CPluginManager::CPlugin *pl;
   137 			ISmmPlugin *plapi;
   138 			const char *plname;
   139 			PluginIter i;
   140 			char buffer[256];
   141 			int len;
   142 			int plnum = g_PluginMngr.GetPluginCount();
   143 
   144 			if (!plnum)
   145 			{
   146 				CONMSG("No plugins loaded.\n");
   147 				return true;
   148 			} else {
   149 				CONMSG("Listing %d plugin%s:\n", plnum, (plnum > 1) ? "s" : "");
   150 			}
   151 
   152 			for (i = g_PluginMngr._begin(); i != g_PluginMngr._end(); i++)
   153 			{
   154 				pl = (*i);
   155 				if (!pl)
   156 				{
   157 					break;
   158 				}
   159 
   160 				len = 0;
   161 
   162 				if (pl->m_Status != Pl_Running)
   163 				{
   164 					len += UTIL_Format(buffer, sizeof(buffer), "  [%02d] <%s>", pl->m_Id, g_PluginMngr.GetStatusText(pl));
   165 				} else {
   166 					len += UTIL_Format(buffer, sizeof(buffer), "  [%02d]", pl->m_Id);
   167 				}
   168 
   169 				if ((plapi = pl->m_API))
   170 				{
   171 					plname = IS_STR_FILLED(plapi->GetName()) ? plapi->GetName() : pl->m_File.c_str();
   172 					len += UTIL_Format(&buffer[len], sizeof(buffer)-len, " %s", plname);
   173 
   174 					if (IS_STR_FILLED(plapi->GetVersion()))
   175 					{
   176 						len += UTIL_Format(&buffer[len], sizeof(buffer)-len, " (%s)", plapi->GetVersion());
   177 					}
   178 					if (IS_STR_FILLED(plapi->GetAuthor()))
   179 					{
   180 						UTIL_Format(&buffer[len], sizeof(buffer)-len, " by %s", plapi->GetAuthor());
   181 					}
   182 				}
   183 
   184 				CONMSG("%s\n", buffer);
   185 			}
   186 
   187 			return true;
   188 		}
   189 		else if (strcmp(command, "cmds") == 0)
   190 		{
   191 			if (args >= 2)
   192 			{
   193 				int id = atoi(info->GetArg(2));
   194 				CPluginManager::CPlugin *pl = g_PluginMngr.FindById(id);
   195 
   196 				if (!pl)
   197 				{
   198 					CONMSG("Plugin %d not found.\n", id);
   199 					return true;
   200 				}
   201 
   202 				if (!pl->m_API)
   203 				{
   204 					CONMSG("Plugin %d is not loaded.\n", id);
   205 				}
   206 				else
   207 				{
   208 					CONMSG("Console commands for %s:\n", pl->m_API->GetName());
   209 					List<ConCommandBase *>::iterator ci;
   210 					size_t count = 0;
   211 
   212 					for (ci=pl->m_Cmds.begin(); ci!=pl->m_Cmds.end(); ci++)
   213 					{
   214 						count++;
   215 						CONMSG(" [%5d] %-s\n", count, (*ci)->GetName());
   216 					}
   217 				}
   218 			}
   219 			else
   220 			{
   221 				CONMSG("Usage: meta cmds <id>\n");
   222 			}
   223 
   224 			return true;
   225 		}
   226 		else if (strcmp(command, "cvars") == 0)
   227 		{
   228 			if (args >= 2)
   229 			{
   230 				int id = atoi(info->GetArg(2));
   231 				CPluginManager::CPlugin *pl = g_PluginMngr.FindById(id);
   232 
   233 				if (!pl)
   234 				{
   235 					CONMSG("Plugin %d not found.\n", id);
   236 					return true;
   237 				}
   238 
   239 				if (!pl->m_API)
   240 				{
   241 					CONMSG("Plugin %d is not loaded.\n", id);
   242 				}
   243 				else
   244 				{
   245 					CONMSG("Registered cvars for %s:\n", pl->m_API->GetName());
   246 					List<ConCommandBase *>::iterator ci;
   247 					size_t count = 0;
   248 
   249 					for (ci=pl->m_Cvars.begin(); ci!=pl->m_Cvars.end(); ci++)
   250 					{
   251 						count++;
   252 						CONMSG(" [%5d] %-s\n", count, (*ci)->GetName());
   253 					}
   254 				}
   255 			}
   256 			else
   257 			{
   258 				CONMSG("Usage: meta cvars <id>\n");
   259 			}
   260 
   261 			return true;
   262 		}
   263 		else if (strcmp(command, "info") == 0)
   264 		{
   265 			if (args >= 2)
   266 			{
   267 				int id = atoi(info->GetArg(2));
   268 				CPluginManager::CPlugin *pl = g_PluginMngr.FindById(id);
   269 				if (!pl)
   270 				{
   271 					CONMSG("Plugin %d not found.\n", id);
   272 					return true;
   273 				}
   274 
   275 				if (!pl->m_API)
   276 				{
   277 					CONMSG("Plugin %d is not loaded.\n", id);
   278 				}
   279 				else
   280 				{
   281 					if (pl->m_Status == Pl_Paused)
   282 					{
   283 						CONMSG("Plugin %d is paused.\n", id);
   284 					}
   285 					else if (pl->m_Status == Pl_Running)
   286 					{
   287 						char run_msg[255];
   288 						bool run = false;
   289 						if (pl->m_API && pl->m_API->QueryRunning(run_msg, sizeof(run_msg)-1))
   290 						{
   291 							run = true;
   292 						}
   293 						if (run)
   294 						{
   295 							CONMSG("Plugin %d is running.\n", id);
   296 						}
   297 						else
   298 						{
   299 							CONMSG("Plugin %d is stopped: %s\n", id, run_msg);
   300 						}
   301 					}
   302 					CONMSG("  Name: \"%s\" by %s\n", pl->m_API->GetName(), pl->m_API->GetAuthor());
   303 					CONMSG("  Version: %s\n", pl->m_API->GetVersion());
   304 					CONMSG("  Description: %s\n", pl->m_API->GetDescription());
   305 					CONMSG("  License: %s\n", pl->m_API->GetLicense());
   306 					CONMSG("  URL: %s\n", pl->m_API->GetURL());
   307 					CONMSG("  Details: API %03d, Date: %s\n", pl->m_API->GetApiVersion(), pl->m_API->GetDate());
   308 				}
   309 				CONMSG("File: %s\n\n", pl->m_File.c_str());
   310 
   311 				return true;
   312 			}
   313 			else
   314 			{
   315 				CONMSG("Usage: meta info <id>\n");
   316 
   317 				return true;
   318 			}
   319 		}
   320 		else if (strcmp(command, "pause") == 0)
   321 		{
   322 			if (args >= 2)
   323 			{
   324 				int id = atoi(info->GetArg(2));
   325 
   326 				char error[255];
   327 
   328 				if (!g_PluginMngr.Pause(id, error, sizeof(error)))
   329 				{
   330 					CONMSG("Pause failed: %s\n", error);
   331 					return true;
   332 				}
   333 				
   334 				CONMSG("Plugin %d has been paused.\n", id);
   335 
   336 				return true;
   337 			}
   338 			else
   339 			{
   340 				CONMSG("Usage: meta pause <id>\n");
   341 
   342 				return true;
   343 			}
   344 		}
   345 		else if (strcmp(command, "unpause") == 0)
   346 		{
   347 			if (args >= 2)
   348 			{
   349 				int id = atoi(info->GetArg(2));
   350 				char error[255];
   351 
   352 				if (!g_PluginMngr.Unpause(id, error, sizeof(error)))
   353 				{
   354 					CONMSG("Unpause failed: %s\n", error);
   355 					return true;
   356 				}
   357 
   358 				CONMSG("Plugin %d has been unpaused.\n", id);
   359 
   360 				return true;
   361 			}
   362 			else
   363 			{
   364 				CONMSG("Usage: meta unpause <id>\n");
   365 
   366 				return true;
   367 			}
   368 		}
   369 		else if (strcmp(command, "load") == 0)
   370 		{
   371 			if (args >= 2)
   372 			{
   373 				const char *file = info->GetArg(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_Metamod.PathFormat(full_path, sizeof(full_path), "%s", file);
   385 				}
   386 				else
   387 				{
   388 					const char *ext = UTIL_GetExtension(file);
   389 #if defined WIN32 || defined _WIN32
   390 					ext = ext ? "" : ".dll";
   391 #else
   392 					ext = ext ? "" : "_i486.so";
   393 #endif
   394 					g_Metamod.PathFormat(full_path,
   395 						sizeof(full_path),
   396 						"%s/%s%s",
   397 						g_Metamod.GetBaseDir(),
   398 						file,
   399 						ext);
   400 				}
   401 
   402 				char error[255]={0};
   403 				bool already;
   404 				CPluginManager::CPlugin *pl;
   405 
   406 				PluginId id = g_PluginMngr.Load(full_path, Pl_Console, already, error, sizeof(error));
   407 				pl = g_PluginMngr.FindById(id);
   408 				if (!pl || id < Pl_MinId || (pl->m_Status < Pl_Paused))
   409 				{
   410 					CONMSG("Failed to load plugin %s (%s).\n", file, error);
   411 					return true;
   412 				}
   413 
   414 				if (!already)
   415 				{
   416 					CONMSG("Plugin \"%s\" loaded with id %d.\n", pl->m_API->GetName(), pl->m_Id);
   417 				} else {
   418 					CONMSG("Plugin \"%s\" is already loaded as %d.\n", pl->m_API->GetName(), pl->m_Id);
   419 				}
   420 				
   421 				return true;
   422 			}
   423 			else
   424 			{
   425 				CONMSG("Usage: meta load <path>\n");
   426 
   427 				return true;
   428 			}
   429 		}
   430 		else if ( (strcmp(command, "alias") == 0) ||
   431 					(strcmp(command, "aliases") == 0) )
   432 		{
   433 			if (args >= 3)
   434 			{
   435 				const char *alias = info->GetArg(2);
   436 				const char *value = info->GetArg(3);
   437 
   438 				g_PluginMngr.SetAlias(alias, value);
   439 				if (value == NULL || value[0] == '\0')
   440 				{
   441 					CONMSG("Deleted alias: %s.\n", alias);
   442 				} else {
   443 					CONMSG("Set alias \"%s\" to: %s\n", alias, value);
   444 				}
   445 			}
   446 			else if (args >= 2)
   447 			{
   448 				const char *alias = info->GetArg(2);
   449 				const char *value = g_PluginMngr.LookupAlias(alias);
   450 				if (value)
   451 				{
   452 					CONMSG("Alias \"%s\" is set to: %s\n", alias, value);
   453 				} else {
   454 					CONMSG("Alias \"%s\" was not found.\n", alias);
   455 				}
   456 			}
   457 			else
   458 			{
   459 				List<CNameAlias *>::iterator iter, end;
   460 				CNameAlias *p;
   461 
   462 				iter = g_PluginMngr._alias_begin();
   463 				end = g_PluginMngr._alias_end();
   464 				size_t total = 0;
   465 				if (iter != end)
   466 				{
   467 					CONMSG("%-10.9s %s\n", "Alias", "File");
   468 					CONMSG(" --- \n");
   469 					for (; iter!=end; iter++)
   470 					{
   471 						p = (*iter);
   472 						CONMSG("%-10.9s %s\n", p->alias.c_str(), p->value.c_str());
   473 						total++;
   474 					}
   475 					CONMSG(" --- \n");
   476 					CONMSG("%d aliases total.\n", total);
   477 				}
   478 				else
   479 				{
   480 					CONMSG("No aliases found.\n");
   481 				}
   482 			}
   483 			return true;
   484 		}
   485 		else if (strcmp(command, "unload") == 0)
   486 		{
   487 			if (args >= 2)
   488 			{
   489 				const char *file = info->GetArg(2);
   490 				int id = atoi(file);
   491 				char error[255]={0};
   492 
   493 				if (id == 0 && isalpha(file[0]))
   494 				{
   495 					char full_path[255];
   496 					const char *alias = g_PluginMngr.LookupAlias(file);
   497 
   498 					if (alias)
   499 					{
   500 						file = alias;
   501 					}
   502 
   503 					/* first check if it's a known filename */
   504 					if (file[0] == '/' || strcmp(&(file[1]), ":\\") == 0)
   505 					{
   506 						g_Metamod.PathFormat(full_path, sizeof(full_path), "%s", file);
   507 					}
   508 					else
   509 					{
   510 						const char *ext = UTIL_GetExtension(file);
   511 #if defined WIN32 || defined _WIN32
   512 						ext = ext ? "" : ".dll";
   513 #else
   514 						ext = ext ? "" : "_i486.so";
   515 #endif
   516 						g_Metamod.PathFormat(full_path,
   517 							sizeof(full_path),
   518 							"%s/%s%s",
   519 							g_Metamod.GetBaseDir(),
   520 							file,
   521 							ext);
   522 					}
   523 
   524 					List<CPluginManager::CPlugin *>::iterator iter, end;
   525 					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 true;
   541 					}
   542 				}
   543 
   544 				if (!g_PluginMngr.Unload(id, false, error, sizeof(error)))
   545 				{
   546 					CONMSG("Unload failed: %s\n", error);
   547 					return true;
   548 				}
   549 
   550 				CONMSG("Plugin %d unloaded.\n", id);
   551 			}
   552 			else
   553 			{
   554 				CONMSG("Usage: meta unload <id>\n");
   555 			}
   556 			return true;
   557 		}
   558 		else if (strcmp(command, "force_unload") == 0)
   559 		{
   560 			if (args >= 2)
   561 			{
   562 				int id = atoi(info->GetArg(2));
   563 				char error[255]={0};
   564 
   565 				if (!g_PluginMngr.Unload(id, false, error, sizeof(error)))
   566 				{
   567 					CONMSG("Force unload failed: %s\n", error);
   568 					return true;
   569 				}
   570 
   571 				CONMSG("Plugin %d force unloaded.\n", id);
   572 
   573 				return true;
   574 			}
   575 			else
   576 			{
   577 				CONMSG("Usage: meta force_unload <id>\n");
   578 
   579 				return true;
   580 			}
   581 		}
   582 		else if (strcmp(command, "clear") == 0)
   583 		{
   584 			if (!g_PluginMngr.UnloadAll())
   585 			{
   586 				CONMSG("One or more plugins resisted removal (cleaned anyway).\n");
   587 				return true;
   588 			} 
   589 
   590 			CONMSG("All plugins unloaded.\n");
   591 
   592 			return true;
   593 		}
   594 		else if (strcmp(command, "retry") == 0)
   595 		{
   596 			if (args >= 2)
   597 			{
   598 				int id = atoi(info->GetArg(2));
   599 				char error[255];
   600 
   601 				if (!g_PluginMngr.Retry(id, error, sizeof(error)))
   602 				{
   603 					CONMSG("Error reloading plugin: %s\n", error);
   604 					return true;
   605 				}
   606 
   607 				CONMSG("Plugin %d successfully reloaded.\n", id);
   608 
   609 				return true;
   610 			}
   611 			else
   612 			{
   613 				CONMSG("Usage: meta retry <id>\n");
   614 
   615 				return true;
   616 			}
   617 		}
   618 	}
   619 
   620 	CONMSG("Metamod:Source Menu\n");
   621 	CONMSG("usage: meta <command> [arguments]\n");
   622 	CONMSG("  alias        - List or set an alias\n");
   623 	CONMSG("  clear        - Unload all plugins forcefully\n");
   624 	CONMSG("  cmds         - Show plugin commands\n");
   625 	CONMSG("  cvars        - Show plugin cvars\n");
   626 	CONMSG("  credits      - About Metamod:Source\n");
   627 	CONMSG("  force_unload - Forcefully unload a plugin\n");
   628 	CONMSG("  game         - Information about GameDLL\n");
   629 	CONMSG("  info         - Information about a plugin\n");
   630 	CONMSG("  list         - List plugins\n");
   631 	CONMSG("  load         - Load a plugin\n");
   632 	CONMSG("  pause        - Pause a running plugin\n");
   633 	CONMSG("  refresh      - Reparse plugins file\n");
   634 	CONMSG("  retry        - Attempt to reload a plugin\n");
   635 	CONMSG("  unload       - Unload a loaded plugin\n");
   636 	CONMSG("  unpause      - Unpause a paused plugin\n");
   637 	CONMSG("  version      - Version information\n");
   638 
   639 	return true;
   640 }
   641 
   642 bool Command_ClientMeta(edict_t *client, IMetamodSourceCommandInfo *info)
   643 {
   644 	const char *cmd = info->GetArg(0);
   645 
   646 	if (strcmp(cmd, "meta") == 0)
   647 	{
   648 		unsigned int args = info->GetArgCount();
   649 		if (args == 1)
   650 		{
   651 			const char *subcmd = info->GetArg(1);
   652 
   653 			if (strcmp(subcmd, "credits") == 0)
   654 			{
   655 				CLIENT_CONMSG(client, "Metamod:Source was developed by:\n");
   656 				CLIENT_CONMSG(client, "  SourceHook: Pavol \"PM OnoTo\" Marko\n");
   657 				CLIENT_CONMSG(client, "  GameDLL/Plugins: David \"BAILOPAN\" Anderson\n");
   658 				CLIENT_CONMSG(client, "  GameDLL: Scott \"Damaged Soul\" Ehlert\n");
   659 				CLIENT_CONMSG(client, "For more information, see the official website\n");
   660 				CLIENT_CONMSG(client, "http://www.sourcemm.net/\n");
   661 
   662 				return true;
   663 			}
   664 			else if(strcmp(subcmd, "version") == 0)
   665 			{
   666 				CLIENT_CONMSG(client, "Metamod:Source version %s\n", SOURCEMM_VERSION);
   667 				CLIENT_CONMSG(client, "Compiled on: %s\n", SOURCEMM_DATE);
   668 				CLIENT_CONMSG(client, "Plugin interface version: %d:%d\n", PLAPI_VERSION, PLAPI_MIN_VERSION);
   669 				CLIENT_CONMSG(client, "SourceHook version: %d:%d\n", g_SourceHook.GetIfaceVersion(), g_SourceHook.GetImplVersion());
   670 				CLIENT_CONMSG(client, "http://www.sourcemm.net/\n");
   671 
   672 				return true;
   673 			}
   674 			else if(strcmp(subcmd, "list") == 0)
   675 			{
   676 				CPluginManager::CPlugin *pl;
   677 				ISmmPlugin *plapi;
   678 				const char *plname;
   679 				PluginIter i;
   680 				char buffer[256];
   681 				int len = 0;
   682 				int plnum = 0;
   683 
   684 				for (i = g_PluginMngr._begin(); i != g_PluginMngr._end(); i++, len=0)
   685 				{
   686 					pl = (*i);
   687 					if (pl && pl->m_Status == Pl_Running)
   688 					{
   689 						plapi = pl->m_API;
   690 						if (!plapi || !plapi->QueryRunning(NULL, 0))
   691 						{
   692 							continue;
   693 						}
   694 						plnum++;
   695 
   696 						len += UTIL_Format(buffer, sizeof(buffer), "  [%02d]", plnum);
   697 
   698 						plname = IS_STR_FILLED(plapi->GetName()) ? plapi->GetName() : pl->m_File.c_str();
   699 						len += UTIL_Format(&buffer[len], sizeof(buffer)-len, " %s", plname);
   700 
   701 						if (IS_STR_FILLED(plapi->GetVersion()))
   702 						{
   703 							len += UTIL_Format(&buffer[len], sizeof(buffer)-len, " (%s)", plapi->GetVersion());
   704 						}
   705 						if (IS_STR_FILLED(plapi->GetAuthor()))
   706 						{
   707 							UTIL_Format(&buffer[len], sizeof(buffer)-len, " by %s", plapi->GetAuthor());
   708 						}
   709 
   710 						CLIENT_CONMSG(client, "%s\n", buffer);
   711 					}
   712 				}
   713 
   714 				if (!plnum)
   715 				{
   716 					CLIENT_CONMSG(client, "No active plugins loaded.\n");
   717 				}
   718 
   719 				return true;
   720 			}
   721 		}
   722 
   723 		CLIENT_CONMSG(client, "Metamod:Source Menu\n");
   724 		CLIENT_CONMSG(client, "usage: meta <command>\n");
   725 		CLIENT_CONMSG(client, "  credits - About Metamod:Source\n");
   726 		CLIENT_CONMSG(client, "  list    - List plugins\n");
   727 		CLIENT_CONMSG(client, "  version - Version information\n");
   728 
   729 		return true;
   730 	}
   731 
   732 	return false;
   733 }