1
0
Fork 0
Univerxel/src/server/config.hpp

58 lines
2.1 KiB
C++

#pragma once
#include <toml.h>
#include "world/Universe.hpp"
namespace config::server {
/// Server side configuration
struct options {
public:
options(toml::node_view<toml::node> config): world() {
assert(config["enabled"]);
#ifndef STANDALONE
allowLocal = config["allow_local"].value_or(allowLocal);
#else
allowLocal = false;
#endif
world.connection.host = config["connection"]["hosts"].value_or(world.connection.host);
world.connection.port = config["connection"]["port"].value_or(world.connection.port);
world.connection.key = config["connection"]["key"].value_or(world.connection.key);
world.connection.cert = config["connection"]["cert"].value_or(world.connection.cert);
world.connection.max_connections = config["max_players"].value_or(world.connection.max_connections);
world.loadDistance = config["world"]["load_distance"].value_or(world.loadDistance);
world.keepDistance = config["world"]["keep_distance"].value_or(world.keepDistance);
world.folderPath = config["world"]["path"].value_or(world.folderPath);
world.floodFillLimit = config["world"]["max_part_size"].value_or((int64_t)world.floodFillLimit);
}
toml::table save() {
return toml::table({
{"enabled", true},
#ifndef STANDALONE
{"allow_local", allowLocal},
#endif
{"connection", toml::table({
{"hosts", world.connection.host},
{"port", world.connection.port},
{"key", world.connection.key},
{"cert", world.connection.cert}
})},
{"max_players", world.connection.max_connections},
{"world", toml::table({
{"load_distance", world.loadDistance},
{"keep_distance", world.keepDistance},
{"path", world.folderPath},
{"max_part_size", (int64_t)world.floodFillLimit}
})}
});
}
/// enable SharedServerUniverse and LocalClientUniverse
bool allowLocal = true;
world::server::Universe::options world;
};
}