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.

203 lines
6.0 KiB

  1. //===== Copyright � 1996-2005, 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)
  85. {
  86. #if 0 // this code is unused, but returns a pointer to a local array - fix this if you need the function
  87. // find the player by their friendsID
  88. player_info_t pi;
  89. for (int i = 0; i < engine->GetMaxClients(); i++)
  90. {
  91. if (engine->GetPlayerInfo(i, &pi ))
  92. {
  93. if (pi.friendsID == (uint)trackerID)
  94. {
  95. return pi.name;
  96. }
  97. }
  98. }
  99. #endif
  100. return NULL;
  101. }
  102. virtual const char *GetPlayerFriendsName(int trackerID)
  103. {
  104. #if 0 // this code is unused, but returns a pointer to a local array - fix this if you need the function
  105. // find the player by their friendsID
  106. player_info_t pi;
  107. for (int i = 0; i < engine->GetMaxClients(); i++)
  108. {
  109. if (engine->GetPlayerInfo(i, &pi ))
  110. {
  111. if (pi.friendsID == (uint)trackerID)
  112. {
  113. return pi.friendsName;
  114. }
  115. }
  116. }
  117. #endif
  118. return NULL;
  119. }
  120. // return the build number of the engine
  121. virtual unsigned int GetEngineBuildNumber()
  122. {
  123. return engine->GetEngineBuildNumber();
  124. }
  125. // return the product version of the mod being played (comes from steam.inf)
  126. virtual const char *GetProductVersionString()
  127. {
  128. return engine->GetProductVersionString();
  129. }
  130. };
  131. EXPOSE_SINGLE_INTERFACE(CRunGameEngine, IRunGameEngine, RUNGAMEENGINE_INTERFACE_VERSION);
  132. //namespace
  133. //{
  134. ////-----------------------------------------------------------------------------
  135. //// Purpose: Interface to running the game engine
  136. ////-----------------------------------------------------------------------------
  137. //abstract_class IRunGameEngine_Old : public IBaseInterface
  138. //{
  139. //public:
  140. // // Returns true if the engine is running, false otherwise.
  141. // virtual bool IsRunning() = 0;
  142. //
  143. // // Adds text to the engine command buffer. Only works if IsRunning()
  144. // // returns true on success, false on failure
  145. // virtual bool AddTextCommand(const char *text) = 0;
  146. //
  147. // // runs the engine with the specified command line parameters. Only works if !IsRunning()
  148. // // returns true on success, false on failure
  149. // virtual bool RunEngine(const char *gameDir, const char *commandLineParams) = 0;
  150. //
  151. // // returns true if the player is currently connected to a game server
  152. // virtual bool IsInGame() = 0;
  153. //
  154. // // gets information about the server the engine is currently ctrue on success, false on failure
  155. // virtual bool GetGameInfo(char *infoBuffer, int bufferSize) = 0;
  156. //
  157. // // tells the engine our userID
  158. // virtual void SetTrackerUserID(int trackerID, const char *trackerName) = 0;
  159. //
  160. // // this next section could probably moved to another interface
  161. // // iterates users
  162. // // returns the number of user
  163. // virtual int GetPlayerCount() = 0;
  164. //
  165. // // returns a playerID for a player
  166. // // playerIndex is in the range [0, GetPlayerCount)
  167. // virtual unsigned int GetPlayerFriendsID(int playerIndex) = 0;
  168. //
  169. // // gets the in-game name of another user, returns NULL if that user doesn't exists
  170. // virtual const char *GetPlayerName(int friendsID) = 0;
  171. //
  172. // // gets the friends name of a player
  173. // virtual const char *GetPlayerFriendsName(int friendsID) = 0;
  174. //};
  175. //
  176. //#define RUNGAMEENGINE_INTERFACE_VERSION_OLD "RunGameEngine004"
  177. //
  178. //EXPOSE_SINGLE_INTERFACE(CRunGameEngine, IRunGameEngine_Old, RUNGAMEENGINE_INTERFACE_VERSION_OLD);
  179. //}