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.

107 lines
3.0 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. //=======================================================================================//
  4. #include "sv_recordingsessionmanager.h"
  5. #include "baserecordingsessionblock.h"
  6. #include "sv_replaycontext.h"
  7. #include "sv_recordingsession.h"
  8. #include "replaysystem.h"
  9. #include "KeyValues.h"
  10. #include "replay/replayutils.h"
  11. #include "filesystem.h"
  12. #include "iserver.h"
  13. #include "sv_filepublish.h"
  14. #include <time.h>
  15. #include "vprof.h"
  16. #include "sv_fileservercleanup.h"
  17. #include "sv_sessionrecorder.h"
  18. // memdbgon must be the last include file in a .cpp file!!!
  19. #include "tier0/memdbgon.h"
  20. //----------------------------------------------------------------------------------------
  21. #define VERSION_SERVERRECORDINGSESSIONMANAGER 0
  22. //----------------------------------------------------------------------------------------
  23. CServerRecordingSessionManager::CServerRecordingSessionManager( IReplayContext *pContext )
  24. : CBaseRecordingSessionManager( pContext ),
  25. m_flNextScheduledCleanup( 0.0f ),
  26. m_bOffload( false )
  27. {
  28. }
  29. CServerRecordingSessionManager::~CServerRecordingSessionManager()
  30. {
  31. }
  32. const char *CServerRecordingSessionManager::GetNewSessionName() const
  33. {
  34. // Setup filename for the session
  35. tm today; VCRHook_LocalTime( &today );
  36. return Replay_va(
  37. "%04i%02i%02i-%02i%02i%02i-%s",
  38. 1900 + today.tm_year, today.tm_mon+1, today.tm_mday,
  39. today.tm_hour, today.tm_min, today.tm_sec,
  40. g_pEngine->GetGameServer()->GetMapName()
  41. );
  42. }
  43. void CServerRecordingSessionManager::Think()
  44. {
  45. VPROF_BUDGET( "CServerRecordingSessionManager::Think", VPROF_BUDGETGROUP_REPLAY );
  46. BaseClass::Think();
  47. }
  48. CBaseRecordingSession *CServerRecordingSessionManager::Create()
  49. {
  50. return new CServerRecordingSession( m_pContext );
  51. }
  52. int CServerRecordingSessionManager::GetVersion() const
  53. {
  54. return VERSION_SERVERRECORDINGSESSIONMANAGER;
  55. }
  56. IReplayContext *CServerRecordingSessionManager::GetReplayContext() const
  57. {
  58. return g_pServerReplayContext;
  59. }
  60. bool CServerRecordingSessionManager::CanDeleteSession( ReplayHandle_t hSession ) const
  61. {
  62. const CBaseRecordingSession *pSession = FindSession( hSession ); AssertMsg( pSession, "The session should always be valid here!" );
  63. return !pSession->IsLocked();
  64. }
  65. void CServerRecordingSessionManager::OnAllSessionsDeleted()
  66. {
  67. SV_GetFileserverCleaner()->DoCleanAsynchronous();
  68. }
  69. CBaseRecordingSession *CServerRecordingSessionManager::OnSessionStart( int nCurrentRecordingStartTick, const char *pSessionName )
  70. {
  71. CBaseRecordingSession *pResult = BaseClass::OnSessionStart( nCurrentRecordingStartTick, pSessionName );
  72. // Cache offload state
  73. m_bOffload = false;
  74. return pResult;
  75. }
  76. void CServerRecordingSessionManager::OnSessionEnd()
  77. {
  78. BaseClass::OnSessionEnd();
  79. extern ConVar replay_fileserver_autocleanup;
  80. if ( replay_fileserver_autocleanup.GetBool() )
  81. {
  82. // Cleanup expired sessions/blocks now
  83. SV_DoFileserverCleanup( false, g_pBlockSpewer );
  84. }
  85. }
  86. //----------------------------------------------------------------------------------------