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.

163 lines
6.4 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //=============================================================================//
  8. #ifndef ISERVERPLUGIN_H
  9. #define ISERVERPLUGIN_H
  10. #ifdef _WIN32
  11. #pragma once
  12. #endif
  13. #include "edict.h"
  14. #include "tier1/interface.h"
  15. #include "tier1/KeyValues.h"
  16. class CCommand;
  17. //
  18. // you will also want to listen for game events via IGameEventManager::AddListener()
  19. //
  20. typedef enum
  21. {
  22. PLUGIN_CONTINUE = 0, // keep going
  23. PLUGIN_OVERRIDE, // run the game dll function but use our return value instead
  24. PLUGIN_STOP, // don't run the game dll function at all
  25. } PLUGIN_RESULT;
  26. typedef enum
  27. {
  28. eQueryCvarValueStatus_ValueIntact=0, // It got the value fine.
  29. eQueryCvarValueStatus_CvarNotFound=1,
  30. eQueryCvarValueStatus_NotACvar=2, // There's a ConCommand, but it's not a ConVar.
  31. eQueryCvarValueStatus_CvarProtected=3 // The cvar was marked with FCVAR_SERVER_CAN_NOT_QUERY, so the server is not allowed to have its value.
  32. } EQueryCvarValueStatus;
  33. typedef int QueryCvarCookie_t;
  34. #define InvalidQueryCvarCookie -1
  35. #define INTERFACEVERSION_ISERVERPLUGINCALLBACKS_VERSION_1 "ISERVERPLUGINCALLBACKS001"
  36. #define INTERFACEVERSION_ISERVERPLUGINCALLBACKS_VERSION_2 "ISERVERPLUGINCALLBACKS002"
  37. #define INTERFACEVERSION_ISERVERPLUGINCALLBACKS "ISERVERPLUGINCALLBACKS003"
  38. //-----------------------------------------------------------------------------
  39. // Purpose: callbacks the engine exposes to the 3rd party plugins (ala MetaMod)
  40. //-----------------------------------------------------------------------------
  41. abstract_class IServerPluginCallbacks
  42. {
  43. public:
  44. // Initialize the plugin to run
  45. // Return false if there is an error during startup.
  46. virtual bool Load( CreateInterfaceFn interfaceFactory, CreateInterfaceFn gameServerFactory ) = 0;
  47. // Called when the plugin should be shutdown
  48. virtual void Unload( void ) = 0;
  49. // called when a plugins execution is stopped but the plugin is not unloaded
  50. virtual void Pause( void ) = 0;
  51. // called when a plugin should start executing again (sometime after a Pause() call)
  52. virtual void UnPause( void ) = 0;
  53. // Returns string describing current plugin. e.g., Admin-Mod.
  54. virtual const char *GetPluginDescription( void ) = 0;
  55. // Called any time a new level is started (after GameInit() also on level transitions within a game)
  56. virtual void LevelInit( char const *pMapName ) = 0;
  57. // The server is about to activate
  58. virtual void ServerActivate( edict_t *pEdictList, int edictCount, int clientMax ) = 0;
  59. // The server should run physics/think on all edicts
  60. virtual void GameFrame( bool simulating ) = 0;
  61. // Called when a level is shutdown (including changing levels)
  62. virtual void LevelShutdown( void ) = 0;
  63. // Client is going active
  64. virtual void ClientActive( edict_t *pEntity ) = 0;
  65. // Client is disconnecting from server
  66. virtual void ClientDisconnect( edict_t *pEntity ) = 0;
  67. // Client is connected and should be put in the game
  68. virtual void ClientPutInServer( edict_t *pEntity, char const *playername ) = 0;
  69. // Sets the client index for the client who typed the command into their console
  70. virtual void SetCommandClient( int index ) = 0;
  71. // A player changed one/several replicated cvars (name etc)
  72. virtual void ClientSettingsChanged( edict_t *pEdict ) = 0;
  73. // Client is connecting to server ( set retVal to false to reject the connection )
  74. // You can specify a rejection message by writing it into reject
  75. virtual PLUGIN_RESULT ClientConnect( bool *bAllowConnect, edict_t *pEntity, const char *pszName, const char *pszAddress, char *reject, int maxrejectlen ) = 0;
  76. // The client has typed a command at the console
  77. virtual PLUGIN_RESULT ClientCommand( edict_t *pEntity, const CCommand &args ) = 0;
  78. // A user has had their network id setup and validated
  79. virtual PLUGIN_RESULT NetworkIDValidated( const char *pszUserName, const char *pszNetworkID ) = 0;
  80. // This is called when a query from IServerPluginHelpers::StartQueryCvarValue is finished.
  81. // iCookie is the value returned by IServerPluginHelpers::StartQueryCvarValue.
  82. // Added with version 2 of the interface.
  83. virtual void OnQueryCvarValueFinished( QueryCvarCookie_t iCookie, edict_t *pPlayerEntity, EQueryCvarValueStatus eStatus, const char *pCvarName, const char *pCvarValue ) = 0;
  84. // added with version 3 of the interface.
  85. virtual void OnEdictAllocated( edict_t *edict ) = 0;
  86. virtual void OnEdictFreed( const edict_t *edict ) = 0;
  87. };
  88. #define INTERFACEVERSION_ISERVERPLUGINHELPERS "ISERVERPLUGINHELPERS001"
  89. typedef enum
  90. {
  91. DIALOG_MSG = 0, // just an on screen message
  92. DIALOG_MENU, // an options menu
  93. DIALOG_TEXT, // a richtext dialog
  94. DIALOG_ENTRY, // an entry box
  95. DIALOG_ASKCONNECT // Ask the client to connect to a specified IP address. Only the "time" and "title" keys are used.
  96. } DIALOG_TYPE;
  97. //-----------------------------------------------------------------------------
  98. // Purpose: functions that only 3rd party plugins need
  99. //-----------------------------------------------------------------------------
  100. abstract_class IServerPluginHelpers
  101. {
  102. public:
  103. // creates an onscreen menu with various option buttons
  104. // The keyvalues param can contain these fields:
  105. // "title" - (string) the title to show in the hud and in the title bar
  106. // "msg" - (string) a longer message shown in the GameUI
  107. // "color" - (color) the color to display the message in the hud (white by default)
  108. // "level" - (int) the priority of this message (closer to 0 is higher), only 1 message can be outstanding at a time
  109. // "time" - (int) the time in seconds this message should stay active in the GameUI (min 10 sec, max 200 sec)
  110. //
  111. // For DIALOG_MENU add sub keys for each option with these fields:
  112. // "command" - (string) client command to run if selected
  113. // "msg" - (string) button text for this option
  114. //
  115. virtual void CreateMessage( edict_t *pEntity, DIALOG_TYPE type, KeyValues *data, IServerPluginCallbacks *plugin ) = 0;
  116. virtual void ClientCommand( edict_t *pEntity, const char *cmd ) = 0;
  117. // Call this to find out the value of a cvar on the client.
  118. //
  119. // It is an asynchronous query, and it will call IServerPluginCallbacks::OnQueryCvarValueFinished when
  120. // the value comes in from the client.
  121. //
  122. // Store the return value if you want to match this specific query to the OnQueryCvarValueFinished call.
  123. // Returns InvalidQueryCvarCookie if the entity is invalid.
  124. virtual QueryCvarCookie_t StartQueryCvarValue( edict_t *pEntity, const char *pName ) = 0;
  125. };
  126. #endif //ISERVERPLUGIN_H