sourcemm/metamod_plugins.cpp
author David Anderson <dvander@alliedmods.net>
Fri Dec 14 14:55:37 2007 +0000 (2007-12-14)
changeset 484 d86328fe5aaf
parent 481 5a2e34651450
child 495 e091f2b5e913
permissions -rw-r--r--
fixed amb1284 - silly bug in client meta handler
     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 #include "metamod_oslink.h"
    29 #if defined _DEBUG
    30 #define DEBUG2
    31 #undef _DEBUG
    32 #endif
    33 #include "metamod.h"
    34 #include "metamod_plugins.h"
    35 #include "metamod_util.h"
    36 #if defined DEBUG2
    37 #undef DEBUG2
    38 #define _DEBUG
    39 #endif
    40 
    41 /** 
    42  * @brief Implements functions from CPlugin.h
    43  * @file CPlugin.cpp
    44  */
    45 
    46 using namespace SourceMM;
    47 
    48 #define ITER_PLEVENT(evn, plid) \
    49 	CPluginManager::CPlugin *_Xpl; \
    50 	SourceHook::List<IMetamodListener *>::iterator event; \
    51 	IMetamodListener *api; \
    52 	for (PluginIter iter = g_PluginMngr._begin(); iter != g_PluginMngr._end(); iter++) { \
    53 		_Xpl = (*iter); \
    54 		if (_Xpl->m_Id == plid) \
    55 			continue; \
    56 		for (event=_Xpl->m_Events.begin(); event!=_Xpl->m_Events.end(); event++) { \
    57 			api = (*event); \
    58 			api->evn(plid); \
    59 		} \
    60 	}
    61 
    62 CPluginManager g_PluginMngr;
    63 
    64 MetamodVersionInfo GlobVersionInfo = 
    65 {
    66 	METAMOD_API_MAJOR,
    67 	METAMOD_API_MINOR,
    68 	SH_IFACE_VERSION,
    69 	SH_IMPL_VERSION,
    70 	PLAPI_MIN_VERSION,
    71 	METAMOD_PLAPI_VERSION,
    72 	SOURCE_ENGINE_UNKNOWN
    73 };
    74 
    75 CPluginManager::CPluginManager()
    76 {
    77 	m_LastId = Pl_MinId;
    78 	m_AllLoaded = false;
    79 }
    80 
    81 CPluginManager::~CPluginManager()
    82 {
    83 	SourceHook::List<CNameAlias *>::iterator iter;
    84 
    85 	for (iter = m_Aliases.begin(); iter != m_Aliases.end(); iter++)
    86 	{
    87 		delete (*iter);
    88 	}
    89 
    90 	m_Aliases.clear();
    91 }
    92 
    93 const char *CPluginManager::LookupAlias(const char *alias)
    94 {
    95 	SourceHook::List<CNameAlias *>::iterator iter;
    96 	CNameAlias *p;
    97 
    98 	for (iter = m_Aliases.begin(); iter != m_Aliases.end(); iter++)
    99 	{
   100 		p = (*iter);
   101 		if (p->alias.compare(alias) == 0)
   102 		{
   103 			return p->value.c_str();
   104 		}
   105 	}
   106 
   107 	return NULL;
   108 }
   109 
   110 SourceHook::List<CNameAlias *>::iterator CPluginManager::_alias_begin()
   111 {
   112 	return m_Aliases.begin();
   113 }
   114 
   115 SourceHook::List<CNameAlias *>::iterator CPluginManager::_alias_end()
   116 {
   117 	return m_Aliases.end();
   118 }
   119 
   120 void CPluginManager::SetAlias(const char *alias, const char *value)
   121 {
   122 	SourceHook::List<CNameAlias *>::iterator iter;
   123 	CNameAlias *p;
   124 
   125 	for (iter = m_Aliases.begin(); iter != m_Aliases.end(); iter++)
   126 	{
   127 		p = (*iter);
   128 		if (p->alias.compare(alias) == 0)
   129 		{
   130 			if (value[0] == '\0')
   131 			{
   132 				iter = m_Aliases.erase(iter);
   133 				return;
   134 			}
   135 			else
   136 			{
   137 				p->value.assign(value);
   138 				return;
   139 			}
   140 		}
   141 	}
   142 
   143 	if (value[0] != '\0')
   144 	{
   145 		p = new CNameAlias;
   146 	
   147 		p->alias.assign(alias);
   148 		p->value.assign(value);
   149 	
   150 		m_Aliases.push_back(p);
   151 	}
   152 }
   153 
   154 CPluginManager::CPlugin::CPlugin() : m_Id(0), m_Source(0), m_API(NULL), m_Lib(NULL), m_UnloadFn(NULL)
   155 {
   156 
   157 }
   158 
   159 PluginId CPluginManager::Load(const char *file, PluginId source, bool &already, char *error, size_t maxlen)
   160 {
   161 	already = false;
   162 	//Check if we're about to reload an old plugin
   163 	PluginIter i = m_Plugins.begin();
   164 	while (i != m_Plugins.end())
   165 	{
   166 		if ((*i) && UTIL_PathCmp(file, (*i)->m_File.c_str()))
   167 		{
   168 			if ((*i)->m_Status < Pl_Paused)
   169 			{
   170 				//Attempt to load the plugin again
   171 				already = true;
   172 				i = m_Plugins.erase(i);
   173 				continue;
   174 			}
   175 			else
   176 			{
   177 				//No need to load it
   178 				already = true;
   179 				return (*i)->m_Id;
   180 			}
   181 		}
   182 		i++;
   183 	}
   184 
   185 	CPlugin *pl = _Load(file, source, error, maxlen);
   186 
   187 	if (!pl)
   188 	{
   189 		return Pl_BadLoad;
   190 	}
   191 
   192 	ITER_PLEVENT(OnPluginLoad, pl->m_Id);
   193 
   194 	return pl->m_Id;
   195 }
   196 
   197 CPluginManager::CPlugin *CPluginManager::FindById(PluginId id)
   198 {
   199 	PluginIter i;
   200 
   201 	for (i=m_Plugins.begin(); i!=m_Plugins.end(); i++)
   202 	{
   203 		if ( (*i)->m_Id == id )\
   204 		{
   205 			return (*i);
   206 		}
   207 	}
   208 
   209 	return NULL;
   210 }
   211 
   212 void CPluginManager::SetAllLoaded()
   213 {
   214 	if (m_AllLoaded)
   215 	{
   216 		return;
   217 	}
   218 
   219 	m_AllLoaded = true;
   220 	PluginIter i;
   221 
   222 	for (i=m_Plugins.begin(); i!=m_Plugins.end(); i++)
   223 	{
   224 		if ( (*i) && (*i)->m_Status == Pl_Running && (*i)->m_API )
   225 		{
   226 			//API 4 is when we added this callback
   227 			//Min version is now 5, so we ignore this check
   228 			//if ( (*i)->m_API->GetApiVersion() >= 004 )
   229 			(*i)->m_API->AllPluginsLoaded();
   230 		}
   231 	}
   232 }
   233 
   234 bool CPluginManager::Pause(PluginId id, char *error, size_t maxlen)
   235 {
   236 	CPlugin *pl = FindById(id);
   237 	
   238 	if (!pl)
   239 	{
   240 		UTIL_Format(error, maxlen, "Plugin id not found");
   241 		return false;
   242 	}
   243 
   244 	bool ret;
   245 	
   246 	if ((ret=_Pause(pl, error, maxlen)) == true)
   247 	{
   248 		ITER_PLEVENT(OnPluginPause, pl->m_Id);
   249 	}
   250 
   251 	return ret;
   252 }
   253 
   254 bool CPluginManager::Unpause(PluginId id, char *error, size_t maxlen)
   255 {
   256 	CPlugin *pl = FindById(id);
   257 	
   258 	if (!pl)
   259 	{
   260 		UTIL_Format(error, maxlen, "Plugin id not found");
   261 		return false;
   262 	}
   263 
   264 	bool ret;
   265 	
   266 	if ( (ret=_Unpause(pl, error, maxlen)) == true )
   267 	{
   268 		ITER_PLEVENT(OnPluginUnpause, pl->m_Id);
   269 	}
   270 
   271 	return ret;
   272 }
   273 
   274 bool CPluginManager::Unload(PluginId id, bool force, char *error, size_t maxlen)
   275 {
   276 	CPlugin *pl = FindById(id);
   277 	
   278 	if (!pl)
   279 	{
   280 		UTIL_Format(error, maxlen, "Plugin %d not found", id);
   281 		return false;
   282 	}
   283 
   284 	bool ret;
   285 	PluginId old_id = pl->m_Id;
   286 	if ( (ret=_Unload(pl, force, error, maxlen)) == true )
   287 	{
   288 		ITER_PLEVENT(OnPluginUnload, old_id);
   289 	}
   290 
   291 	return ret;
   292 }
   293 
   294 bool CPluginManager::Retry(PluginId id, char *error, size_t len)
   295 {
   296 	PluginIter i;
   297 	char buffer[64];
   298 	for (i=m_Plugins.begin(); i!=m_Plugins.end(); i++)
   299 	{
   300 		if ( (*i) && (*i)->m_Id == id )
   301 		{
   302 			if ( (*i)->m_Status >= Pl_Paused)
   303 			{
   304 				UTIL_Format(error, len, "Plugin %d is already running.", id);
   305 				return false;
   306 			}
   307 			CPlugin *pl = _Load((*i)->m_File.c_str(), Pl_Console, error, len);
   308 			if (!pl)
   309 			{
   310 				return false;
   311 			}
   312 			if (pl->m_Status >= Pl_Paused)
   313 			{
   314 				//Now it gets crazy... unload the original copy.
   315 				_Unload( (*i), true, buffer, sizeof(buffer)-1 );
   316 				
   317 				//Set the new copy's id
   318 				pl->m_Id = id;
   319 
   320 				//We just wasted an id... reclaim it
   321 				m_LastId--;
   322 				
   323 				return true;
   324 			}
   325 			else
   326 			{
   327 				//don't really care about the buffer here
   328 				_Unload(pl, true, buffer, sizeof(buffer)-1);
   329 
   330 				//We just wasted an id... reclaim it
   331 				m_LastId--;
   332 				return false;
   333 			}
   334 		}
   335 	}
   336 
   337 	UTIL_Format(error, len, "Plugin %d not found,", id);
   338 	return false;
   339 }
   340 
   341 CPluginManager::CPlugin *CPluginManager::FindByAPI(ISmmPlugin *api)
   342 {
   343 	PluginIter i;
   344 
   345 	//don't find bad plugins!
   346 	if (!api)
   347 	{
   348 		return NULL;
   349 	}
   350 
   351 	for (i=m_Plugins.begin(); i!=m_Plugins.end(); i++)
   352 	{
   353 		if ((*i)->m_API == api)
   354 		{
   355 			return (*i);
   356 		}
   357 	}
   358 
   359 	return NULL;
   360 }
   361 
   362 int CPluginManager::GetPluginCount()
   363 {
   364 	return (int)m_Plugins.size();
   365 }
   366 
   367 const char *CPluginManager::GetStatusText(CPlugin *pl)
   368 {
   369 	switch (pl->m_Status)
   370 	{
   371 	case Pl_NotFound:
   372 		return "NOFILE";
   373 	case Pl_Error:
   374 		return "ERROR";
   375 	case Pl_Refused:
   376 		return "FAILED";
   377 	case Pl_Paused:
   378 		return "PAUSED";
   379 	case Pl_Running:
   380 		{
   381 			if (pl->m_API && pl->m_API->QueryRunning(NULL, 0))
   382 			{
   383 				return "STOPPED";
   384 			} else {
   385 				return "RUNNING";
   386 			}
   387 		}
   388 	default:
   389 		return "-";
   390 	}
   391 }
   392 
   393 CPluginManager::CPlugin *CPluginManager::_Load(const char *file, PluginId source, char *error, size_t maxlen)
   394 {
   395 	FILE *fp;
   396 	CPlugin *pl;
   397 
   398 	pl = new CPlugin();
   399 	*error = '\0';
   400 	
   401 	//Add plugin to list
   402 	pl->m_Id = m_LastId;
   403 	pl->m_File.assign(file);
   404 	m_Plugins.push_back(pl);
   405 	m_LastId++;
   406 
   407 	//Check if the file even exists
   408 	fp = fopen(file, "r");
   409 	if (!fp)
   410 	{
   411 		if (error)
   412 		{
   413 			UTIL_Format(error, maxlen, "File not found: %s", file);
   414 		}
   415 		pl->m_Status = Pl_NotFound;
   416 	}
   417 
   418 	if (fp)
   419 	{
   420 		fclose(fp);
   421 		fp = NULL;
   422 		
   423 		//Load the file
   424 		pl->m_Lib = dlmount(file);
   425 		if (!pl->m_Lib)
   426 		{
   427 			if (error)
   428 			{
   429 				UTIL_Format(error, maxlen, "%s", dlerror());
   430 			}
   431 			pl->m_Status = Pl_Error;
   432 		}
   433 		else
   434 		{
   435 			pl->m_API = NULL;
   436 			
   437 			/**
   438 			 * First, try the new "advanced" interface
   439 			 */
   440 			METAMOD_FN_LOAD fnLoad = (METAMOD_FN_LOAD)dlsym(pl->m_Lib, "CreateInterface_MMS");
   441 			if (fnLoad != NULL)
   442 			{
   443 				if (GlobVersionInfo.source_engine == SOURCE_ENGINE_UNKNOWN)
   444 				{
   445 					GlobVersionInfo.source_engine = g_Metamod.GetSourceEngineBuild();
   446 				}
   447 
   448 				/* Build path information */
   449 				char file_path[256];
   450 				size_t len = g_Metamod.PathFormat(file_path, sizeof(file_path), "%s", file);
   451 
   452 				for (size_t i = len - 1; i >= 0 && i < len; i--)
   453 				{
   454 					if (_IsPathSepChar(file_path[i]))
   455 					{
   456 						file_path[i] = '\0';
   457 						break;
   458 					}
   459 				}
   460 
   461 				MetamodLoaderInfo info;
   462 				info.pl_file = file;
   463 				info.pl_path = file_path;
   464 
   465 				pl->m_API = fnLoad(&GlobVersionInfo, &info);
   466 				pl->m_UnloadFn = (METAMOD_FN_UNLOAD)dlsym(pl->m_Lib, "UnloadInterface_MMS");
   467 			}
   468 
   469 			/**
   470 			 * If we didn't get anything, try the normal/simple interface.
   471 			 */
   472 			if (pl->m_API == NULL)
   473 			{
   474 				CreateInterfaceFn pfn = (CreateInterfaceFn)(dlsym(pl->m_Lib, PL_EXPOSURE_C));
   475 				if (!pfn)
   476 				{
   477 					if (error)
   478 					{
   479 						UTIL_Format(error, maxlen, "Function %s not found", PL_EXPOSURE_C);
   480 					}
   481 					pl->m_Status = Pl_Error;
   482 				}
   483 				else
   484 				{
   485 					pl->m_API = static_cast<ISmmPlugin *>((pfn)(METAMOD_PLAPI_NAME, NULL));
   486 
   487 					if (!pl->m_API)
   488 					{
   489 						if (error)
   490 						{
   491 							UTIL_Format(error, maxlen, "Failed to get API");
   492 						}
   493 						pl->m_Status = Pl_Error;
   494 					}
   495 				}
   496 			}
   497 
   498 			if (pl->m_API != NULL)
   499 			{
   500 				int api = pl->m_API->GetApiVersion();
   501 				if (api < PLAPI_MIN_VERSION)
   502 				{
   503 					if (error)
   504 					{
   505 						if (api == 13)
   506 						{
   507 							UTIL_Format(error, maxlen, "Plugin uses experimental Metamod build, probably 1.6.x (%d < %d)", api, PLAPI_MIN_VERSION);
   508 						}
   509 						else if (api <= 12 && api >= 7)
   510 						{
   511 							UTIL_Format(error, maxlen, "Older Metamod version required, probably 1.4.x (%d < %d)", api, PLAPI_MIN_VERSION);
   512 						}
   513 						else
   514 						{
   515 							UTIL_Format(error, maxlen, "Older Metamod version required, probably 1.0 (%d < %d)", api, PLAPI_MIN_VERSION);
   516 						}
   517 					}
   518 					pl->m_Status = Pl_Error;
   519 				}
   520 				else if (api > METAMOD_PLAPI_VERSION)
   521 				{
   522 					if (error)
   523 					{
   524 						UTIL_Format(error, maxlen, "Plugin requires newer Metamod version (%d > %d)", api, METAMOD_PLAPI_VERSION);
   525 					}
   526 					pl->m_Status = Pl_Error;
   527 				}
   528 				else
   529 				{
   530 					if (pl->m_API->Load(pl->m_Id, &g_Metamod, error, maxlen, m_AllLoaded))
   531 					{
   532 						pl->m_Status = Pl_Running;
   533 						if (m_AllLoaded)
   534 						{
   535 							pl->m_API->AllPluginsLoaded();
   536 						}
   537 					}
   538 					else
   539 					{
   540 						pl->m_Status = Pl_Refused;
   541 					}
   542 				}
   543 			}
   544 		}
   545 	}
   546 
   547 	if (pl->m_Lib && (pl->m_Status < Pl_Paused))
   548 	{
   549 		pl->m_Events.clear();
   550 		g_SourceHook.UnloadPlugin(pl->m_Id);
   551 		UnregAllConCmds(pl);
   552 
   553 		if (pl->m_UnloadFn != NULL)
   554 		{
   555 			pl->m_UnloadFn();
   556 		}
   557 
   558 		dlclose(pl->m_Lib);
   559 		pl->m_Lib = NULL;
   560 		pl->m_API = NULL;
   561 	}
   562 
   563 	return pl;
   564 }
   565 
   566 bool CPluginManager::_Unload(CPluginManager::CPlugin *pl, bool force, char *error, size_t maxlen)
   567 {
   568 	if (error)
   569 	{
   570 		*error = '\0';
   571 	}
   572 
   573 	if (pl->m_API && pl->m_Lib)
   574 	{
   575 		//Note, we'll always tell the plugin it will be unloading...
   576 		if (pl->m_API->Unload(error, maxlen) || force)
   577 		{
   578 			//Make sure to detach it from sourcehook!
   579 			g_SourceHook.UnloadPlugin(pl->m_Id);
   580 
   581 			pl->m_Events.clear();
   582 
   583 			UnregAllConCmds(pl);
   584 
   585 			if (pl->m_UnloadFn != NULL)
   586 			{
   587 				pl->m_UnloadFn();
   588 			}
   589 
   590 			//Clean up the DLL
   591 			dlclose(pl->m_Lib);
   592 			pl->m_Lib = NULL;
   593 			pl->m_API = NULL;
   594 
   595 			//Remove the plugin from the list
   596 			PluginIter i;
   597 			for (i=m_Plugins.begin(); i!=m_Plugins.end(); i++)
   598 			{
   599 				if ( (*i)->m_Id == pl->m_Id )
   600 				{
   601 					i = m_Plugins.erase(i);
   602 					break;
   603 				}
   604 			}
   605 			//Free its memory
   606 			delete pl;
   607 
   608 			return true;
   609 		}
   610 	} else {
   611 		//The plugin is not valid, and let's just remove it from the list anyway
   612 		PluginIter i;
   613 		for (i=m_Plugins.begin(); i!=m_Plugins.end(); i++)
   614 		{
   615 			if ( (*i)->m_Id == pl->m_Id )
   616 			{
   617 				i = m_Plugins.erase(i);
   618 				break;
   619 			}
   620 		}
   621 		delete pl;
   622 
   623 		return true;
   624 	}
   625 
   626 	return false;
   627 }
   628 
   629 bool CPluginManager::_Pause(CPluginManager::CPlugin *pl, char *error, size_t maxlen)
   630 {
   631 	if (error)
   632 	{
   633 		*error = '\0';
   634 	}
   635 
   636 	if (pl->m_Status != Pl_Running || !pl->m_API)
   637 	{
   638 		if (error)
   639 		{
   640 			UTIL_Format(error, maxlen, "Plugin cannot be paused");
   641 		}
   642 	}
   643 	else
   644 	{
   645 		if (pl->m_API->Pause(error, maxlen))
   646 		{
   647 			g_SourceHook.PausePlugin(pl->m_Id);
   648 			pl->m_Status = Pl_Paused;
   649 
   650 			return true;
   651 		}
   652 	}
   653 
   654 	return false;
   655 }
   656 
   657 bool CPluginManager::_Unpause(CPluginManager::CPlugin *pl, char *error, size_t maxlen)
   658 {
   659 	if (error)
   660 	{
   661 		*error = '\0';
   662 	}
   663 
   664 	if (pl->m_Status != Pl_Paused || !pl->m_API)
   665 	{
   666 		if (error)
   667 		{
   668 			UTIL_Format(error, maxlen, "Plugin cannot be unpaused");
   669 		}
   670 	}
   671 	else
   672 	{
   673 		if (pl->m_API->Unpause(error, maxlen))
   674 		{
   675 			g_SourceHook.UnpausePlugin(pl->m_Id);
   676 			pl->m_Status = Pl_Running;
   677 
   678 			return true;
   679 		}
   680 	}
   681 
   682 	return false;
   683 }
   684 
   685 bool CPluginManager::UnloadAll()
   686 {
   687 	PluginIter i;
   688 
   689 	char error[128];
   690 	bool status = true;
   691 
   692 	while ((i = m_Plugins.begin()) != m_Plugins.end())
   693 	{
   694 		if ( !_Unload( (*i), true, error, sizeof(error)) )
   695 		{
   696 			status = false;
   697 		}
   698 	}
   699 
   700 	return status;
   701 }
   702 
   703 bool CPluginManager::Query(PluginId id, const char **file, Pl_Status *status, PluginId *source)
   704 {
   705 	CPlugin *pl = FindById(id);
   706 
   707 	if (!pl)
   708 	{
   709 		return false;
   710 	}
   711 
   712 	if (file != NULL)
   713 	{
   714 		*file = pl->m_File.c_str();
   715 	}
   716 
   717 	if (status != NULL)
   718 	{
   719 		*status = pl->m_Status;
   720 	}
   721 
   722 	if (source != NULL)
   723 	{
   724 		*source = pl->m_Source;
   725 	}
   726 
   727 	return true;
   728 }
   729 
   730 bool CPluginManager::QueryRunning(PluginId id, char *error, size_t maxlength)
   731 {
   732 	CPlugin *pl = FindById(id);
   733 
   734 	if (!pl || !pl->m_API)
   735 	{
   736 		if (error)
   737 		{
   738 			UTIL_Format(error, maxlength, "Plugin not valid");
   739 		}
   740 		return false;
   741 	}
   742 
   743 	return pl->m_API->QueryRunning(error, maxlength);
   744 }
   745 
   746 bool CPluginManager::QueryHandle(PluginId id, void **handle)
   747 {
   748 	CPlugin *pl = FindById(id);
   749 
   750 	if (!pl)
   751 	{
   752 		return false;
   753 	}
   754 
   755 	if (handle)
   756 	{
   757 		*handle = static_cast<void *>(pl->m_Lib);
   758 	}
   759 
   760 	return true;
   761 }
   762 
   763 PluginIter CPluginManager::_begin()
   764 {
   765 	return m_Plugins.begin();
   766 }
   767 
   768 PluginIter CPluginManager::_end()
   769 {
   770 	return m_Plugins.end();
   771 }
   772 
   773 void CPluginManager::AddPluginCvar(ISmmPlugin *api, ConCommandBase *pCvar)
   774 {
   775 	CPlugin *pl = FindByAPI(api);
   776 
   777 	if (!pl)
   778 	{
   779 		return;
   780 	}
   781 
   782 	pl->m_Cvars.push_back(pCvar);
   783 }
   784 
   785 void CPluginManager::AddPluginCmd(ISmmPlugin *api, ConCommandBase *pCmd)
   786 {
   787 	CPlugin *pl = FindByAPI(api);
   788 
   789 	if (!pl)
   790 	{
   791 		return;
   792 	}
   793 
   794 	pl->m_Cmds.push_back(pCmd);
   795 }
   796 
   797 void CPluginManager::RemovePluginCvar(ISmmPlugin *api, ConCommandBase *pCvar)
   798 {
   799 	CPlugin *pl = FindByAPI(api);
   800 
   801 	if (!pl)
   802 	{
   803 		return;
   804 	}
   805 
   806 	pl->m_Cvars.remove(pCvar);
   807 }
   808 
   809 void CPluginManager::RemovePluginCmd(ISmmPlugin *api, ConCommandBase *pCmd)
   810 {
   811 	CPlugin *pl = FindByAPI(api);
   812 
   813 	if (!pl)
   814 	{
   815 		return;
   816 	}
   817 
   818 	pl->m_Cmds.remove(pCmd);
   819 }
   820 
   821 void CPluginManager::UnregAllConCmds(CPlugin *pl)
   822 {
   823 	SourceHook::List<ConCommandBase *>::iterator i;
   824 
   825 	/* :TODO: */
   826 	for (i=pl->m_Cvars.begin(); i!=pl->m_Cvars.end(); i++)
   827 	{
   828 		g_Metamod.UnregisterConCommandBase(pl->m_Id, (*i) );
   829 	}
   830 	pl->m_Cvars.clear();
   831 
   832 	for (i=pl->m_Cmds.begin(); i!=pl->m_Cmds.end(); i++)
   833 	{
   834 		g_Metamod.UnregisterConCommandBase(pl->m_Id, (*i) );
   835 	}
   836 	pl->m_Cmds.clear();
   837 }
   838