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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
|
/*
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
{
/**
* @brief a client variable encapsulation class
* values f client variables can be set through the command console interface
*/
class Cvar
{
public:
/**
* @brief 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 const std::string& name() const {
return cvar_name;
}
/// returns the info of the variable
inline const std::string& info() const {
return cvar_info;
}
/// returns the flags of the variable
inline const unsigned int flags() const {
return cvar_flags;
}
/// returns the float value of the variable
inline const 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* info);
/// std::string assignment
void assign(const std::string& other);
/// char * assignment
void assign(const char* other);
/// float assignment
void assign(const float other);
/// std::string assignment operator
inline Cvar & operator=(const std::string& other)
{
assign(other);
return (*this);
}
/// char * assignment operator
inline Cvar & operator=(const char* other)
{
assign(other);
return (*this);
}
/// float assignment operator
inline Cvar & operator=(const float other)
{
assign(other);
return (*this);
}
/* ---- Static functions for the Cvar registry -------------------- */
/// type definition for the Cvar registry
typedef std::map<std::string, Cvar*> Registry;
/**
* @brief 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);
/**
* @brief 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 float value, const unsigned int flags = 0);
/**
* @brief 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);
/**
* @brief 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 float value, const unsigned int flags = 0);
/// search for a named cvar, returns 0 if not found
static Cvar* find(const std::string& name);
/// search for a named cvar, returns 0 if not found
static Cvar* find(const char* name);
/// delete a cvar from the registry
static void unset(const char* name);
/// delete a cvar from the registry
static void unset(const std::string& 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 *sv_description; // server description
static Cvar *sv_password; // server rcon password
static Cvar *sv_arraysize; // vertex array size in MegaBytes
static Cvar *sv_keepalive; // entity keepalive timeout
static Cvar *con_ansi; // console ANSI colors
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
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__
|