2017-02-06 10:53:41 +00:00
|
|
|
#ifndef OPENMW_BASEEVENT_HPP
|
|
|
|
#define OPENMW_BASEEVENT_HPP
|
2016-10-20 11:28:19 +00:00
|
|
|
|
2016-10-22 17:15:32 +00:00
|
|
|
#include <components/esm/loadcell.hpp>
|
2017-04-08 05:59:21 +00:00
|
|
|
#include <components/openmw-mp/Base/BaseStructs.hpp>
|
2016-10-20 11:28:19 +00:00
|
|
|
#include <RakNetTypes.h>
|
|
|
|
|
|
|
|
namespace mwmp
|
|
|
|
{
|
2017-02-15 18:14:25 +00:00
|
|
|
struct ContainerItem
|
|
|
|
{
|
|
|
|
std::string refId;
|
|
|
|
int count;
|
|
|
|
int charge;
|
2018-01-17 06:09:57 +00:00
|
|
|
double enchantmentCharge;
|
2017-02-15 18:14:25 +00:00
|
|
|
|
|
|
|
int actionCount;
|
|
|
|
|
|
|
|
inline bool operator==(const ContainerItem& rhs)
|
|
|
|
{
|
2017-12-23 11:16:38 +00:00
|
|
|
return refId == rhs.refId && count == rhs.count && charge == rhs.charge && enchantmentCharge == rhs.enchantmentCharge;
|
2017-02-15 18:14:25 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-01-28 10:34:45 +00:00
|
|
|
struct WorldObject
|
2016-10-20 11:28:19 +00:00
|
|
|
{
|
2017-01-28 10:34:45 +00:00
|
|
|
std::string refId;
|
|
|
|
int refNumIndex;
|
2017-04-04 06:23:34 +00:00
|
|
|
int mpNum;
|
2017-01-28 10:34:45 +00:00
|
|
|
int count;
|
2017-02-06 19:28:03 +00:00
|
|
|
int charge;
|
2018-01-17 06:09:57 +00:00
|
|
|
double enchantmentCharge;
|
2017-02-05 11:45:12 +00:00
|
|
|
int goldValue;
|
2017-04-06 12:11:51 +00:00
|
|
|
|
2017-04-10 06:25:20 +00:00
|
|
|
ESM::Position position;
|
2017-04-06 12:11:51 +00:00
|
|
|
|
2017-07-13 06:46:30 +00:00
|
|
|
bool objectState;
|
2017-02-06 21:09:50 +00:00
|
|
|
int doorState;
|
2016-10-24 10:20:04 +00:00
|
|
|
int lockLevel;
|
2016-10-24 21:52:42 +00:00
|
|
|
float scale;
|
2016-10-24 14:52:19 +00:00
|
|
|
|
2016-11-20 20:54:49 +00:00
|
|
|
std::string filename;
|
2016-10-24 14:52:19 +00:00
|
|
|
bool allowSkipping;
|
2016-10-26 09:25:50 +00:00
|
|
|
|
2016-10-27 13:09:02 +00:00
|
|
|
std::string animGroup;
|
|
|
|
int animMode;
|
|
|
|
|
2016-10-26 09:25:50 +00:00
|
|
|
int index;
|
|
|
|
int shortVal;
|
|
|
|
float floatVal;
|
2016-10-26 21:41:14 +00:00
|
|
|
std::string varName;
|
2017-02-06 19:28:03 +00:00
|
|
|
|
2017-05-25 22:28:43 +00:00
|
|
|
bool isDisarmed;
|
2018-01-28 15:00:14 +00:00
|
|
|
bool droppedByPlayer;
|
2017-05-07 00:07:09 +00:00
|
|
|
|
2017-05-30 07:11:01 +00:00
|
|
|
Target master;
|
|
|
|
bool hasMaster;
|
|
|
|
|
2017-05-06 18:57:14 +00:00
|
|
|
std::vector<ContainerItem> containerItems;
|
|
|
|
unsigned int containerItemCount;
|
2017-11-22 22:21:47 +00:00
|
|
|
|
|
|
|
RakNet::RakNetGUID guid; // only for events that can also affect players
|
|
|
|
bool isPlayer;
|
2017-02-04 19:32:06 +00:00
|
|
|
};
|
|
|
|
|
2017-02-06 10:53:41 +00:00
|
|
|
class BaseEvent
|
2017-01-28 10:34:45 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2017-02-06 10:53:41 +00:00
|
|
|
BaseEvent(RakNet::RakNetGUID guid) : guid(guid)
|
2017-01-28 10:34:45 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-02-06 10:53:41 +00:00
|
|
|
BaseEvent()
|
2017-01-28 10:34:45 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-02-15 18:14:25 +00:00
|
|
|
enum WORLD_ACTION
|
|
|
|
{
|
|
|
|
SET = 0,
|
|
|
|
ADD = 1,
|
|
|
|
REMOVE = 2,
|
|
|
|
REQUEST = 3
|
|
|
|
};
|
|
|
|
|
[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 16:27:36 +00:00
|
|
|
enum CONTAINER_SUBACTION
|
|
|
|
{
|
|
|
|
NONE = 0,
|
|
|
|
DRAG = 1,
|
|
|
|
DROP = 2,
|
|
|
|
TAKE_ALL = 3
|
|
|
|
};
|
|
|
|
|
2017-01-28 10:34:45 +00:00
|
|
|
RakNet::RakNetGUID guid;
|
2017-05-06 18:57:14 +00:00
|
|
|
|
|
|
|
std::vector<WorldObject> worldObjects;
|
|
|
|
unsigned int worldObjectCount;
|
2017-01-28 10:34:45 +00:00
|
|
|
|
|
|
|
ESM::Cell cell;
|
2017-11-22 22:21:47 +00:00
|
|
|
std::string consoleCommand;
|
2017-02-15 18:14:25 +00:00
|
|
|
|
2017-02-23 07:16:28 +00:00
|
|
|
unsigned char action; // 0 - Clear and set in entirety, 1 - Add item, 2 - Remove item, 3 - Request items
|
[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 16:27:36 +00:00
|
|
|
unsigned char containerSubAction; // 0 - None, 1 - Drag, 2 - Take all
|
2017-05-14 17:24:06 +00:00
|
|
|
|
|
|
|
bool isValid;
|
2017-01-28 10:34:45 +00:00
|
|
|
};
|
2016-10-20 11:28:19 +00:00
|
|
|
}
|
|
|
|
|
2017-02-06 10:53:41 +00:00
|
|
|
#endif //OPENMW_BASEEVENT_HPP
|