Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

112 lines
3.6 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //=============================================================================//
  8. #ifndef SV_SERVERPLUGIN_H
  9. #define SV_SERVERPLUGIN_H
  10. #ifdef _WIN32
  11. #pragma once
  12. #endif
  13. #include "eiface.h"
  14. #include "engine/iserverplugin.h"
  15. //---------------------------------------------------------------------------------
  16. // Purpose: a single plugin
  17. //---------------------------------------------------------------------------------
  18. class CPlugin
  19. {
  20. public:
  21. CPlugin();
  22. ~CPlugin();
  23. const char *GetName();
  24. bool Load( const char *fileName );
  25. void Unload();
  26. void Disable( bool state );
  27. bool IsDisabled() { return m_bDisable; }
  28. int GetPluginInterfaceVersion() const { return m_iPluginInterfaceVersion; }
  29. IServerPluginCallbacks *GetCallback();
  30. private:
  31. void SetName( const char *name );
  32. char m_szName[128];
  33. bool m_bDisable;
  34. IServerPluginCallbacks *m_pPlugin;
  35. int m_iPluginInterfaceVersion; // Tells if we got INTERFACEVERSION_ISERVERPLUGINCALLBACKS or an older version.
  36. CSysModule *m_pPluginModule;
  37. };
  38. //---------------------------------------------------------------------------------
  39. // Purpose: implenents passthroughs for plugins and their special helper functions
  40. //---------------------------------------------------------------------------------
  41. class CServerPlugin : public IServerPluginHelpers
  42. {
  43. public:
  44. CServerPlugin();
  45. ~CServerPlugin();
  46. // management functions
  47. void LoadPlugins();
  48. void UnloadPlugins();
  49. bool UnloadPlugin( int index );
  50. bool LoadPlugin( const char *fileName );
  51. void DisablePlugins();
  52. void DisablePlugin( int index );
  53. void EnablePlugins();
  54. void EnablePlugin( int index );
  55. void PrintDetails();
  56. // multiplex the passthroughs
  57. virtual void LevelInit( char const *pMapName,
  58. char const *pMapEntities, char const *pOldLevel,
  59. char const *pLandmarkName, bool loadGame, bool background );
  60. virtual void ServerActivate( edict_t *pEdictList, int edictCount, int clientMax );
  61. virtual void GameFrame( bool simulating );
  62. virtual void LevelShutdown( void );
  63. virtual void ClientActive( edict_t *pEntity, bool bLoadGame );
  64. virtual void ClientDisconnect( edict_t *pEntity );
  65. virtual void ClientPutInServer( edict_t *pEntity, char const *playername );
  66. virtual void SetCommandClient( int index );
  67. virtual void ClientSettingsChanged( edict_t *pEdict );
  68. virtual bool ClientConnect( edict_t *pEntity, const char *pszName, const char *pszAddress, char *reject, int maxrejectlen );
  69. virtual void ClientCommand( edict_t *pEntity, const CCommand &args );
  70. virtual void NetworkIDValidated( const char *pszUserName, const char *pszNetworkID );
  71. virtual void OnQueryCvarValueFinished( QueryCvarCookie_t iCookie, edict_t *pPlayerEntity, EQueryCvarValueStatus eStatus, const char *pCvarName, const char *pCvarValue );
  72. // implement helpers
  73. virtual void CreateMessage( edict_t *pEntity, DIALOG_TYPE type, KeyValues *data, IServerPluginCallbacks *plugin );
  74. virtual void ClientCommand( edict_t *pEntity, const char *cmd );
  75. virtual QueryCvarCookie_t StartQueryCvarValue( edict_t *pEntity, const char *pName );
  76. int GetNumLoadedPlugins( void ){ return m_Plugins.Count(); }
  77. private:
  78. CUtlVector<CPlugin *> m_Plugins;
  79. IPluginHelpersCheck *m_PluginHelperCheck;
  80. public:
  81. //New plugin interface callbacks
  82. virtual void OnEdictAllocated( edict_t *edict );
  83. virtual void OnEdictFreed( const edict_t *edict );
  84. };
  85. extern CServerPlugin *g_pServerPluginHandler;
  86. class IClient;
  87. QueryCvarCookie_t SendCvarValueQueryToClient( IClient *client, const char *pCvarName, bool bPluginQuery );
  88. #endif //SV_SERVERPLUGIN_H