DarkflameServer/dNet/ZoneInstanceManager.cpp

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
2022-07-28 13:39:57 +00:00
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;
this->requests.push_back(request);
MasterPackets::SendZoneTransferRequest(server, request->requestID, mythranShift, zoneID, zoneClone);
}
//! Handles a zone transfer response
2022-07-28 13:39:57 +00:00
void ZoneInstanceManager::HandleRequestZoneTransferResponse(uint64_t requestID, Packet* packet) {
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);
2022-07-28 13:39:57 +00:00
std::string serverIP = PacketUtils::ReadString(31, packet, false);
for (uint32_t i = 0; i < this->requests.size(); ++i) {
if (this->requests[i]->requestID == requestID) {
// Call the request callback
this->requests[i]->callback(mythranShift, zoneID, zoneInstance, zoneClone, serverIP, serverPort);
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(
2022-07-28 13:39:57 +00:00
dServer* server,
bool mythranShift,
const std::string& password,
2022-07-28 13:39:57 +00:00
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;
2022-07-28 13:39:57 +00:00
this->requests.push_back(request);
2022-07-28 13:39:57 +00:00
MasterPackets::SendZoneRequestPrivate(server, request->requestID, mythranShift, password);
}