mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-08-06 18:54:13 +00:00
Public release of the DLU server code!
Have fun!
This commit is contained in:
63
dWorldServer/ObjectIDManager.cpp
Normal file
63
dWorldServer/ObjectIDManager.cpp
Normal file
@@ -0,0 +1,63 @@
|
||||
#include "ObjectIDManager.h"
|
||||
|
||||
// Std
|
||||
#include <random>
|
||||
|
||||
// Custom Classes
|
||||
#include "MasterPackets.h"
|
||||
#include "Database.h"
|
||||
#include "dLogger.h"
|
||||
#include "Game.h"
|
||||
|
||||
// Static Variables
|
||||
ObjectIDManager * ObjectIDManager::m_Address = nullptr;
|
||||
static std::uniform_int_distribution<int> uni(10000000, INT32_MAX);
|
||||
|
||||
//! Initializes the manager
|
||||
void ObjectIDManager::Initialize(void) {
|
||||
//this->currentRequestID = 0;
|
||||
this->currentObjectID = uint32_t(1152921508165007067); //Initial value for this server's objectIDs
|
||||
}
|
||||
|
||||
//! Requests a persistent ID
|
||||
void ObjectIDManager::RequestPersistentID(std::function<void(uint32_t)> callback) {
|
||||
PersistentIDRequest * request = new PersistentIDRequest();
|
||||
request->requestID = ++this->currentRequestID;
|
||||
request->callback = callback;
|
||||
|
||||
this->requests.push_back(request);
|
||||
|
||||
MasterPackets::SendPersistentIDRequest(Game::server, request->requestID);
|
||||
}
|
||||
|
||||
//! Handles a persistent ID response
|
||||
void ObjectIDManager::HandleRequestPersistentIDResponse(uint64_t requestID, uint32_t persistentID) {
|
||||
for (uint32_t i = 0; i < this->requests.size(); ++i) {
|
||||
if (this->requests[i]->requestID == requestID) {
|
||||
|
||||
// Call the callback function
|
||||
this->requests[i]->callback(persistentID);
|
||||
|
||||
// Then delete the request
|
||||
delete this->requests[i];
|
||||
this->requests.erase(this->requests.begin() + i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//! Handles cases where we have to get a unique object ID synchronously
|
||||
uint32_t ObjectIDManager::GenerateRandomObjectID()
|
||||
{
|
||||
std::random_device rd;
|
||||
|
||||
std::mt19937 rng(rd());
|
||||
|
||||
return uni(rng);
|
||||
}
|
||||
|
||||
|
||||
//! Generates an object ID server-sided (used for regular entities like smashables)
|
||||
uint32_t ObjectIDManager::GenerateObjectID(void) {
|
||||
return ++this->currentObjectID;
|
||||
}
|
75
dWorldServer/ObjectIDManager.h
Normal file
75
dWorldServer/ObjectIDManager.h
Normal file
@@ -0,0 +1,75 @@
|
||||
#pragma once
|
||||
|
||||
// C++
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
#include <stdint.h>
|
||||
|
||||
/*!
|
||||
\file ObjectIDManager.hpp
|
||||
\brief A manager for handling object ID generation
|
||||
*/
|
||||
|
||||
//! The persistent ID request
|
||||
struct PersistentIDRequest {
|
||||
uint64_t requestID;
|
||||
|
||||
std::function<void(uint32_t)> callback;
|
||||
};
|
||||
|
||||
//! The Object ID Manager
|
||||
class ObjectIDManager {
|
||||
private:
|
||||
static ObjectIDManager * m_Address; //!< The singleton instance
|
||||
|
||||
std::vector<PersistentIDRequest*> requests; //!< All outstanding persistent ID requests
|
||||
uint64_t currentRequestID; //!< The current request ID
|
||||
|
||||
uint32_t currentObjectID; //!< The current object ID
|
||||
|
||||
public:
|
||||
|
||||
//! The singleton instance
|
||||
static ObjectIDManager * Instance() {
|
||||
if (m_Address == 0) {
|
||||
m_Address = new ObjectIDManager;
|
||||
}
|
||||
|
||||
return m_Address;
|
||||
}
|
||||
|
||||
//! Initializes the manager
|
||||
void Initialize(void);
|
||||
|
||||
//! Requests a persistent ID
|
||||
/*!
|
||||
\param callback The callback function
|
||||
*/
|
||||
void RequestPersistentID(std::function<void(uint32_t)> callback);
|
||||
|
||||
|
||||
//! Handles a persistent ID response
|
||||
/*!
|
||||
\param requestID The request ID
|
||||
\param persistentID The persistent ID
|
||||
*/
|
||||
void HandleRequestPersistentIDResponse(uint64_t requestID, uint32_t persistentID);
|
||||
|
||||
//! Generates an object ID server-sided
|
||||
/*!
|
||||
\return A generated object ID
|
||||
*/
|
||||
uint32_t GenerateObjectID(void);
|
||||
|
||||
//! Generates a random object ID server-sided
|
||||
/*!
|
||||
\return A generated object ID
|
||||
*/
|
||||
static uint32_t GenerateRandomObjectID();
|
||||
|
||||
//! Generates a persistent object ID server-sided
|
||||
/*!
|
||||
\return A generated object ID
|
||||
*/
|
||||
uint32_t GeneratePersistentObjectID(void);
|
||||
};
|
124
dWorldServer/PerformanceManager.cpp
Normal file
124
dWorldServer/PerformanceManager.cpp
Normal file
@@ -0,0 +1,124 @@
|
||||
#include "PerformanceManager.h"
|
||||
|
||||
#include "UserManager.h"
|
||||
|
||||
#define HIGH 16
|
||||
#define MEDIUM 33
|
||||
#define LOW 66
|
||||
|
||||
#define SOCIAL { MEDIUM, LOW }
|
||||
#define BATTLE { HIGH, MEDIUM }
|
||||
#define BATTLE_INSTANCE { MEDIUM, LOW }
|
||||
#define RACE { MEDIUM, LOW }
|
||||
#define PROPERTY { LOW, LOW }
|
||||
|
||||
PerformanceProfile PerformanceManager::m_CurrentProfile = SOCIAL;
|
||||
|
||||
PerformanceProfile PerformanceManager::m_DefaultProfile = SOCIAL;
|
||||
|
||||
PerformanceProfile PerformanceManager::m_InactiveProfile = { LOW, LOW };
|
||||
|
||||
std::map<LWOMAPID, PerformanceProfile> PerformanceManager::m_Profiles = {
|
||||
// VE
|
||||
{ 1000, SOCIAL },
|
||||
|
||||
// AG
|
||||
{ 1100, BATTLE },
|
||||
{ 1101, BATTLE_INSTANCE },
|
||||
{ 1102, BATTLE_INSTANCE },
|
||||
{ 1150, PROPERTY },
|
||||
{ 1151, PROPERTY },
|
||||
|
||||
// NS
|
||||
{ 1200, SOCIAL },
|
||||
{ 1201, SOCIAL },
|
||||
{ 1203, RACE },
|
||||
{ 1204, BATTLE_INSTANCE },
|
||||
{ 1250, PROPERTY },
|
||||
{ 1251, PROPERTY },
|
||||
|
||||
// GF
|
||||
{ 1300, BATTLE },
|
||||
{ 1302, BATTLE_INSTANCE },
|
||||
{ 1303, BATTLE_INSTANCE },
|
||||
{ 1350, PROPERTY },
|
||||
|
||||
// FV
|
||||
{ 1400, BATTLE },
|
||||
{ 1402, BATTLE_INSTANCE },
|
||||
{ 1403, RACE },
|
||||
{ 1450, PROPERTY },
|
||||
|
||||
// LUP
|
||||
{ 1600, SOCIAL },
|
||||
{ 1601, SOCIAL },
|
||||
{ 1602, SOCIAL },
|
||||
{ 1603, SOCIAL },
|
||||
{ 1604, SOCIAL },
|
||||
|
||||
// LEGO Club
|
||||
{ 1700, SOCIAL },
|
||||
|
||||
// AM
|
||||
{ 1800, BATTLE },
|
||||
|
||||
// NT
|
||||
{ 1900, SOCIAL },
|
||||
|
||||
// NJ
|
||||
{ 2000, BATTLE },
|
||||
{ 2001, BATTLE_INSTANCE },
|
||||
};
|
||||
|
||||
|
||||
PerformanceManager::PerformanceManager()
|
||||
{
|
||||
}
|
||||
|
||||
PerformanceManager::~PerformanceManager()
|
||||
{
|
||||
}
|
||||
|
||||
void PerformanceManager::SelectProfile(LWOMAPID mapID)
|
||||
{
|
||||
const auto pair = m_Profiles.find(mapID);
|
||||
|
||||
if (pair == m_Profiles.end())
|
||||
{
|
||||
m_CurrentProfile = m_DefaultProfile;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
m_CurrentProfile = pair->second;
|
||||
}
|
||||
|
||||
uint32_t PerformanceManager::GetServerFramerate()
|
||||
{
|
||||
if (UserManager::Instance()->GetUserCount() == 0)
|
||||
{
|
||||
return m_InactiveProfile.serverFramerate;
|
||||
}
|
||||
|
||||
return m_CurrentProfile.serverFramerate;
|
||||
}
|
||||
|
||||
uint32_t PerformanceManager::GetPhysicsFramerate()
|
||||
{
|
||||
if (UserManager::Instance()->GetUserCount() == 0)
|
||||
{
|
||||
return m_InactiveProfile.physicsFramerate;
|
||||
}
|
||||
|
||||
return m_CurrentProfile.physicsFramerate;
|
||||
}
|
||||
|
||||
uint32_t PerformanceManager::GetPhysicsStepRate()
|
||||
{
|
||||
if (UserManager::Instance()->GetUserCount() == 0)
|
||||
{
|
||||
return 10; // Row physics at a really low framerate if the server is empty
|
||||
}
|
||||
|
||||
return m_CurrentProfile.physicsFramerate / m_CurrentProfile.serverFramerate;
|
||||
}
|
32
dWorldServer/PerformanceManager.h
Normal file
32
dWorldServer/PerformanceManager.h
Normal file
@@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "dCommonVars.h"
|
||||
|
||||
struct PerformanceProfile
|
||||
{
|
||||
uint32_t serverFramerate;
|
||||
uint32_t physicsFramerate;
|
||||
};
|
||||
|
||||
|
||||
class PerformanceManager
|
||||
{
|
||||
public:
|
||||
~PerformanceManager();
|
||||
|
||||
static void SelectProfile(LWOMAPID mapID);
|
||||
|
||||
static uint32_t GetServerFramerate();
|
||||
static uint32_t GetPhysicsFramerate();
|
||||
static uint32_t GetPhysicsStepRate();
|
||||
|
||||
private:
|
||||
PerformanceManager();
|
||||
|
||||
static PerformanceProfile m_CurrentProfile;
|
||||
static PerformanceProfile m_DefaultProfile;
|
||||
static PerformanceProfile m_InactiveProfile;
|
||||
static std::map<LWOMAPID, PerformanceProfile> m_Profiles;
|
||||
};
|
1227
dWorldServer/WorldServer.cpp
Normal file
1227
dWorldServer/WorldServer.cpp
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user