mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-06-10 08:44:20 +00:00
chore: cleanup zoneIM (#1985)
This commit is contained in:
@@ -1,26 +1,17 @@
|
|||||||
#define _VARIADIC_MAX 10
|
|
||||||
#include "ZoneInstanceManager.h"
|
#include "ZoneInstanceManager.h"
|
||||||
|
|
||||||
// Custom Classes
|
// Custom Classes
|
||||||
#include "MasterPackets.h"
|
#include "MasterPackets.h"
|
||||||
#include "dServer.h"
|
|
||||||
|
|
||||||
// C++
|
|
||||||
#include <future>
|
|
||||||
|
|
||||||
// Static Variables
|
// Static Variables
|
||||||
ZoneInstanceManager* ZoneInstanceManager::m_Address = nullptr;
|
ZoneInstanceManager* ZoneInstanceManager::m_Address = nullptr;
|
||||||
|
|
||||||
//! Requests a zone transfer
|
//! 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) {
|
void ZoneInstanceManager::RequestZoneTransfer(dServer* server, uint32_t zoneID, uint32_t zoneClone, bool mythranShift, TransferCallback callback) {
|
||||||
|
const auto nextID = ++currentRequestID;
|
||||||
|
requests[nextID] = callback;
|
||||||
|
|
||||||
ZoneTransferRequest* request = new ZoneTransferRequest();
|
MasterPackets::SendZoneTransferRequest(server, nextID, mythranShift, zoneID, zoneClone);
|
||||||
request->requestID = ++currentRequestID;
|
|
||||||
request->callback = callback;
|
|
||||||
|
|
||||||
this->requests.push_back(request);
|
|
||||||
|
|
||||||
MasterPackets::SendZoneTransferRequest(server, request->requestID, mythranShift, zoneID, zoneClone);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Handles a zone transfer response
|
//! Handles a zone transfer response
|
||||||
@@ -43,18 +34,11 @@ void ZoneInstanceManager::HandleRequestZoneTransferResponse(Packet* packet) {
|
|||||||
LUString serverIP(255);
|
LUString serverIP(255);
|
||||||
inStream.Read(serverIP);
|
inStream.Read(serverIP);
|
||||||
|
|
||||||
for (uint32_t i = 0; i < this->requests.size(); ++i) {
|
const auto entry = requests.find(requestID);
|
||||||
if (this->requests[i]->requestID == requestID) {
|
if (entry != requests.end()) {
|
||||||
|
entry->second(mythranShift, zoneID, zoneInstance, zoneClone, serverIP.string, serverPort);
|
||||||
// Call the request callback
|
requests.erase(entry);
|
||||||
this->requests[i]->callback(mythranShift, zoneID, zoneInstance, zoneClone, serverIP.string, 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) {
|
void ZoneInstanceManager::CreatePrivateZone(dServer* server, uint32_t zoneID, uint32_t zoneClone, const std::string& password) {
|
||||||
@@ -65,12 +49,9 @@ void ZoneInstanceManager::RequestPrivateZone(
|
|||||||
dServer* server,
|
dServer* server,
|
||||||
bool mythranShift,
|
bool mythranShift,
|
||||||
const std::string& password,
|
const std::string& password,
|
||||||
std::function<void(bool, uint32_t, uint32_t, uint32_t, std::string, uint16_t)> callback) {
|
TransferCallback callback) {
|
||||||
ZoneTransferRequest* request = new ZoneTransferRequest();
|
const auto nextID = ++currentRequestID;
|
||||||
request->requestID = ++currentRequestID;
|
requests[nextID] = callback;
|
||||||
request->callback = callback;
|
|
||||||
|
|
||||||
this->requests.push_back(request);
|
MasterPackets::SendZoneRequestPrivate(server, nextID, mythranShift, password);
|
||||||
|
|
||||||
MasterPackets::SendZoneRequestPrivate(server, request->requestID, mythranShift, password);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
#include <map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
@@ -14,25 +15,20 @@ class dServer;
|
|||||||
\brief A class for handling zone transfers and zone-related functions
|
\brief A class for handling zone transfers and zone-related functions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//! The zone request
|
|
||||||
struct ZoneTransferRequest {
|
|
||||||
uint64_t requestID;
|
|
||||||
std::function<void(bool, uint32_t, uint32_t, uint32_t, std::string, uint16_t)> callback;
|
|
||||||
};
|
|
||||||
|
|
||||||
//! The zone manager
|
//! The zone manager
|
||||||
class ZoneInstanceManager {
|
class ZoneInstanceManager {
|
||||||
private:
|
private:
|
||||||
static ZoneInstanceManager* m_Address; //!< The singleton instance
|
static ZoneInstanceManager* m_Address; //!< The singleton instance
|
||||||
|
|
||||||
std::vector<ZoneTransferRequest*> requests; //!< The zone transfer requests
|
using TransferCallback = std::function<void(bool, uint32_t, uint32_t, uint32_t, std::string, uint16_t)>;
|
||||||
|
std::map<uint64_t, TransferCallback> requests; //!< The zone transfer requests
|
||||||
uint64_t currentRequestID; //!< The current request ID
|
uint64_t currentRequestID; //!< The current request ID
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
//! The singleton method
|
//! The singleton method
|
||||||
static ZoneInstanceManager* Instance() {
|
static ZoneInstanceManager* Instance() {
|
||||||
if (m_Address == 0) {
|
if (m_Address == nullptr) {
|
||||||
m_Address = new ZoneInstanceManager;
|
m_Address = new ZoneInstanceManager;
|
||||||
m_Address->currentRequestID = 0;
|
m_Address->currentRequestID = 0;
|
||||||
}
|
}
|
||||||
@@ -47,7 +43,7 @@ public:
|
|||||||
\param mythranShift Whether or not this is a mythran shift
|
\param mythranShift Whether or not this is a mythran shift
|
||||||
\param callback The callback function
|
\param callback The callback function
|
||||||
*/
|
*/
|
||||||
void 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);
|
void RequestZoneTransfer(dServer* server, uint32_t zoneID, uint32_t zoneClone, bool mythranShift, TransferCallback callback);
|
||||||
|
|
||||||
//! Handles a zone transfer response
|
//! Handles a zone transfer response
|
||||||
/*!
|
/*!
|
||||||
@@ -58,6 +54,5 @@ public:
|
|||||||
|
|
||||||
void CreatePrivateZone(dServer* server, uint32_t zoneID, uint32_t zoneClone, const std::string& password);
|
void CreatePrivateZone(dServer* server, uint32_t zoneID, uint32_t zoneClone, const std::string& password);
|
||||||
|
|
||||||
void RequestPrivateZone(dServer* server, bool mythranShift, const std::string& password, std::function<void(bool, uint32_t, uint32_t, uint32_t, std::string, uint16_t)> callback);
|
void RequestPrivateZone(dServer* server, bool mythranShift, const std::string& password, TransferCallback callback);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user