diff --git a/dGame/dComponents/Property/PropertyManagementComponent.cpp b/dGame/dComponents/Property/PropertyManagementComponent.cpp index bda4aec55..42591987b 100644 --- a/dGame/dComponents/Property/PropertyManagementComponent.cpp +++ b/dGame/dComponents/Property/PropertyManagementComponent.cpp @@ -336,6 +336,30 @@ bool PropertyManagementComponent::Claim(const LWOOBJID playerId) { return true; } +LWOMAPID PropertyManagementComponent::GetReturnZone() const { + LWOMAPID zoneId = 1100; + + const auto entrance = Game::entityManager->GetEntitiesByComponent(eReplicaComponentType::PROPERTY_ENTRANCE); + if (!entrance.empty()) { + auto* rocketPad = entrance[0]->GetComponent(); + + if (rocketPad != nullptr) { + zoneId = rocketPad->GetDefaultZone(); + } + } + + return zoneId; +} + +void PropertyManagementComponent::OnRequestLeaveProperty(Entity& player) const { + auto* const characterComponent = player.GetComponent(); + if (!characterComponent) return; + + const auto zoneId = GetReturnZone(); + LOG("Player %llu asked to leave the property, sending them to zone %u", player.GetObjectID(), static_cast(zoneId)); + characterComponent->SendToZone(zoneId); +} + void PropertyManagementComponent::OnStartBuilding(Entity& builder) { const bool first = builders.empty(); if (!builders.insert(builder.GetObjectID()).second) return; @@ -353,21 +377,11 @@ void PropertyManagementComponent::OnStartBuilding(Entity& builder) { const auto players = PlayerManager::GetAllPlayers(); - LWOMAPID zoneId = 1100; - - const auto entrance = Game::entityManager->GetEntitiesByComponent(eReplicaComponentType::PROPERTY_ENTRANCE); - originalPrivacyOption = privacyOption; SetPrivacyOption(PropertyPrivacyOption::Private); // Cant visit player which is building - if (!entrance.empty()) { - auto* rocketPad = entrance[0]->GetComponent(); - - if (rocketPad != nullptr) { - zoneId = rocketPad->GetDefaultZone(); - } - } + const LWOMAPID zoneId = GetReturnZone(); // Everyone who can't build here leaves for (auto* player : players) { diff --git a/dGame/dComponents/Property/PropertyManagementComponent.h b/dGame/dComponents/Property/PropertyManagementComponent.h index 234d95bd4..2b685551c 100644 --- a/dGame/dComponents/Property/PropertyManagementComponent.h +++ b/dGame/dComponents/Property/PropertyManagementComponent.h @@ -82,6 +82,16 @@ public: * Returns the paths that this property has * @return the paths that this property has */ + /** + * The world a player who leaves the property goes to: the one its launch pad launches to + */ + LWOMAPID GetReturnZone() const; + + /** + * A player asked to leave the property (RequestLeaveProperty): they go to the return zone + */ + void OnRequestLeaveProperty(Entity& player) const; + std::vector GetPaths() const; /** diff --git a/dGame/dGameMessages/BuildingMessages.cpp b/dGame/dGameMessages/BuildingMessages.cpp index e062e1857..4d8ecd197 100644 --- a/dGame/dGameMessages/BuildingMessages.cpp +++ b/dGame/dGameMessages/BuildingMessages.cpp @@ -500,6 +500,28 @@ namespace GameMessages { } } + void BuildExitConfirmation::Serialize(RakNet::BitStream& bitStream) const { + bitStream.Write(playerID); + } + + bool BuildExitConfirmation::Deserialize(RakNet::BitStream& bitStream) { + VALIDATE_READ(bitStream.Read(playerID)); + return true; + } + + void BuildExitConfirmation::Handle(Entity& entity, const SystemAddress& sysAddr) { + const auto* const player = PlayerManager::GetPlayer(sysAddr); + if (!player) return; + if (playerID != player->GetObjectID()) { + LOG("Ignored BuildExitConfirmation from %llu for %llu", player->GetObjectID(), playerID); + return; + } + + // The mode itself was already ended by the messages before this one (BuildModeSet, PropertyEditorEnd, + // DoneArrangingWithItem); live answered nothing here, so there is nothing more to do. + LOG_DEBUG("Player %llu confirmed leaving build mode", playerID); + } + void UnUseBBBModel::Serialize(RakNet::BitStream& bitStream) const { bitStream.Write(bHasWorldTransform); bitStream.Write(modelID); diff --git a/dGame/dGameMessages/BuildingMessages.h b/dGame/dGameMessages/BuildingMessages.h index 10c7fde41..60639316a 100644 --- a/dGame/dGameMessages/BuildingMessages.h +++ b/dGame/dGameMessages/BuildingMessages.h @@ -171,6 +171,19 @@ namespace GameMessages { NiPoint3 startPos{ NiPoint3Constant::ZERO }; // optional }; + // Client -> server. The client left a build mode (a modular build or the property editor) and says so after its + // last message of that mode (LWOPropertyManagementComponent::DoSetBuildMode). It is addressed to the + // thinking hat the player wears (the item in the hair slot, when it starts builds) or to no object, + // and carries the player. Live sent no answer to it (10 in the captures). + struct BuildExitConfirmation : public NetGameMsg { + BuildExitConfirmation() : NetGameMsg(MessageType::Game::BUILD_EXIT_CONFIRMATION) {} + void Serialize(RakNet::BitStream& bitStream) const override; + bool Deserialize(RakNet::BitStream& bitStream) override; + void Handle(Entity& entity, const SystemAddress& sysAddr) override; + + LWOOBJID playerID{ LWOOBJID_EMPTY }; + }; + // Client -> server. The player put a model back from brick by brick building. struct UnUseBBBModel : public NetGameMsg { UnUseBBBModel() : NetGameMsg(MessageType::Game::UN_USE_BBB_MODEL) {} diff --git a/dGame/dGameMessages/GameMessageFields.inc b/dGame/dGameMessages/GameMessageFields.inc index f63fc5538..f086c5a35 100644 --- a/dGame/dGameMessages/GameMessageFields.inc +++ b/dGame/dGameMessages/GameMessageFields.inc @@ -30,6 +30,7 @@ json ToJson(const GameMessages::ModularBuildConvertModel& m); json ToJson(const GameMessages::SetBuildMode& m); json ToJson(const GameMessages::SetBuildModeConfirmed& m); json ToJson(const GameMessages::BuildModeSet& m); +json ToJson(const GameMessages::BuildExitConfirmation& m); json ToJson(const GameMessages::UnUseBBBModel& m); json ToJson(const GameMessages::BBBLoadItemRequest& m); json ToJson(const GameMessages::BBBSaveRequest& m); @@ -222,6 +223,8 @@ json ToJson(const GameMessages::UpdatePropertyOrModelForFilterCheck& m); json ToJson(const GameMessages::QueryPropertyData& m); json ToJson(const GameMessages::PropertyEditorBegin& m); json ToJson(const GameMessages::PropertyEditorEnd& m); +json ToJson(const GameMessages::PropertyModerationAction& m); +json ToJson(const GameMessages::RequestLeaveProperty& m); json ToJson(const GameMessages::PropertyContentsFromClient& m); json ToJson(const GameMessages::ZonePropertyModelEquipped& m); json ToJson(const GameMessages::ZonePropertyModelRotated& m); @@ -531,6 +534,11 @@ json ToJson(const GameMessages::BuildModeSet& m) { j["startPos"] = ToJson(m.startPos); return j; } +json ToJson(const GameMessages::BuildExitConfirmation& m) { + json j = json::object(); + j["playerID"] = ToJson(m.playerID); + return j; +} json ToJson(const GameMessages::UnUseBBBModel& m) { json j = json::object(); j["bHasWorldTransform"] = ToJson(m.bHasWorldTransform); @@ -1959,6 +1967,17 @@ json ToJson(const GameMessages::PropertyEditorEnd& m) { json j = json::object(); return j; } +json ToJson(const GameMessages::PropertyModerationAction& m) { + json j = json::object(); + j["characterID"] = ToJson(m.characterID); + j["info"] = ToJson(m.info); + j["newModerationStatus"] = ToJson(m.newModerationStatus); + return j; +} +json ToJson(const GameMessages::RequestLeaveProperty& m) { + json j = json::object(); + return j; +} json ToJson(const GameMessages::PropertyContentsFromClient& m) { json j = json::object(); j["queryDB"] = ToJson(m.queryDB); @@ -2559,6 +2578,7 @@ const std::vector& Entries() { { MessageType::Game::SET_BUILD_MODE, eDirection::TO_SERVER, "SetBuildMode", &ReadWith }, { MessageType::Game::SET_BUILD_MODE_CONFIRMED, eDirection::TO_CLIENT, "SetBuildModeConfirmed", &ReadWith }, { MessageType::Game::BUILD_MODE_SET, eDirection::TO_SERVER, "BuildModeSet", &ReadWith }, + { MessageType::Game::BUILD_EXIT_CONFIRMATION, eDirection::TO_SERVER, "BuildExitConfirmation", &ReadWith }, { MessageType::Game::UN_USE_BBB_MODEL, eDirection::TO_SERVER, "UnUseBBBModel", &ReadWith }, { MessageType::Game::BBB_LOAD_ITEM_REQUEST, eDirection::TO_SERVER, "BBBLoadItemRequest", &ReadWith }, { MessageType::Game::BBB_SAVE_REQUEST, eDirection::TO_SERVER, "BBBSaveRequest", &ReadWith }, @@ -2748,6 +2768,8 @@ const std::vector& Entries() { { MessageType::Game::QUERY_PROPERTY_DATA, eDirection::TO_SERVER, "QueryPropertyData", &ReadWith }, { MessageType::Game::PROPERTY_EDITOR_BEGIN, eDirection::TO_SERVER, "PropertyEditorBegin", &ReadWith }, { MessageType::Game::PROPERTY_EDITOR_END, eDirection::TO_SERVER, "PropertyEditorEnd", &ReadWith }, + { MessageType::Game::PROPERTY_MODERATION_ACTION, eDirection::TO_SERVER, "PropertyModerationAction", &ReadWith }, + { MessageType::Game::REQUEST_LEAVE_PROPERTY, eDirection::TO_SERVER, "RequestLeaveProperty", &ReadWith }, { MessageType::Game::PROPERTY_CONTENTS_FROM_CLIENT, eDirection::TO_SERVER, "PropertyContentsFromClient", &ReadWith }, { MessageType::Game::ZONE_PROPERTY_MODEL_EQUIPPED, eDirection::TO_SERVER, "ZonePropertyModelEquipped", &ReadWith }, { MessageType::Game::ZONE_PROPERTY_MODEL_ROTATED, eDirection::TO_SERVER, "ZonePropertyModelRotated", &ReadWith }, diff --git a/dGame/dGameMessages/GameMessageHandler.cpp b/dGame/dGameMessages/GameMessageHandler.cpp index 53516f4e9..c75e059ad 100644 --- a/dGame/dGameMessages/GameMessageHandler.cpp +++ b/dGame/dGameMessages/GameMessageHandler.cpp @@ -122,6 +122,8 @@ namespace { { PROPERTY_EDITOR_BEGIN, []() { return std::make_unique(); } }, { PROPERTY_EDITOR_END, []() { return std::make_unique(); } }, { PROPERTY_CONTENTS_FROM_CLIENT, []() { return std::make_unique(); } }, + { PROPERTY_MODERATION_ACTION, []() { return std::make_unique(); } }, + { REQUEST_LEAVE_PROPERTY, []() { return std::make_unique(); } }, { ZONE_PROPERTY_MODEL_EQUIPPED, []() { return std::make_unique(); } }, { ZONE_PROPERTY_MODEL_ROTATED, []() { return std::make_unique(); } }, { PLACE_PROPERTY_MODEL, []() { return std::make_unique(); } }, @@ -143,6 +145,7 @@ namespace { { MODULAR_BUILD_CONVERT_MODEL, []() { return std::make_unique(); } }, { SET_BUILD_MODE, []() { return std::make_unique(); } }, { BUILD_MODE_SET, []() { return std::make_unique(); } }, + { BUILD_EXIT_CONFIRMATION, []() { return std::make_unique(); } }, { UN_USE_BBB_MODEL, []() { return std::make_unique(); } }, { FETCH_MODEL_METADATA_REQUEST, []() { return std::make_unique(); } }, { BBB_LOAD_ITEM_REQUEST, []() { return std::make_unique(); } }, @@ -240,6 +243,10 @@ void GameMessageHandler::HandleMessage(RakNet::BitStream& inStream, const System return; } + // BuildExitConfirmation is addressed to the thinking hat the player wears, or to no object: an item is not an + // entity here, so the player who sent it takes it + if (!entity && messageID == MessageType::Game::BUILD_EXIT_CONFIRMATION) entity = Game::entityManager->GetEntity(usr->GetLoggedInChar()); + if (!entity) { LOG("Failed to find associated entity (%llu), aborting GM: %4i, %s!", objectID, messageID, StringifiedEnum::ToString(messageID).data()); return; diff --git a/dGame/dGameMessages/PropertyMessages.cpp b/dGame/dGameMessages/PropertyMessages.cpp index b4a13576d..91f89f10a 100644 --- a/dGame/dGameMessages/PropertyMessages.cpp +++ b/dGame/dGameMessages/PropertyMessages.cpp @@ -434,6 +434,42 @@ namespace GameMessages { Game::zoneManager->GetZoneControlObject()->OnZonePropertyEditEnd(); } + void PropertyModerationAction::Serialize(RakNet::BitStream& bitStream) const { + BitStreamUtils::WriteOptional(bitStream, characterID, LWOOBJID_EMPTY); + BitStreamUtils::WriteLengthPrefixed(bitStream, info); + BitStreamUtils::WriteOptional(bitStream, newModerationStatus, -1); + } + + bool PropertyModerationAction::Deserialize(RakNet::BitStream& bitStream) { + VALIDATE_READ(BitStreamUtils::ReadOptional(bitStream, characterID, LWOOBJID_EMPTY)); + VALIDATE_READ(BitStreamUtils::ReadLengthPrefixed(bitStream, info)); + VALIDATE_READ(BitStreamUtils::ReadOptional(bitStream, newModerationStatus, -1)); + return true; + } + + void PropertyModerationAction::Handle(Entity& entity, const SystemAddress& sysAddr) { + auto* property = PropertyManagementComponent::Instance(); + auto* player = PlayerManager::GetPlayer(sysAddr); + if (!property || !player) return; + + // The client only sends it for its own character, on a property it may edit, to ask for status 0 + if (characterID != player->GetObjectID() || !property->CanBuild(*player) || newModerationStatus != 0) { + LOG("Ignored PropertyModerationAction from %llu (character %llu, status %i)", player->GetObjectID(), characterID, newModerationStatus); + return; + } + + // Nothing is stored here and nothing is answered: the approval of an edited property is taken back when the + // edit ends (PropertyManagementComponent::EndBuilding), and live sent no PropertyModerationActionResponse. + LOG_DEBUG("Player %llu started editing a moderated property", player->GetObjectID()); + } + + void RequestLeaveProperty::Handle(Entity& entity, const SystemAddress& sysAddr) { + auto* property = PropertyManagementComponent::Instance(); + auto* player = PlayerManager::GetPlayer(sysAddr); + if (!property || !player) return; + property->OnRequestLeaveProperty(*player); + } + void PropertyContentsFromClient::Serialize(RakNet::BitStream& bitStream) const { bitStream.Write(queryDB); } diff --git a/dGame/dGameMessages/PropertyMessages.h b/dGame/dGameMessages/PropertyMessages.h index 0f686199b..dab11a474 100644 --- a/dGame/dGameMessages/PropertyMessages.h +++ b/dGame/dGameMessages/PropertyMessages.h @@ -227,6 +227,27 @@ namespace GameMessages { void Handle(Entity& entity, const SystemAddress& sysAddr) override; }; + // Client -> server, to the property plaque. The owner started editing a property whose moderation status is not + // 0 and asks for it to be 0 again (LWOPropertyManagementComponent). Laid out as the client writes it + // (PropertyModerationAction::Serialize). Live sent no answer to it (3 in the captures). + struct PropertyModerationAction : public NetGameMsg { + PropertyModerationAction() : NetGameMsg(MessageType::Game::PROPERTY_MODERATION_ACTION) {} + void Serialize(RakNet::BitStream& bitStream) const override; + bool Deserialize(RakNet::BitStream& bitStream) override; + void Handle(Entity& entity, const SystemAddress& sysAddr) override; + + LWOOBJID characterID{ LWOOBJID_EMPTY }; // optional + std::u16string info; + int32_t newModerationStatus{ -1 }; // optional + }; + + // Client -> server, to the property plaque, with no payload. A visitor answered the "the owner is starting to + // build" dialog by leaving (LWOPropertyManagementComponent::onBuildModeVisitorConfirm). + struct RequestLeaveProperty : public NetGameMsg { + RequestLeaveProperty() : NetGameMsg(MessageType::Game::REQUEST_LEAVE_PROPERTY) {} + void Handle(Entity& entity, const SystemAddress& sysAddr) override; + }; + // Client -> server. struct PropertyContentsFromClient : public NetGameMsg { PropertyContentsFromClient() : NetGameMsg(MessageType::Game::PROPERTY_CONTENTS_FROM_CLIENT) {} diff --git a/tests/dGameTests/dGameMessagesTests/BuildingMessagesTests.cpp b/tests/dGameTests/dGameMessagesTests/BuildingMessagesTests.cpp index 64c52f923..22bb16487 100644 --- a/tests/dGameTests/dGameMessagesTests/BuildingMessagesTests.cpp +++ b/tests/dGameTests/dGameMessagesTests/BuildingMessagesTests.cpp @@ -506,3 +506,11 @@ TEST_F(BuildingMessagesTests, NotifyClientUGCModelReadyWire) { ready.WritePacket(bitStream); EXPECT_PACKET_EQ(FromHex("53 05 00 0c 00 00 00 00 88 77 66 55 44 33 22 11 8d 03 08 07 06 05 04 03 02 01"), FromBitStream(bitStream)); } + +// A live client's BuildExitConfirmation after leaving the property editor: sent to the thinking hat the player wears, +// with the player's id +TEST_F(BuildingMessagesTests, BuildExitConfirmationReadsLiveCapture) { + const auto confirmation = FromLiveClientCapture("53 04 00 05 00 00 00 00 43 b4 a8 91 00 00 00 10 30 04 54 db b6 91 00 00 00 10"); + EXPECT_EQ(confirmation.target, 1152921507050599491LL); + EXPECT_EQ(confirmation.playerID, 1152921507051526996LL); +} diff --git a/tests/dGameTests/dGameMessagesTests/PropertyMessagesTests.cpp b/tests/dGameTests/dGameMessagesTests/PropertyMessagesTests.cpp index 238c1291e..2011892da 100644 --- a/tests/dGameTests/dGameMessagesTests/PropertyMessagesTests.cpp +++ b/tests/dGameTests/dGameMessagesTests/PropertyMessagesTests.cpp @@ -651,3 +651,25 @@ TEST_F(PropertyMessagesTests, RequeryPropertyModelsHasNoPayload) { GameMessages::RequeryPropertyModels requery; EXPECT_EQ(Payload(requery).bits, 0u); } + +// A live client's PropertyModerationAction, sent to the property plaque when its owner started editing: the character, +// no text and status 0 +TEST_F(PropertyMessagesTests, PropertyModerationActionReadsLiveCapture) { + const auto action = FromLiveClientCapture("53 04 00 05 00 00 00 00 8a 4e 00 00 00 40 00 04 93 03 aa 6d db 48 80 00 00 08 00 00 00 00 40 00 00 00 00"); + EXPECT_EQ(action.target, 288300744895909514LL); + EXPECT_EQ(action.characterID, 1152921507051526996LL); + EXPECT_TRUE(action.info.empty()); + EXPECT_EQ(action.newModerationStatus, 0); + + // Left at their defaults, the character and the status are one bit each + GameMessages::PropertyModerationAction empty; + EXPECT_PACKET_EQ(FromHex("00 00 00 00 00", 34), Payload(empty)); +} + +// RequestLeaveProperty carries nothing (RequestLeaveProperty::Deserialize reads nothing) +TEST_F(PropertyMessagesTests, RequestLeavePropertyHasNoPayload) { + GameMessages::RequestLeaveProperty leave; + EXPECT_EQ(Payload(leave).bits, 0u); + RakNet::BitStream bitStream; + EXPECT_TRUE(leave.Deserialize(bitStream)); +}