mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-10-02 10:53:44 +00:00
feat(master): the server list names each server's port and machine
Master keeps the address and port auth, chat, the dashboard and the UGC server report when they connect and sends them, with its own and every world's, after the list's world states. A server's machine is the address master sees its connection come from; loopback and master's external_ip are master's machine. Servers can report another port than their RakNet one; the UGC server reports its web port. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -248,6 +248,15 @@ namespace MasterPackets {
|
||||
bitStream.Write(ugcOnline);
|
||||
bitStream.Write(ugcPid);
|
||||
for (const auto& instance : instances) bitStream.Write(static_cast<uint8_t>(instance.state));
|
||||
bitStream.Write<uint32_t>(endpoints.size());
|
||||
for (const auto& endpoint : endpoints) {
|
||||
bitStream.Write(endpoint.type);
|
||||
bitStream.Write(endpoint.zoneID);
|
||||
bitStream.Write(endpoint.instanceID);
|
||||
bitStream.Write(endpoint.ip);
|
||||
bitStream.Write(endpoint.port);
|
||||
bitStream.Write(endpoint.host);
|
||||
}
|
||||
}
|
||||
|
||||
bool ServerListResponse::Deserialize(RakNet::BitStream& bitStream) {
|
||||
@@ -275,6 +284,18 @@ namespace MasterPackets {
|
||||
if (state > static_cast<uint8_t>(eState::DRAINING)) return false;
|
||||
instance.state = static_cast<eState>(state);
|
||||
}
|
||||
uint32_t endpointCount{};
|
||||
VALIDATE_READ(bitStream.Read(endpointCount));
|
||||
if (endpointCount > MAX_INSTANCES + MAX_OTHER_ENDPOINTS) return false;
|
||||
endpoints.resize(endpointCount);
|
||||
for (auto& endpoint : endpoints) {
|
||||
VALIDATE_READ(bitStream.Read(endpoint.type));
|
||||
VALIDATE_READ(bitStream.Read(endpoint.zoneID));
|
||||
VALIDATE_READ(bitStream.Read(endpoint.instanceID));
|
||||
VALIDATE_READ(bitStream.Read(endpoint.ip));
|
||||
VALIDATE_READ(bitStream.Read(endpoint.port));
|
||||
VALIDATE_READ(bitStream.Read(endpoint.host));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -278,6 +278,21 @@ namespace MasterPackets {
|
||||
uint8_t ugcOnline{};
|
||||
uint32_t ugcPid{};
|
||||
|
||||
// Where each server listens and which machine it runs on, after the worlds' states: master, auth, chat, the
|
||||
// dashboard, the UGC server and every world. `ip` and `port` are what the server said it listens on (the
|
||||
// dashboard and the UGC server: their web port); `host` is its machine, the address master sees its
|
||||
// connection come from (master's own machine, and servers connecting from it, are master's external_ip)
|
||||
struct Endpoint {
|
||||
ServiceType type{};
|
||||
uint32_t zoneID{};
|
||||
uint32_t instanceID{};
|
||||
LUString ip{};
|
||||
uint32_t port{};
|
||||
LUString host{};
|
||||
};
|
||||
std::vector<Endpoint> endpoints; // u32 count, at most MAX_INSTANCES + MAX_OTHER_ENDPOINTS
|
||||
static constexpr uint32_t MAX_OTHER_ENDPOINTS = 16;
|
||||
|
||||
ServerListResponse() : LUBitStream(ServiceType::MASTER, MessageType::Master::SERVER_LIST_RESPONSE) {}
|
||||
void Serialize(RakNet::BitStream& bitStream) const override;
|
||||
bool Deserialize(RakNet::BitStream& bitStream) override;
|
||||
|
||||
@@ -170,7 +170,7 @@ Packet* dServer::ReceiveFromMaster() {
|
||||
mMasterSystemAddress = packet->systemAddress;
|
||||
LOG("SendServerInfo called for server type %i", static_cast<int>(GetServerType()));
|
||||
MasterPackets::ServerInfo info;
|
||||
info.port = GetPort();
|
||||
info.port = mAdvertisedPort ? mAdvertisedPort : GetPort();
|
||||
info.zoneID = GetZoneID();
|
||||
info.instanceID = GetInstanceID();
|
||||
info.serverType = GetServerType();
|
||||
|
||||
@@ -72,6 +72,10 @@ public:
|
||||
using ConnectionIdentity = std::function<void(const SystemAddress& sysAddr, TrafficStats::Connection& connection)>;
|
||||
void SetConnectionIdentity(ConnectionIdentity identity) { mConnectionIdentity = std::move(identity); }
|
||||
|
||||
// The port this server tells master it listens on (its ServerInfo, shown on the dashboard's Network page): its
|
||||
// RakNet port unless set. The dashboard and the UGC server set their web port.
|
||||
void SetAdvertisedPort(uint32_t port) { mAdvertisedPort = port; }
|
||||
|
||||
bool IsConnected(const SystemAddress& sysAddr);
|
||||
const std::string& GetIP() const { return mIP; }
|
||||
const int GetPort() const { return mPort; }
|
||||
@@ -124,6 +128,7 @@ protected:
|
||||
Logger* mLogger = nullptr;
|
||||
dConfig* mConfig = nullptr;
|
||||
RakPeerInterface* mPeer = nullptr;
|
||||
uint32_t mAdvertisedPort = 0;
|
||||
ReplicaManager* mReplicaManager = nullptr;
|
||||
NetworkIDManager* mNetIDManager = nullptr;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user