Repository navigation
fix(inventory): a jewel which the server refuses stays a normal held item - #1185
Conversation
…item A held jewel used on another item was marked as used, so that the update of the target ends it. When the server refuses the jewel (OpenMU answers with ItemConsumptionFailed, e.g. a Jewel of Bless on an item at its limit), the target is never updated, and the next unrelated item update, e.g. a rented item expiring, discarded the jewel while the server still had it. MarkUsedOnItem now remembers the target slot, and only the update of that slot ends the jewel. The sound of the use plays only when the request was sent. Refs Mutizens#1184
Mosch0512
left a comment
There was a problem hiding this comment.
Changes requested. One required fix: a refused jewel is still marked as used on its target, so a later update of that target slot still discards it.
Required:
- Clear the "used on" mark when the server refuses the use (
C1 26 FD), see the comment onInventoryContents.cpp.
Non-blocking:
2. A test for a refused jewel followed by an update of the target slot.
3. Pre-existing: a use the server never answers blocks every later item use (EnableUse stays 10).
The sound change in ApplyJewel looks good.
| { | ||
| // The update of the target answers the use; any other update, e.g. a rented item which expired, doesn't. A refused | ||
| // use gets no update of the target at all (OpenMU answers with ItemConsumptionFailed). | ||
| const bool answersTheUse = usedOnIndex == updatedIndex; |
There was a problem hiding this comment.
Required: a refused jewel stays marked as used on its target, so it can still vanish while the server keeps it.
MarkUsedOnItem(targetIndex) is never undone. The refusal (C1 26 FD) lands in ReceiveStatsExtended, case 0xfd, in WSclient.cpp, and that only resets EnableUse. The held jewel keeps m_usedOnIndex, so any later F3 14 for the target slot still matches answersTheUse.
Example: the player drops a Jewel of Bless on a rented item, the server refuses it, and the jewel stays in the hand. The rented target then expires, the server sends F3 14 for that slot, and DiscardPickedItem drops the jewel while the server still has it. It stays invisible until a relog, the same bug this PR fixes for other slots. The comment in InventoryCtrl.h ("a refusal leaves it a normal held item") isn't true yet for that reason.
Suggestion: add a CPickedItem::ClearUsedOnItem() that resets m_usedOnIndex, and call it from the 0xfd branch through a small UI::Inventory helper.
There was a problem hiding this comment.
Fixed in 49381e8 as you suggested: CPickedItem::ClearUsedOnItem() resets the mark, and the 0xfd branch of ReceiveStatsExtended calls it through UI::Inventory::RefusePickedItemUse(), so a refused jewel is a normal held item again and a later update of its target keeps it. The comment in InventoryCtrl.h now says that the refusal clears the mark.
| TEST_CASE("A held jewel whose use was refused stays on an unrelated update [ui][inventory][held item]") | ||
| { | ||
| // The server refused the jewel (ItemConsumptionFailed), so the target is never updated; a rented item expiring | ||
| // in another slot must not end the jewel, which the server still has. |
There was a problem hiding this comment.
Non-blocking: this case only checks an update of an unrelated slot (OtherSlot). After the refusal fix above, a test for the refusal followed by an update of TargetSlot would catch it if the mark ever stops being cleared. As it is, IsHeldItemEndedByUpdate(..., TargetSlot, TargetSlot) returns true whether the use is pending or refused, so this test can't tell them apart. The test could be on CPickedItem or on the helper the 0xfd handler calls.
There was a problem hiding this comment.
Added: "A refused jewel stays on a later update of its target" marks a CPickedItem on the target, checks that the target's update would end it, clears the mark like the refusal does, and checks that the same update keeps it. To test it on a plain CPickedItem, Release() no longer dereferences the item manager of a picked item which was never created.
| // Only a request which was sent gets an answer which ends the held jewel; one which wasn't (another use still | ||
| // pending, or the vault or a trade open) leaves it a normal held item. | ||
| // pending, or the vault or a trade open) leaves it a normal held item, without the sound of the use. | ||
| if (SendRequestUse(iSourceIndex, targetIndex)) |
There was a problem hiding this comment.
Non-blocking (pre-existing, not from this PR): a use the server never answers blocks every later item use. SendRequestUse sets EnableUse = 10, nothing counts it down, and only an answer packet resets it. OpenMU's ItemConsumeAction sends no packet at all when an IItemConsumingPlugIn cancels the use. The held jewel then also stays marked as used. The TODO next to int EnableUse in WSclient.cpp already names this. It could be a follow-up: a time limit on the pending use, or ItemConsumptionFailed on the server's cancel path.
There was a problem hiding this comment.
Agreed, and thanks for tracing it to the server. I'll leave it for a separate follow-up: OpenMU's ItemConsumeAction answering a cancelled use with ItemConsumptionFailed would also reset EnableUse and now clear the mark, with no client change. A time limit on the pending use in the client could come on top, as a safety net for other servers.
A jewel the server refused stayed marked as used on its target, so a later update of that slot, e.g. the target being a rented item which expires, still discarded it while the server kept it. The refusal (ItemConsumptionFailed, C1 26 FD) now clears the mark through UI::Inventory::RefusePickedItemUse, so the jewel is a normal held item again. CPickedItem::Release no longer dereferences the item manager of a picked item which was never created, so the mark can be tested on a plain CPickedItem. Refs Mutizens#1184
|
Thanks, you're right: the refusal never cleared the mark. Fixed in 49381e8, see the inline replies. About the unanswered use: it's from before this PR, as you say, so I'll leave it for a separate follow-up; I think the cleaner fix is on the server, so that every refused use gets an answer. |
Mosch0512
left a comment
There was a problem hiding this comment.
Changes requested. Thanks, the round 1 point is fixed: a refusal now clears the mark, and the new test covers a later update of the target. One required fix is left: any refused use clears the held jewel's mark, not only the jewel's own use.
Required:
- Clear the mark only when the refusal answers the held jewel's use, see the comment on
RefusePickedItemUse.
Non-blocking:
2. The new test calls ClearUsedOnItem() directly, so RefusePickedItemUse and the 0xfd call aren't covered.
3. Pre-existing, from round 1: a use the server never answers still blocks every later item use (EnableUse stays 10). Fine as a follow-up.
| return answersTheUse || isUpdatedItem; | ||
| } | ||
|
|
||
| void RefusePickedItemUse() |
There was a problem hiding this comment.
Required: C1 26 FD doesn't say which use it refuses, but this always clears the held jewel's mark. If another use was sent while the jewel's use was still pending, and that other use is refused, the jewel's own answer (F3 14 of the target) no longer ends it. The player then holds a jewel the server has already destroyed.
This can happen because several packets reset EnableUse before the jewel's answer arrives: ReceiveHelperItem, ReceiveDurability with KeyL, and ReceiveDeleteInventory with Value. After such a reset, SendRequestUse lets a second use go out, for example an MU Helper potion.
Example: the player drops a Jewel of Bless on a weapon, so the mark is set and EnableUse = 10. A helper-buff packet sets EnableUse = 0. The MU Helper sends a potion use, the server refuses it with C1 26 FD, and this function clears the jewel's mark. The server then accepts the jewel: F3 14 for the weapon no longer ends the held jewel, and F3 28 removes nothing because the jewel is in the hand, not in its slot. Putting it back shows a jewel the server no longer has.
Suggestion: remember which item the last sent use was for (e.g. SendRequestUse stores its Index), and clear the mark here only when that is the held item's source slot. Otherwise keep the mark.
There was a problem hiding this comment.
Fixed in 1e6ddd5 as you suggested: SendRequestUse remembers the slot of the last use it sent (GetLastSentUseIndex()), the 0xfd branch passes it to RefusePickedItemUse, and the mark is cleared only when that's the held item's slot (IsRefusalOfHeldItemUse). In your example, the refused potion is the last sent use, so the jewel keeps its mark and the F3 14 of the weapon still ends it.
One narrower case is left, because C1 26 FD doesn't say which use it answers: if the other use went out first and the jewel's use last, a refusal of the other one is taken for the jewel's and clears its mark. If the server then accepts the jewel, its F3 14 no longer ends it, and the player holds a jewel the server has consumed, like before, only after two uses in flight with the jewel's sent last. Telling the two refusals apart would need the server to say which slot it refuses, so I left it there.
| CHECK( | ||
| UI::Inventory::IsHeldItemEndedByUpdate(STORAGE_TYPE::INVENTORY, HeldSlot, jewel.GetUsedOnIndex(), TargetSlot)); | ||
|
|
||
| jewel.ClearUsedOnItem(); |
There was a problem hiding this comment.
Non-blocking: this calls ClearUsedOnItem() on a local CPickedItem, so UI::Inventory::RefusePickedItemUse() and the call in the 0xfd branch aren't covered. If either stopped clearing the held item, the suite would still pass. If you add the check from the required comment, a test of that rule, for example "a refusal of another use keeps the mark", would cover both.
There was a problem hiding this comment.
Added "Only the refusal of the held jewel's own use clears its mark": it covers IsRefusalOfHeldItemUse, which RefusePickedItemUse uses, with the refusal of the jewel's own use, of another use, of no sent use, and the same slot in another storage. RefusePickedItemUse itself and the call in the 0xfd branch need the picked item of the inventory window, so they're only covered through that rule.
| // Only a request which was sent gets an answer which ends the held jewel; one which wasn't (another use still | ||
| // pending, or the vault or a trade open) leaves it a normal held item. | ||
| // pending, or the vault or a trade open) leaves it a normal held item, without the sound of the use. | ||
| if (SendRequestUse(iSourceIndex, targetIndex)) |
There was a problem hiding this comment.
Non-blocking (pre-existing, same as round 1): a use the server never answers still leaves EnableUse at 10 and the jewel marked as used. OpenMU sends nothing when an IItemConsumingPlugIn cancels the use. Fine as a follow-up.
There was a problem hiding this comment.
Agreed, it stays a follow-up.
…ts mark ItemConsumptionFailed (C1 26 FD) doesn't say which use it refuses, but every refusal cleared the held jewel's mark. When another use went out while the jewel's answer was still due (several packets reset EnableUse, e.g. a helper buff, and the MU Helper then sends a potion) and that use was refused, the jewel's own answer no longer ended it, and the player held a jewel the server had already consumed. SendRequestUse remembers the slot of the last use it sent, and the refusal clears the mark only when that's the held item's slot (UI::Inventory::IsRefusalOfHeldItemUse). Refs Mutizens#1184
|
Thanks, good catch with the MU Helper potion. Fixed in 1e6ddd5, see the inline replies. The unanswered use stays a follow-up, as agreed. |
|
About the red CI: the only failing test was "Magic Skeleton cloth is skinned before its first draw and follows the current pose" (SIGSEGV on all three platforms), and it fails the same way on main since #996, before this PR. Cause: since Enhanced Movement, the object's position is part of the pose's movement key. The test (#996) sets the position after its scope recorded the pose, so the pose is stale, Since it blocks every PR, I added the fix here as a separate commit, 1c2b3e2: the test records the pose again after moving the object. It's test-only; the game's models have animations. The whole |
Mosch0512
left a comment
There was a problem hiding this comment.
Changes requested. Thanks, a refusal of another use now keeps the jewel's mark, and the new rule has its own test. Two required points are left.
Required:
- A refusal answers the oldest use still waiting for an answer, but the check takes the newest one sent. So the opposite order of last round's race now loses the jewel, see the comment on
RefusePickedItemUse. - The PR conflicts with main in
tests/gamelogic/test_character_effects_phase.cpp. Commit 1c2b3e2 isn't part of this fix, and main has fixed that test differently, see the comment there.
Non-blocking:
3. The rule is tested, but not the path the refusal takes (SendRequestUse recording the slot, the 0xfd call).
4. Pre-existing, from round 1: a use the server never answers still blocks every later item use. Fine as a follow-up.
| if (pickedItem == nullptr) | ||
| return; | ||
|
|
||
| if (IsRefusalOfHeldItemUse(pickedItem->GetSourceStorageType(), pickedItem->GetSourceLinealPos(), refusedUseIndex)) |
There was a problem hiding this comment.
Required: the server answers uses in the order they were sent, so a refusal answers the oldest use still waiting for an answer. GetLastSentUseIndex() is the newest one sent, so the opposite order of last round's race now breaks.
Example: the player drops a Jewel of Bless from slot 20 on a rented weapon in slot 30, so LastSentUseIndex is 20 and the mark is 30. A helper-buff packet sets EnableUse = 0, and the MU Helper sends a potion from slot 40, so LastSentUseIndex is now 40. The server refuses the jewel with C1 26 FD. RefusePickedItemUse(40) compares 40 with the jewel's 20 and keeps the mark. When the rented weapon expires, F3 14 for slot 30 discards the jewel, which the server still has, until a relog. That is the round 1 bug again.
Suggestion: match the refusal against the oldest unanswered use, not the newest sent. That could be a small queue of sent slots, or the slot of the use EnableUse was set for, kept until that use is answered.
There was a problem hiding this comment.
Fixed in ba4d8df with the small queue you suggested: GameLogic::Items::PendingItemUses keeps the uses which wait for an answer, with the slot of the used item and of the item it was used on. SendRequestUse adds to it; the 0xfd refusal takes the oldest out and clears the jewel's mark only if it's the jewel's use; a successful answer takes its use out by its slot: the deletion of the used item (F3 28 with Value) or its loss of durability (ReceiveDurability with KeyL), the two which already flag the answer to a use, or the F3 14 of the item a jewel was used on. It's cleared in InitGame and holds at most 8 uses, so missing answers can't let it grow.
In your example the refusal takes the jewel's use (slot 20, the oldest), so the mark is cleared and the later F3 14 of the rented weapon keeps the jewel. In last round's order the refusal takes the potion's use and the jewel keeps its mark. Both orders are tests now.
What's left: a use which the server answers with neither of these packets (and doesn't refuse) stays in the queue until a later answer or InitGame, so a later refusal could be taken for it. The protocol doesn't number the uses, so I kept to the answers which flag themselves.
| Vector(1000.f, 2000.f, 300.f, o.Position); | ||
| // The position is part of the pose's movement key, so the pose the scope recorded is stale now; recorded again, | ||
| // the update keeps it instead of rebuilding it from this model, which has no animation to build it from. | ||
| Engine::Object::Pose::Record(&o, &model, false); |
There was a problem hiding this comment.
Required: this commit (1c2b3e2) conflicts with main, so GitHub can't merge the PR. main has since fixed this test the other way: it rebuilds the stale pose and offsets the pin bone so a stale pose fails (7c891d3, 377d950). It isn't part of the jewel fix either. Please drop this commit and merge current main, keeping main's version of the test.
There was a problem hiding this comment.
Done: the branch is reset to the jewel fix and main is merged again, so 1c2b3e2 is gone and the test is main's version. The PR's diff against main no longer touches that file.
| { | ||
| // The jewel came from HeldSlot. A refusal of its use clears the mark; the refusal of another use, e.g. an MU | ||
| // Helper potion sent while the jewel's answer was still due, keeps it, and so does a refusal with no sent use. | ||
| CHECK(UI::Inventory::IsRefusalOfHeldItemUse(STORAGE_TYPE::INVENTORY, HeldSlot, HeldSlot)); |
There was a problem hiding this comment.
Non-blocking: this covers the rule, but not the path the refusal takes. Nothing tests that SendRequestUse records the slot (LastSentUseIndex = Index), or that the 0xfd branch passes GetLastSentUseIndex() to RefusePickedItemUse. If either broke, these tests would still pass. A case that runs a sent use and then a refusal through those functions would cover it, or the PR could say that only the rule is covered.
There was a problem hiding this comment.
The queue is tested on its own now: a refusal answers the oldest use, a successful answer takes its use out by the used item or the item it was used on, the queue stays short, and both orders of the race. SendRequestUse adding to it and the handlers calling it aren't covered: SendRequestUse sends through the socket client, and the handlers read raw packets, so testing them needs a network fake the test suite doesn't have. I'll say so in the description.
| // Only a request which was sent gets an answer which ends the held jewel; one which wasn't (another use still | ||
| // pending, or the vault or a trade open) leaves it a normal held item. | ||
| // pending, or the vault or a trade open) leaves it a normal held item, without the sound of the use. | ||
| if (SendRequestUse(iSourceIndex, targetIndex)) |
There was a problem hiding this comment.
Non-blocking (pre-existing, same as rounds 1 and 2): a use the server never answers still leaves EnableUse at 10 and the jewel marked as used. Fine as a follow-up.
There was a problem hiding this comment.
Agreed, a follow-up. The queue at least keeps such a use from growing without bound; the real fix is still the server answering a cancelled use.
The server answers item uses in the order they were sent, so a refusal (ItemConsumptionFailed) answers the oldest use which waits for an answer, not the last one sent. With the last one, a refused jewel sent before an MU Helper potion kept its mark, and the later update of its target discarded it. GameLogic::Items::PendingItemUses keeps the uses which wait for an answer, with the slot of the used item and of the item it was used on. A refusal takes the oldest out; a successful answer takes its use out by that slot: the deletion of the used item or its loss of durability (both flagged as the answer to a use), or the update of the item a jewel was used on. It's cleared on entering the game and stays short if answers go missing. Refs Mutizens#1184
1c2b3e2 to
ba4d8df
Compare
Mosch0512
left a comment
There was a problem hiding this comment.
Approved. Thanks, both required points from round 3 are fixed. A refusal now answers the oldest pending use, and the tests cover both orders of a jewel and an MU Helper potion. The PR merges cleanly with main again. I checked the queue against OpenMU: a jewel that works sends the update of its target and then the jewel's removal, a potion sends a durability change, and every failure sends C1 26 FD, so each use gets one answer. CI is green.
Non-blocking:
- A use that never gets an answer stays in the queue, so each later refusal is matched with the use before it. The PR description already says so, and no OpenMU plug-in drops a use without an answer today.
Answeredruns on every F3 28 withValueand every F3 14, including packets the server sends on its own. See the comment there.- The wiring isn't tested (
SendRequestUseadding to the queue, the packet handlers calling it). The PR description says so too. - Pre-existing, from round 1: a use the server never answers still blocks every later item use. Fine as a follow-up.
| { | ||
| public: | ||
| // More than this means answers went missing; the oldest is dropped to keep the list short. | ||
| static constexpr std::size_t MaxPending = 8; |
There was a problem hiding this comment.
Non-blocking: a use that never gets an answer, e.g. one an OpenMU IItemConsumingPlugIn cancels, stays in the queue until a refusal takes it, the queue is full, or the player relogs. Until then the jewel's own refusal takes that older entry, so the jewel keeps its mark. The PR description already names this, and no plug-in shipped with OpenMU cancels a use, so it's fine as it is. A time limit on a pending use (see the comment on ApplyJewel) could drop its entry as well.
| // The answer to a use: the used item is gone. | ||
| EnableUse = 0; | ||
| if (Data->SubCode != 0xff) | ||
| GameLogic::Items::HeroPendingItemUses().Answered(Data->SubCode); |
There was a problem hiding this comment.
Non-blocking: OpenMU sets this flag on every item removal (SendItemRemovedAsync(slot, trueFlag = 1)), not only for uses: drops, sales, moves, destroyed ammo or pets. ReceiveModifyItemExtended also calls Answered for every F3 14. A removal or update the server sends on its own, for a slot that a pending use names, takes that use out, so its refusal is then matched with the next use. Since the server answers uses in the order they were sent, this needs a packet the server sends on its own, so the risk is low. A line in the class comment would be enough.
|
|
||
| EnableUse = 10; | ||
| // The protocol's target 0 means none: a use on another item is on an inventory item, never on an equipment slot. | ||
| GameLogic::Items::HeroPendingItemUses().Add(Index, Target != 0 ? std::optional<int>(Target) : std::nullopt); |
There was a problem hiding this comment.
Non-blocking: the queue and the rules are tested, but not this call, the 0xfd call of TakeOldest, or the three Answered calls. The PR description says so. If that gets tested later, a small pair of functions for "use sent" and "use refused", which the tests can call without the socket client, would cover it.
| // Only a request which was sent gets an answer which ends the held jewel; one which wasn't (another use still | ||
| // pending, or the vault or a trade open) leaves it a normal held item. | ||
| // pending, or the vault or a trade open) leaves it a normal held item, without the sound of the use. | ||
| if (SendRequestUse(iSourceIndex, targetIndex)) |
There was a problem hiding this comment.
Non-blocking (pre-existing, same as rounds 1-3): a use the server never answers still leaves EnableUse at 10 and the jewel marked as used. Its queue entry now stays as well. Fine as a follow-up.
Summary
Points 2 and 3 of #1184, both from the review of #1150.
C1 26 FD) instead, so the target is never updated, and the next unrelated F3 14, e.g. a rented item expiring, discarded the jewel while the server still had it. It stayed invisible until a relog.CPickedItem::MarkUsedOnItemnow remembers the target slot, andIsHeldItemEndedByUpdateends a used jewel only on the update of that slot. The updated item itself still ends the held item, as before.C1 26 FDdoesn't name the use it refuses, but the server answers the uses in the order they were sent.GameLogic::Items::PendingItemUseskeeps the uses which wait for an answer (the used item's slot and the slot it was used on):SendRequestUseadds to it, the refusal takes the oldest out and clears the held jewel's mark only if it's the jewel's use, and a successful answer takes its use out (F3 28 withValue,ReceiveDurabilitywithKeyL, or the F3 14 of the jewel's target). It's cleared on entering the game and holds at most 8 uses. A use answered by none of these packets stays queued until a later answer or the next login, so a later refusal could be taken for it; the protocol doesn't number the uses.ApplyJewelplayedSOUND_GET_ITEM01even whenSendRequestUsesent nothing (another use still pending, or the vault or a trade open). It now plays only when the request was sent.Related issues
Refs #1184 (points 2 and 3; point 1 follows in its own PR).
Screenshots or videos
Nothing new to see: the held jewel stays in the hand where it was discarded before, and the sound is the same. The change is covered by the tests and the steps below.
Testing
test_held_item_update: the rule which ends a held item on an update, a refused jewel staying on an unrelated update and on a later update of its target, the refusal of another use keeping the mark, andPendingItemUses(the oldest use answers a refusal, a successful answer takes its use out by either slot, the queue stays short, both orders of a jewel and an MU Helper potion in flight). The wholectestsuite passes (3453), the static checks of the pre-push hook pass, clang-format 21.1.8 on the changed lines is clean, and the changed files compile with clang and-Werror=switch.SendRequestUseadding to the queue and the packet handlers calling it; they go through the socket client and raw packets, which the test suite has no fake for.Checklist
docs/CODING_RULES.mdanddocs/PULL_REQUESTS.md; deliberate exceptions are named above with the reason.docs/build/README.md).