mirror of
https://github.com/EQEmu/Server.git
synced 2026-05-16 18:52:22 +00:00
Merge of a monster
This commit is contained in:
+11
-15
@@ -31,11 +31,7 @@
|
||||
#include <signal.h>
|
||||
#include <time.h>
|
||||
|
||||
#ifndef _WINDOWS
|
||||
#include "../common/unix.h"
|
||||
#endif
|
||||
|
||||
EQEmuLogSys Log;
|
||||
EQEmuLogSys LogSys;
|
||||
|
||||
bool RunLoops = false;
|
||||
|
||||
@@ -43,7 +39,7 @@ void CatchSignal(int sig_num);
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
RegisterExecutablePlatform(ExePlatformLaunch);
|
||||
Log.LoadLogSettingsDefaults();
|
||||
LogSys.LoadLogSettingsDefaults();
|
||||
set_exception_handler();
|
||||
|
||||
std::string launcher_name;
|
||||
@@ -51,13 +47,13 @@ int main(int argc, char *argv[]) {
|
||||
launcher_name = argv[1];
|
||||
}
|
||||
if(launcher_name.length() < 1) {
|
||||
Log.Out(Logs::Detail, Logs::Launcher, "You must specfify a launcher name as the first argument to this program.");
|
||||
Log(Logs::Detail, Logs::Launcher, "You must specfify a launcher name as the first argument to this program.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
Log.Out(Logs::Detail, Logs::Launcher, "Loading server configuration..");
|
||||
Log(Logs::Detail, Logs::Launcher, "Loading server configuration..");
|
||||
if (!EQEmuConfig::LoadConfig()) {
|
||||
Log.Out(Logs::Detail, Logs::Launcher, "Loading server configuration failed.");
|
||||
Log(Logs::Detail, Logs::Launcher, "Loading server configuration failed.");
|
||||
return 1;
|
||||
}
|
||||
auto Config = EQEmuConfig::get();
|
||||
@@ -66,16 +62,16 @@ int main(int argc, char *argv[]) {
|
||||
* Setup nice signal handlers
|
||||
*/
|
||||
if (signal(SIGINT, CatchSignal) == SIG_ERR) {
|
||||
Log.Out(Logs::Detail, Logs::Launcher, "Could not set signal handler");
|
||||
Log(Logs::Detail, Logs::Launcher, "Could not set signal handler");
|
||||
return 1;
|
||||
}
|
||||
if (signal(SIGTERM, CatchSignal) == SIG_ERR) {
|
||||
Log.Out(Logs::Detail, Logs::Launcher, "Could not set signal handler");
|
||||
Log(Logs::Detail, Logs::Launcher, "Could not set signal handler");
|
||||
return 1;
|
||||
}
|
||||
#ifndef WIN32
|
||||
if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) {
|
||||
Log.Out(Logs::Detail, Logs::Launcher, "Could not set signal handler");
|
||||
Log(Logs::Detail, Logs::Launcher, "Could not set signal handler");
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -101,7 +97,7 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
Timer InterserverTimer(INTERSERVER_TIMER); // does auto-reconnect
|
||||
|
||||
Log.Out(Logs::Detail, Logs::Launcher, "Starting main loop...");
|
||||
Log(Logs::Detail, Logs::Launcher, "Starting main loop...");
|
||||
|
||||
ProcLauncher *launch = ProcLauncher::get();
|
||||
RunLoops = true;
|
||||
@@ -160,14 +156,14 @@ int main(int argc, char *argv[]) {
|
||||
delete zone->second;
|
||||
}
|
||||
|
||||
Log.CloseFileLogs();
|
||||
LogSys.CloseFileLogs();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void CatchSignal(int sig_num) {
|
||||
Log.Out(Logs::Detail, Logs::Launcher, "Caught signal %d", sig_num);
|
||||
Log(Logs::Detail, Logs::Launcher, "Caught signal %d", sig_num);
|
||||
RunLoops = false;
|
||||
}
|
||||
|
||||
|
||||
+41
-38
@@ -1,19 +1,19 @@
|
||||
/* EQEMu: Everquest Server Emulator
|
||||
Copyright (C) 2001-2006 EQEMu Development Team (http://eqemulator.net)
|
||||
Copyright (C) 2001-2006 EQEMu Development Team (http://eqemulator.net)
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; version 2 of the License.
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; version 2 of the License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY except by those people which sell it, which
|
||||
are required to give you total support for your newly bought product;
|
||||
without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY except by those people which sell it, which
|
||||
are required to give you total support for your newly bought product;
|
||||
without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "../common/global_define.h"
|
||||
@@ -25,7 +25,7 @@
|
||||
#include "zone_launch.h"
|
||||
|
||||
WorldServer::WorldServer(std::map<std::string, ZoneLaunch *> &zones, const char *name, const EQEmuConfig *config)
|
||||
: m_name(name),
|
||||
: m_name(name),
|
||||
m_config(config),
|
||||
m_zones(zones)
|
||||
{
|
||||
@@ -43,7 +43,7 @@ WorldServer::~WorldServer() {
|
||||
void WorldServer::OnConnected() {
|
||||
|
||||
auto pack = new ServerPacket(ServerOP_LauncherConnectInfo, sizeof(LauncherConnectInfo));
|
||||
LauncherConnectInfo* sci = (LauncherConnectInfo*) pack->pBuffer;
|
||||
LauncherConnectInfo* sci = (LauncherConnectInfo*)pack->pBuffer;
|
||||
strn0cpy(sci->name, m_name, sizeof(sci->name));
|
||||
m_connection->SendPacket(pack);
|
||||
safe_delete(pack);
|
||||
@@ -52,7 +52,7 @@ void WorldServer::OnConnected() {
|
||||
std::map<std::string, ZoneLaunch *>::iterator cur, end;
|
||||
cur = m_zones.begin();
|
||||
end = m_zones.end();
|
||||
for(; cur != end; ++cur) {
|
||||
for (; cur != end; ++cur) {
|
||||
cur->second->SendStatus();
|
||||
}
|
||||
}
|
||||
@@ -61,7 +61,7 @@ void WorldServer::HandleMessage(uint16 opcode, EQ::Net::Packet &p) {
|
||||
ServerPacket tpack(opcode, p);
|
||||
ServerPacket *pack = &tpack;
|
||||
|
||||
switch(opcode) {
|
||||
switch (opcode) {
|
||||
case 0: {
|
||||
break;
|
||||
}
|
||||
@@ -71,18 +71,19 @@ void WorldServer::HandleMessage(uint16 opcode, EQ::Net::Packet &p) {
|
||||
break;
|
||||
}
|
||||
case ServerOP_LauncherZoneRequest: {
|
||||
if(pack->size != sizeof(LauncherZoneRequest)) {
|
||||
Log.Out(Logs::Detail, Logs::Launcher, "Invalid size of LauncherZoneRequest: %d", pack->size);
|
||||
if (pack->size != sizeof(LauncherZoneRequest)) {
|
||||
Log(Logs::Detail, Logs::Launcher, "Invalid size of LauncherZoneRequest: %d", pack->size);
|
||||
break;
|
||||
}
|
||||
const LauncherZoneRequest *lzr = (const LauncherZoneRequest *) pack->pBuffer;
|
||||
|
||||
switch(ZoneRequestCommands(lzr->command)) {
|
||||
const LauncherZoneRequest *lzr = (const LauncherZoneRequest *)pack->pBuffer;
|
||||
|
||||
switch (ZoneRequestCommands(lzr->command)) {
|
||||
case ZR_Start: {
|
||||
if(m_zones.find(lzr->short_name) != m_zones.end()) {
|
||||
Log.Out(Logs::Detail, Logs::Launcher, "World told us to start zone %s, but it is already running.", lzr->short_name);
|
||||
} else {
|
||||
Log.Out(Logs::Detail, Logs::Launcher, "World told us to start zone %s.", lzr->short_name);
|
||||
if (m_zones.find(lzr->short_name) != m_zones.end()) {
|
||||
Log(Logs::Detail, Logs::Launcher, "World told us to start zone %s, but it is already running.", lzr->short_name);
|
||||
}
|
||||
else {
|
||||
Log(Logs::Detail, Logs::Launcher, "World told us to start zone %s.", lzr->short_name);
|
||||
auto l = new ZoneLaunch(this, m_name, lzr->short_name, lzr->port, m_config);
|
||||
m_zones[lzr->short_name] = l;
|
||||
}
|
||||
@@ -90,20 +91,22 @@ void WorldServer::HandleMessage(uint16 opcode, EQ::Net::Packet &p) {
|
||||
}
|
||||
case ZR_Restart: {
|
||||
auto res = m_zones.find(lzr->short_name);
|
||||
if(res == m_zones.end()) {
|
||||
Log.Out(Logs::Detail, Logs::Launcher, "World told us to restart zone %s, but it is not running.", lzr->short_name);
|
||||
} else {
|
||||
Log.Out(Logs::Detail, Logs::Launcher, "World told us to restart zone %s.", lzr->short_name);
|
||||
if (res == m_zones.end()) {
|
||||
Log(Logs::Detail, Logs::Launcher, "World told us to restart zone %s, but it is not running.", lzr->short_name);
|
||||
}
|
||||
else {
|
||||
Log(Logs::Detail, Logs::Launcher, "World told us to restart zone %s.", lzr->short_name);
|
||||
res->second->Restart();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ZR_Stop: {
|
||||
auto res = m_zones.find(lzr->short_name);
|
||||
if(res == m_zones.end()) {
|
||||
Log.Out(Logs::Detail, Logs::Launcher, "World told us to stop zone %s, but it is not running.", lzr->short_name);
|
||||
} else {
|
||||
Log.Out(Logs::Detail, Logs::Launcher, "World told us to stop zone %s.", lzr->short_name);
|
||||
if (res == m_zones.end()) {
|
||||
Log(Logs::Detail, Logs::Launcher, "World told us to stop zone %s, but it is not running.", lzr->short_name);
|
||||
}
|
||||
else {
|
||||
Log(Logs::Detail, Logs::Launcher, "World told us to stop zone %s.", lzr->short_name);
|
||||
res->second->Stop();
|
||||
}
|
||||
break;
|
||||
@@ -115,9 +118,9 @@ void WorldServer::HandleMessage(uint16 opcode, EQ::Net::Packet &p) {
|
||||
//ignore this, world is still being dumb
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
default: {
|
||||
Log.Out(Logs::Detail, Logs::Launcher, "Unknown opcode 0x%x from World of len %d", pack->opcode, pack->size);
|
||||
Log(Logs::Detail, Logs::Launcher, "Unknown opcode 0x%x from World of len %d", pack->opcode, pack->size);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -127,12 +130,12 @@ void WorldServer::HandleMessage(uint16 opcode, EQ::Net::Packet &p) {
|
||||
|
||||
void WorldServer::SendStatus(const char *short_name, uint32 start_count, bool running) {
|
||||
auto pack = new ServerPacket(ServerOP_LauncherZoneStatus, sizeof(LauncherZoneStatus));
|
||||
LauncherZoneStatus* it =(LauncherZoneStatus*) pack->pBuffer;
|
||||
LauncherZoneStatus* it = (LauncherZoneStatus*)pack->pBuffer;
|
||||
|
||||
strn0cpy(it->short_name, short_name, 32);
|
||||
it->start_count = start_count;
|
||||
it->running = running?1:0;
|
||||
it->running = running ? 1 : 0;
|
||||
|
||||
m_connection->SendPacket(pack);
|
||||
safe_delete(pack);
|
||||
}
|
||||
}
|
||||
+23
-23
@@ -77,7 +77,7 @@ void ZoneLaunch::Start() {
|
||||
//spec is consumed, even on failure
|
||||
m_ref = ProcLauncher::get()->Launch(spec);
|
||||
if(m_ref == ProcLauncher::ProcError) {
|
||||
Log.Out(Logs::Detail, Logs::Launcher, "Failure to launch '%s %s %s'. ", m_config->ZoneExe.c_str(), m_zone.c_str(), m_launcherName);
|
||||
Log(Logs::Detail, Logs::Launcher, "Failure to launch '%s %s %s'. ", m_config->ZoneExe.c_str(), m_zone.c_str(), m_launcherName);
|
||||
m_timer.Start(m_config->RestartWait);
|
||||
return;
|
||||
}
|
||||
@@ -89,17 +89,17 @@ void ZoneLaunch::Start() {
|
||||
|
||||
SendStatus();
|
||||
|
||||
Log.Out(Logs::Detail, Logs::Launcher, "Zone %s has been started.", m_zone.c_str());
|
||||
Log(Logs::Detail, Logs::Launcher, "Zone %s has been started.", m_zone.c_str());
|
||||
}
|
||||
|
||||
void ZoneLaunch::Restart() {
|
||||
switch(m_state) {
|
||||
case StateRestartPending:
|
||||
Log.Out(Logs::Detail, Logs::Launcher, "Restart of zone %s requested when a restart is already pending.", m_zone.c_str());
|
||||
Log(Logs::Detail, Logs::Launcher, "Restart of zone %s requested when a restart is already pending.", m_zone.c_str());
|
||||
break;
|
||||
case StateStartPending:
|
||||
//we havent started yet, do nothing
|
||||
Log.Out(Logs::Detail, Logs::Launcher, "Restart of %s before it has started. Ignoring.", m_zone.c_str());
|
||||
Log(Logs::Detail, Logs::Launcher, "Restart of %s before it has started. Ignoring.", m_zone.c_str());
|
||||
break;
|
||||
case StateStarted:
|
||||
//process is running along, kill it off..
|
||||
@@ -107,20 +107,20 @@ void ZoneLaunch::Restart() {
|
||||
break; //we have no proc ref... cannot stop..
|
||||
if(!ProcLauncher::get()->Terminate(m_ref, true)) {
|
||||
//failed to terminate the process, its not likely that it will work if we try again, so give up.
|
||||
Log.Out(Logs::Detail, Logs::Launcher, "Failed to terminate zone %s. Giving up and moving to stopped.", m_zone.c_str());
|
||||
Log(Logs::Detail, Logs::Launcher, "Failed to terminate zone %s. Giving up and moving to stopped.", m_zone.c_str());
|
||||
m_state = StateStopped;
|
||||
break;
|
||||
}
|
||||
Log.Out(Logs::Detail, Logs::Launcher, "Termination signal sent to zone %s.", m_zone.c_str());
|
||||
Log(Logs::Detail, Logs::Launcher, "Termination signal sent to zone %s.", m_zone.c_str());
|
||||
m_timer.Start(m_config->TerminateWait);
|
||||
m_state = StateRestartPending;
|
||||
break;
|
||||
case StateStopPending:
|
||||
Log.Out(Logs::Detail, Logs::Launcher, "Restart of zone %s requested when a stop is pending. Ignoring.", m_zone.c_str());
|
||||
Log(Logs::Detail, Logs::Launcher, "Restart of zone %s requested when a stop is pending. Ignoring.", m_zone.c_str());
|
||||
break;
|
||||
case StateStopped:
|
||||
//process is already stopped... nothing to do..
|
||||
Log.Out(Logs::Detail, Logs::Launcher, "Restart requested when zone %s is already stopped.", m_zone.c_str());
|
||||
Log(Logs::Detail, Logs::Launcher, "Restart requested when zone %s is already stopped.", m_zone.c_str());
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -129,7 +129,7 @@ void ZoneLaunch::Stop(bool graceful) {
|
||||
switch(m_state) {
|
||||
case StateStartPending:
|
||||
//we havent started yet, transition directly to stopped.
|
||||
Log.Out(Logs::Detail, Logs::Launcher, "Stopping zone %s before it has started.", m_zone.c_str());
|
||||
Log(Logs::Detail, Logs::Launcher, "Stopping zone %s before it has started.", m_zone.c_str());
|
||||
m_state = StateStopped;
|
||||
break;
|
||||
case StateStarted:
|
||||
@@ -139,17 +139,17 @@ void ZoneLaunch::Stop(bool graceful) {
|
||||
break; //we have no proc ref... cannot stop..
|
||||
if(!ProcLauncher::get()->Terminate(m_ref, graceful)) {
|
||||
//failed to terminate the process, its not likely that it will work if we try again, so give up.
|
||||
Log.Out(Logs::Detail, Logs::Launcher, "Failed to terminate zone %s. Giving up and moving to stopped.", m_zone.c_str());
|
||||
Log(Logs::Detail, Logs::Launcher, "Failed to terminate zone %s. Giving up and moving to stopped.", m_zone.c_str());
|
||||
m_state = StateStopped;
|
||||
break;
|
||||
}
|
||||
Log.Out(Logs::Detail, Logs::Launcher, "Termination signal sent to zone %s.", m_zone.c_str());
|
||||
Log(Logs::Detail, Logs::Launcher, "Termination signal sent to zone %s.", m_zone.c_str());
|
||||
m_timer.Start(m_config->TerminateWait);
|
||||
m_state = StateStopPending;
|
||||
break;
|
||||
case StateStopped:
|
||||
//process is already stopped... nothing to do..
|
||||
Log.Out(Logs::Detail, Logs::Launcher, "Stop requested when zone %s is already stopped.", m_zone.c_str());
|
||||
Log(Logs::Detail, Logs::Launcher, "Stop requested when zone %s is already stopped.", m_zone.c_str());
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -169,17 +169,17 @@ bool ZoneLaunch::Process() {
|
||||
m_timer.Disable();
|
||||
|
||||
//actually start up the program
|
||||
Log.Out(Logs::Detail, Logs::Launcher, "Starting zone %s", m_zone.c_str());
|
||||
Log(Logs::Detail, Logs::Launcher, "Starting zone %s", m_zone.c_str());
|
||||
Start();
|
||||
|
||||
//now update the shared timer to reflect the proper start interval.
|
||||
if(s_running == 1) {
|
||||
//we are the first zone started. wait that interval.
|
||||
Log.Out(Logs::Detail, Logs::Launcher, "Waiting %d milliseconds before booting the second zone.", m_config->InitialBootWait);
|
||||
Log(Logs::Detail, Logs::Launcher, "Waiting %d milliseconds before booting the second zone.", m_config->InitialBootWait);
|
||||
s_startTimer.Start(m_config->InitialBootWait);
|
||||
} else {
|
||||
//just some follow on zone, use that interval.
|
||||
Log.Out(Logs::Detail, Logs::Launcher, "Waiting %d milliseconds before booting the next zone.", m_config->ZoneBootInterval);
|
||||
Log(Logs::Detail, Logs::Launcher, "Waiting %d milliseconds before booting the next zone.", m_config->ZoneBootInterval);
|
||||
s_startTimer.Start(m_config->ZoneBootInterval);
|
||||
}
|
||||
|
||||
@@ -192,7 +192,7 @@ bool ZoneLaunch::Process() {
|
||||
//waiting for notification that our child has died..
|
||||
if(m_timer.Check()) {
|
||||
//we have timed out, try to kill the child again
|
||||
Log.Out(Logs::Detail, Logs::Launcher, "Zone %s refused to die, killing again.", m_zone.c_str());
|
||||
Log(Logs::Detail, Logs::Launcher, "Zone %s refused to die, killing again.", m_zone.c_str());
|
||||
Restart();
|
||||
}
|
||||
break;
|
||||
@@ -202,12 +202,12 @@ bool ZoneLaunch::Process() {
|
||||
//we have timed out, try to kill the child again
|
||||
m_killFails++;
|
||||
if(m_killFails > 5) { //should get this number from somewhere..
|
||||
Log.Out(Logs::Detail, Logs::Launcher, "Zone %s refused to die, giving up and acting like its dead.", m_zone.c_str());
|
||||
Log(Logs::Detail, Logs::Launcher, "Zone %s refused to die, giving up and acting like its dead.", m_zone.c_str());
|
||||
m_state = StateStopped;
|
||||
s_running--;
|
||||
SendStatus();
|
||||
} else {
|
||||
Log.Out(Logs::Detail, Logs::Launcher, "Zone %s refused to die, killing again.", m_zone.c_str());
|
||||
Log(Logs::Detail, Logs::Launcher, "Zone %s refused to die, killing again.", m_zone.c_str());
|
||||
Stop(false);
|
||||
}
|
||||
}
|
||||
@@ -226,29 +226,29 @@ void ZoneLaunch::OnTerminate(const ProcLauncher::ProcRef &ref, const ProcLaunche
|
||||
|
||||
switch(m_state) {
|
||||
case StateStartPending:
|
||||
Log.Out(Logs::Detail, Logs::Launcher, "Zone %s has gone down before we started it..?? Restart timer started.", m_zone.c_str());
|
||||
Log(Logs::Detail, Logs::Launcher, "Zone %s has gone down before we started it..?? Restart timer started.", m_zone.c_str());
|
||||
m_state = StateStartPending;
|
||||
m_timer.Start(m_config->RestartWait);
|
||||
break;
|
||||
case StateStarted:
|
||||
//something happened to our happy process...
|
||||
Log.Out(Logs::Detail, Logs::Launcher, "Zone %s has gone down. Restart timer started.", m_zone.c_str());
|
||||
Log(Logs::Detail, Logs::Launcher, "Zone %s has gone down. Restart timer started.", m_zone.c_str());
|
||||
m_state = StateStartPending;
|
||||
m_timer.Start(m_config->RestartWait);
|
||||
break;
|
||||
case StateRestartPending:
|
||||
//it finally died, start it on up again
|
||||
Log.Out(Logs::Detail, Logs::Launcher, "Zone %s has terminated. Transitioning to starting state.", m_zone.c_str());
|
||||
Log(Logs::Detail, Logs::Launcher, "Zone %s has terminated. Transitioning to starting state.", m_zone.c_str());
|
||||
m_state = StateStartPending;
|
||||
break;
|
||||
case StateStopPending:
|
||||
//it finally died, transition to close.
|
||||
Log.Out(Logs::Detail, Logs::Launcher, "Zone %s has terminated. Transitioning to stopped state.", m_zone.c_str());
|
||||
Log(Logs::Detail, Logs::Launcher, "Zone %s has terminated. Transitioning to stopped state.", m_zone.c_str());
|
||||
m_state = StateStopped;
|
||||
break;
|
||||
case StateStopped:
|
||||
//we already thought it was stopped... dont care...
|
||||
Log.Out(Logs::Detail, Logs::Launcher, "Notified of zone %s terminating when we thought it was stopped.", m_zone.c_str());
|
||||
Log(Logs::Detail, Logs::Launcher, "Notified of zone %s terminating when we thought it was stopped.", m_zone.c_str());
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user