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