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

71 lines
2.6 KiB
C++

#pragma once
#include "core/utils/toml.hpp"
#include "./world/Universe.hpp"
#include "core/net/protocol.hpp"
namespace config::server {
/// Server side configuration
struct options {
public:
options(toml::node_view<toml::node> config): world() {
assert(config["enabled"] && "probably a broken config file");
#ifndef STANDALONE_SERVER
allowLocal = config["allow_local"].value_or(allowLocal);
#else
allowLocal = false;
#endif
connection.host = config["connection"]["hosts"].value_or(connection.host);
connection.port = config["connection"]["port"].value_or(connection.port);
connection.key = config["connection"]["key"].value_or(connection.key);
connection.cert = config["connection"]["cert"].value_or(connection.cert);
connection.max_connections = config["max_players"].value_or(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);
world.randomTick = config["clock"]["random_tick"].value_or(world.randomTick);
tps = config["clock"]["tick_per_second"].value_or(tps);
upt = config["clock"]["update_per_tick"].value_or(upt);
}
toml::table save() {
return toml::table({
{"enabled", true},
#ifndef STANDALONE_SERVER
{"allow_local", allowLocal},
#endif
{"connection", toml::table({
{"hosts", connection.host},
{"port", connection.port},
{"key", connection.key},
{"cert", connection.cert}
})},
{"max_players", connection.max_connections},
{"world", toml::table({
{"load_distance", world.loadDistance},
{"keep_distance", world.keepDistance},
{"path", world.folderPath},
{"max_part_size", (int64_t)world.floodFillLimit}
})},
{"clock", toml::table({
{"tick_per_second", tps},
{"update_per_tick", upt},
{"random_tick", world.randomTick}
})}
});
}
bool allowLocal = true;
world::server::Universe::options world;
net::exposure connection = net::exposure{"", 4242, 0, "content/key.pem", "content/cert.pem"};
/// Ticks per second
uint tps = 10;
/// Physics update per tick
uint upt = 4;
};
}