mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2024-11-25 15:07:28 +00:00
Merge pull request #276 from cuzitsjonny/main
ChatServer respawn after crash
This commit is contained in:
commit
1006bd17e3
@ -47,9 +47,12 @@ namespace Game {
|
||||
bool shutdownSequenceStarted = false;
|
||||
void ShutdownSequence();
|
||||
dLogger* SetupLogger();
|
||||
void StartAuthServer();
|
||||
void StartChatServer();
|
||||
void HandlePacket(Packet* packet);
|
||||
std::map<uint32_t, std::string> activeSessions;
|
||||
bool shouldShutdown = false;
|
||||
SystemAddress chatServerMasterPeerSysAddr;
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
Diagnostics::SetProcessName("Master");
|
||||
@ -182,35 +185,12 @@ int main(int argc, char** argv) {
|
||||
|
||||
//Depending on the config, start up servers:
|
||||
if (config.GetValue("prestart_servers") != "" && config.GetValue("prestart_servers") == "1") {
|
||||
#ifdef __APPLE__
|
||||
//macOS doesn't need sudo to run on ports < 1024
|
||||
system("./ChatServer&");
|
||||
#elif _WIN32
|
||||
system("start ./ChatServer.exe");
|
||||
#else
|
||||
if (std::atoi(Game::config->GetValue("use_sudo_chat").c_str())) {
|
||||
system("sudo ./ChatServer&");
|
||||
}
|
||||
else {
|
||||
system("./ChatServer&");
|
||||
}
|
||||
#endif
|
||||
StartChatServer();
|
||||
|
||||
Game::im->GetInstance(0, false, 0)->SetIsReady(true);
|
||||
Game::im->GetInstance(1000, false, 0)->SetIsReady(true);
|
||||
|
||||
#ifdef __APPLE__
|
||||
system("./AuthServer&");
|
||||
#elif _WIN32
|
||||
system("start ./AuthServer.exe");
|
||||
#else
|
||||
if (std::atoi(Game::config->GetValue("use_sudo_auth").c_str())) {
|
||||
system("sudo ./AuthServer&");
|
||||
}
|
||||
else {
|
||||
system("./AuthServer&");
|
||||
}
|
||||
#endif
|
||||
StartAuthServer();
|
||||
}
|
||||
|
||||
auto t = std::chrono::high_resolution_clock::now();
|
||||
@ -341,6 +321,10 @@ void HandlePacket(Packet* packet) {
|
||||
if (instance) {
|
||||
Game::im->RemoveInstance(instance); //Delete the old
|
||||
}
|
||||
|
||||
if (packet->systemAddress == chatServerMasterPeerSysAddr && !shouldShutdown) {
|
||||
StartChatServer();
|
||||
}
|
||||
}
|
||||
|
||||
if (packet->data[0] == ID_CONNECTION_LOST) {
|
||||
@ -353,6 +337,10 @@ void HandlePacket(Packet* packet) {
|
||||
Game::im->RemoveInstance(instance); //Delete the old
|
||||
//Game::im->GetInstance(zoneID.GetMapID(), false, 0); //Create the new
|
||||
}
|
||||
|
||||
if (packet->systemAddress == chatServerMasterPeerSysAddr && !shouldShutdown) {
|
||||
StartChatServer();
|
||||
}
|
||||
}
|
||||
|
||||
if (packet->data[1] == MASTER) {
|
||||
@ -441,6 +429,14 @@ void HandlePacket(Packet* packet) {
|
||||
}
|
||||
}
|
||||
|
||||
if (theirServerType == ServerType::Chat) {
|
||||
SystemAddress copy;
|
||||
copy.binaryAddress = packet->systemAddress.binaryAddress;
|
||||
copy.port = packet->systemAddress.port;
|
||||
|
||||
chatServerMasterPeerSysAddr = copy;
|
||||
}
|
||||
|
||||
Game::logger->Log("MasterServer", "Received server info, instance: %i port: %i\n", theirInstanceID, theirPort);
|
||||
|
||||
break;
|
||||
@ -660,6 +656,37 @@ void HandlePacket(Packet* packet) {
|
||||
}
|
||||
}
|
||||
|
||||
void StartChatServer() {
|
||||
#ifdef __APPLE__
|
||||
//macOS doesn't need sudo to run on ports < 1024
|
||||
system("./ChatServer&");
|
||||
#elif _WIN32
|
||||
system("start ./ChatServer.exe");
|
||||
#else
|
||||
if (std::atoi(Game::config->GetValue("use_sudo_chat").c_str())) {
|
||||
system("sudo ./ChatServer&");
|
||||
}
|
||||
else {
|
||||
system("./ChatServer&");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void StartAuthServer() {
|
||||
#ifdef __APPLE__
|
||||
system("./AuthServer&");
|
||||
#elif _WIN32
|
||||
system("start ./AuthServer.exe");
|
||||
#else
|
||||
if (std::atoi(Game::config->GetValue("use_sudo_auth").c_str())) {
|
||||
system("sudo ./AuthServer&");
|
||||
}
|
||||
else {
|
||||
system("./AuthServer&");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void ShutdownSequence() {
|
||||
if (shutdownSequenceStarted) {
|
||||
return;
|
||||
|
@ -73,6 +73,7 @@ namespace Game {
|
||||
}
|
||||
|
||||
bool chatDisabled = false;
|
||||
bool chatConnected = false;
|
||||
bool worldShutdownSequenceStarted = false;
|
||||
bool worldShutdownSequenceComplete = false;
|
||||
void WorldShutdownSequence();
|
||||
@ -212,6 +213,7 @@ int main(int argc, char** argv) {
|
||||
Packet* packet = nullptr;
|
||||
int framesSinceLastFlush = 0;
|
||||
int framesSinceMasterDisconnect = 0;
|
||||
int framesSinceChatDisconnect = 0;
|
||||
int framesSinceLastUsersSave = 0;
|
||||
int framesSinceLastSQLPing = 0;
|
||||
int framesSinceLastUser = 0;
|
||||
@ -319,6 +321,19 @@ int main(int argc, char** argv) {
|
||||
}
|
||||
else framesSinceMasterDisconnect = 0;
|
||||
|
||||
// Check if we're still connected to chat:
|
||||
if (!chatConnected) {
|
||||
framesSinceChatDisconnect++;
|
||||
|
||||
// Attempt to reconnect every 30 seconds.
|
||||
if (framesSinceChatDisconnect >= 2000) {
|
||||
framesSinceChatDisconnect = 0;
|
||||
|
||||
Game::chatServer->Connect(masterIP.c_str(), chatPort, "3.25 ND1", 8);
|
||||
}
|
||||
}
|
||||
else framesSinceChatDisconnect = 0;
|
||||
|
||||
//In world we'd update our other systems here.
|
||||
|
||||
if (zoneID != 0 && deltaTime > 0.0f) {
|
||||
@ -559,11 +574,15 @@ dLogger * SetupLogger(int zoneID, int instanceID) {
|
||||
void HandlePacketChat(Packet* packet) {
|
||||
if (packet->data[0] == ID_DISCONNECTION_NOTIFICATION || packet->data[0] == ID_CONNECTION_LOST) {
|
||||
Game::logger->Log("WorldServer", "Lost our connection to chat.\n");
|
||||
|
||||
chatConnected = false;
|
||||
}
|
||||
|
||||
if (packet->data[0] == ID_CONNECTION_REQUEST_ACCEPTED) {
|
||||
Game::logger->Log("WorldServer", "Established connection to chat\n");
|
||||
Game::chatSysAddr = packet->systemAddress;
|
||||
|
||||
chatConnected = true;
|
||||
}
|
||||
|
||||
if (packet->data[0] == ID_USER_PACKET_ENUM) {
|
||||
|
Loading…
Reference in New Issue
Block a user