Merge remote-tracking branch 'origin/main' into web-dashboard-simplier

# Conflicts:
#	dMasterServer/MasterServer.cpp
This commit is contained in:
Aaron Kimbrell
2026-06-28 01:57:53 -05:00
262 changed files with 3943 additions and 2641 deletions

View File

@@ -308,7 +308,7 @@ const InstancePtr& InstanceManager::FindPrivateInstance(const std::string& passw
continue;
}
LOG("Password: %s == %s => %d", password.c_str(), instance->GetPassword().c_str(), password == instance->GetPassword());
LOG("Checking private zone password match (result: %d)", password == instance->GetPassword());
if (instance->GetPassword() == password) {
return instance;
@@ -332,6 +332,12 @@ int InstanceManager::GetHardCap(LWOMAPID mapID) {
return zone ? zone->population_hard_cap : 12;
}
void InstanceManager::PruneUnreadyInstances() {
for (int i = static_cast<int>(m_Instances.size()) - 1; i >= 0; i--) {
if (!m_Instances[i]->GetIsReady()) m_Instances.erase(m_Instances.cbegin() + i);
}
}
void Instance::SetShutdownComplete(const bool value) {
m_Shutdown = value;
}
@@ -359,4 +365,3 @@ bool Instance::IsFull(bool isFriendTransfer) const {
return true;
}

View File

@@ -133,6 +133,7 @@ public:
const InstancePtr& CreatePrivateInstance(LWOMAPID mapID, LWOCLONEID cloneID, const std::string& password);
const InstancePtr& FindPrivateInstance(const std::string& password);
void SetIsShuttingDown(bool value) { this->m_IsShuttingDown = value; };
void PruneUnreadyInstances();
private:
std::string mExternalIP;

View File

@@ -329,20 +329,14 @@ int main(int argc, char** argv) {
}
Game::randomEngine = std::mt19937(time(0));
uint32_t maxClients = 999;
uint32_t ourPort = 2000;
std::string ourIP = "localhost";
const auto maxClientsString = Game::config->GetValue("max_clients");
if (!maxClientsString.empty()) maxClients = std::stoi(maxClientsString);
const auto masterServerPortString = Game::config->GetValue("master_server_port");
if (!masterServerPortString.empty()) ourPort = std::atoi(masterServerPortString.c_str());
const auto externalIPString = Game::config->GetValue("external_ip");
if (!externalIPString.empty()) ourIP = externalIPString;
uint32_t maxClients = Game::config->GetValue("max_clients", 999);
uint32_t ourPort = Game::config->GetValue("master_server_port", 2000);
std::string ourIP = Game::config->GetValue("external_ip", "localhost");
char salt[BCRYPT_HASHSIZE];
char hash[BCRYPT_HASHSIZE];
const auto& cfgPassword = Game::config->GetValue("master_password");
int res = GenerateBCryptPassword(!cfgPassword.empty() ? cfgPassword : "3.25DARKFLAME1", 13, salt, hash);
const auto& cfgPassword = Game::config->GetValue<std::string>("master_password", "3.25DARKFLAME1");
int res = GenerateBCryptPassword(cfgPassword, 13, salt, hash);
assert(res == 0);
Game::server = new dServer(ourIP, ourPort, 0, maxClients, true, false, Game::logger, "", 0, ServiceType::MASTER, Game::config, &Game::lastSignal, hash);
@@ -551,8 +545,7 @@ void HandlePacket(Packet* packet) {
case MessageType::Master::REQUEST_ZONE_TRANSFER: {
LOG("Received zone transfer req");
RakNet::BitStream inStream(packet->data, packet->length, false);
uint64_t header = inStream.Read(header);
CINSTREAM_SKIP_HEADER;
uint64_t requestID = 0;
uint8_t mythranShift = false;
uint32_t zoneID = 0;
@@ -591,8 +584,7 @@ void HandlePacket(Packet* packet) {
//This is here because otherwise we'd have to include IM in
//non-master servers. This packet allows us to add World
//servers back if master crashed
RakNet::BitStream inStream(packet->data, packet->length, false);
uint64_t header = inStream.Read(header);
CINSTREAM_SKIP_HEADER;
uint32_t theirPort = 0;
uint32_t theirZoneID = 0;
@@ -618,13 +610,13 @@ void HandlePacket(Packet* packet) {
instance->SetSysAddr(packet->systemAddress);
}
}
break;
break;
case ServiceType::CHAT:
chatServerMasterPeerSysAddr = packet->systemAddress;
break;
case ServiceType::AUTH:
authServerMasterPeerSysAddr = packet->systemAddress;
break;
case ServiceType::AUTH:
authServerMasterPeerSysAddr = packet->systemAddress;
break;
case ServiceType::DASHBOARD:
dashboardServerMasterPeerSysAddr = packet->systemAddress;
break;
@@ -683,8 +675,7 @@ void HandlePacket(Packet* packet) {
}
case MessageType::Master::PLAYER_ADDED: {
RakNet::BitStream inStream(packet->data, packet->length, false);
uint64_t header = inStream.Read(header);
CINSTREAM_SKIP_HEADER;
LWOMAPID theirZoneID = 0;
LWOINSTANCEID theirInstanceID = 0;
@@ -693,7 +684,7 @@ void HandlePacket(Packet* packet) {
inStream.Read(theirInstanceID);
const auto& instance =
Game::im->FindInstance(theirZoneID, theirInstanceID);
Game::im->FindInstanceWithPrivate(theirZoneID, theirInstanceID);
if (instance) {
instance->AddPlayer(Player());
} else {
@@ -703,8 +694,7 @@ void HandlePacket(Packet* packet) {
}
case MessageType::Master::PLAYER_REMOVED: {
RakNet::BitStream inStream(packet->data, packet->length, false);
uint64_t header = inStream.Read(header);
CINSTREAM_SKIP_HEADER;
LWOMAPID theirZoneID = 0;
LWOINSTANCEID theirInstanceID = 0;
@@ -721,8 +711,7 @@ void HandlePacket(Packet* packet) {
}
case MessageType::Master::CREATE_PRIVATE_ZONE: {
RakNet::BitStream inStream(packet->data, packet->length, false);
uint64_t header = inStream.Read(header);
CINSTREAM_SKIP_HEADER;
uint32_t mapId;
LWOCLONEID cloneId;
@@ -733,20 +722,21 @@ void HandlePacket(Packet* packet) {
uint32_t len;
inStream.Read<uint32_t>(len);
len = std::min<uint32_t>(len, 50); // cap the master password at 50 characters
for (uint32_t i = 0; len > i; i++) {
char character;
inStream.Read<char>(character);
password += character;
}
const auto& newInst = Game::im->CreatePrivateInstance(mapId, cloneId, password.c_str());
LOG("Creating private zone %i/%i/%i with password %s", newInst->GetMapID(), newInst->GetCloneID(), newInst->GetInstanceID(), password.c_str());
LOG("Creating private zone %i/%i/%i", newInst->GetMapID(), newInst->GetCloneID(), newInst->GetInstanceID());
break;
}
case MessageType::Master::REQUEST_PRIVATE_ZONE: {
RakNet::BitStream inStream(packet->data, packet->length, false);
uint64_t header = inStream.Read(header);
CINSTREAM_SKIP_HEADER;
uint64_t requestID = 0;
uint8_t mythranShift = false;
@@ -758,6 +748,7 @@ void HandlePacket(Packet* packet) {
uint32_t len;
inStream.Read<uint32_t>(len);
len = std::min<uint32_t>(len, 50);
for (uint32_t i = 0; i < len; i++) {
char character; inStream.Read<char>(character);
@@ -766,7 +757,7 @@ void HandlePacket(Packet* packet) {
const auto& instance = Game::im->FindPrivateInstance(password.c_str());
LOG("Join private zone: %llu %d %s %p", requestID, mythranShift, password.c_str(), instance.get());
LOG("Join private zone: %llu %d %p", requestID, mythranShift, instance.get());
if (instance == nullptr) {
return;
@@ -780,8 +771,7 @@ void HandlePacket(Packet* packet) {
}
case MessageType::Master::WORLD_READY: {
RakNet::BitStream inStream(packet->data, packet->length, false);
uint64_t header = inStream.Read(header);
CINSTREAM_SKIP_HEADER;
LWOMAPID zoneID;
LWOINSTANCEID instanceID;
@@ -791,7 +781,7 @@ void HandlePacket(Packet* packet) {
LOG("Got world ready %i %i", zoneID, instanceID);
const auto& instance = Game::im->FindInstance(zoneID, instanceID);
const auto& instance = Game::im->FindInstanceWithPrivate(zoneID, instanceID);
if (instance == nullptr) {
LOG("Failed to find zone to ready");
@@ -804,8 +794,7 @@ void HandlePacket(Packet* packet) {
}
case MessageType::Master::PREP_ZONE: {
RakNet::BitStream inStream(packet->data, packet->length, false);
uint64_t header = inStream.Read(header);
CINSTREAM_SKIP_HEADER;
int32_t zoneID;
inStream.Read(zoneID);
@@ -820,8 +809,7 @@ void HandlePacket(Packet* packet) {
}
case MessageType::Master::AFFIRM_TRANSFER_RESPONSE: {
RakNet::BitStream inStream(packet->data, packet->length, false);
uint64_t header = inStream.Read(header);
CINSTREAM_SKIP_HEADER;
uint64_t requestID;
@@ -889,13 +877,11 @@ int ShutdownSequence(int32_t signal) {
}
// A server might not be finished spinning up yet, remove all of those here.
// prune the unready ones before looping over all of them
Game::im->PruneUnreadyInstances();
for (const auto& instance : Game::im->GetInstances()) {
if (!instance) continue;
if (!instance->GetIsReady()) {
Game::im->RemoveInstance(instance);
}
instance->SetIsShuttingDown(true);
}