summaryrefslogtreecommitdiff
path: root/game/shared/motd.h
blob: 993d572e8065db18164c89c5fd8f783278cf1929 (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
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: motd: Handles a list of message of the day entries
//
//=============================================================================

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

#include "KeyValues.h"
#include "language.h"

//-----------------------------------------------------------------------------
// CMOTDEntryDefinition
//-----------------------------------------------------------------------------
class CMOTDEntryDefinition
{
public:
	CMOTDEntryDefinition( void );
	~CMOTDEntryDefinition( void ) { }

	bool	BInitFromKV( KeyValues *pKVMOTD, CUtlVector<CUtlString> *pVecErrors = NULL );

	const char	*GetName( void ) { return m_pKVMOTD ? m_pKVMOTD->GetName() : "Unknown Entry"; }
	const char	*GetTitle( ELanguage eLang );
	const char	*GetText( ELanguage eLang );
	const char	*GetURL( void ) { return m_pKVMOTD ? m_pKVMOTD->GetString("url","") : NULL; }
	const char	*GetImage( void ) { return m_pKVMOTD ? m_pKVMOTD->GetString("image","") : NULL; }
	const char	*GetPostTimeStr( void ) { return m_pKVMOTD ? m_pKVMOTD->GetString("time") : NULL; }

	const int	GetHeaderType( void ) { return m_pKVMOTD ? m_pKVMOTD->GetInt("header_type") : 0; }
	const char	*GetHeaderTitle( ELanguage eLang );
	const char	*GetHeaderIcon( void ) { return m_pKVMOTD ? m_pKVMOTD->GetString("header_icon","") : NULL; }

	// Post time is the time displayed on the client screen for this post
	const RTime32		GetPostTime( void ) const { return m_PostTime; }

	// Change time is the time at which we last changed this post. If we change wording on
	// a post, we need to know that the change should be sent to clients when they log on afterwards.
	const RTime32		GetChangedTime( void ) const { return m_ChangedTime; }

	const int	 GetNameInt ( void ) const { return m_pKVMOTD ? V_atoi( m_pKVMOTD->GetName() ) : -1; }

private:
	KeyValues	*m_pKVMOTD;
	RTime32		m_PostTime;
	RTime32		m_ChangedTime;
};



//-----------------------------------------------------------------------------
// CMOTDMgr
//-----------------------------------------------------------------------------
class CMOTDManager
{
public:
	// MOTD handling
	bool BInitMOTDEntries( KeyValues *pKVMOTDEntries, CUtlVector<CUtlString> *pVecErrors );
	int  GetNumMOTDAfter( RTime32 iTime );
	CMOTDEntryDefinition *GetNextMOTDAfter( RTime32 iTime );
	int  GetNumMOTDs( void ) { return m_vecMOTDEntries.Count(); }
	CMOTDEntryDefinition *GetMOTDByIndex( int iIndex );

	void PurgeUnusedMOTDEntries( KeyValues *pKVMOTDEntries );

private:
	// Contains the list of MOTD entries.
	CUtlVector< CMOTDEntryDefinition >	m_vecMOTDEntries;

};


#endif // MOTD_H