1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-29 03:15:32 +00:00
openmw-tes3mp/apps/openmw/mwmp
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
..
GUI [Client] Clean up GUIChat slightly 2018-01-05 00:03:05 +02:00
processors [General] Rework container sync to prevent item duping 2018-03-26 19:27:36 +03:00
ActorList.cpp [Client] Make foreach style consistent with other 2017-06-27 22:27:02 +08:00
ActorList.hpp [General] Make most ActorPackets smaller by not including refIds in them 2017-05-27 16:59:23 +03:00
Cell.cpp [Client] Ignore cell changes that move actors to where they already are 2018-01-08 01:37:01 +02:00
Cell.hpp [Client] Fix warnings 2017-07-03 23:41:16 +08:00
CellController.cpp [General] Implement Mark location sync as part of PlayerMiscellaneous 2018-01-31 04:50:29 +02:00
CellController.hpp [Client] When getting an actor, make sure their cell is initialized 2018-01-07 02:35:30 +02:00
DedicatedActor.cpp [Client] Ignore equipment items for DedicatedActors with count below 0 2018-01-27 18:08:45 +02:00
DedicatedActor.hpp [Client] Fix problems with NPC equipment sync 2017-06-09 04:58:56 +03:00
DedicatedPlayer.cpp [General] Implement player scale as part of PlayerShapeshift 2018-02-01 02:11:45 +02:00
DedicatedPlayer.hpp [General] Implement PlayerSpeech packet 2017-10-31 15:19:14 +02:00
GUIController.cpp [Client] Don't log InputBox inputs for client 2018-03-20 06:41:04 +02:00
GUIController.hpp [Client] Unequip items if necessary when attr/skill modifier is set to 0 2018-01-26 00:45:39 +02:00
LocalActor.cpp [General] Rework container sync to prevent item duping 2018-03-26 19:27:36 +03:00
LocalActor.hpp [Client] Use update timer in mwmp::Cell instead of LocalActor 2017-06-10 03:29:51 +03:00
LocalPlayer.cpp [Client] Update inventory views when receiving inventory or equipment 2018-03-26 10:01:26 +03:00
LocalPlayer.hpp [General] Implement selected spell sync as part of PlayerMiscellaneous 2018-02-06 06:36:46 +02:00
Main.cpp [General] Use address keys with clearer meaning in tes3mp config files 2017-07-03 01:31:48 +03:00
Main.hpp [Client] Convert MechanicsHelper to namespace 2017-06-27 16:43:53 +08:00
MechanicsHelper.cpp [Client] Add and use enchantmentType argument for unequipItemsByEffect() 2018-01-27 19:37:16 +02:00
MechanicsHelper.hpp [Client] Add and use enchantmentType argument for unequipItemsByEffect() 2018-01-27 19:37:16 +02:00
Networking.cpp [Client] Use more descriptive message for version mismatch 2018-01-17 08:10:49 +02:00
Networking.hpp [Client] Replace usage of Networking::isDedicatedPlayer() 2017-04-18 18:07:39 +03:00
PlayerList.cpp [General] Change NULL to nullptr 2017-06-27 22:49:28 +08:00
PlayerList.hpp [Client] Set and clear hitAttemptActorId for DedicatedPlayers 2017-05-30 08:20:45 +03:00
WorldEvent.cpp [General] Rework container sync to prevent item duping 2018-03-26 19:27:36 +03:00
WorldEvent.hpp [General] Rework container sync to prevent item duping 2018-03-26 19:27:36 +03:00