mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-08-05 18:24:12 +00:00
fix: signal handling (#1375)
* fix: signal handling * fix: flush WorldServer logger before main loop * fix: consolidate signal code
This commit is contained in:
@@ -55,7 +55,9 @@ void AuthPackets::SendHandshake(dServer* server, const SystemAddress& sysAddr, c
|
||||
RakNet::BitStream bitStream;
|
||||
BitStreamUtils::WriteHeader(bitStream, eConnectionType::SERVER, eServerMessageType::VERSION_CONFIRM);
|
||||
uint32_t netVersion;
|
||||
if (!GeneralUtils::TryParse(Game::config->GetValue("client_net_version"), netVersion)) {
|
||||
const std::string& expectedVersion = Game::config->GetValue("client_net_version");
|
||||
LOG("Expected Version: '%s'", expectedVersion.c_str());
|
||||
if (!GeneralUtils::TryParse(expectedVersion, netVersion)) {
|
||||
LOG("Failed to parse client_net_version. Cannot authenticate to %s:%i", nextServerIP.c_str(), nextServerPort);
|
||||
return;
|
||||
}
|
||||
|
@@ -39,7 +39,7 @@ public:
|
||||
}
|
||||
} ReceiveDownloadCompleteCB;
|
||||
|
||||
dServer::dServer(const std::string& ip, int port, int instanceID, int maxConnections, bool isInternal, bool useEncryption, Logger* logger, const std::string masterIP, int masterPort, ServerType serverType, dConfig* config, bool* shouldShutdown, unsigned int zoneID) {
|
||||
dServer::dServer(const std::string& ip, int port, int instanceID, int maxConnections, bool isInternal, bool useEncryption, Logger* logger, const std::string masterIP, int masterPort, ServerType serverType, dConfig* config, Game::signal_t* lastSignal, unsigned int zoneID) {
|
||||
mIP = ip;
|
||||
mPort = port;
|
||||
mZoneID = zoneID;
|
||||
@@ -55,7 +55,7 @@ dServer::dServer(const std::string& ip, int port, int instanceID, int maxConnect
|
||||
mReplicaManager = nullptr;
|
||||
mServerType = serverType;
|
||||
mConfig = config;
|
||||
mShouldShutdown = shouldShutdown;
|
||||
mShouldShutdown = lastSignal;
|
||||
//Attempt to start our server here:
|
||||
mIsOkay = Startup();
|
||||
|
||||
@@ -75,7 +75,9 @@ dServer::dServer(const std::string& ip, int port, int instanceID, int maxConnect
|
||||
//Connect to master if we are not master:
|
||||
if (serverType != ServerType::Master) {
|
||||
SetupForMasterConnection();
|
||||
ConnectToMaster();
|
||||
if (!ConnectToMaster()) {
|
||||
LOG("Failed ConnectToMaster!");
|
||||
}
|
||||
}
|
||||
|
||||
//Set up Replica if we're a world server:
|
||||
@@ -129,7 +131,7 @@ Packet* dServer::ReceiveFromMaster() {
|
||||
break;
|
||||
}
|
||||
case eMasterMessageType::SHUTDOWN:
|
||||
*mShouldShutdown = true;
|
||||
*mShouldShutdown = -2;
|
||||
break;
|
||||
|
||||
//When we handle these packets in World instead dServer, we just return the packet's pointer.
|
||||
@@ -236,10 +238,12 @@ void dServer::Shutdown() {
|
||||
void dServer::SetupForMasterConnection() {
|
||||
mMasterSocketDescriptor = SocketDescriptor(uint16_t(mPort + 1), 0);
|
||||
mMasterPeer = RakNetworkFactory::GetRakPeerInterface();
|
||||
mMasterPeer->Startup(1, 30, &mMasterSocketDescriptor, 1);
|
||||
bool ret = mMasterPeer->Startup(1, 30, &mMasterSocketDescriptor, 1);
|
||||
if (!ret) LOG("Failed MasterPeer Startup!");
|
||||
}
|
||||
|
||||
bool dServer::ConnectToMaster() {
|
||||
//LOG("Connection to Master %s:%d", mMasterIP.c_str(), mMasterPort);
|
||||
return mMasterPeer->Connect(mMasterIP.c_str(), mMasterPort, "3.25 DARKFLAME1", 15);
|
||||
}
|
||||
|
||||
|
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <csignal>
|
||||
#include "RakPeerInterface.h"
|
||||
#include "ReplicaManager.h"
|
||||
#include "NetworkIDManager.h"
|
||||
@@ -15,6 +16,10 @@ enum class ServerType : uint32_t {
|
||||
World
|
||||
};
|
||||
|
||||
namespace Game {
|
||||
using signal_t = volatile std::sig_atomic_t;
|
||||
}
|
||||
|
||||
class dServer {
|
||||
public:
|
||||
// Default constructor should only used for testing!
|
||||
@@ -31,7 +36,7 @@ public:
|
||||
int masterPort,
|
||||
ServerType serverType,
|
||||
dConfig* config,
|
||||
bool* shouldShutdown,
|
||||
Game::signal_t* shouldShutdown,
|
||||
unsigned int zoneID = 0);
|
||||
~dServer();
|
||||
|
||||
@@ -81,9 +86,9 @@ private:
|
||||
NetworkIDManager* mNetIDManager = nullptr;
|
||||
|
||||
/**
|
||||
* Whether or not to shut down the server. Pointer to Game::shouldShutdown.
|
||||
* Whether or not to shut down the server. Pointer to Game::lastSignal.
|
||||
*/
|
||||
bool* mShouldShutdown = nullptr;
|
||||
Game::signal_t* mShouldShutdown = nullptr;
|
||||
SocketDescriptor mSocketDescriptor;
|
||||
std::string mIP;
|
||||
int mPort;
|
||||
|
Reference in New Issue
Block a user