Public feed #724723

For Chun

public cpp v1 · immutable
Raw Edit
·published 2007-10-03 20:38 UTC
rendered paste body
//============= Copyright © 2007, SrcDev, All rights reserved. ================////// Purpose: Main initialization file////=============================================================================// //---------------------------------------------------------------------------------// Includes//---------------------------------------------------------------------------------#include "plugin_inc.h"#include "plugin_utils.h"//---------------------------------------------------------------------------------// Interfaces//---------------------------------------------------------------------------------IVEngineServer* engine = 0;IFileSystem* filesystem = 0;IGameEventManager2* gameeventmanager2 = 0;IPlayerInfoManager* playerinfomanager = 0;IBotManager* botmanager = 0;IServerPluginHelpers* helpers = 0;IServerGameClients* serverclients = 0;IUniformRandomStream* randomStr = 0;IEngineTrace* enginetrace = 0;ICvar* cvar = 0;INetworkStringTableContainer* networkstringtable = 0;IStaticPropMgrServer* staticpropmgr = 0;IEngineSound* enginesound = 0;IVModelInfo* modelinfo = 0;IVoiceServer* pVoiceServer = 0;IVEngineCache* engineCache = 0;IEffects* effects = 0;IEngineSound* esounds = 0;ISoundEmitterSystemBase* soundemitterbase = 0;IServerGameDLL* gamedll = 0;IPlayerInfo* playerinfo = 0;CBaseEntity* pBase = 0;CBaseCombatWeapon* pWeapon = 0;CBasePlayer* cBasep = 0;IVDebugOverlay* debugoverlay = 0;IServerGameEnts* gameents = 0;ISpatialPartition* partition = 0; // Initialize ConVarsvoid InitCVars( CreateInterfaceFn cvarFactory );template <typename T>inline bool defineInterface(T& interface, CreateInterfaceFn interfaceFactory, const char* version){	return interface = reinterpret_cast<T*>(interfaceFactory(version, 0));}//---------------------------------------------------------------------------------// Class Info//---------------------------------------------------------------------------------class CPlugin: public IServerPluginCallbacks, public IGameEventListener2{public:	CPlugin();	~CPlugin(); 	//---------------------------------------------------------------------------------	// Methods	//---------------------------------------------------------------------------------	virtual bool			Load( CreateInterfaceFn interfaceFactory, CreateInterfaceFn gameServerFactory );	virtual void			Unload( void );	virtual void			Pause( void );	virtual void			UnPause( void );	virtual const char     *GetPluginDescription( void );      	virtual void			LevelInit( char const *pMapName );	virtual void			ServerActivate( edict_t *pEdictList, int edictCount, int clientMax );	virtual void			GameFrame( bool simulating );	virtual void			LevelShutdown( void );	virtual void			ClientActive( edict_t *pEntity );	virtual void			ClientDisconnect( edict_t *pEntity );	virtual void			ClientPutInServer( edict_t *pEntity, char const *playername );	virtual void			SetCommandClient( int index );	virtual void			ClientSettingsChanged( edict_t *pEdict );	virtual PLUGIN_RESULT	ClientConnect( bool *bAllowConnect, edict_t *pEntity, const char *pszName, const char *pszAddress, char *reject, int maxrejectlen );	virtual PLUGIN_RESULT	ClientCommand( edict_t *pEntity );	virtual PLUGIN_RESULT	NetworkIDValidated( const char *pszUserName, const char *pszNetworkID );	virtual void			FireGameEvent( IGameEvent *pEvent );	virtual int				GetCommandIndex() { return m_iClientCommandIndex; } private:	int m_iClientCommandIndex; };  //---------------------------------------------------------------------------------// Interface Globalvar//---------------------------------------------------------------------------------CPlugin g_Plugin;EXPOSE_SINGLE_INTERFACE_GLOBALVAR(CPlugin, IServerPluginCallbacks, INTERFACEVERSION_ISERVERPLUGINCALLBACKS, g_Plugin ); //---------------------------------------------------------------------------------// Constructor + Destructor//---------------------------------------------------------------------------------CPlugin::CPlugin(){	m_iClientCommandIndex = 0;} CPlugin::~CPlugin(){} //---------------------------------------------------------------------------------// Purpose: called when the plugin is loaded, load the interface we need from the engine//---------------------------------------------------------------------------------bool CPlugin::Load( CreateInterfaceFn interfaceFactory, CreateInterfaceFn gameServerFactory ){		// Python Init	Msg("\n===================================================\n");	Msg("	SDKTools (ESPy Helper)\n");	Msg("	Version: %s, Author: %s, Website: %s\n", PLUGIN_VERSION, PLUGIN_AUTHOR, PLUGIN_WEBSITE);	Msg("===================================================\n");	Py_Initialize();	Msg("	Initialized Python.\n");	Msg("	Assigning all interfaces...\n"); 	//---------------------------------------------------------------------------------	// Assign all interfaces	//---------------------------------------------------------------------------------	if (!defineInterface(engine, interfaceFactory, INTERFACEVERSION_VENGINESERVER) ||		!defineInterface(gameeventmanager2, interfaceFactory, INTERFACEVERSION_GAMEEVENTSMANAGER2) ||		!defineInterface(filesystem, interfaceFactory, FILESYSTEM_INTERFACE_VERSION) ||		!defineInterface(playerinfomanager, gameServerFactory, FILESYSTEM_INTERFACE_VERSION) ||		!defineInterface(helpers, interfaceFactory, INTERFACEVERSION_ENGINETRACE_SERVER) ||		!defineInterface(enginetrace, interfaceFactory, INTERFACEVERSION_ENGINETRACE_SERVER) ||		!defineInterface(randomStr, interfaceFactory, VENGINE_SERVER_RANDOM_INTERFACE_VERSION) ||		!defineInterface(gamedll, gameServerFactory, IEFFECTS_INTERFACE_VERSION) ||		!defineInterface(serverclients, gameServerFactory, INTERFACEVERSION_SERVERGAMECLIENTS) ||		!defineInterface(effects, gameServerFactory, IEFFECTS_INTERFACE_VERSION) ||		!defineInterface(networkstringtable, interfaceFactory, INTERFACENAME_NETWORKSTRINGTABLESERVER) ||		!defineInterface(cvar, interfaceFactory, VENGINE_CVAR_INTERFACE_VERSION) ||		!defineInterface(esounds, interfaceFactory, IENGINESOUND_SERVER_INTERFACE_VERSION))	{		return false;	}	defineInterface(pVoiceServer, interfaceFactory, INTERFACEVERSION_VOICESERVER);	defineInterface(engineCache, interfaceFactory, VENGINE_CACHE_INTERFACE_VERSION);	defineInterface(modelinfo, interfaceFactory, VMODELINFO_SERVER_INTERFACE_VERSION);	defineInterface(partition, interfaceFactory, INTERFACEVERSION_SPATIALPARTITION);	defineInterface(staticpropmgr, interfaceFactory, INTERFACEVERSION_STATICPROPMGR_SERVER);	defineInterface(soundemitterbase, interfaceFactory, SOUNDEMITTERSYSTEM_INTERFACE_VERSION);	defineInterface(botmanager, gameServerFactory, INTERFACEVERSION_PLAYERBOTMANAGER); 	// End Header msg	Msg("	Assigned.\n	Loading complete.");	Msg("===================================================\n"); 	// Get global vars	gpGlobals = playerinfomanager->GetGlobalVars(); 	// Other crap	InitCVars( interfaceFactory );	MathLib_Init( 2.2f, 2.2f, 0.0f, 2.0f ); 	// Return	return true;} //---------------------------------------------------------------------------------// Purpose: called when the plugin is unloaded (turned off)//---------------------------------------------------------------------------------void CPlugin::Unload( void ){	Py_Finalize();	gameeventmanager->RemoveListener( this );} //---------------------------------------------------------------------------------// Purpose: called when the plugin is paused (i.e should stop running but isn't unloaded)//---------------------------------------------------------------------------------void CPlugin::Pause( void ){} //---------------------------------------------------------------------------------// Purpose: called when the plugin is unpaused (i.e should start executing again)//---------------------------------------------------------------------------------void CPlugin::UnPause( void ){} //---------------------------------------------------------------------------------// Purpose: the name of this plugin, returned in "plugin_print" command//---------------------------------------------------------------------------------const char *CPlugin::GetPluginDescription( void ){	return PLUGIN_NAME ", v" PLUGIN_VERSION ", " PLUGIN_AUTHOR;} //---------------------------------------------------------------------------------// Purpose: called on level start//---------------------------------------------------------------------------------void CPlugin::LevelInit( char const *pMapName ){} //---------------------------------------------------------------------------------// Purpose: called on level start, when the server is ready to accept client connections//		edictCount is the number of entities in the level, clientMax is the max client count//---------------------------------------------------------------------------------void CPlugin::ServerActivate( edict_t *pEdictList, int edictCount, int clientMax ){ 	// gpGlobals has a variable that can do the below!	//MaxClients = clientMax; } //---------------------------------------------------------------------------------// Purpose: called once per server frame, do recurring work here (like checking for timeouts)//---------------------------------------------------------------------------------void CPlugin::GameFrame( bool simulating ){} //---------------------------------------------------------------------------------// Purpose: called on level end (as the server is shutting down or going to a new map)//---------------------------------------------------------------------------------void CPlugin::LevelShutdown( void ){	gameeventmanager->RemoveListener( this );} //---------------------------------------------------------------------------------// Purpose: called when a client spawns into a server (i.e as they begin to play)//---------------------------------------------------------------------------------void CPlugin::ClientActive( edict_t *pEntity ){} //---------------------------------------------------------------------------------// Purpose: called when a client leaves a server (or is timed out)//---------------------------------------------------------------------------------void CPlugin::ClientDisconnect( edict_t *pEntity ){} //---------------------------------------------------------------------------------// Purpose: called on //---------------------------------------------------------------------------------void CPlugin::ClientPutInServer( edict_t *pEntity, char const *playername ){} //---------------------------------------------------------------------------------// Purpose: called on level start//---------------------------------------------------------------------------------void CPlugin::SetCommandClient( int index ){	m_iClientCommandIndex = index;} //---------------------------------------------------------------------------------// Purpose: called on level start//---------------------------------------------------------------------------------void CPlugin::ClientSettingsChanged( edict_t *pEdict ){} //---------------------------------------------------------------------------------// Purpose: called when a client joins a server//---------------------------------------------------------------------------------PLUGIN_RESULT CPlugin::ClientConnect( bool *bAllowConnect, edict_t *pEntity, const char *pszName, const char *pszAddress, char *reject, int maxrejectlen ){	return PLUGIN_CONTINUE;} //---------------------------------------------------------------------------------// Purpose: called when a client types in a command (only a subset of commands however, not CON_COMMAND's)//---------------------------------------------------------------------------------PLUGIN_RESULT CPlugin::ClientCommand( edict_t *pEntity ){	const char *pcmd = engine->Cmd_Argv(0);	const char *pmsg = engine->Cmd_Argv(1); 	if ( !pEntity || pEntity->IsFree() ) 	{		return PLUGIN_CONTINUE;	} 	if ( StrEq( pcmd, "myteamnumber" ) )	{ 		PrintToChat( engine->IndexOfEdict( pEntity ), 0, UTIL_StrArgs( "Your team number is: %i", UTIL_GetBaseEntity( pEntity )->GetTeamNumber() ) ); 		return PLUGIN_STOP; 	}  	if ( StrEq( pcmd, "radiotext" ) )	{ 		PrintToChat2( 0, 1, "Game_radio_location", UTIL_GetPlayerName( pEntity ), PROP_GetPlayer_String( UTIL_GetBaseEntity( pEntity ), "CNavMesh", "PlaceToName" ) , "Radio test. Please ignore.", "" ); 		return PLUGIN_STOP; 	} 	return PLUGIN_CONTINUE; } //---------------------------------------------------------------------------------// Purpose: called when a client is authenticated//---------------------------------------------------------------------------------PLUGIN_RESULT CPlugin::NetworkIDValidated( const char *pszUserName, const char *pszNetworkID ){	return PLUGIN_CONTINUE;} //---------------------------------------------------------------------------------// Purpose: called when an event is fired//---------------------------------------------------------------------------------void CPlugin::FireGameEvent( IGameEvent *pEvent ){} //---------------------------------------------------------------------------------// COMMANDS//---------------------------------------------------------------------------------CON_COMMAND_F( pymod_run, "Run a Pythonic string", FCVAR_GAMEDLL ){	const char *cmd = engine->Cmd_Argv(1);	PyRun_SimpleString(cmd);}CON_COMMAND_F( srcdev_saytext2_test, "SayText2 Test", FCVAR_GAMEDLL ){	PrintToChat2( 0, 1, "Game_radio_location", "[WF] dark0r", "Heaven", "Fire in teh holez!", "" );	PrintToChat2( 0, 1, "\x01Stats: \x03%s1\x01 got killed by \x04%s2", "[WF] dark0r", "[WF] dark0r", "", "" );} CON_COMMAND_F( srcdev_plugin_info, "Prints the plugin info", FCVAR_GAMEDLL ){	Msg( UTIL_StrArgs( "%s, v%s, %s", PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR ) );}