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