mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-12-20 11:59:40 -06:00
Compare commits
2 Commits
cdclient-r
...
behaviorpa
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3d1b71cb31 | ||
|
|
617a7d4021 |
@@ -322,15 +322,6 @@ link_directories(${PROJECT_BINARY_DIR})
|
||||
# Load all of our third party directories
|
||||
add_subdirectory(thirdparty)
|
||||
|
||||
# Include Boost
|
||||
find_package(Boost COMPONENTS interprocess)
|
||||
|
||||
if(Boost_FOUND)
|
||||
include_directories(${Boost_INCLUDE_DIRS})
|
||||
|
||||
target_link_libraries(dGame ${Boost_LIBRARIES})
|
||||
endif()
|
||||
|
||||
# Glob together all headers that need to be precompiled
|
||||
file(
|
||||
GLOB HEADERS_DDATABASE
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "GeneralUtils.h"
|
||||
|
||||
#include "Game.h"
|
||||
#include "dLogger.h"
|
||||
#include "dServer.h"
|
||||
|
||||
#include "CDTable.h"
|
||||
|
||||
template <
|
||||
typename KeyType,
|
||||
typename MappedType
|
||||
>
|
||||
class CDAbstractProvider
|
||||
{
|
||||
public:
|
||||
virtual void LoadClient() = 0;
|
||||
virtual void LoadHost() = 0;
|
||||
|
||||
virtual const MappedType& GetEntry(const KeyType& key, const MappedType& defaultValue) = 0;
|
||||
};
|
||||
@@ -1,124 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "GeneralUtils.h"
|
||||
|
||||
#include "Game.h"
|
||||
#include "dLogger.h"
|
||||
#include "dServer.h"
|
||||
|
||||
#include "CDTable.h"
|
||||
|
||||
#include "CDAbstractProvider.h"
|
||||
|
||||
#include <boost/interprocess/managed_shared_memory.hpp>
|
||||
#include <boost/interprocess/containers/map.hpp>
|
||||
#include <boost/interprocess/allocators/allocator.hpp>
|
||||
#include <boost/interprocess/containers/string.hpp>
|
||||
#include <functional>
|
||||
#include <utility>
|
||||
#include <chrono>
|
||||
|
||||
template <
|
||||
typename KeyType,
|
||||
typename MappedType
|
||||
>
|
||||
class CDAbstractSharedMemoryMap : public CDAbstractProvider<KeyType, MappedType>
|
||||
{
|
||||
typedef std::pair<const KeyType, MappedType> ValueType;
|
||||
|
||||
typedef boost::interprocess::allocator<ValueType, boost::interprocess::managed_shared_memory::segment_manager> ShmemAllocator;
|
||||
|
||||
typedef boost::interprocess::map<KeyType, MappedType, std::less<KeyType>, ShmemAllocator> Map;
|
||||
|
||||
public:
|
||||
std::map<KeyType, MappedType> m_CacheMap;
|
||||
|
||||
std::string m_Name;
|
||||
|
||||
size_t m_Size;
|
||||
|
||||
bool m_Host;
|
||||
Map* m_HostEntries;
|
||||
|
||||
boost::interprocess::managed_shared_memory m_ClientSegment;
|
||||
ShmemAllocator* m_ClientAllocInst;
|
||||
boost::interprocess::offset_ptr<Map> m_ClientEntires;
|
||||
|
||||
CDAbstractSharedMemoryMap(std::string name, size_t size)
|
||||
{
|
||||
m_Name = name;
|
||||
m_Size = size;
|
||||
m_Host = false;
|
||||
m_HostEntries = nullptr;
|
||||
m_ClientAllocInst = nullptr;
|
||||
m_ClientEntires = nullptr;
|
||||
|
||||
LoadClient();
|
||||
}
|
||||
|
||||
const MappedType& GetEntry(const KeyType& key, const MappedType& defaultValue) override {
|
||||
const auto& cacheIt = m_CacheMap.find(key);
|
||||
if (cacheIt != m_CacheMap.end()) {
|
||||
return cacheIt->second;
|
||||
}
|
||||
|
||||
const auto& it = m_ClientEntires->find(key);
|
||||
if (it == m_ClientEntires->end()) {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
return it->second;
|
||||
}
|
||||
|
||||
const void SetEntry(const KeyType& key, const MappedType& value) {
|
||||
if (m_Host) {
|
||||
// If we are already hosting, we cannot add to the map, throw an error
|
||||
throw std::runtime_error("Can not add to a map that is already being hosted");
|
||||
}
|
||||
|
||||
m_CacheMap.emplace(key, value);
|
||||
}
|
||||
|
||||
void LoadClient() override {
|
||||
try {
|
||||
m_ClientSegment = boost::interprocess::managed_shared_memory(boost::interprocess::open_read_only, m_Name.c_str());
|
||||
|
||||
m_ClientAllocInst = new ShmemAllocator(m_ClientSegment.get_segment_manager());
|
||||
|
||||
m_ClientEntires = m_ClientSegment.find<Map>(m_Name.c_str()).first;
|
||||
|
||||
if (m_ClientEntires == nullptr) {
|
||||
throw std::runtime_error("Could not find shared memory segment " + m_Name);
|
||||
}
|
||||
|
||||
} catch (std::exception &e) {
|
||||
// Not open
|
||||
}
|
||||
}
|
||||
|
||||
void LoadHost() override {
|
||||
try {
|
||||
boost::interprocess::shared_memory_object::remove(m_Name.c_str());
|
||||
|
||||
boost::interprocess::managed_shared_memory segment(boost::interprocess::create_only, m_Name.c_str(), m_Size);
|
||||
|
||||
ShmemAllocator alloc(segment.get_segment_manager());
|
||||
|
||||
m_HostEntries = segment.construct<Map>(m_Name.c_str()) (std::less<KeyType>(), alloc);
|
||||
|
||||
// Copy cache
|
||||
for (const auto& pair : m_CacheMap) {
|
||||
m_HostEntries->insert(std::make_pair(pair.first, pair.second));
|
||||
}
|
||||
|
||||
m_Host = true;
|
||||
|
||||
LoadClient();
|
||||
} catch (std::exception &e) {
|
||||
// Make sure the smemory is removed
|
||||
boost::interprocess::shared_memory_object::remove(m_Name.c_str());
|
||||
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -1,150 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "CDAbstractProvider.h"
|
||||
|
||||
#include <boost/interprocess/managed_shared_memory.hpp>
|
||||
#include <boost/interprocess/containers/map.hpp>
|
||||
#include <boost/interprocess/allocators/allocator.hpp>
|
||||
#include <boost/interprocess/containers/string.hpp>
|
||||
#include <functional>
|
||||
#include <utility>
|
||||
#include <chrono>
|
||||
#include <mutex>
|
||||
|
||||
template <
|
||||
typename KeyType,
|
||||
typename MappedType
|
||||
>
|
||||
class CDAbstractSharedMemoryProvider : public CDAbstractProvider<KeyType, MappedType>
|
||||
{
|
||||
typedef std::pair<const KeyType, MappedType> ValueType;
|
||||
|
||||
typedef boost::interprocess::allocator<ValueType, boost::interprocess::managed_shared_memory::segment_manager> ShmemAllocator;
|
||||
|
||||
typedef boost::interprocess::map<KeyType, MappedType, std::less<KeyType>, ShmemAllocator> Map;
|
||||
|
||||
public:
|
||||
std::string m_Name;
|
||||
std::string m_MapName;
|
||||
std::function <ValueType(CppSQLite3Query&)> m_ParseEntry;
|
||||
std::function <int32_t(int32_t)> m_CalculateSize;
|
||||
|
||||
bool m_Cache;
|
||||
|
||||
std::unordered_map<KeyType, MappedType> m_CacheMap;
|
||||
|
||||
bool m_Host;
|
||||
Map* m_HostEntries;
|
||||
|
||||
boost::interprocess::managed_shared_memory m_ClientSegment;
|
||||
ShmemAllocator* m_ClientAllocInst;
|
||||
boost::interprocess::offset_ptr<Map> m_ClientEntires;
|
||||
|
||||
CDAbstractSharedMemoryProvider(std::string name, std::function <ValueType(CppSQLite3Query&)> parseEntry, std::function <int32_t(int32_t)> calculateSize, bool cache)
|
||||
{
|
||||
m_Name = name;
|
||||
m_MapName = name + "Map";
|
||||
m_ParseEntry = parseEntry;
|
||||
m_CalculateSize = calculateSize;
|
||||
m_Cache = cache;
|
||||
m_Host = false;
|
||||
m_HostEntries = nullptr;
|
||||
|
||||
LoadClient();
|
||||
}
|
||||
|
||||
const MappedType& GetEntry(const KeyType& key, const MappedType& defaultValue) override {
|
||||
if (m_Host) {
|
||||
auto it = m_HostEntries->find(key);
|
||||
if (it == m_HostEntries->end())
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
return it->second;
|
||||
}
|
||||
|
||||
if (m_Cache) {
|
||||
auto it = m_CacheMap.find(key);
|
||||
if (it != m_CacheMap.end()) {
|
||||
return it->second;
|
||||
}
|
||||
}
|
||||
|
||||
const auto& it = m_ClientEntires->find(key);
|
||||
if (it == m_ClientEntires->end())
|
||||
{
|
||||
if (m_Cache) {
|
||||
m_CacheMap.emplace(key, defaultValue);
|
||||
}
|
||||
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
if (m_Cache) {
|
||||
m_CacheMap.emplace(key, it->second);
|
||||
}
|
||||
|
||||
return it->second;
|
||||
}
|
||||
|
||||
void LoadClient() override {
|
||||
try {
|
||||
m_ClientSegment = boost::interprocess::managed_shared_memory(boost::interprocess::open_read_only, m_MapName.c_str());
|
||||
|
||||
m_ClientAllocInst = new ShmemAllocator(m_ClientSegment.get_segment_manager());
|
||||
|
||||
m_ClientEntires = m_ClientSegment.find<Map>(m_Name.c_str()).first;
|
||||
|
||||
if (m_ClientEntires == nullptr) {
|
||||
throw std::runtime_error("Could not find shared memory segment " + m_Name);
|
||||
}
|
||||
|
||||
} catch (boost::interprocess::interprocess_exception& e) {
|
||||
// Not open
|
||||
}
|
||||
}
|
||||
|
||||
void LoadHost() override {
|
||||
try {
|
||||
boost::interprocess::shared_memory_object::remove(m_MapName.c_str());
|
||||
|
||||
auto sizeQuery = CDClientDatabase::ExecuteQuery("SELECT COUNT(*) FROM " + m_Name);
|
||||
|
||||
if (sizeQuery.eof()) {
|
||||
throw std::runtime_error("Could not get size of table " + m_Name);
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t size = sizeQuery.getIntField(0);
|
||||
|
||||
size = m_CalculateSize(size);
|
||||
|
||||
boost::interprocess::managed_shared_memory segment(boost::interprocess::create_only, m_MapName.c_str(), size);
|
||||
|
||||
ShmemAllocator alloc_inst (segment.get_segment_manager());
|
||||
|
||||
m_HostEntries = segment.construct<Map>(m_Name.c_str()) (std::less<KeyType>(), alloc_inst);
|
||||
|
||||
auto tableData = CDClientDatabase::ExecuteQuery("SELECT * FROM " + m_Name);
|
||||
|
||||
while (!tableData.eof()) {
|
||||
ValueType entry = m_ParseEntry(tableData);
|
||||
|
||||
m_HostEntries->insert(entry);
|
||||
|
||||
tableData.nextRow();
|
||||
}
|
||||
|
||||
tableData.finalize();
|
||||
|
||||
m_Host = true;
|
||||
|
||||
LoadClient();
|
||||
} catch (std::exception &e) {
|
||||
// Make sure the smemory is removed
|
||||
boost::interprocess::shared_memory_object::remove(m_MapName.c_str());
|
||||
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -1,74 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "GeneralUtils.h"
|
||||
|
||||
#include "Game.h"
|
||||
#include "dLogger.h"
|
||||
#include "dServer.h"
|
||||
|
||||
#include "CDTable.h"
|
||||
|
||||
#include "CDAbstractProvider.h"
|
||||
|
||||
template <
|
||||
typename KeyType,
|
||||
typename MappedType
|
||||
>
|
||||
class CDAbstractSqliteProvider : public CDAbstractProvider<KeyType, MappedType>
|
||||
{
|
||||
typedef std::pair<const KeyType, MappedType> ValueType;
|
||||
|
||||
public:
|
||||
std::string m_Name;
|
||||
std::function <ValueType(CppSQLite3Query&)> m_ParseEntry;
|
||||
|
||||
std::unordered_map<KeyType, MappedType> m_Entries;
|
||||
|
||||
CDAbstractSqliteProvider(std::string name, std::function <ValueType(CppSQLite3Query&)> parseEntry, bool cache)
|
||||
{
|
||||
m_Name = name;
|
||||
m_ParseEntry = parseEntry;
|
||||
|
||||
LoadClient();
|
||||
}
|
||||
|
||||
void LoadClient() override {
|
||||
// First, get the size of the table
|
||||
uint32_t size = 0;
|
||||
auto tableSize = CDClientDatabase::ExecuteQuery("SELECT COUNT(*) FROM " + m_Name);
|
||||
while (!tableSize.eof()) {
|
||||
size = tableSize.getIntField(0, 0);
|
||||
|
||||
tableSize.nextRow();
|
||||
}
|
||||
|
||||
tableSize.finalize();
|
||||
|
||||
// Reserve the size
|
||||
m_Entries.reserve(size);
|
||||
|
||||
// Now get the data
|
||||
auto tableData = CDClientDatabase::ExecuteQuery("SELECT * FROM " + m_Name);
|
||||
while (!tableData.eof()) {
|
||||
auto entry = m_ParseEntry(tableData);
|
||||
|
||||
m_Entries.insert(entry);
|
||||
|
||||
tableData.nextRow();
|
||||
}
|
||||
|
||||
tableData.finalize();
|
||||
}
|
||||
|
||||
void LoadHost() override {
|
||||
return;
|
||||
}
|
||||
|
||||
const MappedType& GetEntry(const KeyType& key, const MappedType& defaultValue) override {
|
||||
auto it = m_Entries.find(key);
|
||||
if (it != m_Entries.end()) {
|
||||
return it->second;
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
};
|
||||
@@ -78,11 +78,3 @@ CDClientManager::CDClientManager() {
|
||||
CDFeatureGatingTable::Instance();
|
||||
CDRailActivatorComponentTable::Instance();
|
||||
}
|
||||
|
||||
void CDClientManager::LoadHost() {
|
||||
for (auto itr = this->tables.begin(); itr != this->tables.end(); ++itr) {
|
||||
itr->second->LoadHost();
|
||||
}
|
||||
|
||||
CDTable::InitalizeHost();
|
||||
}
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "CDAbstractProvider.h"
|
||||
|
||||
/**
|
||||
* Shared memory provider with CDAbstractSharedMemoryProvider<key, value>
|
||||
*
|
||||
* Depends on the boost::interprocess library — header only
|
||||
*
|
||||
* Requires that CD_PROVIDER_MEMORY is defined and CD_PROVIDER_SQLITE is not defined
|
||||
*/
|
||||
#if defined(CD_PROVIDER_MEMORY) && !defined(CD_PROVIDER_SQLITE)
|
||||
|
||||
#include "CDAbstractSharedMemoryProvider.h"
|
||||
|
||||
#define CD_PROVIDER(provider, key, value) CDAbstractSharedMemoryProvider<key, value>* provider; typedef key CD_KEY; typedef value CD_VALUE
|
||||
#define NEW_CD_PROVIDER(provider, name, parser, size_calculator, cache) provider = new CDAbstractSharedMemoryProvider<CD_KEY, CD_VALUE>(name, parser, size_calculator, cache)
|
||||
|
||||
template<typename KeyType, typename MappedType>
|
||||
using CDProvider = CDAbstractSharedMemoryProvider<KeyType, MappedType>;
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* SQLite provider with CDAbstractSqliteProvider<key, value>
|
||||
*
|
||||
* No extra dependencies
|
||||
*
|
||||
* Requires that CD_PROVIDER_SQLITE or CD_PROVIDER_MEMORY is not defined — the default option
|
||||
*/
|
||||
#if defined(CD_PROVIDER_SQLITE) || !defined(CD_PROVIDER_MEMORY)
|
||||
|
||||
#include "CDAbstractSqliteProvider.h"
|
||||
|
||||
#define CD_PROVIDER(provider, key, value) CDAbstractSqliteProvider<key, value>* provider; typedef key CD_KEY; typedef value CD_VALUE
|
||||
#define NEW_CD_PROVIDER(provider, name, parser, size_calculator, cache) provider = new CDAbstractSqliteProvider<CD_KEY, CD_VALUE>(name, parser, cache)
|
||||
|
||||
template<typename KeyType, typename MappedType>
|
||||
using CDProvider = CDAbstractSqliteProvider<KeyType, MappedType>;
|
||||
|
||||
#endif
|
||||
@@ -1,53 +1,55 @@
|
||||
#include "CDBehaviorParameterTable.h"
|
||||
#include "GeneralUtils.h"
|
||||
|
||||
CDBehaviorParameterTable::CDBehaviorParameterTable(void) {
|
||||
uint64_t GetHash(const uint32_t behaviorID, const uint32_t parameterID) {
|
||||
uint64_t hash = behaviorID;
|
||||
hash <<= 31U;
|
||||
hash |= parameterID;
|
||||
|
||||
return hash;
|
||||
}
|
||||
|
||||
CDBehaviorParameterTable::CDBehaviorParameterTable() {
|
||||
auto tableData = CDClientDatabase::ExecuteQuery("SELECT * FROM BehaviorParameter");
|
||||
uint32_t uniqueParameterId = 0;
|
||||
uint64_t hash = 0;
|
||||
while (!tableData.eof()) {
|
||||
CDBehaviorParameter entry;
|
||||
entry.behaviorID = tableData.getIntField("behaviorID", -1);
|
||||
uint32_t behaviorID = tableData.getIntField("behaviorID", -1);
|
||||
auto candidateStringToAdd = std::string(tableData.getStringField("parameterID", ""));
|
||||
auto parameter = m_ParametersList.find(candidateStringToAdd);
|
||||
uint32_t parameterId;
|
||||
if (parameter != m_ParametersList.end()) {
|
||||
entry.parameterID = parameter;
|
||||
parameterId = parameter->second;
|
||||
} else {
|
||||
entry.parameterID = m_ParametersList.insert(std::make_pair(candidateStringToAdd, uniqueParameterId)).first;
|
||||
uniqueParameterId++;
|
||||
parameterId = m_ParametersList.insert(std::make_pair(candidateStringToAdd, m_ParametersList.size())).first->second;
|
||||
}
|
||||
hash = entry.behaviorID;
|
||||
hash = (hash << 31U) | entry.parameterID->second;
|
||||
entry.value = tableData.getFloatField("value", -1.0f);
|
||||
uint64_t hash = GetHash(behaviorID, parameterId);
|
||||
float value = tableData.getFloatField("value", -1.0f);
|
||||
|
||||
m_Entries.insert(std::make_pair(hash, entry));
|
||||
m_Entries.insert(std::make_pair(hash, value));
|
||||
|
||||
tableData.nextRow();
|
||||
}
|
||||
tableData.finalize();
|
||||
}
|
||||
|
||||
float CDBehaviorParameterTable::GetValue(const uint32_t behaviorID, const std::string& name, const float defaultValue) {
|
||||
auto parameterID = this->m_ParametersList.find(name);
|
||||
if (parameterID == this->m_ParametersList.end()) return defaultValue;
|
||||
|
||||
uint64_t hash = behaviorID;
|
||||
|
||||
hash = (hash << 31U) | parameterID->second;
|
||||
auto hash = GetHash(behaviorID, parameterID->second);
|
||||
|
||||
// Search for specific parameter
|
||||
const auto& it = m_Entries.find(hash);
|
||||
return it != m_Entries.end() ? it->second.value : defaultValue;
|
||||
auto it = m_Entries.find(hash);
|
||||
return it != m_Entries.end() ? it->second : defaultValue;
|
||||
}
|
||||
|
||||
std::map<std::string, float> CDBehaviorParameterTable::GetParametersByBehaviorID(uint32_t behaviorID) {
|
||||
uint64_t hashBase = behaviorID;
|
||||
std::map<std::string, float> returnInfo;
|
||||
uint64_t hash;
|
||||
for (auto& parameterCandidate : m_ParametersList) {
|
||||
hash = (hashBase << 31U) | parameterCandidate.second;
|
||||
for (auto& [parameterString, parameterId] : m_ParametersList) {
|
||||
uint64_t hash = GetHash(hashBase, parameterId);
|
||||
auto infoCandidate = m_Entries.find(hash);
|
||||
if (infoCandidate != m_Entries.end()) {
|
||||
returnInfo.insert(std::make_pair(infoCandidate->second.parameterID->first, infoCandidate->second.value));
|
||||
returnInfo.insert(std::make_pair(parameterString, infoCandidate->second));
|
||||
}
|
||||
}
|
||||
return returnInfo;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,18 +5,15 @@
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
|
||||
struct CDBehaviorParameter {
|
||||
unsigned int behaviorID; //!< The Behavior ID
|
||||
std::unordered_map<std::string, uint32_t>::iterator parameterID; //!< The Parameter ID
|
||||
float value; //!< The value of the behavior template
|
||||
};
|
||||
|
||||
class CDBehaviorParameterTable : public CDTable<CDBehaviorParameterTable> {
|
||||
private:
|
||||
std::unordered_map<uint64_t, CDBehaviorParameter> m_Entries;
|
||||
typedef uint64_t BehaviorParameterHash;
|
||||
typedef float BehaviorParameterValue;
|
||||
std::unordered_map<BehaviorParameterHash, BehaviorParameterValue> m_Entries;
|
||||
std::unordered_map<std::string, uint32_t> m_ParametersList;
|
||||
public:
|
||||
CDBehaviorParameterTable();
|
||||
|
||||
float GetValue(const uint32_t behaviorID, const std::string& name, const float defaultValue = 0);
|
||||
|
||||
std::map<std::string, float> GetParametersByBehaviorID(uint32_t behaviorID);
|
||||
|
||||
@@ -6,10 +6,10 @@
|
||||
#include <unordered_set>
|
||||
|
||||
struct CDBehaviorTemplate {
|
||||
unsigned int behaviorID; //!< The Behavior ID
|
||||
unsigned int templateID; //!< The Template ID (LOT)
|
||||
unsigned int effectID; //!< The Effect ID attached
|
||||
size_t effectHandle; //!< The effect handle
|
||||
unsigned int behaviorID; //!< The Behavior ID
|
||||
unsigned int templateID; //!< The Template ID (LOT)
|
||||
unsigned int effectID; //!< The Effect ID attached
|
||||
std::unordered_set<std::string>::iterator effectHandle; //!< The effect handle
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
#include "CDComponentsRegistryTable.h"
|
||||
#include "eReplicaComponentType.h"
|
||||
|
||||
|
||||
@@ -1,68 +0,0 @@
|
||||
#include "CDTable.h"
|
||||
|
||||
#if defined(CD_PROVIDER_MEMORY)
|
||||
|
||||
#include "CDAbstractSharedMemoryMap.h"
|
||||
|
||||
typedef boost::interprocess::allocator<char, boost::interprocess::managed_shared_memory::segment_manager> CharAllocator;
|
||||
typedef boost::interprocess::basic_string<char, std::char_traits<char>, CharAllocator> my_string;
|
||||
|
||||
CDAbstractSharedMemoryMap<size_t, boost::interprocess::string>* CDStringMap;
|
||||
|
||||
void CDTable::InitalizeHost()
|
||||
{
|
||||
CDStringMap->LoadHost();
|
||||
}
|
||||
|
||||
void CDTable::Initalize()
|
||||
{
|
||||
CDStringMap = new CDAbstractSharedMemoryMap<size_t, boost::interprocess::string>("CDStringMap", 10 * 1000 * 1000);
|
||||
}
|
||||
|
||||
std::string CDTable::GetString(size_t handle)
|
||||
{
|
||||
std::string str = std::string(CDStringMap->GetEntry(handle, "").c_str());
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
size_t CDTable::SetString(std::string value)
|
||||
{
|
||||
size_t hash = 0;
|
||||
|
||||
GeneralUtils::hash_combine(hash, value);
|
||||
|
||||
CDStringMap->SetEntry(hash, boost::interprocess::string(value.c_str()));
|
||||
|
||||
return hash;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
std::unordered_map<size_t, std::string> CDStringMap;
|
||||
|
||||
void CDTable::InitalizeHost()
|
||||
{
|
||||
}
|
||||
|
||||
void CDTable::Initalize()
|
||||
{
|
||||
}
|
||||
|
||||
std::string CDTable::GetString(size_t handle)
|
||||
{
|
||||
return CDStringMap[handle];
|
||||
}
|
||||
|
||||
size_t CDTable::SetString(std::string value)
|
||||
{
|
||||
size_t hash = 0;
|
||||
|
||||
GeneralUtils::hash_combine(hash, value);
|
||||
|
||||
CDStringMap[hash] = value;
|
||||
|
||||
return hash;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -25,50 +25,8 @@
|
||||
#pragma warning (disable : 4244) //Disable double to float conversion warnings
|
||||
#pragma warning (disable : 4715) //Disable "not all control paths return a value"
|
||||
|
||||
#if defined(__unix) || defined(__APPLE__)
|
||||
//For Linux:
|
||||
typedef __int64_t __int64;
|
||||
#endif
|
||||
|
||||
/*!
|
||||
\file CDTable.hpp
|
||||
\brief A virtual class for CDClient Tables
|
||||
*/
|
||||
|
||||
//! The base class for all CD tables
|
||||
template<class Table>
|
||||
class CDTable : public Singleton<Table> {
|
||||
public:
|
||||
|
||||
//! Returns the table's name
|
||||
/*!
|
||||
\return The table name
|
||||
*/
|
||||
virtual std::string GetName() const = 0;
|
||||
|
||||
//! Loads the table into shared memory
|
||||
virtual void LoadHost() {};
|
||||
|
||||
//! Initalizes the table services
|
||||
static void Initalize();
|
||||
|
||||
//! Initalizes the table services as host
|
||||
static void InitalizeHost();
|
||||
|
||||
//! Get a string from a handle
|
||||
/*!
|
||||
\param handle The handle to get the string from
|
||||
\return The string
|
||||
*/
|
||||
static std::string GetString(size_t handle);
|
||||
|
||||
//! Set a string
|
||||
/*!
|
||||
\param value The string to set
|
||||
\return The handle to the string
|
||||
*/
|
||||
static size_t SetString(std::string value);
|
||||
|
||||
protected:
|
||||
virtual ~CDTable() = default;
|
||||
};
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
set(DDATABASE_TABLES_SOURCES "CDTable.cpp" "CDActivitiesTable.cpp"
|
||||
set(DDATABASE_TABLES_SOURCES "CDActivitiesTable.cpp"
|
||||
"CDActivityRewardsTable.cpp"
|
||||
"CDAnimationsTable.cpp"
|
||||
"CDBehaviorParameterTable.cpp"
|
||||
|
||||
@@ -3,12 +3,8 @@
|
||||
#include "Game.h"
|
||||
#include "dLogger.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
void AndBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, const BehaviorBranchContext branch)
|
||||
{
|
||||
for (auto* behavior : this->m_behaviors)
|
||||
{
|
||||
void AndBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, const BehaviorBranchContext branch) {
|
||||
for (auto* behavior : this->m_behaviors) {
|
||||
behavior->Handle(context, bitStream, branch);
|
||||
}
|
||||
}
|
||||
@@ -25,21 +21,14 @@ void AndBehavior::UnCast(BehaviorContext* context, const BehaviorBranchContext b
|
||||
}
|
||||
}
|
||||
|
||||
void AndBehavior::Load()
|
||||
{
|
||||
std::string ss = "behavior ";
|
||||
void AndBehavior::Load() {
|
||||
const auto parameters = GetParameterNames();
|
||||
|
||||
int i = 1;
|
||||
for (const auto& parameter : parameters) {
|
||||
if (parameter.first.rfind("behavior", 0) == 0) {
|
||||
auto* action = GetAction(parameter.second);
|
||||
|
||||
while (true) {
|
||||
std::string s = ss + std::to_string(i);
|
||||
|
||||
if (GetInt(s, 0) == 0) {
|
||||
break;
|
||||
this->m_behaviors.push_back(action);
|
||||
}
|
||||
|
||||
m_behaviors.push_back(GetAction(s));
|
||||
|
||||
++i;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -439,7 +439,7 @@ Behavior::Behavior(const uint32_t behaviorId) {
|
||||
|
||||
this->m_effectId = templateInDatabase.effectID;
|
||||
|
||||
this->m_effectHandle = new std::string(CDTable::GetString(templateInDatabase.effectHandle));
|
||||
this->m_effectHandle = *templateInDatabase.effectHandle != "" ? new std::string(*templateInDatabase.effectHandle) : nullptr;
|
||||
}
|
||||
|
||||
|
||||
@@ -471,8 +471,14 @@ Behavior* Behavior::GetAction(float value) const {
|
||||
}
|
||||
|
||||
std::map<std::string, float> Behavior::GetParameterNames() const {
|
||||
std::map<std::string, float> templatesInDatabase;
|
||||
// Find behavior template by its behavior id.
|
||||
if (!BehaviorParameterTable) BehaviorParameterTable = CDClientManager::Instance().GetTable<CDBehaviorParameterTable>();
|
||||
return BehaviorParameterTable->GetParametersByBehaviorID(this->m_behaviorId);
|
||||
if (BehaviorParameterTable) {
|
||||
templatesInDatabase = BehaviorParameterTable->GetParametersByBehaviorID(this->m_behaviorId);
|
||||
}
|
||||
|
||||
return templatesInDatabase;
|
||||
}
|
||||
|
||||
void Behavior::Load() {
|
||||
|
||||
@@ -26,21 +26,14 @@ void ChainBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitSt
|
||||
this->m_behaviors.at(0)->Calculate(context, bitStream, branch);
|
||||
}
|
||||
|
||||
void ChainBehavior::Load()
|
||||
{
|
||||
std::string ss = "behavior ";
|
||||
void ChainBehavior::Load() {
|
||||
const auto parameters = GetParameterNames();
|
||||
|
||||
int i = 1;
|
||||
for (const auto& parameter : parameters) {
|
||||
if (parameter.first.rfind("behavior", 0) == 0) {
|
||||
auto* action = GetAction(parameter.second);
|
||||
|
||||
while (true) {
|
||||
std::string s = ss + std::to_string(i);
|
||||
|
||||
if (GetInt(s, 0) == 0) {
|
||||
break;
|
||||
this->m_behaviors.push_back(action);
|
||||
}
|
||||
|
||||
m_behaviors.push_back(GetAction(s));
|
||||
|
||||
++i;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,20 +13,14 @@ void NpcCombatSkillBehavior::Calculate(BehaviorContext* context, RakNet::BitStre
|
||||
|
||||
void NpcCombatSkillBehavior::Load() {
|
||||
this->m_npcSkillTime = GetFloat("npc skill time");
|
||||
|
||||
std::string ss = "behavior ";
|
||||
|
||||
int i = 1;
|
||||
const auto parameters = GetParameterNames();
|
||||
|
||||
while (true) {
|
||||
std::string s = ss + std::to_string(i);
|
||||
for (const auto& parameter : parameters) {
|
||||
if (parameter.first.rfind("behavior", 0) == 0) {
|
||||
auto* action = GetAction(parameter.second);
|
||||
|
||||
if (GetInt(s, 0) == 0) {
|
||||
break;
|
||||
this->m_behaviors.push_back(action);
|
||||
}
|
||||
|
||||
m_behaviors.push_back(GetAction(s));
|
||||
|
||||
++i;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1761,41 +1761,6 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef __linux__
|
||||
if (chatCommand == "statm" && entity->GetGMLevel() >= eGameMasterLevel::DEVELOPER)
|
||||
{
|
||||
// Print and format the output of /proc/self/statm
|
||||
std::ifstream statm("/proc/self/statm");
|
||||
|
||||
if (!statm.is_open())
|
||||
{
|
||||
ChatPackets::SendSystemMessage(sysAddr, u"Failed to open /proc/self/statm");
|
||||
return;
|
||||
}
|
||||
|
||||
// Scan for the different fields
|
||||
uint64_t size, resident, share, text, lib, data, dirty;
|
||||
statm >> size >> resident >> share >> text >> lib >> data >> dirty;
|
||||
|
||||
// Get the page size
|
||||
size_t pageSize = sysconf(_SC_PAGESIZE);
|
||||
|
||||
// Print the output
|
||||
ChatPackets::SendSystemMessage(
|
||||
sysAddr,
|
||||
u"Size: " + GeneralUtils::to_u16string((float) ((double) size * pageSize / 1.024e6)) +
|
||||
u"MB\nResident: " + GeneralUtils::to_u16string((float) ((double) resident * pageSize / 1.024e6)) +
|
||||
u"MB\nShared: " + GeneralUtils::to_u16string((float) ((double) share * pageSize / 1.024e6)) +
|
||||
u"MB\nText: " + GeneralUtils::to_u16string((float) ((double) text * pageSize / 1.024e6)) +
|
||||
u"MB\nLibrary: " + GeneralUtils::to_u16string((float) ((double) lib * pageSize / 1.024e6)) +
|
||||
u"MB\nData: " + GeneralUtils::to_u16string((float) ((double) data * pageSize / 1.024e6)) +
|
||||
u"MB\nDirty: " + GeneralUtils::to_u16string((float) ((double) dirty * pageSize / 1.024e6)) +
|
||||
u"MB"
|
||||
);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (chatCommand == "rollloot" && entity->GetGMLevel() >= eGameMasterLevel::OPERATOR && args.size() >= 3) {
|
||||
if (chatCommand == "reloadconfig" && entity->GetGMLevel() >= eGameMasterLevel::DEVELOPER) {
|
||||
Game::config->ReloadConfig();
|
||||
VanityUtilities::SpawnVanity();
|
||||
|
||||
@@ -69,14 +69,13 @@ Instance* InstanceManager::GetInstance(LWOMAPID mapID, bool isFriendTransfer, LW
|
||||
}
|
||||
#endif
|
||||
|
||||
cmd.append(" -zone ");
|
||||
cmd.append(std::to_string(mapID));
|
||||
cmd.append(" -port ");
|
||||
cmd.append(std::to_string(port));
|
||||
cmd.append(" -instance ");
|
||||
cmd.append(std::to_string(m_LastInstanceID));
|
||||
cmd.append(" -maxclients ");
|
||||
cmd.append(std::to_string(maxPlayers));
|
||||
cmd.append(std::to_string(mapID));
|
||||
cmd.append(" -port ");
|
||||
cmd.append(std::to_string(port));
|
||||
cmd.append(" -instance ");
|
||||
cmd.append(std::to_string(m_LastInstanceID));
|
||||
cmd.append(" -maxclients ");
|
||||
cmd.append(std::to_string(maxPlayers));
|
||||
|
||||
cmd.append(" -clone ");
|
||||
cmd.append(std::to_string(cloneID));
|
||||
|
||||
@@ -331,8 +331,6 @@ int main(int argc, char** argv) {
|
||||
ObjectIDManager::Instance()->Initialize(Game::logger);
|
||||
Game::im = new InstanceManager(Game::logger, Game::server->GetIP());
|
||||
|
||||
CDClientManager::Instance()->LoadHost();
|
||||
|
||||
//Depending on the config, start up servers:
|
||||
if (Game::config->GetValue("prestart_servers") != "" && Game::config->GetValue("prestart_servers") == "1") {
|
||||
StartChatServer();
|
||||
|
||||
Reference in New Issue
Block a user