sourcemm/vsp_listener.cpp
author David Anderson <dvander@alliedmods.net>
Fri Apr 06 20:53:07 2007 +0000 (2007-04-06)
changeset 313 297482d07c85
parent 282 7a237e9ea5a1
permissions -rw-r--r--
fixed a post-release error where the vsp listener API simply didn't work :(
     1 /* ======== SourceMM ========
     2  * Copyright (C) 2004-2007 Metamod:Source Development Team
     3  * No warranties of any kind
     4  *
     5  * License: zlib/libpng
     6  *
     7  * Author(s): David "BAILOPAN" Anderson
     8  * ============================
     9  */
    10 
    11 #include "vsp_listener.h"
    12 #include "CPlugin.h"
    13 
    14 using namespace SourceMM;
    15 
    16 VSPListener g_VspListener;
    17 
    18 VSPListener::VSPListener()
    19 {
    20 	m_Loaded = false;
    21 	m_Loadable = false;
    22 }
    23 
    24 void VSPListener::ClientActive(edict_t *pEntity)
    25 {
    26 }
    27 
    28 PLUGIN_RESULT VSPListener::ClientCommand(edict_t *pEntity)
    29 {
    30 	return PLUGIN_CONTINUE;
    31 }
    32 
    33 PLUGIN_RESULT VSPListener::ClientConnect(bool *bAllowConnect, edict_t *pEntity, const char *pszName, const char *pszAddress, char *reject, int maxrejectlen)
    34 {
    35 	return PLUGIN_CONTINUE;
    36 }
    37 
    38 void VSPListener::ClientDisconnect(edict_t *pEntity)
    39 {
    40 }
    41 
    42 void VSPListener::ClientPutInServer(edict_t *pEntity, char const *playername)
    43 {
    44 }
    45 
    46 void VSPListener::ClientSettingsChanged(edict_t *pEdict)
    47 {
    48 }
    49 
    50 void VSPListener::SetCommandClient(int index)
    51 {
    52 }
    53 
    54 void VSPListener::GameFrame(bool simulating)
    55 {
    56 }
    57 
    58 const char *VSPListener::GetPluginDescription()
    59 {
    60 	return "Metamod:Source Interface v" SOURCEMM_VERSION;
    61 }
    62 
    63 bool VSPListener::IsLoaded()
    64 {
    65 	return m_Loaded;
    66 }
    67 
    68 void VSPListener::LevelInit(char const *pMapName)
    69 {
    70 }
    71 
    72 void VSPListener::LevelShutdown()
    73 {
    74 }
    75 
    76 PLUGIN_RESULT VSPListener::NetworkIDValidated(const char *pszUserName, const char *pszNetworkID)
    77 {
    78 	return PLUGIN_CONTINUE;
    79 }
    80 
    81 void VSPListener::Pause()
    82 {
    83 }
    84 
    85 void VSPListener::UnPause()
    86 {
    87 }
    88 
    89 void VSPListener::ServerActivate(edict_t *pEdictList, int edictCount, int clientMax)
    90 {
    91 }
    92 
    93 void VSPListener::Unload()
    94 {
    95 }
    96 
    97 void VSPListener::SetLoadable(bool set)
    98 {
    99 	m_Loadable = set;
   100 }
   101 
   102 bool VSPListener::Load(CreateInterfaceFn interfaceFactory, CreateInterfaceFn gameServerFactory)
   103 {
   104 	if (!g_GameDll.loaded)
   105 	{
   106 		Error("Metamod:Source is not a Valve Server Plugin\n");
   107 
   108 		return false;
   109 	}
   110 
   111 	if (!m_Loadable)
   112 	{
   113 		Warning("Do not manually load Metamod:Source as a Valve Server Plugin\n");
   114 
   115 		return false;
   116 	}
   117 
   118 	if (m_Loaded)
   119 	{
   120 		return false;
   121 	}
   122 
   123 	m_Loaded = true;
   124 	SetLoadable(false);
   125 
   126 	PluginIter iter;
   127 	CPluginManager::CPlugin *pPlugin;
   128 	SourceHook::List<IMetamodListener *>::iterator event;
   129 	IMetamodListener *pML;
   130 	for (iter=g_PluginMngr._begin(); iter!=g_PluginMngr._end(); iter++)
   131 	{
   132 		pPlugin = (*iter);
   133 		if (pPlugin->m_Status < Pl_Paused)
   134 		{
   135 			continue;
   136 		}
   137 		/* Only valid for plugins >= 10 (v1:5, SourceMM 1.4) */
   138 		if (pPlugin->m_API->GetApiVersion() < 10)
   139 		{
   140 			continue;
   141 		}
   142 		for (event=pPlugin->m_Events.begin();
   143 			event!=pPlugin->m_Events.end();
   144 			event++)
   145 		{
   146 			pML = (*event);
   147 			pML->OnVSPListening(this);
   148 		}
   149 	}
   150 
   151 	return true;
   152 }