Mineserver
A rewrite of Minecraft 1.8.9 in C++ !
Loading...
Searching...
No Matches
config.h
Go to the documentation of this file.
1
12#ifndef MINESERVER_CONFIG_H
13#define MINESERVER_CONFIG_H
14
15#include <memory>
16#include <rapidjson/document.h>
17#include <types/chatmessage.h>
18#include <utils/file.h>
19#include <plugins/luaheaders.h>
20
29template <typename T>
30class Field
31{
32private:
33 T value;
34
35 inline rapidjson::Document::ConstMemberIterator canSafelyRead(const rapidjson::Document &document);
36 inline void writeSafely(rapidjson::Document &document, rapidjson::Value &v);
37
38public:
43 std::string section;
48 std::string key;
59 Field(const char *section, const char *key, T def);
64
72 void load(const rapidjson::Document &document);
79 void save(rapidjson::Document &document);
80
86 const T &getValue()
87 {
88 return value;
89 }
90
96 void setValue(T v)
97 {
98 value = v;
99 }
100
106 void registerLuaProperty(lua_State *state);
107};
108
118{
119private:
120 static Config *INSTANCE;
121
122public:
130 Config();
135 ~Config();
136
143 void save();
151 void load();
156 static void registerCommands();
157
164 Field<int> PORT = Field("network", "port", 25565);
173 Field<int> COMPRESSION_LVL = Field("network", "compression_level", -1);
180 Field<int> COMPRESSION_THRESHOLD = Field("network", "compression_threshold", 256);
188 Field<bool> ONLINE_MODE = Field("network", "online_mode", true);
197 Field<bool> PREVENT_PROXY_CONNECTIONS = Field("network", "prevent_proxy_connections", true);
205 Field<std::string> ADDRESS = Field("network", "address", std::string("127.0.0.1"));
213 Field<int> BACKLOG = Field("network", "backlog", 10);
220 Field<ChatMessage> MOTD = Field("display", "motd", ChatMessage("This is a minecraft server"));
227 Field<int> MAX_PLAYERS = Field("server", "max_players", 100);
234 Field<std::string> LOGLEVEL = Field("other", "loglevel", std::string("ALL"));
241 Field<PNGFile> ICON_FILE = Field("display", "icon_file", PNGFile("./icon.png"));
242
250#define CONFIG_FIELDS UF(PORT) UF(MOTD) UF(LOGLEVEL) UF(COMPRESSION_LVL) UF(ONLINE_MODE) UF(ADDRESS) \
251 UF(BACKLOG) UF(MAX_PLAYERS) UF(ICON_FILE) UF(PREVENT_PROXY_CONNECTIONS) UF(COMPRESSION_THRESHOLD)
252
259#define MC_VERSION_NUMBER 47
266#define MC_VERSION_NAME "Mineserver 1.8.9"
267
275 static Config *inst()
276 {
277 return INSTANCE;
278 }
279
285 void loadLuaLib(lua_State *state);
286};
287
288#endif // MINESERVER_CONFIG_H
The file containing minecraft chat message implementation.
Minecraft Chat Message implementation.
Definition chatmessage.h:28
The config class.
Definition config.h:118
Field< int > COMPRESSION_THRESHOLD
The limit size for packets before they are compressed.
Definition config.h:180
static void registerCommands()
Register config commands.
Definition config.cpp:383
Field< std::string > ADDRESS
The address to listen on.
Definition config.h:205
void loadLuaLib(lua_State *state)
Load Config fields in Lua.
Definition config.cpp:390
Field< bool > PREVENT_PROXY_CONNECTIONS
Whether to prevent proxy connections or not.
Definition config.h:197
~Config()
Destroy the Config object.
Definition config.cpp:217
Field< int > COMPRESSION_LVL
The compression level for ZLib.
Definition config.h:173
Field< int > MAX_PLAYERS
Max Players.
Definition config.h:227
Field< int > PORT
The port of the instance.
Definition config.h:164
Field< int > BACKLOG
The backlog for the server.
Definition config.h:213
Field< bool > ONLINE_MODE
The online mode flag.
Definition config.h:188
Field< ChatMessage > MOTD
The Message of the Day.
Definition config.h:220
Config()
Construct a new Config object.
Definition config.cpp:199
Field< std::string > LOGLEVEL
The Log Level.
Definition config.h:234
void load()
Loads the config from disk.
Definition config.cpp:222
void save()
Saves the config on disk.
Definition config.cpp:397
Field< PNGFile > ICON_FILE
The Icon File.
Definition config.h:241
static Config * inst()
Fetch the instance of the config.
Definition config.h:275
The Field Object for the Config.
Definition config.h:31
Field(const char *section, const char *key, T def)
Construct a new Field object.
Definition config.cpp:23
std::string section
Section of the field.
Definition config.h:43
void save(rapidjson::Document &document)
Saves value to the config.
Definition config.cpp:62
void load(const rapidjson::Document &document)
Loads the value from the config.
Definition config.cpp:55
void registerLuaProperty(lua_State *state)
Register this property in Lua.
Definition config.cpp:176
~Field()
Destroy the Field object.
void setValue(T v)
Set the Value of the field.
Definition config.h:96
std::string key
Key of the field.
Definition config.h:48
const T & getValue()
Get the Value of the field.
Definition config.h:86
Wrapper around File for PNG files.
Definition file.h:87
constexpr std::string_view type_name()
Gets the name of the type paramater.
Definition event.h:56
The file containing file (lol) loading logic.
Utility header file for lua things.