mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-06-29 10:04:23 +00:00
Merge remote-tracking branch 'origin/main' into web-dashboard-simplier
# Conflicts: # dMasterServer/MasterServer.cpp
This commit is contained in:
@@ -157,8 +157,7 @@ void AuthPackets::HandleLoginRequest(dServer* server, Packet* packet) {
|
||||
}
|
||||
|
||||
//If we aren't running in live mode, then only GMs are allowed to enter:
|
||||
const auto& closedToNonDevs = Game::config->GetValue("closed_to_non_devs");
|
||||
if (closedToNonDevs.size() > 0 && bool(std::stoi(closedToNonDevs)) && accountInfo->maxGmLevel == eGameMasterLevel::CIVILIAN) {
|
||||
if (Game::config->GetValue<bool>("closed_to_non_devs", false) && accountInfo->maxGmLevel == eGameMasterLevel::CIVILIAN) {
|
||||
stamps.emplace_back(eStamps::GM_REQUIRED, 1);
|
||||
AuthPackets::SendLoginResponse(server, packet->systemAddress, eLoginResponse::PERMISSIONS_NOT_HIGH_ENOUGH, "The server is currently only open to developers.", "", 2001, username, stamps);
|
||||
return;
|
||||
@@ -307,6 +306,6 @@ void AuthPackets::SendLoginResponse(dServer* server, const SystemAddress& sysAdd
|
||||
bitStream.Write(LUString(username));
|
||||
server->SendToMaster(bitStream);
|
||||
|
||||
LOG("Set sessionKey: %i for user %s", sessionKey, username.c_str());
|
||||
LOG("Set session key for user %s", username.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,14 +11,16 @@ ChatMessage ClientPackets::HandleChatMessage(Packet* packet) {
|
||||
CINSTREAM_SKIP_HEADER;
|
||||
|
||||
ChatMessage message;
|
||||
uint32_t messageLength;
|
||||
int32_t messageLength{};
|
||||
|
||||
inStream.Read(message.chatChannel);
|
||||
inStream.Read(message.unknown);
|
||||
inStream.Read(messageLength);
|
||||
|
||||
for (uint32_t i = 0; i < (messageLength - 1); ++i) {
|
||||
uint16_t character;
|
||||
if (messageLength > MAX_MESSAGE_LENGTH || messageLength < 0) return message;
|
||||
|
||||
for (int32_t i = 0; i < (messageLength - 1); ++i) {
|
||||
char16_t character;
|
||||
inStream.Read(character);
|
||||
message.message.push_back(character);
|
||||
}
|
||||
@@ -106,6 +108,7 @@ ChatModerationRequest ClientPackets::HandleChatModerationRequest(Packet* packet)
|
||||
|
||||
uint16_t messageLength;
|
||||
inStream.Read(messageLength);
|
||||
if (messageLength > MAX_MESSAGE_LENGTH) return request;
|
||||
for (uint32_t i = 0; i < messageLength; ++i) {
|
||||
uint16_t character;
|
||||
inStream.Read(character);
|
||||
|
||||
@@ -77,7 +77,8 @@ void MasterPackets::SendZoneTransferResponse(dServer* server, const SystemAddres
|
||||
|
||||
void MasterPackets::HandleServerInfo(Packet* packet) {
|
||||
RakNet::BitStream inStream(packet->data, packet->length, false);
|
||||
uint64_t header = inStream.Read(header);
|
||||
uint64_t header{};
|
||||
inStream.Read(header);
|
||||
|
||||
uint32_t theirPort = 0;
|
||||
uint32_t theirZoneID = 0;
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "BitStreamUtils.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <ranges>
|
||||
|
||||
void HTTPMonitorInfo::Serialize(RakNet::BitStream& bitStream) const {
|
||||
bitStream.Write(port);
|
||||
@@ -88,27 +89,24 @@ void WorldPackets::SendCreateCharacter(const SystemAddress& sysAddr, int64_t rep
|
||||
|
||||
RakNet::BitStream data;
|
||||
|
||||
std::vector<std::unique_ptr<LDFBaseData>> ldfData;
|
||||
ldfData.push_back(std::move(make_unique<LDFData<LWOOBJID>>(u"objid", player)));
|
||||
ldfData.push_back(std::move(make_unique<LDFData<LOT>>(u"template", 1)));
|
||||
ldfData.push_back(std::move(make_unique<LDFData<string>>(u"xmlData", xmlData)));
|
||||
ldfData.push_back(std::move(make_unique<LDFData<u16string>>(u"name", username)));
|
||||
ldfData.push_back(std::move(make_unique<LDFData<int32_t>>(u"gmlevel", static_cast<int32_t>(gm))));
|
||||
ldfData.push_back(std::move(make_unique<LDFData<int32_t>>(u"chatmode", static_cast<int32_t>(gm))));
|
||||
ldfData.push_back(std::move(make_unique<LDFData<int64_t>>(u"reputation", reputation)));
|
||||
ldfData.push_back(std::move(make_unique<LDFData<int32_t>>(u"propertycloneid", cloneID)));
|
||||
LwoNameValue ldfData;
|
||||
ldfData.Insert<LWOOBJID>(u"objid", player);
|
||||
ldfData.Insert<LOT>(u"template", 1);
|
||||
ldfData.Insert<string>(u"xmlData", xmlData);
|
||||
ldfData.Insert<u16string>(u"name", username);
|
||||
ldfData.Insert<int32_t>(u"gmlevel", static_cast<int32_t>(gm));
|
||||
ldfData.Insert<int32_t>(u"chatmode", static_cast<int32_t>(gm));
|
||||
ldfData.Insert<int64_t>(u"reputation", reputation);
|
||||
ldfData.Insert<int32_t>(u"propertycloneid", cloneID);
|
||||
|
||||
data.Write<uint32_t>(ldfData.size());
|
||||
for (const auto& toSerialize : ldfData) toSerialize->WriteToPacket(data);
|
||||
data.Write<uint32_t>(ldfData.values.size());
|
||||
for (const auto& toSerialize : ldfData | std::views::values) toSerialize->WriteToPacket(data);
|
||||
|
||||
//Compress the data before sending:
|
||||
const uint32_t reservedSize = ZCompression::GetMaxCompressedLength(data.GetNumberOfBytesUsed());
|
||||
uint8_t* compressedData = new uint8_t[reservedSize];
|
||||
auto compressedData = std::make_unique<uint8_t[]>(reservedSize);
|
||||
|
||||
// TODO There should be better handling here for not enough memory...
|
||||
if (!compressedData) return;
|
||||
|
||||
size_t size = ZCompression::Compress(data.GetData(), data.GetNumberOfBytesUsed(), compressedData, reservedSize);
|
||||
size_t size = ZCompression::Compress(data.GetData(), data.GetNumberOfBytesUsed(), compressedData.get(), reservedSize);
|
||||
|
||||
assert(size <= reservedSize);
|
||||
|
||||
@@ -123,11 +121,10 @@ void WorldPackets::SendCreateCharacter(const SystemAddress& sysAddr, int64_t rep
|
||||
* an assertion is done to prevent bad data from being saved or sent.
|
||||
*/
|
||||
#pragma warning(disable:6385) // C6385 Reading invalid data from 'compressedData'.
|
||||
bitStream.WriteAlignedBytes(compressedData, size);
|
||||
bitStream.WriteAlignedBytes(compressedData.get(), size);
|
||||
#pragma warning(default:6385)
|
||||
|
||||
SEND_PACKET;
|
||||
delete[] compressedData;
|
||||
LOG("Sent CreateCharacter for ID: %llu", player);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,26 +1,17 @@
|
||||
#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) {
|
||||
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();
|
||||
request->requestID = ++currentRequestID;
|
||||
request->callback = callback;
|
||||
|
||||
this->requests.push_back(request);
|
||||
|
||||
MasterPackets::SendZoneTransferRequest(server, request->requestID, mythranShift, zoneID, zoneClone);
|
||||
MasterPackets::SendZoneTransferRequest(server, nextID, mythranShift, zoneID, zoneClone);
|
||||
}
|
||||
|
||||
//! Handles a zone transfer response
|
||||
@@ -43,18 +34,11 @@ void ZoneInstanceManager::HandleRequestZoneTransferResponse(Packet* packet) {
|
||||
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;
|
||||
}
|
||||
const auto entry = requests.find(requestID);
|
||||
if (entry != requests.end()) {
|
||||
entry->second(mythranShift, zoneID, zoneInstance, zoneClone, serverIP.string, serverPort);
|
||||
requests.erase(entry);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void ZoneInstanceManager::CreatePrivateZone(dServer* server, uint32_t zoneID, uint32_t zoneClone, const std::string& password) {
|
||||
@@ -65,12 +49,9 @@ 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;
|
||||
TransferCallback callback) {
|
||||
const auto nextID = ++currentRequestID;
|
||||
requests[nextID] = callback;
|
||||
|
||||
this->requests.push_back(request);
|
||||
|
||||
MasterPackets::SendZoneRequestPrivate(server, request->requestID, mythranShift, password);
|
||||
MasterPackets::SendZoneRequestPrivate(server, nextID, mythranShift, password);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
@@ -14,25 +15,20 @@ class dServer;
|
||||
\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
|
||||
class ZoneInstanceManager {
|
||||
private:
|
||||
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
|
||||
|
||||
public:
|
||||
|
||||
//! The singleton method
|
||||
static ZoneInstanceManager* Instance() {
|
||||
if (m_Address == 0) {
|
||||
if (m_Address == nullptr) {
|
||||
m_Address = new ZoneInstanceManager;
|
||||
m_Address->currentRequestID = 0;
|
||||
}
|
||||
@@ -47,7 +43,7 @@ public:
|
||||
\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, 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
|
||||
/*!
|
||||
@@ -58,6 +54,5 @@ public:
|
||||
|
||||
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);
|
||||
};
|
||||
|
||||
@@ -215,6 +215,8 @@ bool dServer::Startup() {
|
||||
mPeer = RakNetworkFactory::GetRakPeerInterface();
|
||||
|
||||
if (!mPeer) return false;
|
||||
|
||||
if (mUseEncryption) mPeer->InitializeSecurity(nullptr, nullptr, nullptr, nullptr);
|
||||
if (!mPeer->Startup(mMaxConnections, 10, &mSocketDescriptor, 1)) return false;
|
||||
|
||||
if (mIsInternal) {
|
||||
@@ -226,19 +228,16 @@ bool dServer::Startup() {
|
||||
}
|
||||
|
||||
mPeer->SetMaximumIncomingConnections(mMaxConnections);
|
||||
if (mUseEncryption) mPeer->InitializeSecurity(NULL, NULL, NULL, NULL);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void dServer::UpdateMaximumMtuSize() {
|
||||
auto maxMtuSize = mConfig->GetValue("maximum_mtu_size");
|
||||
mPeer->SetMTUSize(maxMtuSize.empty() ? 1228 : std::stoi(maxMtuSize));
|
||||
mPeer->SetMTUSize(mConfig->GetValue<int32_t>("maximum_mtu_size", 1228));
|
||||
}
|
||||
|
||||
void dServer::UpdateBandwidthLimit() {
|
||||
auto newBandwidth = mConfig->GetValue("maximum_outgoing_bandwidth");
|
||||
mPeer->SetPerConnectionOutgoingBandwidthLimit(!newBandwidth.empty() ? std::stoi(newBandwidth) : 0);
|
||||
mPeer->SetPerConnectionOutgoingBandwidthLimit(mConfig->GetValue<int32_t>("maximum_outgoing_bandwidth", 0));
|
||||
}
|
||||
|
||||
void dServer::Shutdown() {
|
||||
|
||||
Reference in New Issue
Block a user