DarkflameServer/dNet/ZoneInstanceManager.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

68 lines
2.2 KiB
C++
Raw Normal View History

#define _VARIADIC_MAX 10
#include "ZoneInstanceManager.h"
// Custom Classes
#include "MasterPackets.h"
#include "PacketUtils.h"
#include "dServer.h"
// C++
#include <future>
// Static Variables
ZoneInstanceManager* ZoneInstanceManager::m_Address = nullptr;
//! Requests a zone transfer
void ZoneInstanceManager::RequestZoneTransfer(dServer* server, uint32_t zoneID, uint32_t zoneClone, bool mythranShift, std::function<void(bool, uint32_t, uint32_t, uint32_t, std::string, uint16_t)> callback) {
2022-07-28 13:39:57 +00:00
ZoneTransferRequest* request = new ZoneTransferRequest();
request->requestID = ++currentRequestID;
request->callback = callback;
2022-07-28 13:39:57 +00:00
this->requests.push_back(request);
2022-07-28 13:39:57 +00:00
MasterPackets::SendZoneTransferRequest(server, request->requestID, mythranShift, zoneID, zoneClone);
}
//! Handles a zone transfer response
void ZoneInstanceManager::HandleRequestZoneTransferResponse(uint64_t requestID, Packet* packet) {
2022-07-28 13:39:57 +00:00
bool mythranShift = static_cast<bool>(packet->data[16]);
uint32_t zoneID = PacketUtils::ReadU32(17, packet);
uint32_t zoneInstance = PacketUtils::ReadU32(21, packet);
uint32_t zoneClone = PacketUtils::ReadU32(25, packet);
uint16_t serverPort = PacketUtils::ReadU16(29, packet);
std::string serverIP = PacketUtils::ReadString(31, packet, false);
2022-07-28 13:39:57 +00:00
for (uint32_t i = 0; i < this->requests.size(); ++i) {
if (this->requests[i]->requestID == requestID) {
2022-07-28 13:39:57 +00:00
// Call the request callback
this->requests[i]->callback(mythranShift, zoneID, zoneInstance, zoneClone, serverIP, serverPort);
2022-07-28 13:39:57 +00:00
delete this->requests[i];
this->requests.erase(this->requests.begin() + i);
return;
}
}
2022-07-28 13:39:57 +00:00
}
void ZoneInstanceManager::CreatePrivateZone(dServer* server, uint32_t zoneID, uint32_t zoneClone, const std::string& password) {
MasterPackets::SendZoneCreatePrivate(server, zoneID, zoneClone, password);
}
void ZoneInstanceManager::RequestPrivateZone(
dServer* server,
bool mythranShift,
const std::string& password,
std::function<void(bool, uint32_t, uint32_t, uint32_t, std::string, uint16_t)> callback) {
ZoneTransferRequest* request = new ZoneTransferRequest();
request->requestID = ++currentRequestID;
request->callback = callback;
this->requests.push_back(request);
MasterPackets::SendZoneRequestPrivate(server, request->requestID, mythranShift, password);
}