openmw-tes3coop/apps/openmw
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.
2018-03-26 19:27:36 +03:00
..
mwbase [Client] Make it possible to get ContainerWindow from elsewhere in code 2018-03-24 09:00:15 +02:00
mwclass Merge pull request #392 from OpenMW/master while resolving conflicts 2018-03-09 21:07:46 +02:00
mwdialogue Merge pull request #389 from OpenMW/master 2018-02-25 22:05:32 +02:00
mwgui [General] Rework container sync to prevent item duping 2018-03-26 19:27:36 +03:00
mwinput Merge pull request #383 from OpenMW/master 2018-02-11 06:57:54 +02:00
mwmechanics [Client] Use correct count for items in equipment packets 2018-03-12 23:31:37 +02:00
mwmp [General] Rework container sync to prevent item duping 2018-03-26 19:27:36 +03:00
mwphysics [General] Implement setting of physics framerate as part of GameSettings 2018-02-14 05:53:44 +02:00
mwrender Force normal polygon mode for the map camera (Fixes #4235) 2018-03-03 00:15:57 +00:00
mwscript Merge pull request #393 from OpenMW/master 2018-03-10 18:37:51 +02:00
mwsound http to https for supported urls (#1625) 2018-03-08 21:23:24 +01:00
mwstate Remove numeric quicksave slot IDs 2018-02-13 21:01:15 -05:00
mwworld Merge pull request #392 from OpenMW/master while resolving conflicts 2018-03-09 21:07:46 +02:00
android_commandLine.cpp Fix tab indentations in apps/ and components/ 2015-09-16 20:45:37 +02:00
android_commandLine.h Remove empty line at the beginning of files 2015-08-18 23:06:12 +02:00
android_main.c Android: Add callbacks for basic cursor handling. 2018-01-18 21:18:31 -05:00
CMakeLists.txt Merge pull request #390 from OpenMW/master 2018-03-01 05:33:37 +02:00
crashcatcher.cpp crashcatcher: complain when launching gdb fails 2017-02-23 23:28:49 +01:00
doc.hpp Fixed more spelling mistakes 2016-12-15 13:09:40 +01:00
engine.cpp Merge pull request #369 from OpenMW/master 2018-01-10 03:49:53 +02:00
engine.hpp Don't increase simulationTime while the game is minimized (Fixes #4211) 2017-11-16 18:48:49 +00:00
main.cpp Merge pull request #374 from OpenMW/master while resolving conflicts 2018-01-27 22:52:59 +02:00