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.

204 lines
5.7 KiB

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