Files
DarkflameServer/tests/dGameTests/GameDependencies.h
Aaron Kimbrell 0ff5d2bf87 fix: property model and brick by brick fixes (#2041)
* test: the server mock keeps a copy of the last bitstream sent

The bitstreams sent are usually on the sender's stack, so the pointer it kept was dangling once Send returned.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: PlaceModelResponse writes the model's rotation

The client's PlaceModelResponse::Deserialize (0x00dc0170) reads the rotation as an optional w, x, y, z quaternion, but the server wrote the 4-byte response after the rotation flag, so with any rotation other than identity the client ran out of data.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: naming a model no longer renames the property

The model info window sends UpdatePropertyOrModelForFilterCheck with isProperty false (client 0x00cc42e0); only the property editor sends it true (0x00c2e710). A model's name and description aren't stored yet.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: keep a model item's blueprint across saves

A brick built model item's config has blueprintid (lowercase), which the saved item XML didn't keep (only blueprintID), so a picked up model lost its blueprint on the next load and could not be placed again. It is now saved as bp.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: write model behaviors only for property and inventory models

The client makes the mutable model component, which reads the behaviors and editing info, only when the object's config has propertyObjectID or inInventory (ObjectLoader2::LoadModelBehaviorsComponent); every other model gets the plain one, which reads only the model block. Writing the behaviors for every model made the client read them as the next component's data.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: the model vault uses the models' inventory groups, as the client

LWOInventoryComponent_Common::msgUpdateInventoryGroup (0x00c955b0) and msgUpdateInventoryGroupContents (0x00ce1f50) look the inventory type up in m_VaultToPlayerInventory first, which maps VAULT_MODELS to MODELS. The server refused group updates for the model vault.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 09:34:31 -05:00

97 lines
3.1 KiB
C++

#ifndef __GAMEDEPENDENCIES__H__
#define __GAMEDEPENDENCIES__H__
#include "Game.h"
#include "Logger.h"
#include "dServer.h"
#include "CDClientDatabase.h"
#include "CDClientManager.h"
#include "EntityInfo.h"
#include "EntityManager.h"
#include "dConfig.h"
#include "dZoneManager.h"
#include "GameDatabase/TestSQL/TestSQLDatabase.h"
#include "Database.h"
#include <gtest/gtest.h>
#include <vector>
class dZoneManager;
class AssetManager;
// A packet captured by dServerMock::Send. The bytes are copied, so the capture stays valid
// after the sender's local BitStream goes out of scope.
struct CapturedPacket {
std::vector<uint8_t> bytes;
uint32_t bits = 0;
SystemAddress sysAddr = UNASSIGNED_SYSTEM_ADDRESS;
bool broadcast = false;
};
class dServerMock : public dServer {
std::vector<CapturedPacket> sentPackets;
RakNet::BitStream mostRecent;
public:
dServerMock() {};
~dServerMock() {};
// Returns a copy of the most recently sent packet, with its read pointer at the start, or nullptr if nothing was sent.
RakNet::BitStream* GetMostRecentBitStream() { return sentPackets.empty() ? nullptr : &mostRecent; };
const std::vector<CapturedPacket>& GetSentPackets() const { return sentPackets; }
void ClearSentPackets() { sentPackets.clear(); mostRecent.Reset(); }
void Send(RakNet::BitStream& bitStream, const SystemAddress& sysAddr, bool broadcast) override {
CapturedPacket& packet = sentPackets.emplace_back();
packet.bits = bitStream.GetNumberOfBitsUsed();
packet.bytes.assign(bitStream.GetData(), bitStream.GetData() + bitStream.GetNumberOfBytesUsed());
packet.sysAddr = sysAddr;
packet.broadcast = broadcast;
mostRecent.Reset();
mostRecent.WriteBits(packet.bytes.data(), packet.bits, false);
};
void SetZoneId(unsigned int zoneId) { mZoneID = zoneId; }
};
class GameDependenciesTest : public ::testing::Test {
protected:
void SetUpDependencies() {
info.pos = NiPoint3Constant::ZERO;
info.rot = QuatUtils::IDENTITY;
info.scale = 1.0f;
info.spawner = nullptr;
info.lot = 999;
Game::logger = new Logger("./testing.log", true, true);
Game::server = new dServerMock();
Game::config = new dConfig("worldconfig.ini");
Game::entityManager = new EntityManager();
Game::zoneManager = new dZoneManager();
Game::zoneManager->LoadZone(LWOZONEID(1, 0, 0));
Database::_setDatabase(new TestSQLDatabase()); // this new is managed by the Database
// Create a CDClientManager instance and load from defaults
CDClientManager::LoadValuesFromDefaults();
}
void TearDownDependencies() {
if (Game::server) delete Game::server;
// Cleared too: tests without these fixtures (packet capture) run after them and check them
delete Game::entityManager;
Game::entityManager = nullptr;
delete Game::zoneManager;
Game::zoneManager = nullptr;
if (Game::logger) {
Game::logger->Flush();
delete Game::logger;
Game::logger = nullptr;
}
delete Game::config;
Game::config = nullptr;
// A CDClient a test opened (often an in-memory one with only the tables it needs) isn't the next test's
CDClientDatabase::Disconnect();
}
EntityInfo info{};
};
#endif //!__GAMEDEPENDENCIES__H__