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.

133 lines
3.5 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #ifndef TF_STREAMS_H
  7. #define TF_STREAMS_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "vgui_controls/EditablePanel.h"
  12. using namespace vgui;
  13. #define MAX_STREAM_PANELS 5
  14. class CStreamInfo
  15. {
  16. public:
  17. CStreamInfo() : m_numViewers( 0 ) {}
  18. public:
  19. CUtlString m_sGlobalName;
  20. int m_numViewers;
  21. CUtlString m_sDisplayName;
  22. CUtlString m_sTextDescription;
  23. CUtlString m_sUpdatedAtStamp;
  24. CUtlString m_sPreviewImage;
  25. CUtlString m_sPreviewImageLocalFile;
  26. CUtlString m_sPreviewImageSF;
  27. CUtlString m_sLanguage;
  28. CUtlString m_sCountry;
  29. CUtlString m_sVideoFeedUrl;
  30. };
  31. class CTFStreamPanel : public EditablePanel
  32. {
  33. public:
  34. DECLARE_CLASS_SIMPLE( CTFStreamPanel, EditablePanel );
  35. CTFStreamPanel( Panel *parent, const char *panelName );
  36. virtual ~CTFStreamPanel() {}
  37. virtual void ApplySchemeSettings( IScheme *pScheme ) OVERRIDE;
  38. virtual void PerformLayout() OVERRIDE;
  39. virtual void OnCommand( const char *command ) OVERRIDE;
  40. void SetGlobalName( const char *pszGlobalName ) { m_strStreamInfoGlobalName = pszGlobalName; }
  41. CStreamInfo *GetStreamInfo() const;
  42. private:
  43. void UpdatePanels();
  44. void SetPreviewImage( const char *pszPreviewImageFile );
  45. CUtlString m_strStreamInfoGlobalName;
  46. class vgui::ImagePanel *m_pPreviewImage;
  47. };
  48. class CTFStreamListPanel : public EditablePanel, public CGameEventListener
  49. {
  50. public:
  51. DECLARE_CLASS_SIMPLE( CTFStreamListPanel, EditablePanel );
  52. CTFStreamListPanel( Panel *parent, const char *panelName );
  53. virtual ~CTFStreamListPanel() {}
  54. virtual void ApplySchemeSettings( IScheme *pScheme ) OVERRIDE;
  55. virtual void OnThink() OVERRIDE;
  56. virtual void OnCommand( const char *command ) OVERRIDE;
  57. virtual void FireGameEvent( IGameEvent *event ) OVERRIDE;
  58. CTFStreamPanel *m_arrStreamPanels[MAX_STREAM_PANELS];
  59. };
  60. enum ETwitchTvState_t
  61. {
  62. k_ETwitchTvState_None,
  63. k_ETwitchTvState_Loading,
  64. k_ETwitchTvState_NoLink,
  65. k_ETwitchTvState_Linked,
  66. k_ETwitchTvState_Error
  67. };
  68. struct TwitchTvAccountInfo_t
  69. {
  70. uint64 m_uiSteamID;
  71. ETwitchTvState_t m_eTwitchTvState;
  72. double m_dblTimeStampTwitchTvUpdate;
  73. uint64 m_uiTwitchTvUserId;
  74. CUtlString m_sTwitchTvChannel;
  75. };
  76. class CTFStreamManager : public CAutoGameSystemPerFrame
  77. {
  78. public:
  79. CTFStreamManager();
  80. ~CTFStreamManager();
  81. virtual bool Init() OVERRIDE;
  82. virtual void Update( float frametime ) OVERRIDE;
  83. void RequestTopStreams();
  84. CStreamInfo * GetStreamInfoByName( char const *szName );
  85. CUtlVector< CStreamInfo >& GetStreamInfoVec() { return m_streamInfoVec; }
  86. TwitchTvAccountInfo_t* GetTwitchTvAccountInfo( uint64 uiSteamID );
  87. private: // cache stream info
  88. CUtlVector< CStreamInfo > m_streamInfoVec;
  89. private: // query for top X viewers
  90. double m_dblTimeStampLastUpdate;
  91. HTTPRequestHandle m_hHTTPRequestHandle;
  92. CCallResult< CTFStreamManager, HTTPRequestCompleted_t > m_CallbackOnHTTPRequestCompleted;
  93. void Steam_OnHTTPRequestCompletedStreams( HTTPRequestCompleted_t *p, bool bError );
  94. private: // checking for twitch account linking with steam account
  95. void UpdateTwitchTvAccounts();
  96. TwitchTvAccountInfo_t *m_pLoadingAccount;
  97. CUtlVector< TwitchTvAccountInfo_t* > m_vecTwitchTvAccounts; // list of steam id to updated twitch account
  98. HTTPRequestHandle m_hHTTPRequestHandleTwitchTv;
  99. CCallResult< CTFStreamManager, HTTPRequestCompleted_t > m_CallbackOnHTTPRequestCompletedTwitchTv;
  100. void Steam_OnHTTPRequestCompletedMyTwitchTv( HTTPRequestCompleted_t *p, bool bError );
  101. };
  102. CTFStreamManager *StreamManager();
  103. #endif // TF_STREAMS_H