[Client] Fix logic for sending ObjectState packets

The previous logic was meant to prevent packet spam from local scripts, but inadvertently prevented objects from being enabled or disabled correctly from dialogue in certain quests.

Enabling and disabling objects from dialogue and the console is now always allowed to go through.
This commit is contained in:
David Cernat 2022-04-16 01:30:51 +03:00
parent 3af57f0858
commit aa92128cf2

View File

@ -195,21 +195,23 @@ namespace MWScript
/* /*
Start of tes3mp addition Start of tes3mp addition
Send an ID_OBJECT_STATE packet whenever an object is enabled, as long as Send an ID_OBJECT_STATE packet whenever an object should be enabled, as long as the
the player is logged in on the server, the object is still disabled, and our last player is logged in on the server and if triggered from a clientside script our
packet regarding its state did not already attempt to enable it (to prevent last packet regarding its state did not already attempt to enable it (to prevent
packet spam) packet spam)
*/ */
if (mwmp::Main::get().getLocalPlayer()->isLoggedIn()) if (mwmp::Main::get().getLocalPlayer()->isLoggedIn())
{ {
if (ptr.isInCell() && !ptr.getRefData().isEnabled() && unsigned char packetOrigin = ScriptController::getPacketOriginFromContextType(runtime.getContext().getContextType());
ptr.getRefData().getLastCommunicatedState() != MWWorld::RefData::StateCommunication::Enabled)
if (packetOrigin == Interpreter::Context::CONSOLE || packetOrigin == Interpreter::Context::DIALOGUE ||
(ptr.isInCell() && ptr.getRefData().getLastCommunicatedState() != MWWorld::RefData::StateCommunication::Enabled))
{ {
ptr.getRefData().setLastCommunicatedState(MWWorld::RefData::StateCommunication::Enabled); ptr.getRefData().setLastCommunicatedState(MWWorld::RefData::StateCommunication::Enabled);
mwmp::ObjectList* objectList = mwmp::Main::get().getNetworking()->getObjectList(); mwmp::ObjectList* objectList = mwmp::Main::get().getNetworking()->getObjectList();
objectList->reset(); objectList->reset();
objectList->packetOrigin = ScriptController::getPacketOriginFromContextType(runtime.getContext().getContextType()); objectList->packetOrigin = packetOrigin;
objectList->originClientScript = runtime.getContext().getCurrentScriptName(); objectList->originClientScript = runtime.getContext().getCurrentScriptName();
objectList->addObjectState(ptr, true); objectList->addObjectState(ptr, true);
objectList->sendObjectState(); objectList->sendObjectState();
@ -244,21 +246,23 @@ namespace MWScript
/* /*
Start of tes3mp addition Start of tes3mp addition
Send an ID_OBJECT_STATE packet whenever an object should be disabled, as long as Send an ID_OBJECT_STATE packet whenever an object should be disabled, as long as the
the player is logged in on the server, the object is still enabled, and our last player is logged in on the server and if triggered from a clientside script our
packet regarding its state did not already attempt to disable it (to prevent last packet regarding its state did not already attempt to disable it (to prevent
packet spam) packet spam)
*/ */
if (mwmp::Main::get().getLocalPlayer()->isLoggedIn()) if (mwmp::Main::get().getLocalPlayer()->isLoggedIn())
{ {
if (ptr.isInCell() && ptr.getRefData().isEnabled() && unsigned char packetOrigin = ScriptController::getPacketOriginFromContextType(runtime.getContext().getContextType());
ptr.getRefData().getLastCommunicatedState() != MWWorld::RefData::StateCommunication::Disabled)
if (packetOrigin == Interpreter::Context::CONSOLE || packetOrigin == Interpreter::Context::DIALOGUE ||
(ptr.isInCell() && ptr.getRefData().getLastCommunicatedState() != MWWorld::RefData::StateCommunication::Disabled))
{ {
ptr.getRefData().setLastCommunicatedState(MWWorld::RefData::StateCommunication::Disabled); ptr.getRefData().setLastCommunicatedState(MWWorld::RefData::StateCommunication::Disabled);
mwmp::ObjectList *objectList = mwmp::Main::get().getNetworking()->getObjectList(); mwmp::ObjectList *objectList = mwmp::Main::get().getNetworking()->getObjectList();
objectList->reset(); objectList->reset();
objectList->packetOrigin = ScriptController::getPacketOriginFromContextType(runtime.getContext().getContextType()); objectList->packetOrigin = packetOrigin;
objectList->originClientScript = runtime.getContext().getCurrentScriptName(); objectList->originClientScript = runtime.getContext().getCurrentScriptName();
objectList->addObjectState(ptr, false); objectList->addObjectState(ptr, false);
objectList->sendObjectState(); objectList->sendObjectState();