FeatherMC/src/config/ServerProperties.h

128 lines
7.3 KiB
C++

#pragma once
#include "Properties.h"
#include "Property.h"
#include <iostream>
#include <string>
#include <string_view>
#include <unordered_map>
#include <algorithm>
using std::string;
using std::string_view;
using std::unordered_map;
namespace Feather::Config
{
class ServerProperties : public Properties
{
public:
Property<bool> onlineMode = Property<bool>("online-mode", true);
Property<bool> preventProxyConnections = Property<bool>("prevent-proxy-connections", false);
Property<string> serverIp = Property<string>("server-ip", "");
Property<bool> spawnAnimals = Property<bool>("spawn-animals", true);
Property<bool> spawnNpcs = Property<bool>("spawn-npcs", true);
Property<bool> pvp = Property<bool>("pvp", true);
Property<bool> allowFlight = Property<bool>("allow-flight", false);
Property<string> resourcePack = Property<string>("resource-pack", "");
Property<string> motd = Property<string>("motd", "A Minecraft Server");
Property<bool> forceGameMode = Property<bool>("force-gamemode", false);
Property<bool> enforceWhitelist = Property<bool>("enforce-whitelist", false);
//Property<Difficulty> difficulty = Property<Difficulty>("difficulty", DedicatedServerProperties.dispatchNumberOrString(Difficulty::byId, Difficulty::byName), Difficulty::getKey, Difficulty.EASY);
//Property<GameType> gamemode = Property<GameType>("gamemode", DedicatedServerProperties.dispatchNumberOrString(GameType::byId, GameType::byName), GameType::getName, GameType.SURVIVAL);
Property<string> levelName = Property<string>("level-name", "world");
Property<int> serverPort = Property<int>("server-port", 25565);
Property<int> maxBuildHeight = Property<int>("max-build-height", [](int n) { return std::clamp((n + 8) / 16 * 16, 64, 256); }, 256); // round to nearest 16, clamp to range [64, 256]
// (REMOVED) Property<bool> announcePlayerAchievements = Property<bool>("announce-player-achievements");
Property<bool> enableQuery = Property<bool>("enable-query", false);
Property<int> queryPort = Property<int>("query.port", 25565);
Property<bool> enableRcon = Property<bool>("enable-rcon", false);
Property<int> rconPort = Property<int>("rcon.port", 25575);
Property<string> rconPassword = Property<string>("rcon.password", "");
// (REMOVED) Property<string> resourcePackHash = Property<string>("resource-pack-hash");
Property<string> resourcePackSha1 = Property<string>("resource-pack-sha1", "");
Property<bool> hardcore = Property<bool>("hardcore", false);
Property<bool> allowNether = Property<bool>("allow-nether", true);
Property<bool> spawnMonsters = Property<bool>("spawn-monsters", true);
Property<bool> snooperEnabled = Property<bool>("snooper-enabled", true);
Property<bool> useNativeTransport = Property<bool>("use-native-transport", true);
Property<bool> enableCommandBlock = Property<bool>("enable-command-block", false);
Property<int> spawnProtection = Property<int>("spawn-protection", 16);
Property<int> opPermissionLevel = Property<int>("op-permission-level", 4);
Property<int> functionPermissionLevel = Property<int>("function-permission-level", 2);
Property<long> maxTickTime = Property<long>("max-tick-time");//, TimeUnit.MINUTES.toMillis(1L));
Property<int> viewDistance = Property<int>("view-distance", 10);
Property<int> maxPlayers = Property<int>("max-players", 20);
Property<int> networkCompressionThreshold = Property<int>("network-compression-threshold", 256);
Property<bool> broadcastRconToOps = Property<bool>("broadcast-rcon-to-ops", true);
Property<bool> broadcastConsoleToOps = Property<bool>("broadcast-console-to-ops", true);
Property<int> maxWorldSize = Property<int>("max-world-size", [](int n) { return std::clamp(n, 1, 29999984); }, 29999984);
Property<bool> syncChunkWrites = Property<bool>("sync-chunk-writes", true);
Property<bool> enableJmxMonitoring = Property<bool>("enable-jmx-monitoring", false);
Property<bool> enableStatus = Property<bool>("enable-status", true);
Property<int> entityBroadcastRangePercentage = Property<int>("entity-broadcast-range-percentage", [](int n) { return std::clamp(n, 10, 1000); }, 100);
/*mutable*/ Property<int> playerIdleTimeout = Property<int>("player-idle-timeout", 0);
/*mutable*/ Property<bool> whiteList = Property<bool>("white-list", false);
//Property<WorldGenSettings> worldGenSettings = WorldGenSettings.create(properties);
ServerProperties(const char* path) : path(path)
{
Load();
onlineMode.Init(this);
preventProxyConnections.Init(this);
serverIp.Init(this);
spawnAnimals.Init(this);
spawnNpcs.Init(this);
pvp.Init(this);
allowFlight.Init(this);
resourcePack.Init(this);
motd.Init(this);
forceGameMode.Init(this);
enforceWhitelist.Init(this);
levelName.Init(this);
serverPort.Init(this);
maxBuildHeight.Init(this);
//announcePlayerAchievements.Init(this);
enableQuery.Init(this);
queryPort.Init(this);
enableRcon.Init(this);
rconPort.Init(this);
rconPassword.Init(this);
//resourcePackHash.Init(this);
resourcePackSha1.Init(this);
hardcore.Init(this);
allowNether.Init(this);
spawnMonsters.Init(this);
snooperEnabled.Init(this);
useNativeTransport.Init(this);
enableCommandBlock.Init(this);
spawnProtection.Init(this);
opPermissionLevel.Init(this);
functionPermissionLevel.Init(this);
maxTickTime.Init(this);
viewDistance.Init(this);
maxPlayers.Init(this);
networkCompressionThreshold.Init(this);
broadcastRconToOps.Init(this);
broadcastConsoleToOps.Init(this);
maxWorldSize.Init(this);
syncChunkWrites.Init(this);
enableJmxMonitoring.Init(this);
enableStatus.Init(this);
entityBroadcastRangePercentage.Init(this);
playerIdleTimeout.Init(this);
whiteList.Init(this);
}
void Load();
void Save();
private:
const char* path;
};
}