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.

205 lines
5.8 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //===========================================================================//
  7. #include "IRunGameEngine.h"
  8. #include "EngineInterface.h"
  9. #include "tier1/strtools.h"
  10. #include "IGameUIFuncs.h"
  11. #include "tier1/convar.h"
  12. // memdbgon must be the last include file in a .cpp file!!!
  13. #include "tier0/memdbgon.h"
  14. //-----------------------------------------------------------------------------
  15. // Purpose: Interface to running the engine from the UI dlls
  16. //-----------------------------------------------------------------------------
  17. class CRunGameEngine : public IRunGameEngine
  18. {
  19. public:
  20. // Returns true if the engine is running, false otherwise.
  21. virtual bool IsRunning()
  22. {
  23. return true;
  24. }
  25. // Adds text to the engine command buffer. Only works if IsRunning()
  26. // returns true on success, false on failure
  27. virtual bool AddTextCommand(const char *text)
  28. {
  29. engine->ClientCmd_Unrestricted((char *)text);
  30. return true;
  31. }
  32. // runs the engine with the specified command line parameters. Only works if !IsRunning()
  33. // returns true on success, false on failure
  34. virtual bool RunEngine(const char *gameName, const char *commandLineParams)
  35. {
  36. return false;
  37. }
  38. virtual bool RunEngine2(const char *gameDir, const char *commandLineParams, bool isSourceGame)
  39. {
  40. return false;
  41. }
  42. virtual ERunResult RunEngine( int iAppID, const char *gameDir, const char *commandLineParams )
  43. {
  44. return k_ERunResultOkay;
  45. }
  46. // returns true if the player is currently connected to a game server
  47. virtual bool IsInGame()
  48. {
  49. return engine->GetLevelName() && strlen(engine->GetLevelName()) > 0;
  50. }
  51. // gets information about the server the engine is currently connected to
  52. // returns true on success, false on failure
  53. virtual bool GetGameInfo(char *infoBuffer, int bufferSize)
  54. {
  55. //!! need to implement
  56. return false;
  57. }
  58. virtual void SetTrackerUserID(int trackerID, const char *trackerName)
  59. {
  60. gameuifuncs->SetFriendsID(trackerID, trackerName);
  61. // update the player's name if necessary
  62. ConVarRef name( "name" );
  63. if ( name.IsValid() && trackerName && *trackerName && !Q_strcmp( name.GetString(), "unnamed" ) )
  64. {
  65. name.SetValue(trackerName);
  66. }
  67. }
  68. // iterates users
  69. // returns the number of user
  70. virtual int GetPlayerCount()
  71. {
  72. return engine->GetMaxClients();
  73. }
  74. // returns a playerID for a player
  75. // playerIndex is in the range [0, GetPlayerCount)
  76. virtual unsigned int GetPlayerFriendsID(int playerIndex)
  77. {
  78. player_info_t pi;
  79. if ( engine->GetPlayerInfo(playerIndex, &pi ) )
  80. return pi.friendsID;
  81. return 0;
  82. }
  83. // gets the in-game name of another user, returns NULL if that user doesn't exists
  84. virtual const char *GetPlayerName(int trackerID, char *name, int namelen)
  85. {
  86. // find the player by their friendsID
  87. player_info_t pi;
  88. for (int i = 0; i < engine->GetMaxClients(); i++)
  89. {
  90. if (engine->GetPlayerInfo(i, &pi ))
  91. {
  92. if (pi.friendsID == (uint)trackerID)
  93. {
  94. Q_strncpy( name, pi.name, namelen );
  95. return name;
  96. }
  97. }
  98. }
  99. return NULL;
  100. }
  101. virtual const char *GetPlayerFriendsName(int trackerID, char *name, int namelen)
  102. {
  103. // find the player by their friendsID
  104. player_info_t pi;
  105. for (int i = 0; i < engine->GetMaxClients(); i++)
  106. {
  107. if (engine->GetPlayerInfo(i, &pi ))
  108. {
  109. if (pi.friendsID == (uint)trackerID)
  110. {
  111. Q_strncpy( name, pi.friendsName, namelen );
  112. return name;
  113. }
  114. }
  115. }
  116. return NULL;
  117. }
  118. // return the build number of the engine
  119. virtual unsigned int GetEngineBuildNumber()
  120. {
  121. return engine->GetEngineBuildNumber();
  122. }
  123. // return the product version of the mod being played (comes from steam.inf)
  124. virtual const char *GetProductVersionString()
  125. {
  126. return engine->GetProductVersionString();
  127. }
  128. };
  129. EXPOSE_SINGLE_INTERFACE(CRunGameEngine, IRunGameEngine, RUNGAMEENGINE_INTERFACE_VERSION);
  130. //namespace
  131. //{
  132. ////-----------------------------------------------------------------------------
  133. //// Purpose: Interface to running the game engine
  134. ////-----------------------------------------------------------------------------
  135. //abstract_class IRunGameEngine_Old : public IBaseInterface
  136. //{
  137. //public:
  138. // // Returns true if the engine is running, false otherwise.
  139. // virtual bool IsRunning() = 0;
  140. //
  141. // // Adds text to the engine command buffer. Only works if IsRunning()
  142. // // returns true on success, false on failure
  143. // virtual bool AddTextCommand(const char *text) = 0;
  144. //
  145. // // runs the engine with the specified command line parameters. Only works if !IsRunning()
  146. // // returns true on success, false on failure
  147. // virtual bool RunEngine(const char *gameDir, const char *commandLineParams) = 0;
  148. //
  149. // // returns true if the player is currently connected to a game server
  150. // virtual bool IsInGame() = 0;
  151. //
  152. // // gets information about the server the engine is currently ctrue on success, false on failure
  153. // virtual bool GetGameInfo(char *infoBuffer, int bufferSize) = 0;
  154. //
  155. // // tells the engine our userID
  156. // virtual void SetTrackerUserID(int trackerID, const char *trackerName) = 0;
  157. //
  158. // // this next section could probably moved to another interface
  159. // // iterates users
  160. // // returns the number of user
  161. // virtual int GetPlayerCount() = 0;
  162. //
  163. // // returns a playerID for a player
  164. // // playerIndex is in the range [0, GetPlayerCount)
  165. // virtual unsigned int GetPlayerFriendsID(int playerIndex) = 0;
  166. //
  167. // // gets the in-game name of another user, returns NULL if that user doesn't exists
  168. // virtual const char *GetPlayerName(int friendsID) = 0;
  169. //
  170. // // gets the friends name of a player
  171. // virtual const char *GetPlayerFriendsName(int friendsID) = 0;
  172. //};
  173. //
  174. //#define RUNGAMEENGINE_INTERFACE_VERSION_OLD "RunGameEngine004"
  175. //
  176. //#ifndef _XBOX
  177. //EXPOSE_SINGLE_INTERFACE(CRunGameEngine, IRunGameEngine_Old, RUNGAMEENGINE_INTERFACE_VERSION_OLD);
  178. //#endif
  179. //}