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.

120 lines
3.6 KiB

  1. //========= Copyright � Valve Corporation, All rights reserved. =======================//
  2. //
  3. // Purpose: Jobs for communicating with the custom Steam backend (Game Coordinator)
  4. //
  5. //=====================================================================================//
  6. #if !defined( NO_STEAM ) && !defined( NO_STEAM_GAMECOORDINATOR ) && !defined( SWDS )
  7. #include "mm_framework.h"
  8. #include "steam_datacenterjobs.h"
  9. #include "generic_gcmessages.h"
  10. // NOTE: This has to be the last file included!
  11. #include "tier0/memdbgon.h"
  12. using GCSDK::CGCMsg;
  13. //-----------------------------------------------------------------------------
  14. // Purpose: Constructor
  15. // Inputs: pKVStats - A pointer to a KV with the global stats to update
  16. //-----------------------------------------------------------------------------
  17. CGCClientJobUpdateStats::CGCClientJobUpdateStats( KeyValues *pKVStats )
  18. : CGCClientJob( GGCClient() ), m_pKVCmd( NULL )
  19. {
  20. m_pKVCmd = pKVStats->MakeCopy();
  21. m_pKVCmd->SetName( "stat_agg" );
  22. }
  23. //-----------------------------------------------------------------------------
  24. // Purpose: Destructor
  25. //-----------------------------------------------------------------------------
  26. CGCClientJobUpdateStats::~CGCClientJobUpdateStats( )
  27. {
  28. if ( m_pKVCmd )
  29. m_pKVCmd->deleteThis();
  30. }
  31. //-----------------------------------------------------------------------------
  32. // Purpose: Runs the job
  33. //-----------------------------------------------------------------------------
  34. bool CGCClientJobUpdateStats::BYieldingRunGCJob()
  35. {
  36. CGCMsg<MsgGCGenericKV_t> msg( k_EMsgGCKVCommand );
  37. CUtlBuffer bufDest;
  38. m_pKVCmd->WriteAsBinary( bufDest );
  39. msg.AddVariableLenData( bufDest.Base(), bufDest.TellPut() );
  40. m_pGCClient->BSendMessage( msg );
  41. return true;
  42. }
  43. //-----------------------------------------------------------------------------
  44. // Purpose: Constructor
  45. // Inputs: pKVStats - A pointer to a KV with the global stats to update
  46. //-----------------------------------------------------------------------------
  47. CGCClientJobDataRequest::CGCClientJobDataRequest( )
  48. : CGCClientJob( GGCClient() ),
  49. m_pKVRequest( NULL ),
  50. m_pKVResults( NULL ),
  51. m_bComplete( false ),
  52. m_bSuccess( false ),
  53. m_bWaitForRead( true )
  54. {
  55. }
  56. //-----------------------------------------------------------------------------
  57. // Purpose: Destructor
  58. //-----------------------------------------------------------------------------
  59. CGCClientJobDataRequest::~CGCClientJobDataRequest( )
  60. {
  61. if ( m_pKVRequest )
  62. m_pKVRequest->deleteThis();
  63. if ( m_pKVResults )
  64. m_pKVResults->deleteThis();
  65. }
  66. //-----------------------------------------------------------------------------
  67. // Purpose: Runs the job
  68. //-----------------------------------------------------------------------------
  69. bool CGCClientJobDataRequest::BYieldingRunGCJob()
  70. {
  71. CGCMsg<MsgGCGenericKV_t> msgOut( k_EMsgGCKVCommand );
  72. CGCMsg<MsgGCGenericKVResponse_t> msgIn;
  73. CUtlBuffer bufOut;
  74. m_pKVRequest = new KeyValues( "datarequest" );
  75. m_pKVRequest->WriteAsBinary( bufOut );
  76. msgOut.AddVariableLenData( bufOut.Base(), bufOut.TellPut() );
  77. m_bSuccess = BYldSendMessageAndGetReply( msgOut, 30, &msgIn, k_EMsgGCKVCommandResponse )
  78. && msgIn.Body().m_bSuccess;
  79. if ( m_bSuccess )
  80. {
  81. CUtlBuffer bufIn( msgIn.PubVarData(), msgIn.CubVarData(), CUtlBuffer::READ_ONLY );
  82. m_pKVResults = new KeyValues( "results" );
  83. m_bSuccess &= m_pKVResults->ReadAsBinary( bufIn );
  84. }
  85. m_bComplete = true;
  86. // Once we're complete give the datacenter code a reasonable chance
  87. // to get the data back before we finish and delete ourselves.
  88. int nFramesToWait = 5;
  89. while ( m_bWaitForRead && nFramesToWait-- > 0 )
  90. {
  91. BYieldingWaitOneFrame();
  92. }
  93. return true;
  94. }
  95. #endif