summaryrefslogtreecommitdiff
path: root/replay/cl_recordingsessionblock.h
blob: 1f60330c1ac6a6b49af0485e26c9914cf7813df7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
//========= Copyright Valve Corporation, All rights reserved. ============//
//
//=======================================================================================//

#ifndef CL_RECORDINGSESSIONBLOCK_H
#define CL_RECORDINGSESSIONBLOCK_H
#ifdef _WIN32
#pragma once
#endif

//----------------------------------------------------------------------------------------

#include "baserecordingsessionblock.h"
#include "engine/http.h"

//----------------------------------------------------------------------------------------

class CClientRecordingSessionBlock : public CBaseRecordingSessionBlock
{
	typedef CBaseRecordingSessionBlock BaseClass;

public:
	CClientRecordingSessionBlock( IReplayContext *pContext );

	bool			NeedsUpdate() const;
	bool			ShouldDownloadNow() const;
	bool			DownloadedSuccessfully() const;

	int				GetNumDownloadAttempts() const		{ return m_nDownloadAttempts; }

	virtual bool	Read( KeyValues *pIn );
	virtual void	Write( KeyValues *pOut );
	virtual void	OnDelete();

	// Resets the download status to be "ready for download" if the # of download attempts
	// is under 3.  Returns false if reset failed, otherwise true.
	bool			AttemptToResetForDownload();

	// Checks data against the block's md5 digest
	bool			ValidateData( const void *pData, int nSize, unsigned char *pOutHash = NULL ) const;

	enum DownloadStatus_t
	{
		DOWNLOADSTATUS_ABORTED,			// Download was aborted for some reason
		DOWNLOADSTATUS_ERROR,			// Refer to m_nError for more detail
		DOWNLOADSTATUS_WAITING,			// Waiting for the file to be ready on the server
		DOWNLOADSTATUS_READYTODOWNLOAD,	// File is ready to be downloaded
		DOWNLOADSTATUS_CONNECTING,		// Connecting to file server
		DOWNLOADSTATUS_DOWNLOADING,		// Currently downloading
		DOWNLOADSTATUS_DOWNLOADED,		// Successfully downloaded file
		
		MAX_DOWNLOADSTATUS
	};

	// Persistent:
	DownloadStatus_t	m_nDownloadStatus;
	uint32				m_uBytesDownloaded;
	bool				m_bDataInvalid;		// Hash didn't match data?
	HTTPError_t			m_nHttpError;

private:
	// Non-persistent:
	int					m_nDownloadAttempts;		// Should be modified via AttemptToResetForDownload()
};

//----------------------------------------------------------------------------------------

inline CClientRecordingSessionBlock *CL_CastBlock( IReplaySerializeable *pBlock )
{
	return static_cast< CClientRecordingSessionBlock * >( pBlock );
}

inline const CClientRecordingSessionBlock *CL_CastBlock( const IReplaySerializeable *pBlock )
{
	return static_cast< const CClientRecordingSessionBlock * >( pBlock );
}

//----------------------------------------------------------------------------------------

#endif // CL_RECORDINGSESSIONBLOCK_H