sourcemm/metamod_plugins.cpp
author David Anderson <dvander@alliedmods.net>
Tue Oct 30 18:22:12 2007 +0000 (2007-10-30)
changeset 434 c36e37d6aadf
parent 407 af2530a35c5c
child 481 5a2e34651450
permissions -rw-r--r--
now builds on ep1
     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 				/* Build path information */
   443 				char file_path[256];
   444 				size_t len = g_Metamod.PathFormat(file_path, sizeof(file_path), "%s", file);
   445 
   446 				for (size_t i = len - 1; i >= 0 && i < len; i--)
   447 				{
   448 					if (_IsPathSepChar(file_path[i]))
   449 					{
   450 						file_path[i] = '\0';
   451 						break;
   452 					}
   453 				}
   454 
   455 				MetamodLoaderInfo info;
   456 				info.pl_file = file;
   457 				info.pl_path = file_path;
   458 
   459 				pl->m_API = fnLoad(&GlobVersionInfo, &info);
   460 				pl->m_UnloadFn = (METAMOD_FN_UNLOAD)dlsym(pl->m_Lib, "UnloadInterface_MMS");
   461 			}
   462 
   463 			/**
   464 			 * If we didn't get anything, try the normal/simple interface.
   465 			 */
   466 			if (pl->m_API == NULL)
   467 			{
   468 				CreateInterfaceFn pfn = (CreateInterfaceFn)(dlsym(pl->m_Lib, PL_EXPOSURE_C));
   469 				if (!pfn)
   470 				{
   471 					if (error)
   472 					{
   473 						UTIL_Format(error, maxlen, "Function %s not found", PL_EXPOSURE_C);
   474 					}
   475 					pl->m_Status = Pl_Error;
   476 				}
   477 				else
   478 				{
   479 					pl->m_API = static_cast<ISmmPlugin *>((pfn)(METAMOD_PLAPI_NAME, NULL));
   480 
   481 					if (!pl->m_API)
   482 					{
   483 						if (error)
   484 						{
   485 							UTIL_Format(error, maxlen, "Failed to get API");
   486 						}
   487 						pl->m_Status = Pl_Error;
   488 					}
   489 				}
   490 			}
   491 
   492 			if (pl->m_API != NULL)
   493 			{
   494 				int api = pl->m_API->GetApiVersion();
   495 				if (api < PLAPI_MIN_VERSION)
   496 				{
   497 					if (error)
   498 					{
   499 						if (api == 13)
   500 						{
   501 							UTIL_Format(error, maxlen, "Plugin uses experimental Metamod build, probably 1.6.x (%d < %d)", api, PLAPI_MIN_VERSION);
   502 						}
   503 						else if (api <= 12 && api >= 7)
   504 						{
   505 							UTIL_Format(error, maxlen, "Older Metamod version required, probably 1.4.x (%d < %d)", api, PLAPI_MIN_VERSION);
   506 						}
   507 						else
   508 						{
   509 							UTIL_Format(error, maxlen, "Older Metamod version required, probably 1.0 (%d < %d)", api, PLAPI_MIN_VERSION);
   510 						}
   511 					}
   512 					pl->m_Status = Pl_Error;
   513 				}
   514 				else if (api > METAMOD_PLAPI_VERSION)
   515 				{
   516 					if (error)
   517 					{
   518 						UTIL_Format(error, maxlen, "Plugin requires newer Metamod version (%d > %d)", api, METAMOD_PLAPI_VERSION);
   519 					}
   520 					pl->m_Status = Pl_Error;
   521 				}
   522 				else
   523 				{
   524 					if (pl->m_API->Load(pl->m_Id, &g_Metamod, error, maxlen, m_AllLoaded))
   525 					{
   526 						pl->m_Status = Pl_Running;
   527 						if (m_AllLoaded)
   528 						{
   529 							pl->m_API->AllPluginsLoaded();
   530 						}
   531 					}
   532 					else
   533 					{
   534 						pl->m_Status = Pl_Refused;
   535 					}
   536 				}
   537 			}
   538 		}
   539 	}
   540 
   541 	if (pl->m_Lib && (pl->m_Status < Pl_Paused))
   542 	{
   543 		pl->m_Events.clear();
   544 		g_SourceHook.UnloadPlugin(pl->m_Id);
   545 		UnregAllConCmds(pl);
   546 
   547 		if (pl->m_UnloadFn != NULL)
   548 		{
   549 			pl->m_UnloadFn();
   550 		}
   551 
   552 		dlclose(pl->m_Lib);
   553 		pl->m_Lib = NULL;
   554 		pl->m_API = NULL;
   555 	}
   556 
   557 	return pl;
   558 }
   559 
   560 bool CPluginManager::_Unload(CPluginManager::CPlugin *pl, bool force, char *error, size_t maxlen)
   561 {
   562 	if (error)
   563 	{
   564 		*error = '\0';
   565 	}
   566 
   567 	if (pl->m_API && pl->m_Lib)
   568 	{
   569 		//Note, we'll always tell the plugin it will be unloading...
   570 		if (pl->m_API->Unload(error, maxlen) || force)
   571 		{
   572 			//Make sure to detach it from sourcehook!
   573 			g_SourceHook.UnloadPlugin(pl->m_Id);
   574 
   575 			pl->m_Events.clear();
   576 
   577 			UnregAllConCmds(pl);
   578 
   579 			if (pl->m_UnloadFn != NULL)
   580 			{
   581 				pl->m_UnloadFn();
   582 			}
   583 
   584 			//Clean up the DLL
   585 			dlclose(pl->m_Lib);
   586 			pl->m_Lib = NULL;
   587 			pl->m_API = NULL;
   588 
   589 			//Remove the plugin from the list
   590 			PluginIter i;
   591 			for (i=m_Plugins.begin(); i!=m_Plugins.end(); i++)
   592 			{
   593 				if ( (*i)->m_Id == pl->m_Id )
   594 				{
   595 					i = m_Plugins.erase(i);
   596 					break;
   597 				}
   598 			}
   599 			//Free its memory
   600 			delete pl;
   601 
   602 			return true;
   603 		}
   604 	} else {
   605 		//The plugin is not valid, and let's just remove it from the list anyway
   606 		PluginIter i;
   607 		for (i=m_Plugins.begin(); i!=m_Plugins.end(); i++)
   608 		{
   609 			if ( (*i)->m_Id == pl->m_Id )
   610 			{
   611 				i = m_Plugins.erase(i);
   612 				break;
   613 			}
   614 		}
   615 		delete pl;
   616 
   617 		return true;
   618 	}
   619 
   620 	return false;
   621 }
   622 
   623 bool CPluginManager::_Pause(CPluginManager::CPlugin *pl, char *error, size_t maxlen)
   624 {
   625 	if (error)
   626 	{
   627 		*error = '\0';
   628 	}
   629 
   630 	if (pl->m_Status != Pl_Running || !pl->m_API)
   631 	{
   632 		if (error)
   633 		{
   634 			UTIL_Format(error, maxlen, "Plugin cannot be paused");
   635 		}
   636 	}
   637 	else
   638 	{
   639 		if (pl->m_API->Pause(error, maxlen))
   640 		{
   641 			g_SourceHook.PausePlugin(pl->m_Id);
   642 			pl->m_Status = Pl_Paused;
   643 
   644 			return true;
   645 		}
   646 	}
   647 
   648 	return false;
   649 }
   650 
   651 bool CPluginManager::_Unpause(CPluginManager::CPlugin *pl, char *error, size_t maxlen)
   652 {
   653 	if (error)
   654 	{
   655 		*error = '\0';
   656 	}
   657 
   658 	if (pl->m_Status != Pl_Paused || !pl->m_API)
   659 	{
   660 		if (error)
   661 		{
   662 			UTIL_Format(error, maxlen, "Plugin cannot be unpaused");
   663 		}
   664 	}
   665 	else
   666 	{
   667 		if (pl->m_API->Unpause(error, maxlen))
   668 		{
   669 			g_SourceHook.UnpausePlugin(pl->m_Id);
   670 			pl->m_Status = Pl_Running;
   671 
   672 			return true;
   673 		}
   674 	}
   675 
   676 	return false;
   677 }
   678 
   679 bool CPluginManager::UnloadAll()
   680 {
   681 	PluginIter i;
   682 
   683 	char error[128];
   684 	bool status = true;
   685 
   686 	while ((i = m_Plugins.begin()) != m_Plugins.end())
   687 	{
   688 		if ( !_Unload( (*i), true, error, sizeof(error)) )
   689 		{
   690 			status = false;
   691 		}
   692 	}
   693 
   694 	return status;
   695 }
   696 
   697 bool CPluginManager::Query(PluginId id, const char **file, Pl_Status *status, PluginId *source)
   698 {
   699 	CPlugin *pl = FindById(id);
   700 
   701 	if (!pl)
   702 	{
   703 		return false;
   704 	}
   705 
   706 	if (file != NULL)
   707 	{
   708 		*file = pl->m_File.c_str();
   709 	}
   710 
   711 	if (status != NULL)
   712 	{
   713 		*status = pl->m_Status;
   714 	}
   715 
   716 	if (source != NULL)
   717 	{
   718 		*source = pl->m_Source;
   719 	}
   720 
   721 	return true;
   722 }
   723 
   724 bool CPluginManager::QueryRunning(PluginId id, char *error, size_t maxlength)
   725 {
   726 	CPlugin *pl = FindById(id);
   727 
   728 	if (!pl || !pl->m_API)
   729 	{
   730 		if (error)
   731 		{
   732 			UTIL_Format(error, maxlength, "Plugin not valid");
   733 		}
   734 		return false;
   735 	}
   736 
   737 	return pl->m_API->QueryRunning(error, maxlength);
   738 }
   739 
   740 bool CPluginManager::QueryHandle(PluginId id, void **handle)
   741 {
   742 	CPlugin *pl = FindById(id);
   743 
   744 	if (!pl)
   745 	{
   746 		return false;
   747 	}
   748 
   749 	if (handle)
   750 	{
   751 		*handle = static_cast<void *>(pl->m_Lib);
   752 	}
   753 
   754 	return true;
   755 }
   756 
   757 PluginIter CPluginManager::_begin()
   758 {
   759 	return m_Plugins.begin();
   760 }
   761 
   762 PluginIter CPluginManager::_end()
   763 {
   764 	return m_Plugins.end();
   765 }
   766 
   767 void CPluginManager::AddPluginCvar(ISmmPlugin *api, ConCommandBase *pCvar)
   768 {
   769 	CPlugin *pl = FindByAPI(api);
   770 
   771 	if (!pl)
   772 	{
   773 		return;
   774 	}
   775 
   776 	pl->m_Cvars.push_back(pCvar);
   777 }
   778 
   779 void CPluginManager::AddPluginCmd(ISmmPlugin *api, ConCommandBase *pCmd)
   780 {
   781 	CPlugin *pl = FindByAPI(api);
   782 
   783 	if (!pl)
   784 	{
   785 		return;
   786 	}
   787 
   788 	pl->m_Cmds.push_back(pCmd);
   789 }
   790 
   791 void CPluginManager::RemovePluginCvar(ISmmPlugin *api, ConCommandBase *pCvar)
   792 {
   793 	CPlugin *pl = FindByAPI(api);
   794 
   795 	if (!pl)
   796 	{
   797 		return;
   798 	}
   799 
   800 	pl->m_Cvars.remove(pCvar);
   801 }
   802 
   803 void CPluginManager::RemovePluginCmd(ISmmPlugin *api, ConCommandBase *pCmd)
   804 {
   805 	CPlugin *pl = FindByAPI(api);
   806 
   807 	if (!pl)
   808 	{
   809 		return;
   810 	}
   811 
   812 	pl->m_Cmds.remove(pCmd);
   813 }
   814 
   815 void CPluginManager::UnregAllConCmds(CPlugin *pl)
   816 {
   817 	SourceHook::List<ConCommandBase *>::iterator i;
   818 
   819 	/* :TODO: */
   820 	for (i=pl->m_Cvars.begin(); i!=pl->m_Cvars.end(); i++)
   821 	{
   822 		g_Metamod.UnregisterConCommandBase(pl->m_Id, (*i) );
   823 	}
   824 	pl->m_Cvars.clear();
   825 
   826 	for (i=pl->m_Cmds.begin(); i!=pl->m_Cmds.end(); i++)
   827 	{
   828 		g_Metamod.UnregisterConCommandBase(pl->m_Id, (*i) );
   829 	}
   830 	pl->m_Cmds.clear();
   831 }
   832