DarkflameServer/dNet/ZoneInstanceManager.cpp
wincent 4004534732 Initial work on TCP transport layer:
* Optionally compiled additional TCP transport layer.
* Config to enable it.
* Tested and functional with lcdr's tcpudp dll, udp being disabled in the dll due to port issues.
* Removed unused RakNet replica manager and id manager. We've got our own replica manager since pre-open-source.
* Utilizes async boost behavior.

Todo:
* Figure out how to do ping calculations.
* Fix crashes on universe shutdown.
* Test TLS on a VPS.
* Remove unnecessary logging.
* Test with lots of clients.
* Finish "master" to "manager" naming refactor.
2024-10-13 22:42:59 +02:00

77 lines
2.3 KiB
C++

#define _VARIADIC_MAX 10
#include "ZoneInstanceManager.h"
// Custom Classes
#include "MasterPackets.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->GetTransportLayerPtr(), request->requestID, mythranShift, zoneID, zoneClone);
}
//! Handles a zone transfer response
void ZoneInstanceManager::HandleRequestZoneTransferResponse(Packet* packet) {
CINSTREAM_SKIP_HEADER;
uint64_t requestID;
inStream.Read(requestID);
bool mythranShift;
uint8_t tmp;
inStream.Read(tmp);
mythranShift = tmp > 0;
uint32_t zoneID;
inStream.Read(zoneID);
uint32_t zoneInstance;
inStream.Read(zoneInstance);
uint32_t zoneClone;
inStream.Read(zoneClone);
uint16_t serverPort;
inStream.Read(serverPort);
LUString serverIP(255);
inStream.Read(serverIP);
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.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) {
MasterPackets::SendZoneCreatePrivate(server->GetTransportLayerPtr(), 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->GetTransportLayerPtr(), request->requestID, mythranShift, password);
}