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.

827 lines
38 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //===========================================================================//
  8. #ifndef EIFACE_H
  9. #define EIFACE_H
  10. #ifdef _WIN32
  11. #pragma once
  12. #endif
  13. #include "convar.h"
  14. #include "icvar.h"
  15. #include "edict.h"
  16. #include "mathlib/vplane.h"
  17. #include "iserverentity.h"
  18. #include "engine/ivmodelinfo.h"
  19. #include "soundflags.h"
  20. #include "bitvec.h"
  21. #include "engine/iserverplugin.h"
  22. #include "tier1/bitbuf.h"
  23. //-----------------------------------------------------------------------------
  24. // forward declarations
  25. //-----------------------------------------------------------------------------
  26. class SendTable;
  27. class ServerClass;
  28. class IMoveHelper;
  29. struct Ray_t;
  30. class CGameTrace;
  31. typedef CGameTrace trace_t;
  32. struct typedescription_t;
  33. class CSaveRestoreData;
  34. struct datamap_t;
  35. class SendTable;
  36. class ServerClass;
  37. class IMoveHelper;
  38. struct Ray_t;
  39. struct studiohdr_t;
  40. class CBaseEntity;
  41. class CRestore;
  42. class CSave;
  43. class variant_t;
  44. struct vcollide_t;
  45. class IRecipientFilter;
  46. class CBaseEntity;
  47. class ITraceFilter;
  48. struct client_textmessage_t;
  49. class INetChannelInfo;
  50. class ISpatialPartition;
  51. class IScratchPad3D;
  52. class CStandardSendProxies;
  53. class IAchievementMgr;
  54. class CGamestatsData;
  55. class CSteamID;
  56. class IReplayFactory;
  57. class IReplaySystem;
  58. class IServer;
  59. typedef struct player_info_s player_info_t;
  60. //-----------------------------------------------------------------------------
  61. // defines
  62. //-----------------------------------------------------------------------------
  63. #ifdef _WIN32
  64. #define DLLEXPORT __stdcall
  65. #else
  66. #define DLLEXPORT /* */
  67. #endif
  68. #define INTERFACEVERSION_VENGINESERVER_VERSION_21 "VEngineServer021"
  69. #define INTERFACEVERSION_VENGINESERVER_VERSION_22 "VEngineServer022"
  70. #define INTERFACEVERSION_VENGINESERVER "VEngineServer023"
  71. #define INTERFACEVERSION_VENGINESERVER_INT 23
  72. struct bbox_t
  73. {
  74. Vector mins;
  75. Vector maxs;
  76. };
  77. //-----------------------------------------------------------------------------
  78. // Purpose: Interface the engine exposes to the game DLL
  79. //-----------------------------------------------------------------------------
  80. abstract_class IVEngineServer
  81. {
  82. public:
  83. // Tell engine to change level ( "changelevel s1\n" or "changelevel2 s1 s2\n" )
  84. virtual void ChangeLevel( const char *s1, const char *s2 ) = 0;
  85. // Ask engine whether the specified map is a valid map file (exists and has valid version number).
  86. virtual int IsMapValid( const char *filename ) = 0;
  87. // Is this a dedicated server?
  88. virtual bool IsDedicatedServer( void ) = 0;
  89. // Is in Hammer editing mode?
  90. virtual int IsInEditMode( void ) = 0;
  91. // Add to the server/client lookup/precache table, the specified string is given a unique index
  92. // NOTE: The indices for PrecacheModel are 1 based
  93. // a 0 returned from those methods indicates the model or sound was not correctly precached
  94. // However, generic and decal are 0 based
  95. // If preload is specified, the file is loaded into the server/client's cache memory before level startup, otherwise
  96. // it'll only load when actually used (which can cause a disk i/o hitch if it occurs during play of a level).
  97. virtual int PrecacheModel( const char *s, bool preload = false ) = 0;
  98. virtual int PrecacheSentenceFile( const char *s, bool preload = false ) = 0;
  99. virtual int PrecacheDecal( const char *name, bool preload = false ) = 0;
  100. virtual int PrecacheGeneric( const char *s, bool preload = false ) = 0;
  101. // Check's if the name is precached, but doesn't actually precache the name if not...
  102. virtual bool IsModelPrecached( char const *s ) const = 0;
  103. virtual bool IsDecalPrecached( char const *s ) const = 0;
  104. virtual bool IsGenericPrecached( char const *s ) const = 0;
  105. // Note that sounds are precached using the IEngineSound interface
  106. // Special purpose PVS checking
  107. // Get the cluster # for the specified position
  108. virtual int GetClusterForOrigin( const Vector &org ) = 0;
  109. // Get the PVS bits for a specified cluster and copy the bits into outputpvs. Returns the number of bytes needed to pack the PVS
  110. virtual int GetPVSForCluster( int cluster, int outputpvslength, unsigned char *outputpvs ) = 0;
  111. // Check whether the specified origin is inside the specified PVS
  112. virtual bool CheckOriginInPVS( const Vector &org, const unsigned char *checkpvs, int checkpvssize ) = 0;
  113. // Check whether the specified worldspace bounding box is inside the specified PVS
  114. virtual bool CheckBoxInPVS( const Vector &mins, const Vector &maxs, const unsigned char *checkpvs, int checkpvssize ) = 0;
  115. // Returns the server assigned userid for this player. Useful for logging frags, etc.
  116. // returns -1 if the edict couldn't be found in the list of players.
  117. virtual int GetPlayerUserId( const edict_t *e ) = 0;
  118. virtual const char *GetPlayerNetworkIDString( const edict_t *e ) = 0;
  119. // Return the current number of used edict slots
  120. virtual int GetEntityCount( void ) = 0;
  121. // Given an edict, returns the entity index
  122. virtual int IndexOfEdict( const edict_t *pEdict ) = 0;
  123. // Given and entity index, returns the corresponding edict pointer
  124. virtual edict_t *PEntityOfEntIndex( int iEntIndex ) = 0;
  125. // Get stats info interface for a client netchannel
  126. virtual INetChannelInfo* GetPlayerNetInfo( int playerIndex ) = 0;
  127. // Allocate space for string and return index/offset of string in global string list
  128. // If iForceEdictIndex is not -1, then it will return the edict with that index. If that edict index
  129. // is already used, it'll return null.
  130. virtual edict_t *CreateEdict( int iForceEdictIndex = -1 ) = 0;
  131. // Remove the specified edict and place back into the free edict list
  132. virtual void RemoveEdict( edict_t *e ) = 0;
  133. // Memory allocation for entity class data
  134. virtual void *PvAllocEntPrivateData( long cb ) = 0;
  135. virtual void FreeEntPrivateData( void *pEntity ) = 0;
  136. // Save/restore uses a special memory allocator (which zeroes newly allocated memory, etc.)
  137. virtual void *SaveAllocMemory( size_t num, size_t size ) = 0;
  138. virtual void SaveFreeMemory( void *pSaveMem ) = 0;
  139. // Emit an ambient sound associated with the specified entity
  140. virtual void EmitAmbientSound( int entindex, const Vector &pos, const char *samp, float vol, soundlevel_t soundlevel, int fFlags, int pitch, float delay = 0.0f ) = 0;
  141. // Fade out the client's volume level toward silence (or fadePercent)
  142. virtual void FadeClientVolume( const edict_t *pEdict, float fadePercent, float fadeOutSeconds, float holdTime, float fadeInSeconds ) = 0;
  143. // Sentences / sentence groups
  144. virtual int SentenceGroupPick( int groupIndex, char *name, int nameBufLen ) = 0;
  145. virtual int SentenceGroupPickSequential( int groupIndex, char *name, int nameBufLen, int sentenceIndex, int reset ) = 0;
  146. virtual int SentenceIndexFromName( const char *pSentenceName ) = 0;
  147. virtual const char *SentenceNameFromIndex( int sentenceIndex ) = 0;
  148. virtual int SentenceGroupIndexFromName( const char *pGroupName ) = 0;
  149. virtual const char *SentenceGroupNameFromIndex( int groupIndex ) = 0;
  150. virtual float SentenceLength( int sentenceIndex ) = 0;
  151. // Issue a command to the command parser as if it was typed at the server console.
  152. virtual void ServerCommand( const char *str ) = 0;
  153. // Execute any commands currently in the command parser immediately (instead of once per frame)
  154. virtual void ServerExecute( void ) = 0;
  155. // Issue the specified command to the specified client (mimics that client typing the command at the console).
  156. virtual void ClientCommand( edict_t *pEdict, PRINTF_FORMAT_STRING const char *szFmt, ... ) = 0;
  157. // Set the lightstyle to the specified value and network the change to any connected clients. Note that val must not
  158. // change place in memory (use MAKE_STRING) for anything that's not compiled into your mod.
  159. virtual void LightStyle( int style, const char *val ) = 0;
  160. // Project a static decal onto the specified entity / model (for level placed decals in the .bsp)
  161. virtual void StaticDecal( const Vector &originInEntitySpace, int decalIndex, int entityIndex, int modelIndex, bool lowpriority ) = 0;
  162. // Given the current PVS(or PAS) and origin, determine which players should hear/receive the message
  163. virtual void Message_DetermineMulticastRecipients( bool usepas, const Vector& origin, CBitVec< ABSOLUTE_PLAYER_LIMIT >& playerbits ) = 0;
  164. // Begin a message from a server side entity to its client side counterpart (func_breakable glass, e.g.)
  165. virtual bf_write *EntityMessageBegin( int ent_index, ServerClass * ent_class, bool reliable ) = 0;
  166. // Begin a usermessage from the server to the client .dll
  167. virtual bf_write *UserMessageBegin( IRecipientFilter *filter, int msg_type ) = 0;
  168. // Finish the Entity or UserMessage and dispatch to network layer
  169. virtual void MessageEnd( void ) = 0;
  170. // Print szMsg to the client console.
  171. virtual void ClientPrintf( edict_t *pEdict, const char *szMsg ) = 0;
  172. // SINGLE PLAYER/LISTEN SERVER ONLY (just matching the client .dll api for this)
  173. // Prints the formatted string to the notification area of the screen ( down the right hand edge
  174. // numbered lines starting at position 0
  175. virtual void Con_NPrintf( int pos, PRINTF_FORMAT_STRING const char *fmt, ... ) = 0;
  176. // SINGLE PLAYER/LISTEN SERVER ONLY(just matching the client .dll api for this)
  177. // Similar to Con_NPrintf, but allows specifying custom text color and duration information
  178. virtual void Con_NXPrintf( const struct con_nprint_s *info, PRINTF_FORMAT_STRING const char *fmt, ... ) = 0;
  179. // Change a specified player's "view entity" (i.e., use the view entity position/orientation for rendering the client view)
  180. virtual void SetView( const edict_t *pClient, const edict_t *pViewent ) = 0;
  181. // Get a high precision timer for doing profiling work
  182. virtual float Time( void ) = 0;
  183. // Set the player's crosshair angle
  184. virtual void CrosshairAngle( const edict_t *pClient, float pitch, float yaw ) = 0;
  185. // Get the current game directory (hl2, tf2, hl1, cstrike, etc.)
  186. virtual void GetGameDir( char *szGetGameDir, int maxlength ) = 0;
  187. // Used by AI node graph code to determine if .bsp and .ain files are out of date
  188. virtual int CompareFileTime( const char *filename1, const char *filename2, int *iCompare ) = 0;
  189. // Locks/unlocks the network string tables (.e.g, when adding bots to server, this needs to happen).
  190. // Be sure to reset the lock after executing your code!!!
  191. virtual bool LockNetworkStringTables( bool lock ) = 0;
  192. // Create a bot with the given name. Returns NULL if fake client can't be created
  193. virtual edict_t *CreateFakeClient( const char *netname ) = 0;
  194. // Get a convar keyvalue for s specified client
  195. virtual const char *GetClientConVarValue( int clientIndex, const char *name ) = 0;
  196. // Parse a token from a file
  197. virtual const char *ParseFile( const char *data, char *token, int maxlen ) = 0;
  198. // Copies a file
  199. virtual bool CopyFile( const char *source, const char *destination ) = 0;
  200. // Reset the pvs, pvssize is the size in bytes of the buffer pointed to by pvs.
  201. // This should be called right before any calls to AddOriginToPVS
  202. virtual void ResetPVS( byte *pvs, int pvssize ) = 0;
  203. // Merge the pvs bits into the current accumulated pvs based on the specified origin ( not that each pvs origin has an 8 world unit fudge factor )
  204. virtual void AddOriginToPVS( const Vector &origin ) = 0;
  205. // Mark a specified area portal as open/closed.
  206. // Use SetAreaPortalStates if you want to set a bunch of them at a time.
  207. virtual void SetAreaPortalState( int portalNumber, int isOpen ) = 0;
  208. // Queue a temp entity for transmission
  209. virtual void PlaybackTempEntity( IRecipientFilter& filter, float delay, const void *pSender, const SendTable *pST, int classID ) = 0;
  210. // Given a node number and the specified PVS, return with the node is in the PVS
  211. virtual int CheckHeadnodeVisible( int nodenum, const byte *pvs, int vissize ) = 0;
  212. // Using area bits, cheeck whether area1 flows into area2 and vice versa (depends on area portal state)
  213. virtual int CheckAreasConnected( int area1, int area2 ) = 0;
  214. // Given an origin, determine which area index the origin is within
  215. virtual int GetArea( const Vector &origin ) = 0;
  216. // Get area portal bit set
  217. virtual void GetAreaBits( int area, unsigned char *bits, int buflen ) = 0;
  218. // Given a view origin (which tells us the area to start looking in) and a portal key,
  219. // fill in the plane that leads out of this area (it points into whatever area it leads to).
  220. virtual bool GetAreaPortalPlane( Vector const &vViewOrigin, int portalKey, VPlane *pPlane ) = 0;
  221. // Save/restore wrapper - FIXME: At some point we should move this to it's own interface
  222. virtual bool LoadGameState( char const *pMapName, bool createPlayers ) = 0;
  223. virtual void LoadAdjacentEnts( const char *pOldLevel, const char *pLandmarkName ) = 0;
  224. virtual void ClearSaveDir() = 0;
  225. // Get the pristine map entity lump string. (e.g., used by CS to reload the map entities when restarting a round.)
  226. virtual const char* GetMapEntitiesString() = 0;
  227. // Text message system -- lookup the text message of the specified name
  228. virtual client_textmessage_t *TextMessageGet( const char *pName ) = 0;
  229. // Print a message to the server log file
  230. virtual void LogPrint( const char *msg ) = 0;
  231. // Builds PVS information for an entity
  232. virtual void BuildEntityClusterList( edict_t *pEdict, PVSInfo_t *pPVSInfo ) = 0;
  233. // A solid entity moved, update spatial partition
  234. virtual void SolidMoved( edict_t *pSolidEnt, ICollideable *pSolidCollide, const Vector* pPrevAbsOrigin, bool testSurroundingBoundsOnly ) = 0;
  235. // A trigger entity moved, update spatial partition
  236. virtual void TriggerMoved( edict_t *pTriggerEnt, bool testSurroundingBoundsOnly ) = 0;
  237. // Create/destroy a custom spatial partition
  238. virtual ISpatialPartition *CreateSpatialPartition( const Vector& worldmin, const Vector& worldmax ) = 0;
  239. virtual void DestroySpatialPartition( ISpatialPartition * ) = 0;
  240. // Draw the brush geometry in the map into the scratch pad.
  241. // Flags is currently unused.
  242. virtual void DrawMapToScratchPad( IScratchPad3D *pPad, unsigned long iFlags ) = 0;
  243. // This returns which entities, to the best of the server's knowledge, the client currently knows about.
  244. // This is really which entities were in the snapshot that this client last acked.
  245. // This returns a bit vector with one bit for each entity.
  246. //
  247. // USE WITH CARE. Whatever tick the client is really currently on is subject to timing and
  248. // ordering differences, so you should account for about a quarter-second discrepancy in here.
  249. // Also, this will return NULL if the client doesn't exist or if this client hasn't acked any frames yet.
  250. //
  251. // iClientIndex is the CLIENT index, so if you use pPlayer->entindex(), subtract 1.
  252. virtual const CBitVec<MAX_EDICTS>* GetEntityTransmitBitsForClient( int iClientIndex ) = 0;
  253. // Is the game paused?
  254. virtual bool IsPaused() = 0;
  255. // Marks the filename for consistency checking. This should be called after precaching the file.
  256. virtual void ForceExactFile( const char *s ) = 0;
  257. virtual void ForceModelBounds( const char *s, const Vector &mins, const Vector &maxs ) = 0;
  258. virtual void ClearSaveDirAfterClientLoad() = 0;
  259. // Sets a USERINFO client ConVar for a fakeclient
  260. virtual void SetFakeClientConVarValue( edict_t *pEntity, const char *cvar, const char *value ) = 0;
  261. // Marks the material (vmt file) for consistency checking. If the client and server have different
  262. // contents for the file, the client's vmt can only use the VertexLitGeneric shader, and can only
  263. // contain $baseTexture and $bumpmap vars.
  264. virtual void ForceSimpleMaterial( const char *s ) = 0;
  265. // Is the engine in Commentary mode?
  266. virtual int IsInCommentaryMode( void ) = 0;
  267. // Mark some area portals as open/closed. It's more efficient to use this
  268. // than a bunch of individual SetAreaPortalState calls.
  269. virtual void SetAreaPortalStates( const int *portalNumbers, const int *isOpen, int nPortals ) = 0;
  270. // Called when relevant edict state flags change.
  271. virtual void NotifyEdictFlagsChange( int iEdict ) = 0;
  272. // Only valid during CheckTransmit. Also, only the PVS, networked areas, and
  273. // m_pTransmitInfo are valid in the returned strucutre.
  274. virtual const CCheckTransmitInfo* GetPrevCheckTransmitInfo( edict_t *pPlayerEdict ) = 0;
  275. virtual CSharedEdictChangeInfo* GetSharedEdictChangeInfo() = 0;
  276. // Tells the engine we can immdiately re-use all edict indices
  277. // even though we may not have waited enough time
  278. virtual void AllowImmediateEdictReuse( ) = 0;
  279. // Returns true if the engine is an internal build. i.e. is using the internal bugreporter.
  280. virtual bool IsInternalBuild( void ) = 0;
  281. virtual IChangeInfoAccessor *GetChangeAccessor( const edict_t *pEdict ) = 0;
  282. // Name of most recently load .sav file
  283. virtual char const *GetMostRecentlyLoadedFileName() = 0;
  284. virtual char const *GetSaveFileName() = 0;
  285. // Matchmaking
  286. virtual void MultiplayerEndGame() = 0;
  287. virtual void ChangeTeam( const char *pTeamName ) = 0;
  288. // Cleans up the cluster list
  289. virtual void CleanUpEntityClusterList( PVSInfo_t *pPVSInfo ) = 0;
  290. virtual void SetAchievementMgr( IAchievementMgr *pAchievementMgr ) =0;
  291. virtual IAchievementMgr *GetAchievementMgr() = 0;
  292. virtual int GetAppID() = 0;
  293. virtual bool IsLowViolence() = 0;
  294. // Call this to find out the value of a cvar on the client.
  295. //
  296. // It is an asynchronous query, and it will call IServerGameDLL::OnQueryCvarValueFinished when
  297. // the value comes in from the client.
  298. //
  299. // Store the return value if you want to match this specific query to the OnQueryCvarValueFinished call.
  300. // Returns InvalidQueryCvarCookie if the entity is invalid.
  301. virtual QueryCvarCookie_t StartQueryCvarValue( edict_t *pPlayerEntity, const char *pName ) = 0;
  302. virtual void InsertServerCommand( const char *str ) = 0;
  303. // Fill in the player info structure for the specified player index (name, model, etc.)
  304. virtual bool GetPlayerInfo( int ent_num, player_info_t *pinfo ) = 0;
  305. // Returns true if this client has been fully authenticated by Steam
  306. virtual bool IsClientFullyAuthenticated( edict_t *pEdict ) = 0;
  307. // This makes the host run 1 tick per frame instead of checking the system timer to see how many ticks to run in a certain frame.
  308. // i.e. it does the same thing timedemo does.
  309. virtual void SetDedicatedServerBenchmarkMode( bool bBenchmarkMode ) = 0;
  310. // Methods to set/get a gamestats data container so client & server running in same process can send combined data
  311. virtual void SetGamestatsData( CGamestatsData *pGamestatsData ) = 0;
  312. virtual CGamestatsData *GetGamestatsData() = 0;
  313. // Returns the SteamID of the specified player. It'll be NULL if the player hasn't authenticated yet.
  314. virtual const CSteamID *GetClientSteamID( edict_t *pPlayerEdict ) = 0;
  315. // Returns the SteamID of the game server
  316. virtual const CSteamID *GetGameServerSteamID() = 0;
  317. // Send a client command keyvalues
  318. // keyvalues are deleted inside the function
  319. virtual void ClientCommandKeyValues( edict_t *pEdict, KeyValues *pCommand ) = 0;
  320. // Returns the SteamID of the specified player. It'll be NULL if the player hasn't authenticated yet.
  321. virtual const CSteamID *GetClientSteamIDByPlayerIndex( int entnum ) = 0;
  322. // Gets a list of all clusters' bounds. Returns total number of clusters.
  323. virtual int GetClusterCount() = 0;
  324. virtual int GetAllClusterBounds( bbox_t *pBBoxList, int maxBBox ) = 0;
  325. // Create a bot with the given name. Returns NULL if fake client can't be created
  326. virtual edict_t *CreateFakeClientEx( const char *netname, bool bReportFakeClient = true ) = 0;
  327. // Server version from the steam.inf, this will be compared to the GC version
  328. virtual int GetServerVersion() const = 0;
  329. // Get sv.GetTime()
  330. virtual float GetServerTime() const = 0;
  331. // Exposed for server plugin authors
  332. virtual IServer *GetIServer() = 0;
  333. virtual bool IsPlayerNameLocked( const edict_t *pEdict ) = 0;
  334. virtual bool CanPlayerChangeName( const edict_t *pEdict ) = 0;
  335. // Find the canonical name of a map, given a partial or non-canonical map name.
  336. // Except in the case of an exact match, pMapName is updated to the canonical name of the match.
  337. // NOTE That this is subject to the same limitation as ServerGameDLL::CanProvideLevel -- This is non-blocking, so it
  338. // is possible that blocking ServerGameDLL::PrepareLevelResources call may be able to pull a better match than
  339. // is immediately available to this call (e.g. blocking lookups of cloud maps)
  340. enum eFindMapResult {
  341. // A direct match for this name was found
  342. eFindMap_Found,
  343. // No match for this map name could be found.
  344. eFindMap_NotFound,
  345. // A fuzzy match for this mapname was found and pMapName was updated to the full name.
  346. // Ex: cp_dust -> cp_dustbowl
  347. eFindMap_FuzzyMatch,
  348. // A match for this map name was found, and the map name was updated to the canonical version of the
  349. // name.
  350. // Ex: workshop/1234 -> workshop/cp_qualified_name.ugc1234
  351. eFindMap_NonCanonical,
  352. // No currently available match for this map name could be found, but it may be possible to load ( see caveat
  353. // about PrepareLevelResources above )
  354. eFindMap_PossiblyAvailable
  355. };
  356. virtual eFindMapResult FindMap( /* in/out */ char *pMapName, int nMapNameMax ) = 0;
  357. virtual void SetPausedForced( bool bPaused, float flDuration = -1.f ) = 0;
  358. };
  359. // These only differ in new items added to the end
  360. typedef IVEngineServer IVEngineServer021;
  361. typedef IVEngineServer IVEngineServer022;
  362. #define INTERFACEVERSION_SERVERGAMEDLL_VERSION_8 "ServerGameDLL008"
  363. #define INTERFACEVERSION_SERVERGAMEDLL_VERSION_9 "ServerGameDLL009"
  364. #define INTERFACEVERSION_SERVERGAMEDLL "ServerGameDLL010"
  365. #define INTERFACEVERSION_SERVERGAMEDLL_INT 10
  366. class IServerGCLobby;
  367. //-----------------------------------------------------------------------------
  368. // Purpose: These are the interfaces that the game .dll exposes to the engine
  369. //-----------------------------------------------------------------------------
  370. abstract_class IServerGameDLL
  371. {
  372. public:
  373. // Initialize the game (one-time call when the DLL is first loaded )
  374. // Return false if there is an error during startup.
  375. virtual bool DLLInit( CreateInterfaceFn engineFactory,
  376. CreateInterfaceFn physicsFactory,
  377. CreateInterfaceFn fileSystemFactory,
  378. CGlobalVars *pGlobals) = 0;
  379. // Setup replay interfaces on the server
  380. virtual bool ReplayInit( CreateInterfaceFn fnReplayFactory ) = 0;
  381. // This is called when a new game is started. (restart, map)
  382. virtual bool GameInit( void ) = 0;
  383. // Called any time a new level is started (after GameInit() also on level transitions within a game)
  384. virtual bool LevelInit( char const *pMapName,
  385. char const *pMapEntities, char const *pOldLevel,
  386. char const *pLandmarkName, bool loadGame, bool background ) = 0;
  387. // The server is about to activate
  388. virtual void ServerActivate( edict_t *pEdictList, int edictCount, int clientMax ) = 0;
  389. // The server should run physics/think on all edicts
  390. virtual void GameFrame( bool simulating ) = 0;
  391. // Called once per simulation frame on the final tick
  392. virtual void PreClientUpdate( bool simulating ) = 0;
  393. // Called when a level is shutdown (including changing levels)
  394. virtual void LevelShutdown( void ) = 0;
  395. // This is called when a game ends (server disconnect, death, restart, load)
  396. // NOT on level transitions within a game
  397. virtual void GameShutdown( void ) = 0;
  398. // Called once during DLL shutdown
  399. virtual void DLLShutdown( void ) = 0;
  400. // Get the simulation interval (must be compiled with identical values into both client and game .dll for MOD!!!)
  401. // Right now this is only requested at server startup time so it can't be changed on the fly, etc.
  402. virtual float GetTickInterval( void ) const = 0;
  403. // Give the list of datatable classes to the engine. The engine matches class names from here with
  404. // edict_t::classname to figure out how to encode a class's data for networking
  405. virtual ServerClass* GetAllServerClasses( void ) = 0;
  406. // Returns string describing current .dll. e.g., TeamFortress 2, Half-Life 2.
  407. // Hey, it's more descriptive than just the name of the game directory
  408. virtual const char *GetGameDescription( void ) = 0;
  409. // Let the game .dll allocate it's own network/shared string tables
  410. virtual void CreateNetworkStringTables( void ) = 0;
  411. // Save/restore system hooks
  412. virtual CSaveRestoreData *SaveInit( int size ) = 0;
  413. virtual void SaveWriteFields( CSaveRestoreData *, const char *, void *, datamap_t *, typedescription_t *, int ) = 0;
  414. virtual void SaveReadFields( CSaveRestoreData *, const char *, void *, datamap_t *, typedescription_t *, int ) = 0;
  415. virtual void SaveGlobalState( CSaveRestoreData * ) = 0;
  416. virtual void RestoreGlobalState( CSaveRestoreData * ) = 0;
  417. virtual void PreSave( CSaveRestoreData * ) = 0;
  418. virtual void Save( CSaveRestoreData * ) = 0;
  419. virtual void GetSaveComment( char *comment, int maxlength, float flMinutes, float flSeconds, bool bNoTime = false ) = 0;
  420. virtual void WriteSaveHeaders( CSaveRestoreData * ) = 0;
  421. virtual void ReadRestoreHeaders( CSaveRestoreData * ) = 0;
  422. virtual void Restore( CSaveRestoreData *, bool ) = 0;
  423. virtual bool IsRestoring() = 0;
  424. // Returns the number of entities moved across the transition
  425. virtual int CreateEntityTransitionList( CSaveRestoreData *, int ) = 0;
  426. // Build the list of maps adjacent to the current map
  427. virtual void BuildAdjacentMapList( void ) = 0;
  428. // Retrieve info needed for parsing the specified user message
  429. virtual bool GetUserMessageInfo( int msg_type, char *name, int maxnamelength, int& size ) = 0;
  430. // Hand over the StandardSendProxies in the game DLL's module.
  431. virtual CStandardSendProxies* GetStandardSendProxies() = 0;
  432. // Called once during startup, after the game .dll has been loaded and after the client .dll has also been loaded
  433. virtual void PostInit() = 0;
  434. // Called once per frame even when no level is loaded...
  435. virtual void Think( bool finalTick ) = 0;
  436. #ifdef _XBOX
  437. virtual void GetTitleName( const char *pMapName, char* pTitleBuff, int titleBuffSize ) = 0;
  438. #endif
  439. virtual void PreSaveGameLoaded( char const *pSaveName, bool bCurrentlyInGame ) = 0;
  440. // Returns true if the game DLL wants the server not to be made public.
  441. // Used by commentary system to hide multiplayer commentary servers from the master.
  442. virtual bool ShouldHideServer( void ) = 0;
  443. virtual void InvalidateMdlCache() = 0;
  444. // * This function is new with version 6 of the interface.
  445. //
  446. // This is called when a query from IServerPluginHelpers::StartQueryCvarValue is finished.
  447. // iCookie is the value returned by IServerPluginHelpers::StartQueryCvarValue.
  448. // Added with version 2 of the interface.
  449. virtual void OnQueryCvarValueFinished( QueryCvarCookie_t iCookie, edict_t *pPlayerEntity, EQueryCvarValueStatus eStatus, const char *pCvarName, const char *pCvarValue ) = 0;
  450. // Called after the steam API has been activated post-level startup
  451. virtual void GameServerSteamAPIActivated( void ) = 0;
  452. // Called after the steam API has been shutdown post-level startup
  453. virtual void GameServerSteamAPIShutdown( void ) = 0;
  454. virtual void SetServerHibernation( bool bHibernating ) = 0;
  455. // interface to the new GC based lobby system
  456. virtual IServerGCLobby *GetServerGCLobby() = 0;
  457. // Return override string to show in the server browser
  458. // "map" column, or NULL to just use the default value
  459. // (the map name)
  460. virtual const char *GetServerBrowserMapOverride() = 0;
  461. // Get gamedata string to send to the master serer updater.
  462. virtual const char *GetServerBrowserGameData() = 0;
  463. // Called to add output to the status command
  464. virtual void Status( void (*print) (const char *fmt, ...) ) = 0;
  465. // Informs the game we would like to load this level, giving it a chance to prepare dynamic resources.
  466. //
  467. // - pszMapName is the name of the map we're looking for, and may be overridden to e.g. the canonical name of the
  468. // map.
  469. //
  470. // - pszMapFile is the file we intend to use for this map ( e.g. maps/<mapname>.bsp ), and may be overridden to the
  471. // file representing this map name. ( e.g. /path/to/steamapps/workshop/cp_mymap.ugc12345.bsp )
  472. //
  473. // This call is blocking, and may block for extended periods. See AsyncPrepareLevelResources below.
  474. virtual void PrepareLevelResources( /* in/out */ char *pszMapName, size_t nMapNameSize,
  475. /* in/out */ char *pszMapFile, size_t nMapFileSize ) = 0;
  476. // Asynchronous version of PrepareLevelResources. Returns preparation status of map when called.
  477. // If passed, flProgress is filled with the current progress percentage [ 0.f to 1.f ] for the InProgress
  478. // result
  479. enum ePrepareLevelResourcesResult
  480. {
  481. // Good to go
  482. ePrepareLevelResources_Prepared,
  483. // Game DLL is async preparing (e.g. streaming resources). flProgress will be filled if passed.
  484. ePrepareLevelResources_InProgress
  485. };
  486. virtual ePrepareLevelResourcesResult AsyncPrepareLevelResources( /* in/out */ char *pszMapName, size_t nMapNameSize,
  487. /* in/out */ char *pszMapFile, size_t nMapFileSize,
  488. float *flProgress = NULL ) = 0;
  489. // Ask the game DLL to evaluate what it would do with this map name were it passed to PrepareLevelResources.
  490. // NOTE That this is this is syncronous and non-blocking, so it is possible that async PrepareLevelResources call
  491. // may be able to pull a better match than is immediately available to this call (e.g. blocking lookups of
  492. // cloud maps)
  493. enum eCanProvideLevelResult {
  494. // Have no knowledge of this level name, it will be up to the engine to provide. (e.g. as maps/levelname.bsp)
  495. eCanProvideLevel_CannotProvide,
  496. // Can provide resources for this level, and pMapName has been updated to the canonical name we would provide it
  497. // under (as with PrepareLevelResources)
  498. eCanProvideLevel_CanProvide,
  499. // We recognize this level name as something we might be able to prepare, but without a blocking/async call to
  500. // PrepareLevelResources, it is not possible to say whether it is available.
  501. eCanProvideLevel_Possibly
  502. };
  503. virtual eCanProvideLevelResult CanProvideLevel( /* in/out */ char *pMapName, int nMapNameMax ) = 0;
  504. // Called to see if the game server is okay with a manual changelevel or map command
  505. virtual bool IsManualMapChangeOkay( const char **pszReason ) = 0;
  506. };
  507. typedef IServerGameDLL IServerGameDLL008;
  508. //-----------------------------------------------------------------------------
  509. // Just an interface version name for the random number interface
  510. // See vstdlib/random.h for the interface definition
  511. // NOTE: If you change this, also change VENGINE_CLIENT_RANDOM_INTERFACE_VERSION in cdll_int.h
  512. //-----------------------------------------------------------------------------
  513. #define VENGINE_SERVER_RANDOM_INTERFACE_VERSION "VEngineRandom001"
  514. #define INTERFACEVERSION_SERVERGAMEENTS "ServerGameEnts001"
  515. //-----------------------------------------------------------------------------
  516. // Purpose: Interface to get at server entities
  517. //-----------------------------------------------------------------------------
  518. abstract_class IServerGameEnts
  519. {
  520. public:
  521. virtual ~IServerGameEnts() {}
  522. // Only for debugging. Set the edict base so you can get an edict's index in the debugger while debugging the game .dll
  523. virtual void SetDebugEdictBase(edict_t *base) = 0;
  524. // The engine wants to mark two entities as touching
  525. virtual void MarkEntitiesAsTouching( edict_t *e1, edict_t *e2 ) = 0;
  526. // Frees the entity attached to this edict
  527. virtual void FreeContainingEntity( edict_t * ) = 0;
  528. // This allows the engine to get at edicts in a CGameTrace.
  529. virtual edict_t* BaseEntityToEdict( CBaseEntity *pEnt ) = 0;
  530. virtual CBaseEntity* EdictToBaseEntity( edict_t *pEdict ) = 0;
  531. // This sets a bit in pInfo for each edict in the list that wants to be transmitted to the
  532. // client specified in pInfo.
  533. //
  534. // This is also where an entity can force other entities to be transmitted if it refers to them
  535. // with ehandles.
  536. virtual void CheckTransmit( CCheckTransmitInfo *pInfo, const unsigned short *pEdictIndices, int nEdicts ) = 0;
  537. };
  538. #define INTERFACEVERSION_SERVERGAMECLIENTS_VERSION_3 "ServerGameClients003"
  539. #define INTERFACEVERSION_SERVERGAMECLIENTS "ServerGameClients004"
  540. //-----------------------------------------------------------------------------
  541. // Purpose: Player / Client related functions
  542. //-----------------------------------------------------------------------------
  543. abstract_class IServerGameClients
  544. {
  545. public:
  546. // Get server maxplayers and lower bound for same
  547. virtual void GetPlayerLimits( int& minplayers, int& maxplayers, int &defaultMaxPlayers ) const = 0;
  548. // Client is connecting to server ( return false to reject the connection )
  549. // You can specify a rejection message by writing it into reject
  550. virtual bool ClientConnect( edict_t *pEntity, const char *pszName, const char *pszAddress, char *reject, int maxrejectlen ) = 0;
  551. // Client is going active
  552. // If bLoadGame is true, don't spawn the player because its state is already setup.
  553. virtual void ClientActive( edict_t *pEntity, bool bLoadGame ) = 0;
  554. // Client is disconnecting from server
  555. virtual void ClientDisconnect( edict_t *pEntity ) = 0;
  556. // Client is connected and should be put in the game
  557. virtual void ClientPutInServer( edict_t *pEntity, char const *playername ) = 0;
  558. // The client has typed a command at the console
  559. virtual void ClientCommand( edict_t *pEntity, const CCommand &args ) = 0;
  560. // Sets the client index for the client who typed the command into his/her console
  561. virtual void SetCommandClient( int index ) = 0;
  562. // A player changed one/several replicated cvars (name etc)
  563. virtual void ClientSettingsChanged( edict_t *pEdict ) = 0;
  564. // Determine PVS origin and set PVS for the player/viewentity
  565. virtual void ClientSetupVisibility( edict_t *pViewEntity, edict_t *pClient, unsigned char *pvs, int pvssize ) = 0;
  566. // A block of CUserCmds has arrived from the user, decode them and buffer for execution during player simulation
  567. virtual float ProcessUsercmds( edict_t *player, bf_read *buf, int numcmds, int totalcmds,
  568. int dropped_packets, bool ignore, bool paused ) = 0;
  569. // Let the game .dll do stuff after messages have been sent to all of the clients once the server frame is complete
  570. virtual void PostClientMessagesSent_DEPRECIATED( void ) = 0;
  571. // For players, looks up the CPlayerState structure corresponding to the player
  572. virtual CPlayerState *GetPlayerState( edict_t *player ) = 0;
  573. // Get the ear position for a specified client
  574. virtual void ClientEarPosition( edict_t *pEntity, Vector *pEarOrigin ) = 0;
  575. // returns number of delay ticks if player is in Replay mode (0 = no delay)
  576. virtual int GetReplayDelay( edict_t *player, int& entity ) = 0;
  577. // Anything this game .dll wants to add to the bug reporter text (e.g., the entity/model under the picker crosshair)
  578. // can be added here
  579. virtual void GetBugReportInfo( char *buf, int buflen ) = 0;
  580. // A user has had their network id setup and validated
  581. virtual void NetworkIDValidated( const char *pszUserName, const char *pszNetworkID ) = 0;
  582. // The client has submitted a keyvalues command
  583. virtual void ClientCommandKeyValues( edict_t *pEntity, KeyValues *pKeyValues ) = 0;
  584. // Hook for player spawning
  585. virtual void ClientSpawned( edict_t *pPlayer ) = 0;
  586. };
  587. typedef IServerGameClients IServerGameClients003;
  588. #define INTERFACEVERSION_UPLOADGAMESTATS "ServerUploadGameStats001"
  589. abstract_class IUploadGameStats
  590. {
  591. public:
  592. // Note that this call will block the server until the upload is completed, so use only at levelshutdown if at all.
  593. virtual bool UploadGameStats(
  594. char const *mapname, // Game map name
  595. unsigned int blobversion, // Version of the binary blob data
  596. unsigned int blobsize, // Size in bytes of blob data
  597. const void *pvBlobData ) = 0; // Pointer to the blob data.
  598. // Call when created to init the CSER connection
  599. virtual void InitConnection( void ) = 0;
  600. // Call periodically to poll steam for a CSER connection
  601. virtual void UpdateConnection( void ) = 0;
  602. // If user has disabled stats tracking, do nothing
  603. virtual bool IsGameStatsLoggingEnabled() = 0;
  604. // Gets a non-personally identifiable unique ID for this steam user, used for tracking total gameplay time across
  605. // multiple stats sessions, but isn't trackable back to their Steam account or id.
  606. // Buffer should be 16 bytes, ID will come back as a hexadecimal string version of a GUID
  607. virtual void GetPseudoUniqueId( char *buf, size_t bufsize ) = 0;
  608. // For determining general % of users running using cyber cafe accounts...
  609. virtual bool IsCyberCafeUser( void ) = 0;
  610. // Only works in single player
  611. virtual bool IsHDREnabled( void ) = 0;
  612. };
  613. #define INTERFACEVERSION_PLUGINHELPERSCHECK "PluginHelpersCheck001"
  614. //-----------------------------------------------------------------------------
  615. // Purpose: allows the game dll to control which plugin functions can be run
  616. //-----------------------------------------------------------------------------
  617. abstract_class IPluginHelpersCheck
  618. {
  619. public:
  620. virtual bool CreateMessage( const char *plugin, edict_t *pEntity, DIALOG_TYPE type, KeyValues *data ) = 0;
  621. };
  622. //-----------------------------------------------------------------------------
  623. // Purpose: Interface exposed from the client .dll back to the engine for specifying shared .dll IAppSystems (e.g., ISoundEmitterSystem)
  624. //-----------------------------------------------------------------------------
  625. abstract_class IServerDLLSharedAppSystems
  626. {
  627. public:
  628. virtual int Count() = 0;
  629. virtual char const *GetDllName( int idx ) = 0;
  630. virtual char const *GetInterfaceName( int idx ) = 0;
  631. };
  632. #define SERVER_DLL_SHARED_APPSYSTEMS "VServerDllSharedAppSystems001"
  633. #define INTERFACEVERSION_SERVERGAMETAGS "ServerGameTags001"
  634. //-----------------------------------------------------------------------------
  635. // Purpose: querying the game dll for Server cvar tags
  636. //-----------------------------------------------------------------------------
  637. abstract_class IServerGameTags
  638. {
  639. public:
  640. // Get the list of cvars that require tags to show differently in the server browser
  641. virtual void GetTaggedConVarList( KeyValues *pCvarTagList ) = 0;
  642. };
  643. //-----------------------------------------------------------------------------
  644. // Purpose: Provide hooks for the GC based lobby system
  645. //-----------------------------------------------------------------------------
  646. abstract_class IServerGCLobby
  647. {
  648. public:
  649. virtual bool HasLobby() const = 0;
  650. virtual bool SteamIDAllowedToConnect( const CSteamID &steamId ) const = 0;
  651. virtual void UpdateServerDetails(void) = 0;
  652. virtual bool ShouldHibernate() = 0;
  653. };
  654. #endif // EIFACE_H