WIP: basic server, no features

This commit is contained in:
Aaron Kimbrell
2026-01-25 22:33:51 -06:00
parent c723ce2588
commit f1847d1f20
67 changed files with 7655 additions and 37 deletions

View File

@@ -68,6 +68,7 @@ void HandlePacket(Packet* packet);
std::map<uint32_t, std::string> activeSessions;
SystemAddress authServerMasterPeerSysAddr;
SystemAddress chatServerMasterPeerSysAddr;
SystemAddress dashboardServerMasterPeerSysAddr;
int GenerateBCryptPassword(const std::string& password, const int workFactor, char salt[BCRYPT_HASHSIZE], char hash[BCRYPT_HASHSIZE]) {
int32_t bcryptState = ::bcrypt_gensalt(workFactor, salt);
@@ -381,6 +382,11 @@ int main(int argc, char** argv) {
StartAuthServer();
}
// Start web dashboard if enabled
if (Game::config->GetValue("enable_dashboard") == "1") {
StartDashboardServer();
}
auto t = std::chrono::high_resolution_clock::now();
Packet* packet = nullptr;
constexpr uint32_t logFlushTime = 15 * masterFramerate;
@@ -505,6 +511,11 @@ void HandlePacket(Packet* packet) {
authServerMasterPeerSysAddr = UNASSIGNED_SYSTEM_ADDRESS;
StartAuthServer();
}
if (packet->systemAddress == dashboardServerMasterPeerSysAddr) {
dashboardServerMasterPeerSysAddr = UNASSIGNED_SYSTEM_ADDRESS;
StartDashboardServer();
}
}
if (packet->data[0] == ID_CONNECTION_LOST) {
@@ -526,6 +537,11 @@ void HandlePacket(Packet* packet) {
authServerMasterPeerSysAddr = UNASSIGNED_SYSTEM_ADDRESS;
StartAuthServer();
}
if (packet->systemAddress == dashboardServerMasterPeerSysAddr) {
dashboardServerMasterPeerSysAddr = UNASSIGNED_SYSTEM_ADDRESS;
StartDashboardServer();
}
}
if (packet->length < 4) return;
@@ -609,6 +625,9 @@ void HandlePacket(Packet* packet) {
case ServiceType::AUTH:
authServerMasterPeerSysAddr = packet->systemAddress;
break;
case ServiceType::DASHBOARD:
dashboardServerMasterPeerSysAddr = packet->systemAddress;
break;
default:
// We just ignore any other server type
break;
@@ -907,7 +926,10 @@ int ShutdownSequence(int32_t signal) {
}
}
if (allInstancesShutdown && authServerMasterPeerSysAddr == UNASSIGNED_SYSTEM_ADDRESS && chatServerMasterPeerSysAddr == UNASSIGNED_SYSTEM_ADDRESS) {
if (allInstancesShutdown && \
authServerMasterPeerSysAddr == UNASSIGNED_SYSTEM_ADDRESS && \
chatServerMasterPeerSysAddr == UNASSIGNED_SYSTEM_ADDRESS && \
dashboardServerMasterPeerSysAddr == UNASSIGNED_SYSTEM_ADDRESS) {
LOG("Finished shutting down MasterServer!");
break;
}
@@ -919,6 +941,26 @@ int ShutdownSequence(int32_t signal) {
if (framesSinceShutdownStart == maxShutdownTime) {
LOG("Finished shutting down by timeout!");
// log what we were waiting on: worlds, chat, auth, dashboard, etc
if (authServerMasterPeerSysAddr != UNASSIGNED_SYSTEM_ADDRESS) {
LOG("Auth server did not shutdown in time");
}
if (chatServerMasterPeerSysAddr != UNASSIGNED_SYSTEM_ADDRESS) {
LOG("Chat server did not shutdown in time");
}
if (dashboardServerMasterPeerSysAddr != UNASSIGNED_SYSTEM_ADDRESS) {
LOG("Web server did not shutdown in time");
}
for (const auto& instance : Game::im->GetInstances()) {
if (instance == nullptr) {
continue;
}
if (!instance->GetShutdownComplete()) {
LOG("Instance zone %i clone %i instance %i port %i did not shutdown in time", instance->GetMapID(), instance->GetCloneID(), instance->GetInstanceID(), instance->GetPort());
}
}
break;
}
}

View File

@@ -107,6 +107,42 @@ uint32_t StartAuthServer() {
return auth_pid;
}
uint32_t StartDashboardServer() {
if (Game::ShouldShutdown()) {
LOG("Currently shutting down. DashboardServer will not be restarted.");
return 0;
}
auto web_path = BinaryPathFinder::GetBinaryDir() / "DashboardServer";
#ifdef _WIN32
web_path.replace_extension(".exe");
auto web_startup = startup;
auto web_info = PROCESS_INFORMATION{};
if (!CreateProcessW(web_path.wstring().data(), web_path.wstring().data(),
nullptr, nullptr, false, 0, nullptr, nullptr,
&web_startup, &web_info))
{
LOG("Failed to launch DashboardServer");
return 0;
}
// get pid and close unused handles
auto web_pid = web_info.dwProcessId;
CloseHandle(web_info.hProcess);
CloseHandle(web_info.hThread);
#else // *nix systems
const auto web_pid = fork();
if (web_pid < 0) {
LOG("Failed to launch DashboardServer");
return 0;
} else if (web_pid == 0) {
// We are the child process
execl(web_path.string().c_str(), web_path.string().c_str(), nullptr);
}
#endif
LOG("DashboardServer PID is %d", web_pid);
return web_pid;
}
uint32_t StartWorldServer(LWOMAPID mapID, uint16_t port, LWOINSTANCEID lastInstanceID, int maxPlayers, LWOCLONEID cloneID) {
auto world_path = BinaryPathFinder::GetBinaryDir() / "WorldServer";
#ifdef _WIN32

View File

@@ -3,4 +3,5 @@
uint32_t StartAuthServer();
uint32_t StartChatServer();
uint32_t StartDashboardServer();
uint32_t StartWorldServer(LWOMAPID mapID, uint16_t port, LWOINSTANCEID lastInstanceID, int maxPlayers, LWOCLONEID cloneID);