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.

156 lines
6.2 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================
  7. #include "cbase.h"
  8. // for messaging with the GC
  9. #include "tf_gcmessages.h"
  10. #include "tf_item_inventory.h"
  11. #include "econ_game_account_server.h"
  12. #include "gc_clientsystem.h"
  13. //-----------------------------------------------------------------------------
  14. CON_COMMAND_F( cl_gameserver_create_identity, "Creates a new game server account associated with the currently logged in steam account", FCVAR_CLIENTDLL )
  15. {
  16. if ( steamapicontext && steamapicontext->SteamUser() )
  17. {
  18. CSteamID steamID = steamapicontext->SteamUser()->GetSteamID();
  19. GCSDK::CProtoBufMsg< CMsgGC_GameServer_CreateIdentity> msg( k_EMsgGC_GameServer_CreateIdentity );
  20. msg.Body().set_account_id( steamID.GetAccountID() );
  21. GCClientSystem()->BSendMessage( msg );
  22. Msg( "Request to create a game server account sent--please wait.\n" );
  23. }
  24. else
  25. {
  26. Msg( "You must be logged into Steam to create a game server account.\n" );
  27. }
  28. }
  29. CON_COMMAND_F( cl_gameserver_list, "List all the game server accounts owned by the currently logged in steam account", FCVAR_CLIENTDLL )
  30. {
  31. if ( steamapicontext && steamapicontext->SteamUser() )
  32. {
  33. CSteamID steamID = steamapicontext->SteamUser()->GetSteamID();
  34. GCSDK::CProtoBufMsg< CMsgGC_GameServer_List > msg( k_EMsgGC_GameServer_List );
  35. msg.Body().set_account_id( steamID.GetAccountID() );
  36. GCClientSystem()->BSendMessage( msg );
  37. Msg( "Request to retrieve owned game server accounts--please wait.\n" );
  38. }
  39. else
  40. {
  41. Msg( "You must be logged into Steam to get the list of game server accounts.\n" );
  42. }
  43. }
  44. CON_COMMAND_F( cl_gameserver_reset_identity, "Resets the identity token for a given game server", FCVAR_CLIENTDLL )
  45. {
  46. if ( steamapicontext && steamapicontext->SteamUser() )
  47. {
  48. if ( args.ArgC() > 1 )
  49. {
  50. CSteamID steamID = steamapicontext->SteamUser()->GetSteamID();
  51. GCSDK::CProtoBufMsg< CMsgGC_GameServer_ResetIdentity > msg( k_EMsgGC_GameServer_ResetIdentity );
  52. msg.Body().set_game_server_account_id( atoi( args[1] ) );
  53. GCClientSystem()->BSendMessage( msg );
  54. Msg( "Request to reset owned game server account identity token--please wait.\n" );
  55. }
  56. else
  57. {
  58. Msg( "Usage: cl_gameserver_reset_identity <game server account id>\n");
  59. }
  60. }
  61. else
  62. {
  63. Msg( "You must be logged into Steam to reset a game server's identity token.\n" );
  64. }
  65. }
  66. class CGC_GameServer_CreateIdentityResponse : public GCSDK::CGCClientJob
  67. {
  68. public:
  69. CGC_GameServer_CreateIdentityResponse( GCSDK::CGCClient *pClient ) : GCSDK::CGCClientJob( pClient ) {}
  70. virtual bool BYieldingRunGCJob( GCSDK::IMsgNetPacket *pNetPacket )
  71. {
  72. GCSDK::CProtoBufMsg< CMsgGC_GameServer_CreateIdentityResponse > msg( pNetPacket );
  73. if ( msg.Body().account_created() )
  74. {
  75. Msg( "Game server account created successfully!\n" );
  76. Msg( "Set these convars on your game server to have it log in and receive benefits:\n" );
  77. Msg( "tf_server_identity_account_id %u\n", msg.Body().game_server_account_id() );
  78. Msg( "tf_server_identity_token \"%s\"\n\n", msg.Body().game_server_identity_token().c_str() );
  79. }
  80. else
  81. {
  82. Msg( "Unable to create a game server account attached to your Steam account.\n" );
  83. switch ( msg.Body().status() )
  84. {
  85. default:
  86. case CMsgGC_GameServer_CreateIdentityResponse::kStatus_GenericFailure:
  87. Msg( "Failure code %d. Contact Steam support.\n", (int)msg.Body().status() );
  88. break;
  89. case CMsgGC_GameServer_CreateIdentityResponse::kStatus_TooMany:
  90. Msg( "Too many game server accounts already registered with your Steam account.\n" );
  91. break;
  92. case CMsgGC_GameServer_CreateIdentityResponse::kStatus_NoPrivs:
  93. Msg( "Your Steam account doesn't have rights to create game server accounts.\n" );
  94. break;
  95. }
  96. }
  97. return true;
  98. }
  99. };
  100. GC_REG_JOB( GCSDK::CGCClient, CGC_GameServer_CreateIdentityResponse, "CGC_GameServer_CreateIdentityResponse", k_EMsgGC_GameServer_CreateIdentityResponse, GCSDK::k_EServerTypeGCClient );
  101. class CGC_GameServer_ListResponse : public GCSDK::CGCClientJob
  102. {
  103. public:
  104. CGC_GameServer_ListResponse( GCSDK::CGCClient *pClient ) : GCSDK::CGCClientJob( pClient ) {}
  105. virtual bool BYieldingRunGCJob( GCSDK::IMsgNetPacket *pNetPacket )
  106. {
  107. GCSDK::CProtoBufMsg< CMsgGC_GameServer_ListResponse > msg( pNetPacket );
  108. Msg( "Owned Game Servers: %d\n", msg.Body().owned_game_servers_size() );
  109. for ( int i = 0; i < msg.Body().owned_game_servers_size(); ++i )
  110. {
  111. const CMsgGC_GameServer_ListResponse_GameServerIdentity &identity = msg.Body().owned_game_servers( i );
  112. const char *pStanding = GameServerAccount_GetStandingString( (eGameServerScoreStanding)identity.game_server_standing() );
  113. const char *pStandingTrend = GameServerAccount_GetStandingTrendString( (eGameServerScoreStandingTrend)identity.game_server_standing_trend() );
  114. Msg( "%d - Account ID: %u Identity Token: %s Standing: %s Trend: %s\n", i + 1, identity.game_server_account_id(), identity.game_server_identity_token().c_str(), pStanding, pStandingTrend );
  115. }
  116. return true;
  117. }
  118. };
  119. GC_REG_JOB( GCSDK::CGCClient, CGC_GameServer_ListResponse, "CGC_GameServer_ListResponse", k_EMsgGC_GameServer_ListResponse, GCSDK::k_EServerTypeGCClient );
  120. class CGC_GameServer_ResetIdentityResponse : public GCSDK::CGCClientJob
  121. {
  122. public:
  123. CGC_GameServer_ResetIdentityResponse( GCSDK::CGCClient *pClient ) : GCSDK::CGCClientJob( pClient ) {}
  124. virtual bool BYieldingRunGCJob( GCSDK::IMsgNetPacket *pNetPacket )
  125. {
  126. GCSDK::CProtoBufMsg< CMsgGC_GameServer_ResetIdentityResponse > msg( pNetPacket );
  127. if ( msg.Body().game_server_identity_token_reset() )
  128. {
  129. Msg( "Game server account identity reset!\n" );
  130. Msg( "Set these convars on your game server to have it log in and receive benefits:\n" );
  131. Msg( "tf_server_identity_account_id %u\n", msg.Body().game_server_account_id() );
  132. Msg( "tf_server_identity_token \"%s\"\n\n", msg.Body().game_server_identity_token().c_str() );
  133. }
  134. else
  135. {
  136. Msg( "Failed to reset game server account identity--check to make sure the game server account id is correct!\n" );
  137. }
  138. return true;
  139. }
  140. };
  141. GC_REG_JOB( GCSDK::CGCClient, CGC_GameServer_ResetIdentityResponse, "CGC_GameServer_ResetIdentityResponse", k_EMsgGC_GameServer_ResetIdentityResponse, GCSDK::k_EServerTypeGCClient );