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.

217 lines
6.1 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. // SERVERBROWSER HACK: -- it just stuffs commands into command buffer
  30. // which is pretty horrible because it doesn't let game code to react
  31. if ( text && StringHasPrefix( text, "connect " ) && g_pMatchFramework )
  32. {
  33. g_pMatchFramework->CloseSession();
  34. }
  35. engine->ClientCmd_Unrestricted((char *)text);
  36. return true;
  37. }
  38. // runs the engine with the specified command line parameters. Only works if !IsRunning()
  39. // returns true on success, false on failure
  40. virtual bool RunEngine(const char *gameName, const char *commandLineParams)
  41. {
  42. return false;
  43. }
  44. virtual bool RunEngine2(const char *gameDir, const char *commandLineParams, bool isSourceGame)
  45. {
  46. return false;
  47. }
  48. virtual ERunResult RunEngine( int iAppID, const char *gameDir, const char *commandLineParams )
  49. {
  50. return k_ERunResultOkay;
  51. }
  52. // returns true if the player is currently connected to a game server
  53. virtual bool IsInGame()
  54. {
  55. return engine->GetLevelName() && strlen(engine->GetLevelName()) > 0;
  56. }
  57. // gets information about the server the engine is currently connected to
  58. // returns true on success, false on failure
  59. virtual bool GetGameInfo(char *infoBuffer, int bufferSize)
  60. {
  61. //!! need to implement
  62. return false;
  63. }
  64. virtual void SetTrackerUserID(int trackerID, const char *trackerName)
  65. {
  66. gameuifuncs->SetFriendsID(trackerID, trackerName);
  67. // update the player's name if necessary
  68. ConVarRef name( "name" );
  69. if ( name.IsValid() && trackerName && *trackerName && !Q_strcmp( name.GetString(), "unnamed" ) )
  70. {
  71. name.SetValue(trackerName);
  72. }
  73. }
  74. // iterates users
  75. // returns the number of user
  76. virtual int GetPlayerCount()
  77. {
  78. return engine->GetMaxClients();
  79. }
  80. // returns a playerID for a player
  81. // playerIndex is in the range [0, GetPlayerCount)
  82. virtual unsigned int GetPlayerFriendsID(int playerIndex)
  83. {
  84. player_info_t pi;
  85. if ( engine->GetPlayerInfo(playerIndex, &pi ) )
  86. return pi.friendsID;
  87. return 0;
  88. }
  89. // gets the in-game name of another user, returns NULL if that user doesn't exists
  90. virtual const char *GetPlayerName(int trackerID)
  91. {
  92. #if 0// DDK: this code could very likely cause a crash
  93. Assert(false);
  94. // find the player by their friendsID
  95. player_info_t pi;
  96. for (int i = 0; i < engine->GetMaxClients(); i++)
  97. {
  98. if (engine->GetPlayerInfo(i, &pi ))
  99. {
  100. if (pi.friendsID == (uint)trackerID)
  101. {
  102. return pi.name;
  103. }
  104. }
  105. }
  106. #endif
  107. return NULL;
  108. }
  109. virtual const char *GetPlayerFriendsName(int trackerID)
  110. {
  111. #if 0// DDK: this code could very likely cause a crash
  112. Assert(false);
  113. // find the player by their friendsID
  114. player_info_t pi;
  115. for (int i = 0; i < engine->GetMaxClients(); i++)
  116. {
  117. if (engine->GetPlayerInfo(i, &pi ))
  118. {
  119. if (pi.friendsID == (uint)trackerID)
  120. {
  121. return pi.friendsName;
  122. }
  123. }
  124. }
  125. #endif
  126. return NULL;
  127. }
  128. // return the build number of the engine
  129. virtual unsigned int GetEngineBuildNumber()
  130. {
  131. return engine->GetEngineBuildNumber();
  132. }
  133. // return the product version of the mod being played (comes from steam.inf)
  134. virtual const char *GetProductVersionString()
  135. {
  136. return engine->GetProductVersionString();
  137. }
  138. };
  139. EXPOSE_SINGLE_INTERFACE(CRunGameEngine, IRunGameEngine, RUNGAMEENGINE_INTERFACE_VERSION);
  140. //namespace
  141. //{
  142. ////-----------------------------------------------------------------------------
  143. //// Purpose: Interface to running the game engine
  144. ////-----------------------------------------------------------------------------
  145. //abstract_class IRunGameEngine_Old : public IBaseInterface
  146. //{
  147. //public:
  148. // // Returns true if the engine is running, false otherwise.
  149. // virtual bool IsRunning() = 0;
  150. //
  151. // // Adds text to the engine command buffer. Only works if IsRunning()
  152. // // returns true on success, false on failure
  153. // virtual bool AddTextCommand(const char *text) = 0;
  154. //
  155. // // runs the engine with the specified command line parameters. Only works if !IsRunning()
  156. // // returns true on success, false on failure
  157. // virtual bool RunEngine(const char *gameDir, const char *commandLineParams) = 0;
  158. //
  159. // // returns true if the player is currently connected to a game server
  160. // virtual bool IsInGame() = 0;
  161. //
  162. // // gets information about the server the engine is currently ctrue on success, false on failure
  163. // virtual bool GetGameInfo(char *infoBuffer, int bufferSize) = 0;
  164. //
  165. // // tells the engine our userID
  166. // virtual void SetTrackerUserID(int trackerID, const char *trackerName) = 0;
  167. //
  168. // // this next section could probably moved to another interface
  169. // // iterates users
  170. // // returns the number of user
  171. // virtual int GetPlayerCount() = 0;
  172. //
  173. // // returns a playerID for a player
  174. // // playerIndex is in the range [0, GetPlayerCount)
  175. // virtual unsigned int GetPlayerFriendsID(int playerIndex) = 0;
  176. //
  177. // // gets the in-game name of another user, returns NULL if that user doesn't exists
  178. // virtual const char *GetPlayerName(int friendsID) = 0;
  179. //
  180. // // gets the friends name of a player
  181. // virtual const char *GetPlayerFriendsName(int friendsID) = 0;
  182. //};
  183. //
  184. //#define RUNGAMEENGINE_INTERFACE_VERSION_OLD "RunGameEngine004"
  185. //
  186. //#ifndef _XBOX
  187. //EXPOSE_SINGLE_INTERFACE(CRunGameEngine, IRunGameEngine_Old, RUNGAMEENGINE_INTERFACE_VERSION_OLD);
  188. //#endif
  189. //}