Compare commits

..

1 Commits

Author SHA1 Message Date
jadebenn
f18412b83e testing clang-format settings 2024-04-03 21:14:20 -05:00
18 changed files with 155 additions and 108 deletions

36
.clang-format Normal file
View File

@@ -0,0 +1,36 @@
---
# Use defaults from the GNU style, but with 4 columns indentation.
BasedOnStyle: LLVM
UseTab: Always
IndentWidth: 4
TabWidth: 4
---
Language: Cpp
# Force pointers to the type for C++.
DerivePointerAlignment: false
PointerAlignment: Left
# Indent all namespaces
NamespaceIndentation: All
# Do not enforce a column limit
ColumnLimit: 0
# Allow short statements on one line
AllowShortIfStatementsOnASingleLine: AllIfsAndElse
AllowShortLoopsOnASingleLine: true
AllowShortBlocksOnASingleLine: Always
AllowShortEnumsOnASingleLine: true
AllowShortFunctionsOnASingleLine: true
# Do not remove braces on short statements
RemoveBracesLLVM: false
# Add spaces between braces and contents
Cpp11BracedListStyle: false
# Brace wrapping rules
# BreakBeforeBraces: Custom
# BraceWrapping:
# BraceWrappingAfterControlStatementStyle: MultiLine

View File

@@ -9,18 +9,6 @@ set(CMAKE_POLICY_DEFAULT_CMP0063 NEW) # Set CMAKE visibility policy to NEW on p
set(CMAKE_VISIBILITY_INLINES_HIDDEN ON) # Set C and C++ symbol visibility to hide inlined functions set(CMAKE_VISIBILITY_INLINES_HIDDEN ON) # Set C and C++ symbol visibility to hide inlined functions
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake") set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
# Check if link-time-optimization is supported and apply it if possible in release builds
include(CheckIPOSupported)
check_ipo_supported(RESULT supported OUTPUT error)
if(supported)
message(STATUS "IPO / LTO enabled")
set(CMAKE_POLICY_DEFAULT_CMP0069 NEW)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE TRUE)
else()
message(STATUS "IPO / LTO not supported: <${error}>")
endif()
# Read variables from file # Read variables from file
FILE(READ "${CMAKE_SOURCE_DIR}/CMakeVariables.txt" variables) FILE(READ "${CMAKE_SOURCE_DIR}/CMakeVariables.txt" variables)
@@ -115,7 +103,7 @@ make_directory(${CMAKE_BINARY_DIR}/resServer)
make_directory(${CMAKE_BINARY_DIR}/logs) make_directory(${CMAKE_BINARY_DIR}/logs)
# Copy resource files on first build # Copy resource files on first build
set(RESOURCE_FILES "sharedconfig.ini" "authconfig.ini" "chatconfig.ini" "worldconfig.ini" "masterconfig.ini" "blocklist.dcf") set(RESOURCE_FILES "sharedconfig.ini" "authconfig.ini" "chatconfig.ini" "worldconfig.ini" "masterconfig.ini" "blacklist.dcf")
message(STATUS "Checking resource file integrity") message(STATUS "Checking resource file integrity")
include(Utils) include(Utils)

View File

@@ -27,8 +27,8 @@ dChatFilter::dChatFilter(const std::string& filepath, bool dontGenerateDCF) {
ExportWordlistToDCF(filepath + ".dcf", true); ExportWordlistToDCF(filepath + ".dcf", true);
} }
if (BinaryIO::DoesFileExist("blocklist.dcf")) { if (BinaryIO::DoesFileExist("blacklist.dcf")) {
ReadWordlistDCF("blocklist.dcf", false); ReadWordlistDCF("blacklist.dcf", false);
} }
//Read player names that are ok as well: //Read player names that are ok as well:
@@ -44,20 +44,20 @@ dChatFilter::~dChatFilter() {
m_DeniedWords.clear(); m_DeniedWords.clear();
} }
void dChatFilter::ReadWordlistPlaintext(const std::string& filepath, bool allowList) { void dChatFilter::ReadWordlistPlaintext(const std::string& filepath, bool whiteList) {
std::ifstream file(filepath); std::ifstream file(filepath);
if (file) { if (file) {
std::string line; std::string line;
while (std::getline(file, line)) { while (std::getline(file, line)) {
line.erase(std::remove(line.begin(), line.end(), '\r'), line.end()); line.erase(std::remove(line.begin(), line.end(), '\r'), line.end());
std::transform(line.begin(), line.end(), line.begin(), ::tolower); //Transform to lowercase std::transform(line.begin(), line.end(), line.begin(), ::tolower); //Transform to lowercase
if (allowList) m_ApprovedWords.push_back(CalculateHash(line)); if (whiteList) m_ApprovedWords.push_back(CalculateHash(line));
else m_DeniedWords.push_back(CalculateHash(line)); else m_DeniedWords.push_back(CalculateHash(line));
} }
} }
} }
bool dChatFilter::ReadWordlistDCF(const std::string& filepath, bool allowList) { bool dChatFilter::ReadWordlistDCF(const std::string& filepath, bool whiteList) {
std::ifstream file(filepath, std::ios::binary); std::ifstream file(filepath, std::ios::binary);
if (file) { if (file) {
fileHeader hdr; fileHeader hdr;
@@ -70,13 +70,13 @@ bool dChatFilter::ReadWordlistDCF(const std::string& filepath, bool allowList) {
if (hdr.formatVersion == formatVersion) { if (hdr.formatVersion == formatVersion) {
size_t wordsToRead = 0; size_t wordsToRead = 0;
BinaryIO::BinaryRead(file, wordsToRead); BinaryIO::BinaryRead(file, wordsToRead);
if (allowList) m_ApprovedWords.reserve(wordsToRead); if (whiteList) m_ApprovedWords.reserve(wordsToRead);
else m_DeniedWords.reserve(wordsToRead); else m_DeniedWords.reserve(wordsToRead);
size_t word = 0; size_t word = 0;
for (size_t i = 0; i < wordsToRead; ++i) { for (size_t i = 0; i < wordsToRead; ++i) {
BinaryIO::BinaryRead(file, word); BinaryIO::BinaryRead(file, word);
if (allowList) m_ApprovedWords.push_back(word); if (whiteList) m_ApprovedWords.push_back(word);
else m_DeniedWords.push_back(word); else m_DeniedWords.push_back(word);
} }
@@ -90,14 +90,14 @@ bool dChatFilter::ReadWordlistDCF(const std::string& filepath, bool allowList) {
return false; return false;
} }
void dChatFilter::ExportWordlistToDCF(const std::string& filepath, bool allowList) { void dChatFilter::ExportWordlistToDCF(const std::string& filepath, bool whiteList) {
std::ofstream file(filepath, std::ios::binary | std::ios_base::out); std::ofstream file(filepath, std::ios::binary | std::ios_base::out);
if (file) { if (file) {
BinaryIO::BinaryWrite(file, uint32_t(dChatFilterDCF::header)); BinaryIO::BinaryWrite(file, uint32_t(dChatFilterDCF::header));
BinaryIO::BinaryWrite(file, uint32_t(dChatFilterDCF::formatVersion)); BinaryIO::BinaryWrite(file, uint32_t(dChatFilterDCF::formatVersion));
BinaryIO::BinaryWrite(file, size_t(allowList ? m_ApprovedWords.size() : m_DeniedWords.size())); BinaryIO::BinaryWrite(file, size_t(whiteList ? m_ApprovedWords.size() : m_DeniedWords.size()));
for (size_t word : allowList ? m_ApprovedWords : m_DeniedWords) { for (size_t word : whiteList ? m_ApprovedWords : m_DeniedWords) {
BinaryIO::BinaryWrite(file, word); BinaryIO::BinaryWrite(file, word);
} }
@@ -105,10 +105,10 @@ void dChatFilter::ExportWordlistToDCF(const std::string& filepath, bool allowLis
} }
} }
std::vector<std::pair<uint8_t, uint8_t>> dChatFilter::IsSentenceOkay(const std::string& message, eGameMasterLevel gmLevel, bool allowList) { std::vector<std::pair<uint8_t, uint8_t>> dChatFilter::IsSentenceOkay(const std::string& message, eGameMasterLevel gmLevel, bool whiteList) {
if (gmLevel > eGameMasterLevel::FORUM_MODERATOR) return { }; //If anything but a forum mod, return true. if (gmLevel > eGameMasterLevel::FORUM_MODERATOR) return { }; //If anything but a forum mod, return true.
if (message.empty()) return { }; if (message.empty()) return { };
if (!allowList && m_DeniedWords.empty()) return { { 0, message.length() } }; if (!whiteList && m_DeniedWords.empty()) return { { 0, message.length() } };
std::stringstream sMessage(message); std::stringstream sMessage(message);
std::string segment; std::string segment;
@@ -126,16 +126,16 @@ std::vector<std::pair<uint8_t, uint8_t>> dChatFilter::IsSentenceOkay(const std::
size_t hash = CalculateHash(segment); size_t hash = CalculateHash(segment);
if (std::find(m_UserUnapprovedWordCache.begin(), m_UserUnapprovedWordCache.end(), hash) != m_UserUnapprovedWordCache.end() && allowList) { if (std::find(m_UserUnapprovedWordCache.begin(), m_UserUnapprovedWordCache.end(), hash) != m_UserUnapprovedWordCache.end() && whiteList) {
listOfBadSegments.emplace_back(position, originalSegment.length()); listOfBadSegments.emplace_back(position, originalSegment.length());
} }
if (std::find(m_ApprovedWords.begin(), m_ApprovedWords.end(), hash) == m_ApprovedWords.end() && allowList) { if (std::find(m_ApprovedWords.begin(), m_ApprovedWords.end(), hash) == m_ApprovedWords.end() && whiteList) {
m_UserUnapprovedWordCache.push_back(hash); m_UserUnapprovedWordCache.push_back(hash);
listOfBadSegments.emplace_back(position, originalSegment.length()); listOfBadSegments.emplace_back(position, originalSegment.length());
} }
if (std::find(m_DeniedWords.begin(), m_DeniedWords.end(), hash) != m_DeniedWords.end() && !allowList) { if (std::find(m_DeniedWords.begin(), m_DeniedWords.end(), hash) != m_DeniedWords.end() && !whiteList) {
m_UserUnapprovedWordCache.push_back(hash); m_UserUnapprovedWordCache.push_back(hash);
listOfBadSegments.emplace_back(position, originalSegment.length()); listOfBadSegments.emplace_back(position, originalSegment.length());
} }

View File

@@ -21,10 +21,10 @@ public:
dChatFilter(const std::string& filepath, bool dontGenerateDCF); dChatFilter(const std::string& filepath, bool dontGenerateDCF);
~dChatFilter(); ~dChatFilter();
void ReadWordlistPlaintext(const std::string& filepath, bool allowList); void ReadWordlistPlaintext(const std::string& filepath, bool whiteList);
bool ReadWordlistDCF(const std::string& filepath, bool allowList); bool ReadWordlistDCF(const std::string& filepath, bool whiteList);
void ExportWordlistToDCF(const std::string& filepath, bool allowList); void ExportWordlistToDCF(const std::string& filepath, bool whiteList);
std::vector<std::pair<uint8_t, uint8_t>> IsSentenceOkay(const std::string& message, eGameMasterLevel gmLevel, bool allowList = true); std::vector<std::pair<uint8_t, uint8_t>> IsSentenceOkay(const std::string& message, eGameMasterLevel gmLevel, bool whiteList = true);
private: private:
bool m_DontGenerateDCF; bool m_DontGenerateDCF;

View File

@@ -29,8 +29,8 @@ enum class eWorldMessageType : uint32_t {
ROUTE_PACKET, // Social? ROUTE_PACKET, // Social?
POSITION_UPDATE, POSITION_UPDATE,
MAIL, MAIL,
WORD_CHECK, // AllowList word check WORD_CHECK, // Whitelist word check
STRING_CHECK, // AllowList string check STRING_CHECK, // Whitelist string check
GET_PLAYERS_IN_ZONE, GET_PLAYERS_IN_ZONE,
REQUEST_UGC_MANIFEST_INFO, REQUEST_UGC_MANIFEST_INFO,
BLUEPRINT_GET_ALL_DATA_REQUEST, BLUEPRINT_GET_ALL_DATA_REQUEST,

View File

@@ -83,7 +83,7 @@ void UserManager::Initialize() {
auto chatListStream = Game::assetManager->GetFile("chatplus_en_us.txt"); auto chatListStream = Game::assetManager->GetFile("chatplus_en_us.txt");
if (!chatListStream) { if (!chatListStream) {
LOG("Failed to load %s", (Game::assetManager->GetResPath() / "chatplus_en_us.txt").string().c_str()); LOG("Failed to load %s", (Game::assetManager->GetResPath() / "chatplus_en_us.txt").string().c_str());
throw std::runtime_error("Aborting initialization due to missing chat allowlist file."); throw std::runtime_error("Aborting initialization due to missing chat whitelist file.");
} }
while (std::getline(chatListStream, line, '\n')) { while (std::getline(chatListStream, line, '\n')) {

View File

@@ -150,13 +150,13 @@ void BaseCombatAIComponent::Update(const float deltaTime) {
m_dpEntityEnemy->SetPosition(m_Parent->GetPosition()); m_dpEntityEnemy->SetPosition(m_Parent->GetPosition());
//Process enter events //Process enter events
for (const auto id : m_dpEntity->GetNewObjects()) { for (auto en : m_dpEntity->GetNewObjects()) {
m_Parent->OnCollisionPhantom(id); m_Parent->OnCollisionPhantom(en->GetObjectID());
} }
//Process exit events //Process exit events
for (const auto id : m_dpEntity->GetRemovedObjects()) { for (auto en : m_dpEntity->GetRemovedObjects()) {
m_Parent->OnCollisionLeavePhantom(id); m_Parent->OnCollisionLeavePhantom(en->GetObjectID());
} }
// Check if we should stop the tether effect // Check if we should stop the tether effect

View File

@@ -187,7 +187,7 @@ PhantomPhysicsComponent::PhantomPhysicsComponent(Entity* parent) : PhysicsCompon
//add fallback cube: //add fallback cube:
m_dpEntity = new dpEntity(m_Parent->GetObjectID(), 2.0f, 2.0f, 2.0f); m_dpEntity = new dpEntity(m_Parent->GetObjectID(), 2.0f, 2.0f, 2.0f);
} }
m_dpEntity->SetScale(m_Scale); m_dpEntity->SetScale(m_Scale);
m_dpEntity->SetRotation(m_Rotation); m_dpEntity->SetRotation(m_Rotation);
m_dpEntity->SetPosition(m_Position); m_dpEntity->SetPosition(m_Position);
@@ -323,13 +323,14 @@ void PhantomPhysicsComponent::Update(float deltaTime) {
if (!m_dpEntity) return; if (!m_dpEntity) return;
//Process enter events //Process enter events
for (const auto id : m_dpEntity->GetNewObjects()) { for (auto en : m_dpEntity->GetNewObjects()) {
ApplyCollisionEffect(id, m_EffectType, m_DirectionalMultiplier); if (!en) continue;
m_Parent->OnCollisionPhantom(id); ApplyCollisionEffect(en->GetObjectID(), m_EffectType, m_DirectionalMultiplier);
m_Parent->OnCollisionPhantom(en->GetObjectID());
//If we are a respawn volume, inform the client: //If we are a respawn volume, inform the client:
if (m_IsRespawnVolume) { if (m_IsRespawnVolume) {
auto* const entity = Game::entityManager->GetEntity(id); auto entity = Game::entityManager->GetEntity(en->GetObjectID());
if (entity) { if (entity) {
GameMessages::SendPlayerReachedRespawnCheckpoint(entity, m_RespawnPos, m_RespawnRot); GameMessages::SendPlayerReachedRespawnCheckpoint(entity, m_RespawnPos, m_RespawnRot);
@@ -340,9 +341,10 @@ void PhantomPhysicsComponent::Update(float deltaTime) {
} }
//Process exit events //Process exit events
for (const auto id : m_dpEntity->GetRemovedObjects()) { for (auto en : m_dpEntity->GetRemovedObjects()) {
ApplyCollisionEffect(id, m_EffectType, 1.0f); if (!en) continue;
m_Parent->OnCollisionLeavePhantom(id); ApplyCollisionEffect(en->GetObjectID(), m_EffectType, 1.0f);
m_Parent->OnCollisionLeavePhantom(en->GetObjectID());
} }
} }

View File

@@ -352,11 +352,16 @@ void PropertyManagementComponent::UpdateModelPosition(const LWOOBJID id, const N
auto* spawner = Game::zoneManager->GetSpawner(spawnerId); auto* spawner = Game::zoneManager->GetSpawner(spawnerId);
info.nodes[0]->config.push_back(new LDFData<LWOOBJID>(u"modelBehaviors", 0)); auto ldfModelBehavior = new LDFData<LWOOBJID>(u"modelBehaviors", 0);
info.nodes[0]->config.push_back(new LDFData<LWOOBJID>(u"userModelID", info.spawnerID)); auto userModelID = new LDFData<LWOOBJID>(u"userModelID", info.spawnerID);
info.nodes[0]->config.push_back(new LDFData<int>(u"modelType", 2)); auto modelType = new LDFData<int>(u"modelType", 2);
info.nodes[0]->config.push_back(new LDFData<bool>(u"propertyObjectID", true)); auto propertyObjectID = new LDFData<bool>(u"propertyObjectID", true);
info.nodes[0]->config.push_back(new LDFData<int>(u"componentWhitelist", 1)); auto componentWhitelist = new LDFData<int>(u"componentWhitelist", 1);
info.nodes[0]->config.push_back(componentWhitelist);
info.nodes[0]->config.push_back(ldfModelBehavior);
info.nodes[0]->config.push_back(modelType);
info.nodes[0]->config.push_back(propertyObjectID);
info.nodes[0]->config.push_back(userModelID);
auto* model = spawner->Spawn(); auto* model = spawner->Spawn();
@@ -580,17 +585,29 @@ void PropertyManagementComponent::Load() {
GeneralUtils::SetBit(blueprintID, eObjectBits::CHARACTER); GeneralUtils::SetBit(blueprintID, eObjectBits::CHARACTER);
GeneralUtils::SetBit(blueprintID, eObjectBits::PERSISTENT); GeneralUtils::SetBit(blueprintID, eObjectBits::PERSISTENT);
settings.push_back(new LDFData<LWOOBJID>(u"blueprintid", blueprintID)); LDFBaseData* ldfBlueprintID = new LDFData<LWOOBJID>(u"blueprintid", blueprintID);
settings.push_back(new LDFData<int>(u"componentWhitelist", 1)); LDFBaseData* componentWhitelist = new LDFData<int>(u"componentWhitelist", 1);
settings.push_back(new LDFData<int>(u"modelType", 2)); LDFBaseData* modelType = new LDFData<int>(u"modelType", 2);
settings.push_back(new LDFData<bool>(u"propertyObjectID", true)); LDFBaseData* propertyObjectID = new LDFData<bool>(u"propertyObjectID", true);
settings.push_back(new LDFData<LWOOBJID>(u"userModelID", databaseModel.id)); LDFBaseData* userModelID = new LDFData<LWOOBJID>(u"userModelID", databaseModel.id);
settings.push_back(ldfBlueprintID);
settings.push_back(componentWhitelist);
settings.push_back(modelType);
settings.push_back(propertyObjectID);
settings.push_back(userModelID);
} else { } else {
settings.push_back(new LDFData<int>(u"modelType", 2)); auto modelType = new LDFData<int>(u"modelType", 2);
settings.push_back(new LDFData<LWOOBJID>(u"userModelID", databaseModel.id)); auto userModelID = new LDFData<LWOOBJID>(u"userModelID", databaseModel.id);
settings.push_back(new LDFData<LWOOBJID>(u"modelBehaviors", 0)); auto ldfModelBehavior = new LDFData<LWOOBJID>(u"modelBehaviors", 0);
settings.push_back(new LDFData<bool>(u"propertyObjectID", true)); auto propertyObjectID = new LDFData<bool>(u"propertyObjectID", true);
settings.push_back(new LDFData<int>(u"componentWhitelist", 1)); auto componentWhitelist = new LDFData<int>(u"componentWhitelist", 1);
settings.push_back(componentWhitelist);
settings.push_back(ldfModelBehavior);
settings.push_back(modelType);
settings.push_back(propertyObjectID);
settings.push_back(userModelID);
} }
node->config = settings; node->config = settings;

View File

@@ -5,7 +5,7 @@
#include "EntityManager.h" #include "EntityManager.h"
#include "SimplePhysicsComponent.h" #include "SimplePhysicsComponent.h"
const std::unordered_set<LWOOBJID> ProximityMonitorComponent::m_EmptyObjectSet = {}; const std::map<LWOOBJID, dpEntity*> ProximityMonitorComponent::m_EmptyObjectMap = {};
ProximityMonitorComponent::ProximityMonitorComponent(Entity* parent, int radiusSmall, int radiusLarge) : Component(parent) { ProximityMonitorComponent::ProximityMonitorComponent(Entity* parent, int radiusSmall, int radiusLarge) : Component(parent) {
if (radiusSmall != -1 && radiusLarge != -1) { if (radiusSmall != -1 && radiusLarge != -1) {
@@ -38,26 +38,26 @@ void ProximityMonitorComponent::SetProximityRadius(dpEntity* entity, const std::
m_ProximitiesData.insert(std::make_pair(name, entity)); m_ProximitiesData.insert(std::make_pair(name, entity));
} }
const std::unordered_set<LWOOBJID>& ProximityMonitorComponent::GetProximityObjects(const std::string& name) { const std::map<LWOOBJID, dpEntity*>& ProximityMonitorComponent::GetProximityObjects(const std::string& name) {
const auto iter = m_ProximitiesData.find(name); const auto& iter = m_ProximitiesData.find(name);
if (iter == m_ProximitiesData.cend()) { if (iter == m_ProximitiesData.end()) {
return m_EmptyObjectSet; return m_EmptyObjectMap;
} }
return iter->second->GetCurrentlyCollidingObjects(); return iter->second->GetCurrentlyCollidingObjects();
} }
bool ProximityMonitorComponent::IsInProximity(const std::string& name, LWOOBJID objectID) { bool ProximityMonitorComponent::IsInProximity(const std::string& name, LWOOBJID objectID) {
const auto iter = m_ProximitiesData.find(name); const auto& iter = m_ProximitiesData.find(name);
if (iter == m_ProximitiesData.cend()) { if (iter == m_ProximitiesData.end()) {
return false; return false;
} }
const auto& collisions = iter->second->GetCurrentlyCollidingObjects(); const auto& collitions = iter->second->GetCurrentlyCollidingObjects();
return collisions.contains(objectID); return collitions.find(objectID) != collitions.end();
} }
void ProximityMonitorComponent::Update(float deltaTime) { void ProximityMonitorComponent::Update(float deltaTime) {
@@ -66,13 +66,13 @@ void ProximityMonitorComponent::Update(float deltaTime) {
prox.second->SetPosition(m_Parent->GetPosition()); prox.second->SetPosition(m_Parent->GetPosition());
//Process enter events //Process enter events
for (const auto id : prox.second->GetNewObjects()) { for (auto* en : prox.second->GetNewObjects()) {
m_Parent->OnCollisionProximity(id, prox.first, "ENTER"); m_Parent->OnCollisionProximity(en->GetObjectID(), prox.first, "ENTER");
} }
//Process exit events //Process exit events
for (const auto id : prox.second->GetRemovedObjects()) { for (auto* en : prox.second->GetRemovedObjects()) {
m_Parent->OnCollisionProximity(id, prox.first, "LEAVE"); m_Parent->OnCollisionProximity(en->GetObjectID(), prox.first, "LEAVE");
} }
} }
} }

View File

@@ -6,8 +6,6 @@
#ifndef PROXIMITYMONITORCOMPONENT_H #ifndef PROXIMITYMONITORCOMPONENT_H
#define PROXIMITYMONITORCOMPONENT_H #define PROXIMITYMONITORCOMPONENT_H
#include <unordered_set>
#include "BitStream.h" #include "BitStream.h"
#include "Entity.h" #include "Entity.h"
#include "dpWorld.h" #include "dpWorld.h"
@@ -44,9 +42,9 @@ public:
/** /**
* Returns the last of entities that are used to check proximity, given a name * Returns the last of entities that are used to check proximity, given a name
* @param name the proximity name to retrieve physics objects for * @param name the proximity name to retrieve physics objects for
* @return a set of physics entity object IDs for this name * @return a map of physics entities for this name, indexed by object ID
*/ */
const std::unordered_set<LWOOBJID>& GetProximityObjects(const std::string& name); const std::map<LWOOBJID, dpEntity*>& GetProximityObjects(const std::string& name);
/** /**
* Checks if the passed object is in proximity of the named proximity sensor * Checks if the passed object is in proximity of the named proximity sensor
@@ -72,7 +70,7 @@ private:
/** /**
* Default value for the proximity data * Default value for the proximity data
*/ */
static const std::unordered_set<LWOOBJID> m_EmptyObjectSet; static const std::map<LWOOBJID, dpEntity*> m_EmptyObjectMap;
}; };
#endif // PROXIMITYMONITORCOMPONENT_H #endif // PROXIMITYMONITORCOMPONENT_H

View File

@@ -2663,11 +2663,17 @@ void GameMessages::HandleBBBSaveRequest(RakNet::BitStream& inStream, Entity* ent
info.spawnerID = entity->GetObjectID(); info.spawnerID = entity->GetObjectID();
info.spawnerNodeID = 0; info.spawnerNodeID = 0;
info.settings.push_back(new LDFData<LWOOBJID>(u"blueprintid", blueprintID)); LDFBaseData* ldfBlueprintID = new LDFData<LWOOBJID>(u"blueprintid", blueprintID);
info.settings.push_back(new LDFData<int>(u"componentWhitelist", 1)); LDFBaseData* componentWhitelist = new LDFData<int>(u"componentWhitelist", 1);
info.settings.push_back(new LDFData<int>(u"modelType", 2)); LDFBaseData* modelType = new LDFData<int>(u"modelType", 2);
info.settings.push_back(new LDFData<bool>(u"propertyObjectID", true)); LDFBaseData* propertyObjectID = new LDFData<bool>(u"propertyObjectID", true);
info.settings.push_back(new LDFData<LWOOBJID>(u"userModelID", newIDL)); LDFBaseData* userModelID = new LDFData<LWOOBJID>(u"userModelID", newIDL);
info.settings.push_back(ldfBlueprintID);
info.settings.push_back(componentWhitelist);
info.settings.push_back(modelType);
info.settings.push_back(propertyObjectID);
info.settings.push_back(userModelID);
Entity* newEntity = Game::entityManager->CreateEntity(info, nullptr); Entity* newEntity = Game::entityManager->CreateEntity(info, nullptr);
if (newEntity) { if (newEntity) {

View File

@@ -63,7 +63,7 @@ void AuthPackets::HandleHandshake(dServer* server, Packet* packet) {
if (port != packet->systemAddress.port) LOG("WARNING: Port written in packet does not match the port the client is connecting over!"); if (port != packet->systemAddress.port) LOG("WARNING: Port written in packet does not match the port the client is connecting over!");
inStream.IgnoreBytes(33); inStream.IgnoreBytes(33);
LOG_DEBUG("Client Data [Version: %i, Service: %s, Process: %u, Port: %u, Sysaddr Port: %u]", clientVersion, StringifiedEnum::ToString(serviceId).data(), processID, port, packet->systemAddress.port); LOG_DEBUG("Client Data [Version: %i, Service: %s, Process: %u, Port: %u, Sysaddr Port: %u]", clientVersion, StringifiedEnum::ToString(serviceId).data(), processID, port, packet->systemAddress.port);
SendHandshake(server, packet->systemAddress, server->GetIP(), server->GetPort(), server->GetServerType()); SendHandshake(server, packet->systemAddress, server->GetIP(), server->GetPort(), server->GetServerType());
@@ -72,7 +72,7 @@ void AuthPackets::HandleHandshake(dServer* server, Packet* packet) {
void AuthPackets::SendHandshake(dServer* server, const SystemAddress& sysAddr, const std::string& nextServerIP, uint16_t nextServerPort, const ServerType serverType) { void AuthPackets::SendHandshake(dServer* server, const SystemAddress& sysAddr, const std::string& nextServerIP, uint16_t nextServerPort, const ServerType serverType) {
RakNet::BitStream bitStream; RakNet::BitStream bitStream;
BitStreamUtils::WriteHeader(bitStream, eConnectionType::SERVER, eServerMessageType::VERSION_CONFIRM); BitStreamUtils::WriteHeader(bitStream, eConnectionType::SERVER, eServerMessageType::VERSION_CONFIRM);
const auto clientNetVersionString = Game::config->GetValue("client_net_version"); const auto clientNetVersionString = Game::config->GetValue("client_net_version");
const uint32_t clientNetVersion = GeneralUtils::TryParse<uint32_t>(clientNetVersionString).value_or(171022); const uint32_t clientNetVersion = GeneralUtils::TryParse<uint32_t>(clientNetVersionString).value_or(171022);

View File

@@ -3,6 +3,8 @@
#include "dpShapeBox.h" #include "dpShapeBox.h"
#include "dpGrid.h" #include "dpGrid.h"
#include <iostream>
dpEntity::dpEntity(const LWOOBJID& objectID, dpShapeType shapeType, bool isStatic) { dpEntity::dpEntity(const LWOOBJID& objectID, dpShapeType shapeType, bool isStatic) {
m_ObjectID = objectID; m_ObjectID = objectID;
m_IsStatic = isStatic; m_IsStatic = isStatic;
@@ -74,17 +76,16 @@ void dpEntity::CheckCollision(dpEntity* other) {
return; return;
} }
const auto objId = other->GetObjectID(); bool wasFound = m_CurrentlyCollidingObjects.contains(other->GetObjectID());
const auto objItr = m_CurrentlyCollidingObjects.find(objId);
const bool wasFound = objItr != m_CurrentlyCollidingObjects.cend(); bool isColliding = m_CollisionShape->IsColliding(other->GetShape());
const bool isColliding = m_CollisionShape->IsColliding(other->GetShape());
if (isColliding && !wasFound) { if (isColliding && !wasFound) {
m_CurrentlyCollidingObjects.emplace(objId); m_CurrentlyCollidingObjects.emplace(other->GetObjectID(), other);
m_NewObjects.push_back(objId); m_NewObjects.push_back(other);
} else if (!isColliding && wasFound) { } else if (!isColliding && wasFound) {
m_CurrentlyCollidingObjects.erase(objItr); m_CurrentlyCollidingObjects.erase(other->GetObjectID());
m_RemovedObjects.push_back(objId); m_RemovedObjects.push_back(other);
} }
} }

View File

@@ -2,8 +2,7 @@
#include "NiPoint3.h" #include "NiPoint3.h"
#include "NiQuaternion.h" #include "NiQuaternion.h"
#include <vector> #include <vector>
#include <unordered_set> #include <map>
#include <span>
#include "dCommonVars.h" #include "dCommonVars.h"
#include "dpCommon.h" #include "dpCommon.h"
@@ -50,9 +49,9 @@ public:
bool GetSleeping() const { return m_Sleeping; } bool GetSleeping() const { return m_Sleeping; }
void SetSleeping(bool value) { m_Sleeping = value; } void SetSleeping(bool value) { m_Sleeping = value; }
std::span<const LWOOBJID> GetNewObjects() const { return m_NewObjects; } const std::vector<dpEntity*>& GetNewObjects() const { return m_NewObjects; }
std::span<const LWOOBJID> GetRemovedObjects() const { return m_RemovedObjects; } const std::vector<dpEntity*>& GetRemovedObjects() const { return m_RemovedObjects; }
const std::unordered_set<LWOOBJID>& GetCurrentlyCollidingObjects() const { return m_CurrentlyCollidingObjects; } const std::map<LWOOBJID, dpEntity*>& GetCurrentlyCollidingObjects() const { return m_CurrentlyCollidingObjects; }
void PreUpdate() { m_NewObjects.clear(); m_RemovedObjects.clear(); } void PreUpdate() { m_NewObjects.clear(); m_RemovedObjects.clear(); }
@@ -81,7 +80,7 @@ private:
bool m_IsGargantuan = false; bool m_IsGargantuan = false;
std::vector<LWOOBJID> m_NewObjects; std::vector<dpEntity*> m_NewObjects;
std::vector<LWOOBJID> m_RemovedObjects; std::vector<dpEntity*> m_RemovedObjects;
std::unordered_set<LWOOBJID> m_CurrentlyCollidingObjects; std::map<LWOOBJID, dpEntity*> m_CurrentlyCollidingObjects;
}; };

View File

@@ -21,7 +21,7 @@ void WanderingVendor::OnProximityUpdate(Entity* self, Entity* entering, std::str
const auto proxObjs = proximityMonitorComponent->GetProximityObjects("playermonitor"); const auto proxObjs = proximityMonitorComponent->GetProximityObjects("playermonitor");
bool foundPlayer = false; bool foundPlayer = false;
for (const auto id : proxObjs) { for (const auto id : proxObjs | std::views::keys) {
auto* entity = Game::entityManager->GetEntity(id); auto* entity = Game::entityManager->GetEntity(id);
if (entity && entity->IsPlayer()) { if (entity && entity->IsPlayer()) {
foundPlayer = true; foundPlayer = true;

View File

@@ -23,13 +23,13 @@ void AgBusDoor::OnProximityUpdate(Entity* self, Entity* entering, std::string na
m_Counter = 0; m_Counter = 0;
m_OuterCounter = 0; m_OuterCounter = 0;
for (const auto id : proximityMonitorComponent->GetProximityObjects("busDoor")) { for (const auto& pair : proximityMonitorComponent->GetProximityObjects("busDoor")) {
const auto* const entity = Game::entityManager->GetEntity(id); auto* entity = Game::entityManager->GetEntity(pair.first);
if (entity != nullptr && entity->IsPlayer()) m_Counter++; if (entity != nullptr && entity->IsPlayer()) m_Counter++;
} }
for (const auto id : proximityMonitorComponent->GetProximityObjects("busDoorOuter")) { for (const auto& pair : proximityMonitorComponent->GetProximityObjects("busDoorOuter")) {
const auto* const entity = Game::entityManager->GetEntity(id); auto* entity = Game::entityManager->GetEntity(pair.first);
if (entity != nullptr && entity->IsPlayer()) m_OuterCounter++; if (entity != nullptr && entity->IsPlayer()) m_OuterCounter++;
} }