mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2024-11-09 17:58:20 +00:00
feat: split out system() calls from the rest of MasterServer (#1368)
This commit is contained in:
parent
1bdce8384f
commit
f08df25085
@ -1,6 +1,7 @@
|
|||||||
set(DMASTERSERVER_SOURCES
|
set(DMASTERSERVER_SOURCES
|
||||||
"InstanceManager.cpp"
|
"InstanceManager.cpp"
|
||||||
"ObjectIDManager.cpp"
|
"ObjectIDManager.cpp"
|
||||||
|
"Start.cpp"
|
||||||
)
|
)
|
||||||
|
|
||||||
add_library(dMasterServer ${DMASTERSERVER_SOURCES})
|
add_library(dMasterServer ${DMASTERSERVER_SOURCES})
|
||||||
|
@ -9,10 +9,11 @@
|
|||||||
#include "CDZoneTableTable.h"
|
#include "CDZoneTableTable.h"
|
||||||
#include "MasterPackets.h"
|
#include "MasterPackets.h"
|
||||||
#include "BitStreamUtils.h"
|
#include "BitStreamUtils.h"
|
||||||
#include "BinaryPathFinder.h"
|
|
||||||
#include "eConnectionType.h"
|
#include "eConnectionType.h"
|
||||||
#include "eMasterMessageType.h"
|
#include "eMasterMessageType.h"
|
||||||
|
|
||||||
|
#include "Start.h"
|
||||||
|
|
||||||
InstanceManager::InstanceManager(Logger* logger, const std::string& externalIP) {
|
InstanceManager::InstanceManager(Logger* logger, const std::string& externalIP) {
|
||||||
mLogger = logger;
|
mLogger = logger;
|
||||||
mExternalIP = externalIP;
|
mExternalIP = externalIP;
|
||||||
@ -57,33 +58,7 @@ Instance* InstanceManager::GetInstance(LWOMAPID mapID, bool isFriendTransfer, LW
|
|||||||
instance = new Instance(mExternalIP, port, mapID, ++m_LastInstanceID, cloneID, softCap, maxPlayers);
|
instance = new Instance(mExternalIP, port, mapID, ++m_LastInstanceID, cloneID, softCap, maxPlayers);
|
||||||
|
|
||||||
//Start the actual process:
|
//Start the actual process:
|
||||||
#ifdef _WIN32
|
StartWorldServer(mapID, port, m_LastInstanceID, maxPlayers, cloneID);
|
||||||
std::string cmd = "start " + (BinaryPathFinder::GetBinaryDir() / "WorldServer.exe").string() + " -zone ";
|
|
||||||
#else
|
|
||||||
std::string cmd;
|
|
||||||
if (std::atoi(Game::config->GetValue("use_sudo_world").c_str())) {
|
|
||||||
cmd = "sudo " + (BinaryPathFinder::GetBinaryDir() / "WorldServer").string() + " -zone ";
|
|
||||||
} else {
|
|
||||||
cmd = (BinaryPathFinder::GetBinaryDir() / "WorldServer").string() + " -zone ";
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
cmd.append(std::to_string(mapID));
|
|
||||||
cmd.append(" -port ");
|
|
||||||
cmd.append(std::to_string(port));
|
|
||||||
cmd.append(" -instance ");
|
|
||||||
cmd.append(std::to_string(m_LastInstanceID));
|
|
||||||
cmd.append(" -maxclients ");
|
|
||||||
cmd.append(std::to_string(maxPlayers));
|
|
||||||
|
|
||||||
cmd.append(" -clone ");
|
|
||||||
cmd.append(std::to_string(cloneID));
|
|
||||||
|
|
||||||
#ifndef _WIN32
|
|
||||||
cmd.append("&"); //Sends our next process to the background on Linux
|
|
||||||
#endif
|
|
||||||
|
|
||||||
auto ret = system(cmd.c_str());
|
|
||||||
|
|
||||||
m_Instances.push_back(instance);
|
m_Instances.push_back(instance);
|
||||||
|
|
||||||
@ -318,28 +293,7 @@ Instance* InstanceManager::CreatePrivateInstance(LWOMAPID mapID, LWOCLONEID clon
|
|||||||
instance = new Instance(mExternalIP, port, mapID, ++m_LastInstanceID, cloneID, maxPlayers, maxPlayers, true, password);
|
instance = new Instance(mExternalIP, port, mapID, ++m_LastInstanceID, cloneID, maxPlayers, maxPlayers, true, password);
|
||||||
|
|
||||||
//Start the actual process:
|
//Start the actual process:
|
||||||
std::string cmd = "start " + (BinaryPathFinder::GetBinaryDir() / "WorldServer").string() + " -zone ";
|
StartWorldServer(mapID, port, m_LastInstanceID, maxPlayers, cloneID);
|
||||||
|
|
||||||
#ifndef _WIN32
|
|
||||||
cmd = (BinaryPathFinder::GetBinaryDir() / "WorldServer").string() + " -zone ";
|
|
||||||
#endif
|
|
||||||
|
|
||||||
cmd.append(std::to_string(mapID));
|
|
||||||
cmd.append(" -port ");
|
|
||||||
cmd.append(std::to_string(port));
|
|
||||||
cmd.append(" -instance ");
|
|
||||||
cmd.append(std::to_string(m_LastInstanceID));
|
|
||||||
cmd.append(" -maxclients ");
|
|
||||||
cmd.append(std::to_string(maxPlayers));
|
|
||||||
|
|
||||||
cmd.append(" -clone ");
|
|
||||||
cmd.append(std::to_string(cloneID));
|
|
||||||
|
|
||||||
#ifndef WIN32
|
|
||||||
cmd.append("&"); //Sends our next process to the background on Linux
|
|
||||||
#endif
|
|
||||||
|
|
||||||
auto ret = system(cmd.c_str());
|
|
||||||
|
|
||||||
m_Instances.push_back(instance);
|
m_Instances.push_back(instance);
|
||||||
|
|
||||||
|
@ -43,6 +43,7 @@
|
|||||||
#include "PacketUtils.h"
|
#include "PacketUtils.h"
|
||||||
#include "FdbToSqlite.h"
|
#include "FdbToSqlite.h"
|
||||||
#include "BitStreamUtils.h"
|
#include "BitStreamUtils.h"
|
||||||
|
#include "Start.h"
|
||||||
|
|
||||||
namespace Game {
|
namespace Game {
|
||||||
Logger* logger = nullptr;
|
Logger* logger = nullptr;
|
||||||
@ -58,8 +59,6 @@ bool shutdownSequenceStarted = false;
|
|||||||
void ShutdownSequence(int32_t signal = -1);
|
void ShutdownSequence(int32_t signal = -1);
|
||||||
int32_t FinalizeShutdown(int32_t signal = -1);
|
int32_t FinalizeShutdown(int32_t signal = -1);
|
||||||
Logger* SetupLogger();
|
Logger* SetupLogger();
|
||||||
void StartAuthServer();
|
|
||||||
void StartChatServer();
|
|
||||||
void HandlePacket(Packet* packet);
|
void HandlePacket(Packet* packet);
|
||||||
std::map<uint32_t, std::string> activeSessions;
|
std::map<uint32_t, std::string> activeSessions;
|
||||||
SystemAddress authServerMasterPeerSysAddr;
|
SystemAddress authServerMasterPeerSysAddr;
|
||||||
@ -814,43 +813,6 @@ void HandlePacket(Packet* packet) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void StartChatServer() {
|
|
||||||
if (Game::shouldShutdown) {
|
|
||||||
LOG("Currently shutting down. Chat will not be restarted.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
#ifdef __APPLE__
|
|
||||||
//macOS doesn't need sudo to run on ports < 1024
|
|
||||||
auto result = system(((BinaryPathFinder::GetBinaryDir() / "ChatServer").string() + "&").c_str());
|
|
||||||
#elif _WIN32
|
|
||||||
auto result = system(("start " + (BinaryPathFinder::GetBinaryDir() / "ChatServer.exe").string()).c_str());
|
|
||||||
#else
|
|
||||||
if (std::atoi(Game::config->GetValue("use_sudo_chat").c_str())) {
|
|
||||||
auto result = system(("sudo " + (BinaryPathFinder::GetBinaryDir() / "ChatServer").string() + "&").c_str());
|
|
||||||
} else {
|
|
||||||
auto result = system(((BinaryPathFinder::GetBinaryDir() / "ChatServer").string() + "&").c_str());
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void StartAuthServer() {
|
|
||||||
if (Game::shouldShutdown) {
|
|
||||||
LOG("Currently shutting down. Auth will not be restarted.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
#ifdef __APPLE__
|
|
||||||
auto result = system(((BinaryPathFinder::GetBinaryDir() / "AuthServer").string() + "&").c_str());
|
|
||||||
#elif _WIN32
|
|
||||||
auto result = system(("start " + (BinaryPathFinder::GetBinaryDir() / "AuthServer.exe").string()).c_str());
|
|
||||||
#else
|
|
||||||
if (std::atoi(Game::config->GetValue("use_sudo_auth").c_str())) {
|
|
||||||
auto result = system(("sudo " + (BinaryPathFinder::GetBinaryDir() / "AuthServer").string() + "&").c_str());
|
|
||||||
} else {
|
|
||||||
auto result = system(((BinaryPathFinder::GetBinaryDir() / "AuthServer").string() + "&").c_str());
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void ShutdownSequence(int32_t signal) {
|
void ShutdownSequence(int32_t signal) {
|
||||||
if (shutdownSequenceStarted) {
|
if (shutdownSequenceStarted) {
|
||||||
return;
|
return;
|
||||||
|
71
dMasterServer/Start.cpp
Normal file
71
dMasterServer/Start.cpp
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
#include "Start.h"
|
||||||
|
#include "Logger.h"
|
||||||
|
#include "dConfig.h"
|
||||||
|
#include "Game.h"
|
||||||
|
#include "BinaryPathFinder.h"
|
||||||
|
|
||||||
|
void StartChatServer() {
|
||||||
|
if (Game::shouldShutdown) {
|
||||||
|
LOG("Currently shutting down. Chat will not be restarted.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#ifdef __APPLE__
|
||||||
|
//macOS doesn't need sudo to run on ports < 1024
|
||||||
|
auto result = system(((BinaryPathFinder::GetBinaryDir() / "ChatServer").string() + "&").c_str());
|
||||||
|
#elif _WIN32
|
||||||
|
auto result = system(("start " + (BinaryPathFinder::GetBinaryDir() / "ChatServer.exe").string()).c_str());
|
||||||
|
#else
|
||||||
|
if (std::atoi(Game::config->GetValue("use_sudo_chat").c_str())) {
|
||||||
|
auto result = system(("sudo " + (BinaryPathFinder::GetBinaryDir() / "ChatServer").string() + "&").c_str());
|
||||||
|
} else {
|
||||||
|
auto result = system(((BinaryPathFinder::GetBinaryDir() / "ChatServer").string() + "&").c_str());
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void StartAuthServer() {
|
||||||
|
if (Game::shouldShutdown) {
|
||||||
|
LOG("Currently shutting down. Auth will not be restarted.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#ifdef __APPLE__
|
||||||
|
auto result = system(((BinaryPathFinder::GetBinaryDir() / "AuthServer").string() + "&").c_str());
|
||||||
|
#elif _WIN32
|
||||||
|
auto result = system(("start " + (BinaryPathFinder::GetBinaryDir() / "AuthServer.exe").string()).c_str());
|
||||||
|
#else
|
||||||
|
if (std::atoi(Game::config->GetValue("use_sudo_auth").c_str())) {
|
||||||
|
auto result = system(("sudo " + (BinaryPathFinder::GetBinaryDir() / "AuthServer").string() + "&").c_str());
|
||||||
|
} else {
|
||||||
|
auto result = system(((BinaryPathFinder::GetBinaryDir() / "AuthServer").string() + "&").c_str());
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void StartWorldServer(LWOMAPID mapID, uint16_t port, LWOINSTANCEID lastInstanceID, int maxPlayers, LWOCLONEID cloneID) {
|
||||||
|
#ifdef _WIN32
|
||||||
|
std::string cmd = "start " + (BinaryPathFinder::GetBinaryDir() / "WorldServer.exe").string() + " -zone ";
|
||||||
|
#else
|
||||||
|
std::string cmd;
|
||||||
|
if (std::atoi(Game::config->GetValue("use_sudo_world").c_str())) {
|
||||||
|
cmd = "sudo " + (BinaryPathFinder::GetBinaryDir() / "WorldServer").string() + " -zone ";
|
||||||
|
} else {
|
||||||
|
cmd = (BinaryPathFinder::GetBinaryDir() / "WorldServer").string() + " -zone ";
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
cmd.append(std::to_string(mapID));
|
||||||
|
cmd.append(" -port ");
|
||||||
|
cmd.append(std::to_string(port));
|
||||||
|
cmd.append(" -instance ");
|
||||||
|
cmd.append(std::to_string(lastInstanceID));
|
||||||
|
cmd.append(" -maxclients ");
|
||||||
|
cmd.append(std::to_string(maxPlayers));
|
||||||
|
cmd.append(" -clone ");
|
||||||
|
cmd.append(std::to_string(cloneID));
|
||||||
|
|
||||||
|
#ifndef _WIN32
|
||||||
|
cmd.append("&"); //Sends our next process to the background on Linux
|
||||||
|
#endif
|
||||||
|
|
||||||
|
auto ret = system(cmd.c_str());
|
||||||
|
}
|
6
dMasterServer/Start.h
Normal file
6
dMasterServer/Start.h
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "dCommonVars.h"
|
||||||
|
|
||||||
|
void StartAuthServer();
|
||||||
|
void StartChatServer();
|
||||||
|
void StartWorldServer(LWOMAPID mapID, uint16_t port, LWOINSTANCEID lastInstanceID, int maxPlayers, LWOCLONEID cloneID);
|
Loading…
Reference in New Issue
Block a user