Merge pull request #1388 from DarkflameUniverse/fix--make-all-settings-have-sane-defaults-where-possible

fix: don't crash if some configs values aren't present
This commit is contained in:
Gie "Max" Vanommeslaeghe 2024-01-05 11:34:50 +01:00 committed by GitHub
commit 66ac5a1b7a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 65 additions and 72 deletions

View File

@ -83,12 +83,15 @@ int main(int argc, char** argv) {
Game::randomEngine = std::mt19937(time(0)); Game::randomEngine = std::mt19937(time(0));
//It's safe to pass 'localhost' here, as the IP is only used as the external IP. //It's safe to pass 'localhost' here, as the IP is only used as the external IP.
uint32_t maxClients = 50; uint32_t maxClients = 999;
uint32_t ourPort = 1001; //LU client is hardcoded to use this for auth port, so I'm making it the default. uint32_t ourPort = 1001; //LU client is hardcoded to use this for auth port, so I'm making it the default.
if (Game::config->GetValue("max_clients") != "") maxClients = std::stoi(Game::config->GetValue("max_clients")); std::string ourIP = "localhost";
if (Game::config->GetValue("auth_server_port") != "") ourPort = std::atoi(Game::config->GetValue("auth_server_port").c_str()); GeneralUtils::TryParse(Game::config->GetValue("max_clients"), maxClients);
GeneralUtils::TryParse(Game::config->GetValue("auth_server_port"), ourPort);
const auto externalIPString = Game::config->GetValue("external_ip");
if (!externalIPString.empty()) ourIP = externalIPString;
Game::server = new dServer(Game::config->GetValue("external_ip"), ourPort, 0, maxClients, false, true, Game::logger, masterIP, masterPort, ServerType::Auth, Game::config, &Game::lastSignal); Game::server = new dServer(ourIP, ourPort, 0, maxClients, false, true, Game::logger, masterIP, masterPort, ServerType::Auth, Game::config, &Game::lastSignal);
//Run it until server gets a kill message from Master: //Run it until server gets a kill message from Master:
auto t = std::chrono::high_resolution_clock::now(); auto t = std::chrono::high_resolution_clock::now();

View File

@ -99,14 +99,19 @@ int main(int argc, char** argv) {
masterPort = masterInfo->port; masterPort = masterInfo->port;
} }
//It's safe to pass 'localhost' here, as the IP is only used as the external IP. //It's safe to pass 'localhost' here, as the IP is only used as the external IP.
uint32_t maxClients = 50; uint32_t maxClients = 999;
uint32_t ourPort = 1501; uint32_t ourPort = 1501;
if (Game::config->GetValue("max_clients") != "") maxClients = std::stoi(Game::config->GetValue("max_clients")); std::string ourIP = "localhost";
if (Game::config->GetValue("chat_server_port") != "") ourPort = std::atoi(Game::config->GetValue("chat_server_port").c_str()); GeneralUtils::TryParse(Game::config->GetValue("max_clients"), maxClients);
GeneralUtils::TryParse(Game::config->GetValue("chat_server_port"), ourPort);
const auto externalIPString = Game::config->GetValue("external_ip");
if (!externalIPString.empty()) ourIP = externalIPString;
Game::server = new dServer(Game::config->GetValue("external_ip"), ourPort, 0, maxClients, false, true, Game::logger, masterIP, masterPort, ServerType::Chat, Game::config, &Game::lastSignal); Game::server = new dServer(ourIP, ourPort, 0, maxClients, false, true, Game::logger, masterIP, masterPort, ServerType::Chat, Game::config, &Game::lastSignal);
Game::chatFilter = new dChatFilter(Game::assetManager->GetResPath().string() + "/chatplus_en_us", bool(std::stoi(Game::config->GetValue("dont_generate_dcf")))); bool dontGenerateDCF = false;
GeneralUtils::TryParse(Game::config->GetValue("dont_generate_dcf"), dontGenerateDCF);
Game::chatFilter = new dChatFilter(Game::assetManager->GetResPath().string() + "/chatplus_en_us", dontGenerateDCF);
Game::randomEngine = std::mt19937(time(0)); Game::randomEngine = std::mt19937(time(0));

View File

@ -17,7 +17,7 @@
InstanceManager::InstanceManager(Logger* logger, const std::string& externalIP) { InstanceManager::InstanceManager(Logger* logger, const std::string& externalIP) {
mLogger = logger; mLogger = logger;
mExternalIP = externalIP; mExternalIP = externalIP;
m_LastPort = std::atoi(Game::config->GetValue("world_port_start").c_str()); GeneralUtils::TryParse(Game::config->GetValue("world_port_start"), m_LastPort);
m_LastInstanceID = LWOINSTANCEID_INVALID; m_LastInstanceID = LWOINSTANCEID_INVALID;
} }

View File

@ -134,7 +134,7 @@ private:
Logger* mLogger; Logger* mLogger;
std::string mExternalIP; std::string mExternalIP;
std::vector<Instance*> m_Instances; std::vector<Instance*> m_Instances;
unsigned short m_LastPort; unsigned short m_LastPort = 3000;
LWOINSTANCEID m_LastInstanceID; LWOINSTANCEID m_LastInstanceID;
/** /**

View File

@ -81,45 +81,21 @@ int main(int argc, char** argv) {
Game::logger = SetupLogger(); Game::logger = SetupLogger();
if (!Game::logger) return EXIT_FAILURE; if (!Game::logger) return EXIT_FAILURE;
if (!dConfig::Exists("authconfig.ini")) { if (!dConfig::Exists("authconfig.ini")) LOG("Could not find authconfig.ini, using default settings");
LOG("Couldnt find authconfig.ini"); if (!dConfig::Exists("chatconfig.ini")) LOG("Could not find chatconfig.ini, using default settings");
return EXIT_FAILURE; if (!dConfig::Exists("masterconfig.ini")) LOG("Could not find masterconfig.ini, using default settings");
} if (!dConfig::Exists("sharedconfig.ini")) LOG("Could not find sharedconfig.ini, using default settings");
if (!dConfig::Exists("worldconfig.ini")) LOG("Could not find worldconfig.ini, using default settings");
if (!dConfig::Exists("chatconfig.ini")) {
LOG("Couldnt find chatconfig.ini");
return EXIT_FAILURE;
}
if (!dConfig::Exists("masterconfig.ini")) {
LOG("Couldnt find masterconfig.ini");
return EXIT_FAILURE;
}
if (!dConfig::Exists("sharedconfig.ini")) {
LOG("Couldnt find sharedconfig.ini");
return EXIT_FAILURE;
}
if (!dConfig::Exists("worldconfig.ini")) {
LOG("Couldnt find worldconfig.ini");
return EXIT_FAILURE;
}
Game::config = new dConfig("masterconfig.ini"); Game::config = new dConfig("masterconfig.ini");
Game::logger->SetLogToConsole(Game::config->GetValue("log_to_console") != "0"); Game::logger->SetLogToConsole(Game::config->GetValue("log_to_console") != "0");
Game::logger->SetLogDebugStatements(Game::config->GetValue("log_debug_statements") == "1"); Game::logger->SetLogDebugStatements(Game::config->GetValue("log_debug_statements") == "1");
uint32_t clientNetVersion = 0; uint32_t clientNetVersion = 171022;
if (!GeneralUtils::TryParse(Game::config->GetValue("client_net_version"), clientNetVersion)) { const auto clientNetVersionString = Game::config->GetValue("client_net_version");
LOG("Failed to parse (%s) as net version. Cannot start server as no clients could connect.",Game::config->GetValue("client_net_version").c_str()); if (!clientNetVersionString.empty()) GeneralUtils::TryParse(clientNetVersionString, clientNetVersion);
LOG("As of version 1.1.1, client_net_version is required to be defined in sharedconfig.ini as opposed to in CMakeVariables.txt as NET_VERSION.");
LOG("Rerun cmake to ensure all config values exist. If client_net_version already exists in sharedconfig.ini, please ensure it is a valid number.");
LOG("like 171022");
return EXIT_FAILURE;
}
LOG("Using net version %s", Game::config->GetValue("client_net_version").c_str()); LOG("Using net version %i", clientNetVersion);
LOG("Starting Master server..."); LOG("Starting Master server...");
LOG("Version: %s", PROJECT_VERSION); LOG("Version: %s", PROJECT_VERSION);
@ -292,19 +268,22 @@ int main(int argc, char** argv) {
Game::randomEngine = std::mt19937(time(0)); Game::randomEngine = std::mt19937(time(0));
uint32_t maxClients = 999; uint32_t maxClients = 999;
uint32_t ourPort = 1000; uint32_t ourPort = 2000;
if (Game::config->GetValue("max_clients") != "") maxClients = std::stoi(Game::config->GetValue("max_clients")); std::string ourIP = "localhost";
if (Game::config->GetValue("master_server_port") != "") ourPort = std::stoi(Game::config->GetValue("master_server_port")); const auto maxClientsString = Game::config->GetValue("max_clients");
if (!maxClientsString.empty()) maxClients = std::stoi(maxClientsString);
const auto masterServerPortString = Game::config->GetValue("master_server_port");
if (!masterServerPortString.empty()) ourPort = std::atoi(masterServerPortString.c_str());
const auto externalIPString = Game::config->GetValue("external_ip");
if (!externalIPString.empty()) ourIP = externalIPString;
Game::server = new dServer(Game::config->GetValue("external_ip"), ourPort, 0, maxClients, true, false, Game::logger, "", 0, ServerType::Master, Game::config, &Game::lastSignal); Game::server = new dServer(ourIP, ourPort, 0, maxClients, true, false, Game::logger, "", 0, ServerType::Master, Game::config, &Game::lastSignal);
//Query for the database for a server labeled "master" std::string master_server_ip = "localhost";
const auto masterServerIPString = Game::config->GetValue("master_ip");
if (!masterServerIPString.empty()) master_server_ip = masterServerIPString;
auto master_server_ip = Game::config->GetValue("master_ip"); if (master_server_ip == "") master_server_ip = Game::server->GetIP();
if (master_server_ip == "") {
master_server_ip = Game::server->GetIP();
}
Database::Get()->SetMasterIp(master_server_ip, Game::server->GetPort()); Database::Get()->SetMasterIp(master_server_ip, Game::server->GetPort());
@ -313,7 +292,7 @@ int main(int argc, char** argv) {
Game::im = new InstanceManager(Game::logger, Game::server->GetIP()); Game::im = new InstanceManager(Game::logger, Game::server->GetIP());
//Depending on the config, start up servers: //Depending on the config, start up servers:
if (Game::config->GetValue("prestart_servers") != "" && Game::config->GetValue("prestart_servers") == "1") { if (Game::config->GetValue("prestart_servers") != "0") {
StartChatServer(); StartChatServer();
Game::im->GetInstance(0, false, 0); Game::im->GetInstance(0, false, 0);

View File

@ -54,14 +54,12 @@ void AuthPackets::HandleHandshake(dServer* server, Packet* packet) {
void AuthPackets::SendHandshake(dServer* server, const SystemAddress& sysAddr, const std::string& nextServerIP, uint16_t nextServerPort, const ServerType serverType) { void AuthPackets::SendHandshake(dServer* server, const SystemAddress& sysAddr, const std::string& nextServerIP, uint16_t nextServerPort, const ServerType serverType) {
RakNet::BitStream bitStream; RakNet::BitStream bitStream;
BitStreamUtils::WriteHeader(bitStream, eConnectionType::SERVER, eServerMessageType::VERSION_CONFIRM); BitStreamUtils::WriteHeader(bitStream, eConnectionType::SERVER, eServerMessageType::VERSION_CONFIRM);
uint32_t netVersion;
const std::string& expectedVersion = Game::config->GetValue("client_net_version"); uint32_t clientNetVersion = 171022;
LOG("Expected Version: '%s'", expectedVersion.c_str()); const auto clientNetVersionString = Game::config->GetValue("client_net_version");
if (!GeneralUtils::TryParse(expectedVersion, netVersion)) { if (!clientNetVersionString.empty()) GeneralUtils::TryParse(clientNetVersionString, clientNetVersion);
LOG("Failed to parse client_net_version. Cannot authenticate to %s:%i", nextServerIP.c_str(), nextServerPort);
return; bitStream.Write<uint32_t>(clientNetVersion);
}
bitStream.Write<uint32_t>(netVersion);
bitStream.Write<uint32_t>(0x93); bitStream.Write<uint32_t>(0x93);
if (serverType == ServerType::Auth) bitStream.Write(uint32_t(1)); //Conn: auth if (serverType == ServerType::Auth) bitStream.Write(uint32_t(1)); //Conn: auth
@ -95,7 +93,6 @@ void AuthPackets::HandleLoginRequest(dServer* server, Packet* packet) {
} }
if (Game::config->GetValue("dont_use_keys") != "1" && accountInfo->maxGmLevel == eGameMasterLevel::CIVILIAN) { if (Game::config->GetValue("dont_use_keys") != "1" && accountInfo->maxGmLevel == eGameMasterLevel::CIVILIAN) {
LOG("");
//Check to see if we have a play key: //Check to see if we have a play key:
if (accountInfo->playKeyId == 0) { if (accountInfo->playKeyId == 0) {
AuthPackets::SendLoginResponse(server, packet->systemAddress, eLoginResponse::PERMISSIONS_NOT_HIGH_ENOUGH, "Your account doesn't have a play key associated with it!", "", 2001, username); AuthPackets::SendLoginResponse(server, packet->systemAddress, eLoginResponse::PERMISSIONS_NOT_HIGH_ENOUGH, "Your account doesn't have a play key associated with it!", "", 2001, username);

View File

@ -14,6 +14,7 @@
#include "BitStreamUtils.h" #include "BitStreamUtils.h"
#include "MasterPackets.h" #include "MasterPackets.h"
#include "ZoneInstanceManager.h" #include "ZoneInstanceManager.h"
#include "StringifiedEnum.h"
//! Replica Constructor class //! Replica Constructor class
class ReplicaConstructor : public ReceiveConstructionInterface { class ReplicaConstructor : public ReceiveConstructionInterface {
@ -65,9 +66,9 @@ dServer::dServer(const std::string& ip, int port, int instanceID, int maxConnect
if (mIsOkay) { if (mIsOkay) {
if (zoneID == 0) if (zoneID == 0)
LOG("Server is listening on %s:%i with encryption: %i", ip.c_str(), port, int(useEncryption)); LOG("%s Server is listening on %s:%i with encryption: %i", StringifiedEnum::ToString(serverType).data(), ip.c_str(), port, int(useEncryption));
else else
LOG("Server is listening on %s:%i with encryption: %i, running zone %i / %i", ip.c_str(), port, int(useEncryption), zoneID, instanceID); LOG("%s Server is listening on %s:%i with encryption: %i, running zone %i / %i", StringifiedEnum::ToString(serverType).data(), ip.c_str(), port, int(useEncryption), zoneID, instanceID);
} else { LOG("FAILED TO START SERVER ON IP/PORT: %s:%i", ip.c_str(), port); return; } } else { LOG("FAILED TO START SERVER ON IP/PORT: %s:%i", ip.c_str(), port); return; }
mLogger->SetLogToConsole(prevLogSetting); mLogger->SetLogToConsole(prevLogSetting);

View File

@ -10,14 +10,17 @@
#include "dConfig.h" #include "dConfig.h"
void dpWorld::Initialize(unsigned int zoneID, bool generateNewNavMesh) { void dpWorld::Initialize(unsigned int zoneID, bool generateNewNavMesh) {
phys_sp_tilecount = std::atoi(Game::config->GetValue("phys_sp_tilecount").c_str()); const auto physSpTilecount = Game::config->GetValue("phys_sp_tilecount");
phys_sp_tilesize = std::atoi(Game::config->GetValue("phys_sp_tilesize").c_str()); if (!physSpTilecount.empty()) GeneralUtils::TryParse(physSpTilecount, phys_sp_tilecount);
const auto physSpTilesize = Game::config->GetValue("phys_sp_tilesize");
if (!physSpTilesize.empty()) GeneralUtils::TryParse(physSpTilesize, phys_sp_tilesize);
const auto physSpatialPartitioning = Game::config->GetValue("phys_spatial_partitioning");
if (!physSpatialPartitioning.empty()) phys_spatial_partitioning = physSpatialPartitioning == "1";
//If spatial partitioning is enabled, then we need to create the m_Grid. //If spatial partitioning is enabled, then we need to create the m_Grid.
//if m_Grid exists, then the old method will be used. //if m_Grid exists, then the old method will be used.
//SP will NOT be used unless it is added to ShouldUseSP(); //SP will NOT be used unless it is added to ShouldUseSP();
if (std::atoi(Game::config->GetValue("phys_spatial_partitioning").c_str()) == 1 if (ShouldUseSP(zoneID)) {
&& ShouldUseSP(zoneID)) {
m_Grid = new dpGrid(phys_sp_tilecount, phys_sp_tilesize); m_Grid = new dpGrid(phys_sp_tilecount, phys_sp_tilesize);
} }
@ -123,6 +126,8 @@ void dpWorld::RemoveEntity(dpEntity* entity) {
} }
bool dpWorld::ShouldUseSP(unsigned int zoneID) { bool dpWorld::ShouldUseSP(unsigned int zoneID) {
if (!phys_spatial_partitioning) return false;
// TODO: Add to this list as needed. // TODO: Add to this list as needed.
// Only large maps should be added as tiling likely makes little difference on small maps. // Only large maps should be added as tiling likely makes little difference on small maps.

View File

@ -36,7 +36,7 @@ public:
private: private:
dpGrid* m_Grid; dpGrid* m_Grid;
bool phys_spatial_partitioning = 1; bool phys_spatial_partitioning = true;
int phys_sp_tilesize = 205; int phys_sp_tilesize = 205;
int phys_sp_tilecount = 12; int phys_sp_tilecount = 12;

View File

@ -210,7 +210,10 @@ int main(int argc, char** argv) {
ObjectIDManager::Instance()->Initialize(); ObjectIDManager::Instance()->Initialize();
UserManager::Instance()->Initialize(); UserManager::Instance()->Initialize();
Game::chatFilter = new dChatFilter(Game::assetManager->GetResPath().string() + "/chatplus_en_us", bool(std::stoi(Game::config->GetValue("dont_generate_dcf"))));
bool dontGenerateDCF = false;
GeneralUtils::TryParse(Game::config->GetValue("dont_generate_dcf"), dontGenerateDCF);
Game::chatFilter = new dChatFilter(Game::assetManager->GetResPath().string() + "/chatplus_en_us", dontGenerateDCF);
Game::server = new dServer(masterIP, ourPort, instanceID, maxClients, false, true, Game::logger, masterIP, masterPort, ServerType::World, Game::config, &Game::lastSignal, zoneID); Game::server = new dServer(masterIP, ourPort, instanceID, maxClients, false, true, Game::logger, masterIP, masterPort, ServerType::World, Game::config, &Game::lastSignal, zoneID);