2020-07-23 09:49:35 +01:00
|
|
|
#include "ServerProperties.h"
|
|
|
|
#include <iostream>
|
|
|
|
#include <fstream>
|
|
|
|
#include <string_view>
|
|
|
|
#include <algorithm>
|
2020-07-24 03:46:37 +01:00
|
|
|
#include <ctime>
|
|
|
|
#include <cstring>
|
|
|
|
#include <iomanip>
|
2020-07-23 09:49:35 +01:00
|
|
|
|
|
|
|
#include "../util/StringUtil.h"
|
|
|
|
|
|
|
|
namespace Feather
|
|
|
|
{
|
2020-07-24 03:46:37 +01:00
|
|
|
void ServerProperties::Load()
|
2020-07-23 09:49:35 +01:00
|
|
|
{
|
|
|
|
std::ifstream file;
|
|
|
|
file.open(path);
|
|
|
|
|
|
|
|
printf("Reading %s...\n", path);
|
|
|
|
if (file.is_open())
|
|
|
|
{
|
|
|
|
string line;
|
|
|
|
while(std::getline(file, line))
|
|
|
|
{
|
|
|
|
// trip whitespace
|
|
|
|
StringUtil::trim(line);
|
|
|
|
|
|
|
|
// skip comments
|
|
|
|
if (line[0] == '#') continue;
|
|
|
|
|
|
|
|
// key=value
|
|
|
|
size_t pos = line.find('=');
|
|
|
|
|
|
|
|
// java also accepts key:value
|
|
|
|
if (pos == string::npos)
|
|
|
|
pos = line.find(':');
|
|
|
|
|
|
|
|
if (pos == string::npos)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
string key = line.substr(0, pos);
|
|
|
|
StringUtil::trim(key);
|
|
|
|
string value = line.substr(pos + 1);
|
|
|
|
StringUtil::trim(value);
|
|
|
|
|
|
|
|
properties.insert( {key, value} );
|
|
|
|
}
|
|
|
|
file.close();
|
|
|
|
}
|
2020-07-24 03:46:37 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
printf("Could not find %s\n");
|
|
|
|
}
|
2020-07-23 09:49:35 +01:00
|
|
|
}
|
|
|
|
|
2020-07-24 03:46:37 +01:00
|
|
|
void ServerProperties::Save()
|
2020-07-23 09:49:35 +01:00
|
|
|
{
|
2020-07-24 03:46:37 +01:00
|
|
|
std::ofstream file;
|
|
|
|
file.open(path);
|
2020-07-23 09:49:35 +01:00
|
|
|
|
2020-07-24 03:46:37 +01:00
|
|
|
file << "#Minecraft server properties" << std::endl;
|
|
|
|
|
|
|
|
auto time = std::time(nullptr);
|
|
|
|
auto localTime = *std::localtime(&time);
|
|
|
|
|
|
|
|
// The following code abbreviates a time zone like "Pacifc Daylight Time"
|
|
|
|
// to a short form like "PDT". If the time zone is already abbreviated
|
|
|
|
// then it won't change the abbreviation
|
|
|
|
|
|
|
|
char timeZone[256];
|
|
|
|
strftime(timeZone, 256, "%Z", &localTime);
|
|
|
|
|
|
|
|
char timeZoneAbbr[5];
|
|
|
|
int counter = 0;
|
|
|
|
for (int i = 0; i < strlen(timeZone); i++)
|
|
|
|
{
|
|
|
|
char c = timeZone[i];
|
|
|
|
if (std::isupper(c)) {
|
|
|
|
timeZoneAbbr[counter++] = c;
|
|
|
|
// stop before last char to insert 0
|
|
|
|
if (counter >= 4) {
|
|
|
|
timeZoneAbbr[counter] = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2020-07-23 09:49:35 +01:00
|
|
|
}
|
|
|
|
|
2020-07-24 03:46:37 +01:00
|
|
|
// Ex: Thu Jul 23 01:43:47 PDT 2020
|
|
|
|
file << "#" << std::put_time(&localTime, "%a %b %d %H:%M:%S ") << timeZoneAbbr << std::put_time(&localTime, " %Y") << std::endl;
|
2020-07-23 09:49:35 +01:00
|
|
|
|
2020-07-24 03:46:37 +01:00
|
|
|
file << onlineMode.key << "=" << onlineMode.ToString() << std::endl;
|
|
|
|
file << preventProxyConnections.key << "=" << preventProxyConnections.ToString() << std::endl;
|
|
|
|
file << serverIp.key << "=" << serverIp.ToString() << std::endl;
|
|
|
|
file << spawnAnimals.key << "=" << spawnAnimals.ToString() << std::endl;
|
|
|
|
file << spawnNpcs.key << "=" << spawnNpcs.ToString() << std::endl;
|
|
|
|
file << pvp.key << "=" << pvp.ToString() << std::endl;
|
|
|
|
file << allowFlight.key << "=" << allowFlight.ToString() << std::endl;
|
|
|
|
file << resourcePack.key << "=" << resourcePack.ToString() << std::endl;
|
|
|
|
file << motd.key << "=" << motd.ToString() << std::endl;
|
|
|
|
file << forceGameMode.key << "=" << forceGameMode.ToString() << std::endl;
|
|
|
|
file << enforceWhitelist.key << "=" << enforceWhitelist.ToString() << std::endl;
|
|
|
|
file << levelName.key << "=" << levelName.ToString() << std::endl;
|
|
|
|
file << serverPort.key << "=" << serverPort.ToString() << std::endl;
|
|
|
|
file << maxBuildHeight.key << "=" << maxBuildHeight.ToString() << std::endl;
|
|
|
|
//file << announcePlayerAchievements.key << "=" << announcePlayerAchievements.ToString() << std::endl;
|
|
|
|
file << enableQuery.key << "=" << enableQuery.ToString() << std::endl;
|
|
|
|
file << queryPort.key << "=" << queryPort.ToString() << std::endl;
|
|
|
|
file << enableRcon.key << "=" << enableRcon.ToString() << std::endl;
|
|
|
|
file << rconPort.key << "=" << rconPort.ToString() << std::endl;
|
|
|
|
file << rconPassword.key << "=" << rconPassword.ToString() << std::endl;
|
|
|
|
//file << resourcePackHash.key << "=" << resourcePackHash.ToString() << std::endl;
|
|
|
|
file << resourcePackSha1.key << "=" << resourcePackSha1.ToString() << std::endl;
|
|
|
|
file << hardcore.key << "=" << hardcore.ToString() << std::endl;
|
|
|
|
file << allowNether.key << "=" << allowNether.ToString() << std::endl;
|
|
|
|
file << spawnMonsters.key << "=" << spawnMonsters.ToString() << std::endl;
|
|
|
|
file << snooperEnabled.key << "=" << snooperEnabled.ToString() << std::endl;
|
|
|
|
file << useNativeTransport.key << "=" << useNativeTransport.ToString() << std::endl;
|
|
|
|
file << enableCommandBlock.key << "=" << enableCommandBlock.ToString() << std::endl;
|
|
|
|
file << spawnProtection.key << "=" << spawnProtection.ToString() << std::endl;
|
|
|
|
file << opPermissionLevel.key << "=" << opPermissionLevel.ToString() << std::endl;
|
|
|
|
file << functionPermissionLevel.key << "=" << functionPermissionLevel.ToString() << std::endl;
|
|
|
|
file << maxTickTime.key << "=" << maxTickTime.ToString() << std::endl;
|
|
|
|
file << viewDistance.key << "=" << viewDistance.ToString() << std::endl;
|
|
|
|
file << maxPlayers.key << "=" << maxPlayers.ToString() << std::endl;
|
|
|
|
file << networkCompressionThreshold.key << "=" << networkCompressionThreshold.ToString() << std::endl;
|
|
|
|
file << broadcastRconToOps.key << "=" << broadcastRconToOps.ToString() << std::endl;
|
|
|
|
file << broadcastConsoleToOps.key << "=" << broadcastConsoleToOps.ToString() << std::endl;
|
|
|
|
file << maxWorldSize.key << "=" << maxWorldSize.ToString() << std::endl;
|
|
|
|
file << syncChunkWrites.key << "=" << syncChunkWrites.ToString() << std::endl;
|
|
|
|
file << enableJmxMonitoring.key << "=" << enableJmxMonitoring.ToString() << std::endl;
|
|
|
|
file << enableStatus.key << "=" << enableStatus.ToString() << std::endl;
|
|
|
|
file << entityBroadcastRangePercentage.key << "=" << entityBroadcastRangePercentage.ToString() << std::endl;
|
|
|
|
file << playerIdleTimeout.key << "=" << playerIdleTimeout.ToString() << std::endl;
|
|
|
|
file << whiteList.key << "=" << whiteList.ToString() << std::endl;
|
2020-07-23 09:49:35 +01:00
|
|
|
|
2020-07-24 03:46:37 +01:00
|
|
|
file << std::endl;
|
|
|
|
file.close();
|
2020-07-23 09:49:35 +01:00
|
|
|
}
|
|
|
|
}
|