-
Notifications
You must be signed in to change notification settings - Fork 0
/
minecraft-server-properties.h
509 lines (413 loc) · 13.2 KB
/
minecraft-server-properties.h
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
// minecraft-server-properties.h
#ifndef MINECRAFT_SERVER_PROPERTIES_H
#define MINECRAFT_SERVER_PROPERTIES_H
#include <string.h>
#include <rlibrary/rstringstream.h> // gets rstream
#include <rlibrary/rdynarray.h>
namespace minecraft_controller
{
// property seen as input; this type is provided
// for the implementation to use
struct minecraft_server_input_property
{
minecraft_server_input_property();
minecraft_server_input_property(const char* pkey,const char* pvalue);
rtypes::str key;
rtypes::str value;
};
// generic property base type
template<typename T>
struct minecraft_server_property
{
minecraft_server_property(); // field is null
minecraft_server_property(const T& defaultValue); // field is default value
virtual ~minecraft_server_property();
void put(rtypes::rstream&) const;
const char* get_key() const
{ return _getKeyName(); }
const T& get_value() const
{ return _value; }
// returns false if the conversion failed; this
// flags the value as user-set
bool set_value(const rtypes::str&);
// returns true if the user explicitly specified a
// value for the property during the session
bool is_user_supplied() const
{ return !_isDefault; }
protected:
T _value;
bool _isNull; // if true, property field becomes: Key=
bool _isDefault; // this basically flags whether or not the user supplied a value explicitly for a session
virtual bool _readValue(rtypes::rstream&);
virtual void _putValue(rtypes::rstream&) const;
virtual const char* _getKeyName() const = 0; // (must be lower-case)
};
//
// base property types
typedef minecraft_server_property<bool> boolean_prop;
typedef minecraft_server_property<int> numeric_prop; // or otherwise enumerable in some way
typedef minecraft_server_property<rtypes::str> string_prop;
//
// individual property types
struct mcraft_allow_flight : boolean_prop
{
mcraft_allow_flight(): boolean_prop(false) {}
private:
virtual const char* _getKeyName() const
{ return "allow-flight"; }
};
struct mcraft_allow_nether : boolean_prop
{
mcraft_allow_nether(): boolean_prop(true) {}
private:
virtual const char* _getKeyName() const
{ return "allow-nether"; }
};
struct mcraft_announce_player_achievements : boolean_prop
{
mcraft_announce_player_achievements(): boolean_prop(true) {}
private:
virtual const char* _getKeyName() const
{ return "announce-player-achievements"; }
};
struct mcraft_broadcast_console_to_ops : boolean_prop
{
mcraft_broadcast_console_to_ops(): boolean_prop(false) {}
private:
virtual const char* _getKeyName() const
{ return "broadcast-console-to-ops"; }
};
struct mcraft_difficulty : numeric_prop
{
enum {
mcraft_difficulty_peaceful,
mcraft_difficulty_easy,
mcraft_difficulty_normal,
mcraft_difficulty_hard
};
mcraft_difficulty(): numeric_prop(mcraft_difficulty_easy) {}
private:
virtual const char* _getKeyName() const
{ return "difficulty"; }
};
struct mcraft_enable_command_block : boolean_prop
{
mcraft_enable_command_block(): boolean_prop(false) {}
private:
virtual const char* _getKeyName() const
{ return "enable-command-block"; }
};
struct mcraft_enable_query : boolean_prop
{
mcraft_enable_query(): boolean_prop(false) {}
private:
virtual const char* _getKeyName() const
{ return "enable-query"; }
};
struct mcraft_enable_rcon : boolean_prop
{
mcraft_enable_rcon(): boolean_prop(false) {}
private:
virtual const char* _getKeyName() const
{ return "enable-rcon"; }
};
struct mcraft_force_gamemode : boolean_prop
{
mcraft_force_gamemode(): boolean_prop(true) {}
private:
virtual const char* _getKeyName() const
{ return "force-gamemode"; }
};
struct mcraft_gamemode : numeric_prop
{
enum {
mcraft_gamemode_survival = 0,
mcraft_gamemode_creative = 1,
mcraft_gamemode_adventure = 2
};
mcraft_gamemode(): numeric_prop(mcraft_gamemode_survival) {}
private:
virtual const char* _getKeyName() const
{ return "gamemode"; }
};
struct mcraft_generate_structures : boolean_prop
{
mcraft_generate_structures(): boolean_prop(true) {}
private:
virtual const char* _getKeyName() const
{ return "generate-structures"; }
};
struct mcraft_generator_settings : string_prop
{
// default null
private:
virtual const char* _getKeyName() const
{ return "generator-settings"; }
};
struct mcraft_hardcore : boolean_prop
{
mcraft_hardcore(): boolean_prop(false) {}
private:
virtual const char* _getKeyName() const
{ return "hardcore"; }
};
struct mcraft_level_name : string_prop
{
mcraft_level_name(): string_prop("world") {}
private:
virtual const char* _getKeyName() const
{ return "level-name"; }
};
struct mcraft_level_seed : string_prop
{
private:
virtual const char* _getKeyName() const
{ return "level-seed"; }
};
struct mcraft_level_type : numeric_prop
{
enum {
mcraft_level_default,
mcraft_level_flat,
mcraft_level_largebiomes,
mcraft_level_amplified,
mcraft_level_customized
};
mcraft_level_type(): numeric_prop(mcraft_level_default) {}
private:
virtual bool _readValue(rtypes::rstream&);
virtual void _putValue(rtypes::rstream&) const;
virtual const char* _getKeyName() const
{ return "level-type"; }
};
struct mcraft_max_build_height : numeric_prop
{
mcraft_max_build_height(): numeric_prop(256) {}
private:
virtual const char* _getKeyName() const
{ return "max-build-height"; }
};
struct mcraft_max_players : numeric_prop
{
mcraft_max_players(): numeric_prop(20) {}
private:
virtual const char* _getKeyName() const
{ return "max-players"; }
};
struct mcraft_max_tick_time : numeric_prop
{
mcraft_max_tick_time(): numeric_prop(60000) {}
private:
virtual const char* _getKeyName() const
{ return "max-tick-time"; }
};
struct mcraft_max_world_size : numeric_prop
{
mcraft_max_world_size(): numeric_prop(29999984) {}
private:
virtual const char* _getKeyName() const
{ return "max-world-size"; }
};
struct mcraft_motd : string_prop
{
mcraft_motd(): string_prop("A Minecraft Server") {}
private:
virtual bool _readValue(rtypes::rstream&);
virtual const char* _getKeyName() const
{ return "motd"; }
};
struct mcraft_network_compression_threshold : numeric_prop
{
mcraft_network_compression_threshold(): numeric_prop(256) {}
private:
virtual const char* _getKeyName() const
{ return "network-compression-threshold"; }
};
struct mcraft_online_mode : boolean_prop
{
mcraft_online_mode(): boolean_prop(true) {}
private:
virtual const char* _getKeyName() const
{ return "online-mode"; }
};
struct mcraft_op_permission_level : numeric_prop
{
enum {
mcraft_op_level1 = 1,
mcraft_op_level2 = 2,
mcraft_op_level3 = 3,
mcraft_op_level4 = 4
};
mcraft_op_permission_level(): numeric_prop(mcraft_op_level3) {}
private:
virtual const char* _getKeyName() const
{ return "op-permission-level"; }
};
struct mcraft_player_idle_timeout : numeric_prop
{
mcraft_player_idle_timeout(): numeric_prop(20) {}
private:
virtual const char* _getKeyName() const
{ return "player-idle-timeout"; }
};
struct mcraft_prevent_proxy_connections : boolean_prop
{
mcraft_prevent_proxy_connections(): boolean_prop(true) {}
private:
virtual const char* _getKeyName() const
{ return "prevent-proxy-connections"; }
};
struct mcraft_pvp : boolean_prop
{
mcraft_pvp(): boolean_prop(true) {}
private:
virtual const char* _getKeyName() const
{ return "pvp"; }
};
struct mcraft_resource_pack : string_prop
{
private:
virtual const char* _getKeyName() const
{ return "resource-pack"; }
};
struct mcraft_resource_pack_sha1 : string_prop
{
private:
virtual const char* _getKeyName() const
{ return "resource-pack-sha1"; }
};
struct mcraft_server_ip : string_prop
{
private:
virtual const char* _getKeyName() const
{ return "server-ip"; }
};
struct mcraft_server_name : string_prop
{ // NOTE: server-name is now defunct but kept for legacy support
private:
virtual const char* _getKeyName() const
{ return "server-name"; }
};
struct mcraft_server_port : numeric_prop
{
mcraft_server_port(): numeric_prop(25565) {}
private:
virtual const char* _getKeyName() const
{ return "server-port"; }
};
struct mcraft_snooper_enabled : boolean_prop
{
mcraft_snooper_enabled(): boolean_prop(false) {}
private:
virtual const char* _getKeyName() const
{ return "snooper-enabled"; }
};
struct mcraft_spawn_animals : boolean_prop
{
mcraft_spawn_animals(): boolean_prop(true) {}
private:
virtual const char* _getKeyName() const
{ return "spawn-animals"; }
};
struct mcraft_spawn_monsters : boolean_prop
{
mcraft_spawn_monsters(): boolean_prop(true) {}
private:
virtual const char* _getKeyName() const
{ return "spawn-monsters"; }
};
struct mcraft_spawn_npcs : boolean_prop
{
mcraft_spawn_npcs(): boolean_prop(true) {}
private:
virtual const char* _getKeyName() const
{ return "spawn-npcs"; }
};
struct mcraft_spawn_protection : numeric_prop
{
mcraft_spawn_protection(): numeric_prop(16) {}
private:
virtual const char* _getKeyName() const
{ return "spawn-protection"; }
};
struct mcraft_use_native_transport : boolean_prop
{
mcraft_use_native_transport(): boolean_prop(true) {}
private:
virtual const char* _getKeyName() const
{ return "use-native-transport"; }
};
struct mcraft_view_distance : numeric_prop
{
mcraft_view_distance(): numeric_prop(10) {}
private:
virtual const char* _getKeyName() const
{ return "view-distance"; }
};
struct mcraft_white_list : boolean_prop
{
mcraft_white_list(): boolean_prop(false) {}
private:
virtual const char* _getKeyName() const
{ return "white-list"; }
};
//
// property list type
template<typename T>
class minecraft_property_generic_list
{
public:
minecraft_server_property<T>* lookup(const char* propName)
{ return reinterpret_cast<minecraft_server_property<T>*> (_lookup(propName)); }
const minecraft_server_property<T>* lookup(const char* propName) const
{ return reinterpret_cast<const minecraft_server_property<T>*> (_lookup(propName)); }
minecraft_server_property<T>* operator [](rtypes::size_type i)
{ return reinterpret_cast<minecraft_server_property<T>*>(_list[i]); }
const minecraft_server_property<T>* operator [](rtypes::size_type i) const
{ return reinterpret_cast<minecraft_server_property<T>*>(_list[i]); }
rtypes::size_type size() const
{ return _list.size(); }
protected:
~minecraft_property_generic_list();
void* _lookup(const char*);
const void* _lookup(const char*) const;
void _pushBack(minecraft_server_property<T>* pitem) // type-safe insertion
{ _list.push_back(pitem); }
private:
rtypes::dynamic_array<void*> _list;
};
class minecraft_boolean_property_list : public minecraft_property_generic_list<bool>
{
public:
minecraft_boolean_property_list();
};
class minecraft_numeric_property_list : public minecraft_property_generic_list<int>
{
public:
minecraft_numeric_property_list();
};
class minecraft_string_property_list : public minecraft_property_generic_list<rtypes::str>
{
public:
minecraft_string_property_list();
};
struct minecraft_server_property_list
{
minecraft_boolean_property_list booleanProps;
minecraft_numeric_property_list numericProps;
minecraft_string_property_list stringProps;
void read(rtypes::rstream&);
void write(rtypes::rstream&) const;
};
//
}
// include out-of-line implementation
#include "minecraft-server-properties.tcc"
#endif
/*
* Local Variables:
* mode:c++
* indent-tabs-mode:nil
* tab-width:4
* End:
*/