-
Notifications
You must be signed in to change notification settings - Fork 0
/
minecraft-server-properties.cpp
149 lines (142 loc) · 4.91 KB
/
minecraft-server-properties.cpp
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
// minecraft-server-properties.cpp
#include "minecraft-server-properties.h"
#include <rlibrary/rutility.h>
using namespace rtypes;
using namespace minecraft_controller;
// minecraft_controller::minecraft_server_input_property
minecraft_server_input_property::minecraft_server_input_property()
{
}
minecraft_server_input_property::minecraft_server_input_property(const char* pkey,const char* pvalue)
: key(pkey), value(pvalue)
{
}
// minecraft_controller::minecraft_server_property derivations
bool mcraft_level_type::_readValue(rstream& stream)
{
str id;
stream >> id;
rutil_to_lower_ref(id);
if (id == "flat")
_value = mcraft_level_flat;
else if (id == "largebiomes")
_value = mcraft_level_largebiomes;
else if (id == "amplified")
_value = mcraft_level_amplified;
else if (id == "customized")
_value = mcraft_level_customized;
else if (id == "default")
_value = mcraft_level_default;
else
return false;
return true;
}
void mcraft_level_type::_putValue(rstream& stream) const
{
switch ( get_value() )
{
case mcraft_level_flat:
stream << "FLAT";
break;
case mcraft_level_largebiomes:
stream << "LARGEBIOMES";
break;
case mcraft_level_amplified:
stream << "AMPLIFIED";
break;
case mcraft_level_customized:
stream << "CUSTOMIZED";
default:
stream << "DEFAULT";
break;
}
}
bool mcraft_motd::_readValue(rstream& stream)
{
stream.getline(_value);
return _value.length() > 0;
}
// minecraft_controller::minecraft_server_generic_property_list derivations
minecraft_boolean_property_list::minecraft_boolean_property_list()
{
_pushBack( new mcraft_allow_flight );
_pushBack( new mcraft_allow_nether );
_pushBack( new mcraft_announce_player_achievements );
_pushBack( new mcraft_broadcast_console_to_ops );
_pushBack( new mcraft_enable_query );
_pushBack( new mcraft_enable_rcon );
_pushBack( new mcraft_enable_command_block );
_pushBack( new mcraft_force_gamemode );
_pushBack( new mcraft_generate_structures );
_pushBack( new mcraft_hardcore );
_pushBack( new mcraft_online_mode );
_pushBack( new mcraft_prevent_proxy_connections );
_pushBack( new mcraft_pvp );
_pushBack( new mcraft_snooper_enabled );
_pushBack( new mcraft_spawn_animals );
_pushBack( new mcraft_spawn_monsters );
_pushBack( new mcraft_spawn_npcs );
_pushBack( new mcraft_use_native_transport );
_pushBack( new mcraft_white_list );
}
minecraft_numeric_property_list::minecraft_numeric_property_list()
{
_pushBack( new mcraft_difficulty );
_pushBack( new mcraft_gamemode );
_pushBack( new mcraft_level_type );
_pushBack( new mcraft_max_build_height );
_pushBack( new mcraft_max_players );
_pushBack( new mcraft_max_tick_time );
_pushBack( new mcraft_max_world_size );
_pushBack( new mcraft_network_compression_threshold );
_pushBack( new mcraft_op_permission_level );
_pushBack( new mcraft_player_idle_timeout );
_pushBack( new mcraft_server_port );
_pushBack( new mcraft_spawn_protection );
_pushBack( new mcraft_view_distance );
}
minecraft_string_property_list::minecraft_string_property_list()
{
_pushBack( new mcraft_generator_settings );
_pushBack( new mcraft_level_seed );
_pushBack( new mcraft_motd );
_pushBack( new mcraft_resource_pack );
_pushBack( new mcraft_resource_pack_sha1 );
_pushBack( new mcraft_server_ip );
_pushBack( new mcraft_server_name );
}
// minecraft_controller::minecraft_server_property_list
void minecraft_server_property_list::read(rstream& input)
{
stringstream lineInput;
lineInput.delimit_whitespace(false);
lineInput.add_extra_delimiter("=\n");
while ( input.has_input() ) {
str key, value;
lineInput.clear();
input.getline( lineInput.get_device() );
lineInput >> key >> value;
if (key.length() > 0) {
// check each type of property; if not found then strip
// from the properties list
minecraft_server_property<bool>* bprop;
minecraft_server_property<int>* iprop;
minecraft_server_property<str>* sprop;
if ((bprop = booleanProps.lookup(key.c_str())) != NULL)
bprop->set_value(value);
else if ((iprop = numericProps.lookup(key.c_str())) != NULL)
iprop->set_value(value);
else if ((sprop = stringProps.lookup(key.c_str())) != NULL)
sprop->set_value(value);
}
}
}
void minecraft_server_property_list::write(rstream& output) const
{
for (size_type i = 0;i<booleanProps.size();i++)
booleanProps[i]->put(output), output << newline;
for (size_type i = 0;i<numericProps.size();i++)
numericProps[i]->put(output), output << newline;
for (size_type i = 0;i<stringProps.size();i++)
stringProps[i]->put(output), output << newline;
}