Commit Graph

66 Commits (ffi-server-rewrite)

Author SHA1 Message Date
David Cernat 5f6ddcfc59 [General] Rework container sync to prevent item duping
A main priority in TES3MP development is to avoid making major changes to OpenMW code, so as to avoid merge conflicts in the future. Whenever avoiding potential conflicts seems especially difficult for the proper implementation of a particular multiplayer feature, that multiplayer feature is often put off until later or partially implemented with the intent of being revisited in the future.

Container sync is the perfect example. Previously, the OpenMW code for container actions was kept exactly as it was, with clients unilaterally accepting their own container changes as per singleplayer-specific code, with only the addition that clients sent container packets every time they made a change in a container, packets which were then forwarded unquestioningly by the server to other players. This meant that two players clicking on the same item in a container at the same time both managed to take it, thus duplicating the item.

Immediately after the packets were already forwarded, server scripts were able to check for incorrect changes, such as the removal of more items than should have existed in a container, but they had to send their own packets that attempted to fix what had already been accepted on the initial client and then forwarded to all clients, which was quite onerous in some scenarios, such as when a player on a slow connection immediately dropped items in the world after taking them from a container (which is why the default TES3MP serverside scripts made no attempt at sending corrective packets at all, preferring to expect the matter to be solved in a later C++ implementation).

This commit fixes item duping in containers by preventing container actions from initially running on clients and by ending the automatic forwarding of container packets by the server. Instead, clients now send container packets that act as requests for container actions, and serverside scripts have to forward these requests themselves. In other words, without a matching Container event in the server's Lua scripts, players are completely unable to affect containers for themselves or for others.

To forward a received Container packet, the following line must be used in a Container event in the Lua scripts:

tes3mp.SendContainer(true, true)

When an invalid action count is used in a container request, the serverside scripts can amend it using the following new function:

tes3mp.SetReceivedContainerItemActionCount(objectIndex, itemIndex, actionCount)

Thus, the serverside scripts are able to allow only container actions that are correct based on their own recorded contents for that container.

The OpenMW code allowing unilateral container actions in mwgui/container.cpp is now prevented from executing. When a player's container request is returned to them, code in mwmp/WorldEvent.cpp simulates those container actions instead.
7 years ago
Andrei Kortunov 3694b6ec90 Move onClose() check to item models 7 years ago
scrawl d58ff4a736 Remove obsolete Container GUI keyboard handling 7 years ago
scrawl e7d2a8a4dc Call clear() for every window 7 years ago
scrawl 2b03bc0c56 Call WindowBase::onFrame() for every active window 7 years ago
scrawl 4fff2e2e34 Refactor exitCurrentGuiMode 7 years ago
scrawl 84657271c7 Improve WindowManager API with a generic way of passing a Ptr to the opened GUI window 7 years ago
scrawl 01391b7eed Rename WindowBase's open/close to onOpen/onClose 7 years ago
scrawl e23775e338 Fix -Woverloaded-virtual clang warnings 10 years ago
scrawl 4b704f665f Reduce includes, move DragAndDrop to separate file 10 years ago
scrawl 715d357f24 Use a controller to move Drag&Drop widget with the mouse cursor 11 years ago
scrawl f2799ea1d9 Reset item model when reference is reset (Fixes #1628)
This caused crashes when the window was resized after the reference no longer exists (e.g. when a savegame is loaded)
11 years ago
Digmaster e3e51324a4 Esc button exits all non-modal GUI windows 11 years ago
slothlife f33559fead Fixes for MSVC warnings, less overall changes
Kept some fixes from the first round of review. Found out that several
targets weren't being built with the same basic warnings disabled.
Disabled a few warnings for external libraries specifically, rather than
applying them to all targets.
11 years ago
scrawl d01f89b153 Rewrite some awful code 11 years ago
scrawl 780bf5a2cd Implement pickpocket detection. Play a voiced dialogue entry when detected. 11 years ago
scrawl 0c4a963132 Container UI rewrite 12 years ago
Britt Mathis 6128b9276f Removed non-essential includes from all MWGui header files. 12 years ago
Britt Mathis f7383905b7 Finally eliminated calls to MWBase::WindowManager in constructors 12 years ago
Britt Mathis ce9bc6d9ba MwGui windowManager calls fixed to use MWBase::Environment::get().getWindowManager, filenames in MwGui now comply with naming conventions 12 years ago
scrawl b0199c703c Companion UI 12 years ago
scrawl c0b0227e8a enchanting 12 years ago
scrawl 0ee0dbdb97 Added "dispose corpse" button, added stealing (all items visible and no penalty yet) 12 years ago
greye 2057f5619e move ESMStore to MWWorld 12 years ago
Marc Zinnschlag 6534c2a55a Issue #107: WindowManager is accessed only through the interface class from now on 13 years ago
scrawl 30461438f6 still left: spell success formula 13 years ago
scrawl f1d3978897 Issue #290: Auto-Close MW-reference related GUI windows 13 years ago
scrawl 6eb15f7680 auto-select the alchemy tools with highest quality 13 years ago
scrawl c004f5d570 adjust the "total cost"/"total sold" value when trading items, added some checks with respective user notifications 13 years ago
scrawl db49e2c046 bought/sold items now use a separate ContainerStore, this fixes a stacking issue among other things 13 years ago
scrawl fb47681fbd fix a bug, some cleanup 13 years ago
scrawl 50a8eb05d9 transfering items between player and merchant works and shows a red frame for bought/sold items. 13 years ago
scrawl e2400ca7b2 only show items in the trade window that the NPC actually trades (services enum) 13 years ago
scrawl 41efea4c1d in the trade window, don't show items that the merchant has equipped. 13 years ago
scrawl c5185cf2e4 drop item on avatar from external container bugfix 13 years ago
scrawl 477f1b42ab fixed another item dropping bug 13 years ago
scrawl 3f4ce32727 implemented player encumbrance bar 13 years ago
scrawl 175623bf22 change the drag&drop to not use a seperate containerstore 13 years ago
scrawl 71de10cb7e equipping items works, but only if you have more than one of the item that you're equipping 13 years ago
scrawl ab6336b745 using items via the inventory is now possible by dragging them on the avatar (only implemented for books right now) 13 years ago
scrawl 7fbee0d488 use MyGUI::InputManager instead of MWInputManager to detect ctrl/shift 13 years ago
scrawl 24a0fecd37 implemented item count selection dialog 13 years ago
scrawl 320cc7d020 implemented ctrl and shift-keys for item drag&drop (take all, take 1) 13 years ago
scrawl d3e162ec83 dropping items works 13 years ago
scrawl f31853d30b mouse wheel works when mouse is over an item 13 years ago
scrawl 78b06d0ebf inventory window pinning 13 years ago
scrawl 0114bf948c revised filters 13 years ago
scrawl fd18c95c5f implemented filters (no gui yet) 13 years ago
scrawl d64fccec6f display the item count in the tooltip 13 years ago
scrawl ed6ff0a94a cleanup 3 13 years ago