Counter Strike : Global Offensive Source Code
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.

199 lines
9.2 KiB

  1. //========= Copyright � 1996-2005, 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_VERSION_3 "ISERVERPLUGINCALLBACKS003"
  38. #define INTERFACEVERSION_ISERVERPLUGINCALLBACKS "ISERVERPLUGINCALLBACKS004"
  39. //-----------------------------------------------------------------------------
  40. // Purpose: callbacks the engine exposes to the 3rd party plugins (ala MetaMod)
  41. //-----------------------------------------------------------------------------
  42. abstract_class IServerPluginCallbacks
  43. {
  44. public:
  45. // Initialize the plugin to run
  46. // Return false if there is an error during startup.
  47. virtual bool Load( CreateInterfaceFn interfaceFactory, CreateInterfaceFn gameServerFactory ) = 0;
  48. // Called when the plugin should be shutdown
  49. virtual void Unload( void ) = 0;
  50. // called when a plugins execution is stopped but the plugin is not unloaded
  51. virtual void Pause( void ) = 0;
  52. // called when a plugin should start executing again (sometime after a Pause() call)
  53. virtual void UnPause( void ) = 0;
  54. // Returns string describing current plugin. e.g., Admin-Mod.
  55. virtual const char *GetPluginDescription( void ) = 0;
  56. // Called any time a new level is started (after GameInit() also on level transitions within a game)
  57. virtual void LevelInit( char const *pMapName ) = 0;
  58. // The server is about to activate
  59. virtual void ServerActivate( edict_t *pEdictList, int edictCount, int clientMax ) = 0;
  60. // The server should run physics/think on all edicts
  61. virtual void GameFrame( bool simulating ) = 0;
  62. // Called when a level is shutdown (including changing levels)
  63. virtual void LevelShutdown( void ) = 0;
  64. // Client is going active
  65. virtual void ClientActive( edict_t *pEntity ) = 0;
  66. // Client is fully connected ( has received initial baseline of entities )
  67. virtual void ClientFullyConnect( edict_t *pEntity ) = 0;
  68. // Client is disconnecting from server
  69. virtual void ClientDisconnect( edict_t *pEntity ) = 0;
  70. // Client is connected and should be put in the game
  71. virtual void ClientPutInServer( edict_t *pEntity, char const *playername ) = 0;
  72. // Sets the client index for the client who typed the command into their console
  73. virtual void SetCommandClient( int index ) = 0;
  74. // A player changed one/several replicated cvars (name etc)
  75. virtual void ClientSettingsChanged( edict_t *pEdict ) = 0;
  76. // Client is connecting to server ( set retVal to false to reject the connection )
  77. // You can specify a rejection message by writing it into reject
  78. virtual PLUGIN_RESULT ClientConnect( bool *bAllowConnect, edict_t *pEntity, const char *pszName, const char *pszAddress, char *reject, int maxrejectlen ) = 0;
  79. // The client has typed a command at the console
  80. virtual PLUGIN_RESULT ClientCommand( edict_t *pEntity, const CCommand &args ) = 0;
  81. // A user has had their network id setup and validated
  82. virtual PLUGIN_RESULT NetworkIDValidated( const char *pszUserName, const char *pszNetworkID ) = 0;
  83. // This is called when a query from IServerPluginHelpers::StartQueryCvarValue is finished.
  84. // iCookie is the value returned by IServerPluginHelpers::StartQueryCvarValue.
  85. // Added with version 2 of the interface.
  86. virtual void OnQueryCvarValueFinished( QueryCvarCookie_t iCookie, edict_t *pPlayerEntity, EQueryCvarValueStatus eStatus, const char *pCvarName, const char *pCvarValue ) = 0;
  87. // added with version 3 of the interface.
  88. virtual void OnEdictAllocated( edict_t *edict ) = 0;
  89. virtual void OnEdictFreed( const edict_t *edict ) = 0;
  90. //
  91. // Allow plugins to validate and configure network encryption keys (added in Version 4 of the interface)
  92. // Game server must run with -externalnetworkcryptkey flag, and 3rd party client software must set the
  93. // matching encryption key in the client game process.
  94. //
  95. // BNetworkCryptKeyCheckRequired allows the server to allow connections from clients or relays that don't have
  96. // an encryption key. The function must return true if the client encryption key is required, and false if the client
  97. // is allowed to connect without an encryption key. It is recommended that if client wants to use encryption key
  98. // this function should return true to require it on the server side as well.
  99. // Any plugin in the chain that returns true will flag connection to require encryption key for the engine and check
  100. // with other plugins will not be continued.
  101. // If no plugin returns true to require encryption key then the default implementation will require encryption key
  102. // if the client wants to use it.
  103. virtual bool BNetworkCryptKeyCheckRequired( uint32 unFromIP, uint16 usFromPort, uint32 unAccountIdProvidedByClient,
  104. bool bClientWantsToUseCryptKey ) = 0;
  105. // BNetworkCryptKeyValidate allows the server to validate client's over the wire encrypted payload cookie and return
  106. // false if the client cookie is malformed to prevent connection to the server. If this function returns true then
  107. // the plugin allows the client to connect with the encryption key, and upon return the engine expects the plugin
  108. // to have copied 16-bytes of client encryption key into the buffer pointed at by pbPlainTextKeyForNetChan. That key
  109. // must match the plaintext key supplied by 3rd party client software to the client game process, not the client cookie
  110. // transmitted unencrypted over the wire as part of the connection packet.
  111. // Any plugin in the chain that returns true will stop evaluation of other plugins and the 16-bytes encryption key
  112. // copied into pbPlainTextKeyForNetchan will be used. If a plugin returns false then evaluation of other plugins will
  113. // continue and buffer data in pbPlainTextKeyForNetchan will be preserved from previous calls.
  114. // If no plugin returns true and the encryption key is required then the client connection will be rejected with
  115. // an invalid certificate error.
  116. virtual bool BNetworkCryptKeyValidate( uint32 unFromIP, uint16 usFromPort, uint32 unAccountIdProvidedByClient,
  117. int nEncryptionKeyIndexFromClient, int numEncryptedBytesFromClient, byte *pbEncryptedBufferFromClient,
  118. byte *pbPlainTextKeyForNetchan ) = 0;
  119. };
  120. #define INTERFACEVERSION_ISERVERPLUGINHELPERS "ISERVERPLUGINHELPERS001"
  121. typedef enum
  122. {
  123. DIALOG_MSG = 0, // just an on screen message
  124. DIALOG_MENU, // an options menu
  125. DIALOG_TEXT, // a richtext dialog
  126. DIALOG_ENTRY, // an entry box
  127. DIALOG_ASKCONNECT // Ask the client to connect to a specified IP address. Only the "time" and "title" keys are used.
  128. } DIALOG_TYPE;
  129. //-----------------------------------------------------------------------------
  130. // Purpose: functions that only 3rd party plugins need
  131. //-----------------------------------------------------------------------------
  132. abstract_class IServerPluginHelpers
  133. {
  134. public:
  135. // creates an onscreen menu with various option buttons
  136. // The keyvalues param can contain these fields:
  137. // "title" - (string) the title to show in the hud and in the title bar
  138. // "msg" - (string) a longer message shown in the GameUI
  139. // "color" - (color) the color to display the message in the hud (white by default)
  140. // "level" - (int) the priority of this message (closer to 0 is higher), only 1 message can be outstanding at a time
  141. // "time" - (int) the time in seconds this message should stay active in the GameUI (min 10 sec, max 200 sec)
  142. //
  143. // For DIALOG_MENU add sub keys for each option with these fields:
  144. // "command" - (string) client command to run if selected
  145. // "msg" - (string) button text for this option
  146. //
  147. virtual void CreateMessage( edict_t *pEntity, DIALOG_TYPE type, KeyValues *data, IServerPluginCallbacks *plugin ) = 0;
  148. virtual void ClientCommand( edict_t *pEntity, const char *cmd ) = 0;
  149. // Call this to find out the value of a cvar on the client.
  150. //
  151. // It is an asynchronous query, and it will call IServerPluginCallbacks::OnQueryCvarValueFinished when
  152. // the value comes in from the client.
  153. //
  154. // Store the return value if you want to match this specific query to the OnQueryCvarValueFinished call.
  155. // Returns InvalidQueryCvarCookie if the entity is invalid.
  156. virtual QueryCvarCookie_t StartQueryCvarValue( edict_t *pEntity, const char *pName ) = 0;
  157. };
  158. #endif //ISERVERPLUGIN_H