Files
DarkflameServer/dNet/ZoneInstanceManager.h
Aaron Kimbrell 4cf0909d52 feat(master): an edit mode flag on a private instance, down to its world server
CreatePrivateZone carries editMode as one more byte, written only when set, so
a plain private zone is sent as before. Master keeps it on the instance, starts
the world server with -editmode 1, and gives a private instance's replacement
(a reload or a live update) the same flag. Nothing sets it yet.

A capped string now skips the characters it cut, so what follows it is read
from the right place. A request to join a private instance that is still
starting is answered once its world server is ready, instead of at once with
an address nothing listens on yet.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-10 17:34:13 -06:00

70 lines
2.3 KiB
C++

#pragma once
#include <functional>
#include <map>
#include <vector>
#include <string>
// RakNet
#include "RakNetTypes.h"
#include "Stamps.h"
class dServer;
namespace MasterPackets {
struct RequestZoneTransferResponse;
}
/*!
\file ZoneInstanceManager.hpp
\brief A class for handling zone transfers and zone-related functions
*/
//! The zone manager
class ZoneInstanceManager {
private:
static ZoneInstanceManager* m_Address; //!< The singleton instance
using TransferCallback = std::function<void(bool, uint32_t, uint32_t, uint32_t, std::string, uint16_t)>;
// Also gets the login stamps that came back with the response (see Stamps.h)
using StampedTransferCallback = std::function<void(bool, uint32_t, uint32_t, uint32_t, std::string, uint16_t, Stamps)>;
std::map<uint64_t, StampedTransferCallback> requests; //!< The zone transfer requests
uint64_t currentRequestID; //!< The current request ID
public:
//! The singleton method
static ZoneInstanceManager* Instance() {
if (m_Address == nullptr) {
m_Address = new ZoneInstanceManager;
m_Address->currentRequestID = 0;
}
return m_Address;
}
//! Requests a zone transfer
/*!
\param zoneID The zone ID
\param zoneClone The zone clone
\param mythranShift Whether or not this is a mythran shift
\param callback The callback function
*/
void RequestZoneTransfer(dServer* server, uint32_t zoneID, uint32_t zoneClone, bool mythranShift, TransferCallback callback);
//! Requests a zone transfer for a login: the stamps travel to master, which adds its own, and come back to the callback
void RequestZoneTransfer(dServer* server, uint32_t zoneID, uint32_t zoneClone, bool mythranShift, const Stamps& stamps, StampedTransferCallback callback);
//! Handles a zone transfer response
/*!
\param requestID The request ID
\param packet The packet
*/
void HandleRequestZoneTransferResponse(const MasterPackets::RequestZoneTransferResponse& response);
// editMode: a GM's edit mode instance, whose world server constructs none of the zone's objects
void CreatePrivateZone(dServer* server, uint32_t zoneID, uint32_t zoneClone, const std::string& password, bool editMode = false);
void RequestPrivateZone(dServer* server, bool mythranShift, const std::string& password, TransferCallback callback);
};