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