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.

195 lines
5.0 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Generic in-game abuse reporting
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "cbase.h"
  8. #include "GameEventListener.h"
  9. #include "tf_shared_content_manager.h"
  10. #include "confirm_dialog.h"
  11. #include "clientmode_tf.h"
  12. #include "tf_gamerules.h"
  13. // memdbgon must be the last include file in a .cpp file!!!
  14. #include "tier0/memdbgon.h"
  15. // Declare singleton object
  16. static C_TFSharedContentManager s_SharedContentManager;
  17. C_TFSharedContentManager *TFSharedContentManager() { return &s_SharedContentManager; }
  18. //-----------------------------------------------------------------------------
  19. // Romevision-specific dialog and callback
  20. //-----------------------------------------------------------------------------
  21. extern ConVar tf_romevision_opt_in;
  22. extern ConVar tf_romevision_skip_prompt;
  23. void PromptAcceptRomevisionSharingCallback( bool bConfirm, void *pContext )
  24. {
  25. if ( bConfirm )
  26. {
  27. tf_romevision_opt_in.SetValue( true );
  28. }
  29. }
  30. static void PromptAcceptRomevisionSharing()
  31. {
  32. if ( tf_romevision_opt_in.GetBool() == false )
  33. {
  34. ShowConfirmOptOutDialog( "#TF_Prompt_Romevision_Title", "#TF_Prompt_Romevision_Message",
  35. "#TF_Prompt_Romevsion_OK", "#TF_Prompt_Romevsion_Cancel",
  36. "#TF_Prompt_Romevsion_Opt_Out", "tf_romevision_skip_prompt",
  37. PromptAcceptRomevisionSharingCallback, NULL );
  38. }
  39. }
  40. //-----------------------------------------------------------------------------
  41. bool C_TFSharedContentManager::Init()
  42. {
  43. m_iSharedVisionFlags = TF_VISION_FILTER_NONE;
  44. m_PlayersWhoHaveOfferedVision.Purge();
  45. m_SharedVisionQueue.Purge();
  46. return true;
  47. }
  48. //-----------------------------------------------------------------------------
  49. void C_TFSharedContentManager::Update( float frametime )
  50. {
  51. // check our shared vision queue
  52. if ( m_SharedVisionQueue.Count() > 0 )
  53. {
  54. int iTeam = GetLocalPlayerTeam();
  55. bool bPrompt = false;
  56. if ( iTeam == TEAM_SPECTATOR )
  57. {
  58. bPrompt = true;
  59. }
  60. else if ( iTeam > LAST_SHARED_TEAM )
  61. {
  62. C_TFPlayer *pTFLocalPlayer = C_TFPlayer::GetLocalTFPlayer();
  63. if ( pTFLocalPlayer && pTFLocalPlayer->GetPlayerClass() && ( pTFLocalPlayer->GetPlayerClass()->GetClassIndex() > TF_CLASS_UNDEFINED ) )
  64. {
  65. bPrompt = true;
  66. }
  67. }
  68. if ( bPrompt )
  69. {
  70. OfferSharedVision_Internal( m_SharedVisionQueue[0].iFlag, m_SharedVisionQueue[0].unAccountID );
  71. m_SharedVisionQueue.Remove( 0 );
  72. }
  73. }
  74. }
  75. //-----------------------------------------------------------------------------
  76. bool C_TFSharedContentManager::CanOfferVision( int iFlag )
  77. {
  78. bool bRetVal = false;
  79. switch ( iFlag )
  80. {
  81. case TF_VISION_FILTER_ROME:
  82. if ( TFGameRules() && TFGameRules()->IsMannVsMachineMode() )
  83. {
  84. bRetVal = true;
  85. }
  86. break;
  87. default:
  88. break;
  89. }
  90. return bRetVal;
  91. }
  92. //-----------------------------------------------------------------------------
  93. void C_TFSharedContentManager::OfferSharedVision( int iFlag, uint32 unAccountID )
  94. {
  95. if ( !CanOfferVision( iFlag ) )
  96. return;
  97. for ( int i = 0 ; i < m_SharedVisionQueue.Count() ; i++ )
  98. {
  99. if ( ( m_SharedVisionQueue[i].iFlag == iFlag ) && ( m_SharedVisionQueue[i].unAccountID == unAccountID ) )
  100. {
  101. // we already have this entry in the queue
  102. return;
  103. }
  104. }
  105. shared_vision_entry_t data = { iFlag, unAccountID };
  106. m_SharedVisionQueue.AddToTail( data );
  107. }
  108. //-----------------------------------------------------------------------------
  109. void C_TFSharedContentManager::PrintChatText( int iFlag, uint32 unAccountID )
  110. {
  111. // add some chat text saying who has offered the vision, but only once-per-player to avoid spam
  112. if ( m_PlayersWhoHaveOfferedVision.Find( unAccountID ) == m_PlayersWhoHaveOfferedVision.InvalidIndex() )
  113. {
  114. const char *pszPlayerName = NULL;
  115. CBasePlayer *pPlayer = GetPlayerByAccountID( unAccountID );
  116. if ( pPlayer )
  117. {
  118. pszPlayerName = pPlayer->GetPlayerName();
  119. }
  120. if ( pszPlayerName && pszPlayerName[0] )
  121. {
  122. KeyValuesAD pKeyValues( "data" );
  123. pKeyValues->SetString( "player", pszPlayerName );
  124. const char *pText = NULL;
  125. switch ( iFlag )
  126. {
  127. case TF_VISION_FILTER_ROME:
  128. if ( TFGameRules() && TFGameRules()->IsMannVsMachineMode() )
  129. {
  130. pText = "#TF_Player_OptionalVision";
  131. }
  132. break;
  133. default:
  134. break;
  135. }
  136. if ( pText )
  137. {
  138. GetClientModeTFNormal()->PrintTextToChat( pText, pKeyValues );
  139. }
  140. }
  141. m_PlayersWhoHaveOfferedVision.AddToHead( unAccountID );
  142. }
  143. }
  144. //-----------------------------------------------------------------------------
  145. void C_TFSharedContentManager::OfferSharedVision_Internal( int iFlag, uint32 unAccountID )
  146. {
  147. if ( !CanOfferVision( iFlag ) )
  148. return;
  149. // If we haven't already offered it
  150. if ( ( m_iSharedVisionFlags & iFlag ) == 0 )
  151. {
  152. switch( iFlag )
  153. {
  154. case TF_VISION_FILTER_ROME:
  155. if ( !IsLocalPlayerUsingVisionFilterFlags( TF_VISION_FILTER_ROME ) && ( tf_romevision_skip_prompt.GetBool() == false ) )
  156. {
  157. PromptAcceptRomevisionSharing();
  158. }
  159. break;
  160. default:
  161. break;
  162. }
  163. AddSharedVision( iFlag );
  164. }
  165. // Display who is offering the shared vision
  166. PrintChatText( iFlag, unAccountID );
  167. }