Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
blob: acb6f89de9a62f9cb156f3ed1066f18596d1f159 (plain)
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*
   core/cvar.h
   This file is part of the Osirion project and is distributed under
   the terms of the GNU General Public License version 2
*/

#ifndef __INCLUDED_CORE_CVAR_H__
#define __INCLUDED_CORE_CVAR_H__

#include <string>
#include <map>

namespace core
{

/// a variable encapsulation class
class Cvar
{
public:
	/// Cvar flags
	/**
	 * Archive	a cvar with this flag will be saved to the configuration file
	 * ReadOnly	the value of cvar with this flag can not be altered from the commandline
	 * Game		a cvar with this flag is only valid when a game is loaded
	 * Info		a cvar that updates player info
	 */
	enum Flags {Archive=1, ReadOnly=2, Game=4, Info=8};
	
	/// create a new variable
	Cvar(const char *name, const unsigned int flags = 0);

/*----- inspectors ------------------------------------------------ */

	/// returns the name of the variable
	inline std::string const &name() { return cvar_name; }

	/// returns the info of the variable
	inline std::string const &info() { return cvar_info; }

	/// returns the flags of the variable
	inline unsigned int flags() const { return cvar_flags; }

	/// returns the float value of the variable
	inline float value() const { return cvar_value; }

	/// returns the string value of the variable
	inline const std::string &str() const { return cvar_str; }

/*----- mutators -------------------------------------------------- */

	/// set the info string
	void set_info(const char *);

	/// char * assignment operator 
	Cvar &operator=(const char *other);

	/// std::string assignment operator
	Cvar &operator=(const std::string &other);

	/// float assignment operator
	Cvar &operator=(float other);

/* ---- Static functions for the Cvar registry -------------------- */

	/// type definition for the Cvar registry
	typedef std::map<std::string, Cvar*> Registry;
	
	/// get a cvar value from the registry
	/** If the a cvar with the given name already exists in the registry,
 	*  its value will not be changed. If the cvar does not exist,
 	*  it will be created
 	*/
	static Cvar *get(const char *name, const char *value, const unsigned int flags=0);

	/// get a cvar value from the registry
	/** If the a cvar with the given name already exists in the registry,
 	*  its value will not be changed. If the cvar does not exist,
 	*  it will be created
 	*/
	static Cvar *get(const char *name, float value, const unsigned int flags=0);

	/// set a cvar value
	/** If the a cvar with the given name already exists in the registry,
 	* its value will be replaced
 	*/
	static Cvar *set(const char *name, const char *value, const unsigned int flags=0);

	/// set a cvar value
	/** If the a cvar with the given name already exists in the registry,
 	* its value will be replaced
 	*/
	static Cvar *set(const char *name, float value, const unsigned int flags=0);

	/// delete a cvar from the registry
	static void unset(const char *name);

	/// delete a cvar from the registry
	static void unset(std::string const &name);

	/// search for a named cvar, returns 0 if not found
	static Cvar *find(std::string const &name);

	/// search for a named cvar, returns 0 if not found
	static Cvar *find(const char *name);

	/// list the cvar registry
	static void list();

	/// the Cvar registry
	static inline Registry & registry() { return cvar_registry; }

	static Cvar		*sv_dedicated;	// dedicated server
	static Cvar		*sv_private;	// client with private server
	static Cvar		*sv_framerate;	// server framerate
	static Cvar		*sv_name;	// server name

	static Cvar		*con_ansi;	// console ANSI colors

	static Cvar		*cl_prediction;	// client prediction

	static Cvar		*net_host;	// network server ip (default binds to all interfaces)
	static Cvar		*net_port;	// network port
	static Cvar		*net_maxclients;// maximum number of connected clients
	static Cvar		*net_timeout;	// network timeout in seconds
	static Cvar		*net_framerate;	// client network send framerate

	static Cvar		*rconpassword;	// rcon password

private:
	std::string		cvar_name;
	std::string		cvar_info;
	std::string 		cvar_str;

	unsigned int 		cvar_flags;
	float 			cvar_value;

	static Registry		cvar_registry;

};

}

#endif // __INCLUDED_CORE_CVAR_H__