mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2024-12-03 12:13:38 +00:00
08020cd86d
* chore: cleanup LU(W)string writing and add methods for reading remove redunent "packet" from packet reading helpers move write header to bitstreamutils since it's not packet related add tests for reading/writing LU(W)Strings * remove un-needed function defintions in header * make reading and writing more efficient * p p * quotes * remove unneeded default --------- Co-authored-by: David Markowitz <39972741+EmosewaMC@users.noreply.github.com>
68 lines
2.2 KiB
C++
68 lines
2.2 KiB
C++
#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) {
|
|
|
|
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
|
|
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);
|
|
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;
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
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);
|
|
}
|