You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
openmw-tes3mp/apps/openmw/mwmp/ObjectList.hpp

93 lines
3.5 KiB
C++

#ifndef OPENMW_OBJECTLIST_HPP
#define OPENMW_OBJECTLIST_HPP
#include <components/openmw-mp/Base/BaseObject.hpp>
#include "../mwworld/cellstore.hpp"
#include <RakNetTypes.h>
namespace mwmp
{
class Networking;
class ObjectList : public BaseObjectList
{
public:
ObjectList();
virtual ~ObjectList();
void reset();
BaseObject getBaseObject(const MWWorld::Ptr& ptr);
void addContainerItem(mwmp::BaseObject& baseObject, const MWWorld::Ptr& itemPtr, int actionCount);
void addEntireContainer(const MWWorld::Ptr& ptr);
void editContainers(MWWorld::CellStore* cellStore);
void placeObjects(MWWorld::CellStore* cellStore);
void spawnObjects(MWWorld::CellStore* cellStore);
void deleteObjects(MWWorld::CellStore* cellStore);
void lockObjects(MWWorld::CellStore* cellStore);
void triggerTrapObjects(MWWorld::CellStore* cellStore);
void scaleObjects(MWWorld::CellStore* cellStore);
void setObjectStates(MWWorld::CellStore* cellStore);
void moveObjects(MWWorld::CellStore* cellStore);
void rotateObjects(MWWorld::CellStore* cellStore);
void animateObjects(MWWorld::CellStore* cellStore);
void activateDoors(MWWorld::CellStore* cellStore);
void setDoorDestinations(MWWorld::CellStore* cellStore);
void runConsoleCommands(MWWorld::CellStore* cellStore);
void setLocalShorts(MWWorld::CellStore* cellStore);
void setLocalFloats(MWWorld::CellStore* cellStore);
void setMemberShorts();
void setGlobalShorts();
void playMusic();
void playVideo();
void addAllContainers(MWWorld::CellStore* cellStore);
void addRequestedContainers(MWWorld::CellStore* cellStore, const std::vector<BaseObject>& requestObjects);
[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
void addObjectPlace(const MWWorld::Ptr& ptr, bool droppedByPlayer = false);
void addObjectSpawn(const MWWorld::Ptr& ptr);
void addObjectSpawn(const MWWorld::Ptr& ptr, const MWWorld::Ptr& master);
void addObjectDelete(const MWWorld::Ptr& ptr);
void addObjectLock(const MWWorld::Ptr& ptr, int lockLevel);
void addObjectTrap(const MWWorld::Ptr& ptr, const ESM::Position& pos, bool isDisarmed);
void addObjectScale(const MWWorld::Ptr& ptr, float scale);
void addObjectState(const MWWorld::Ptr& ptr, bool objectState);
void addObjectAnimPlay(const MWWorld::Ptr& ptr, std::string group, int mode);
[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
void addDoorState(const MWWorld::Ptr& ptr, int state);
void addMusicPlay(std::string filename);
void addVideoPlay(std::string filename, bool allowSkipping);
void addScriptLocalShort(const MWWorld::Ptr& ptr, int index, int shortVal);
void addScriptLocalFloat(const MWWorld::Ptr& ptr, int index, float floatVal);
void addScriptMemberShort(std::string refId, int index, int shortVal);
void addScriptGlobalShort(std::string varName, int shortVal);
void sendObjectPlace();
void sendObjectSpawn();
void sendObjectDelete();
void sendObjectLock();
void sendObjectTrap();
void sendObjectScale();
void sendObjectState();
void sendObjectAnimPlay();
void sendDoorState();
void sendMusicPlay();
void sendVideoPlay();
void sendScriptLocalShort();
void sendScriptLocalFloat();
void sendScriptMemberShort();
void sendScriptGlobalShort();
void sendContainer();
private:
Networking *getNetworking();
};
}
#endif //OPENMW_OBJECTLIST_HPP