From 75f6d82f084eeb3515b7d470603df4f774dd0c0d Mon Sep 17 00:00:00 2001 From: David Cernat Date: Tue, 25 Oct 2016 22:44:15 +0300 Subject: [PATCH] Add a way of filtering out ingame scripts for upcoming script packets --- apps/openmw/engine.cpp | 7 +++++++ apps/openmw/mwmp/Main.cpp | 21 ++++++++++++++++++++- apps/openmw/mwmp/Main.hpp | 3 ++- apps/openmw/mwscript/interpretercontext.cpp | 4 ++++ apps/openmw/mwscript/interpretercontext.hpp | 3 +++ 5 files changed, 36 insertions(+), 2 deletions(-) diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index f21ddbec6..14821c219 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -77,6 +77,13 @@ void OMW::Engine::executeLocalScripts() { MWScript::InterpreterContext interpreterContext ( &script.second.getRefData().getLocals(), script.second); + + // Added by tes3mp + if (mwmp::Main::isValidPacketScript(script.first)) + { + interpreterContext.sendPackets = true; + } + mEnvironment.getScriptManager()->run (script.first, interpreterContext); } } diff --git a/apps/openmw/mwmp/Main.cpp b/apps/openmw/mwmp/Main.cpp index 8c3ab61fe..02aa47bbd 100644 --- a/apps/openmw/mwmp/Main.cpp +++ b/apps/openmw/mwmp/Main.cpp @@ -224,4 +224,23 @@ void Main::PressedKey(int key) if (pMain == nullptr) return; if (get().getGUIController()->pressedKey(key)) return; // if any gui bind pressed -} \ No newline at end of file +} + +// When sending packets with ingame script values, certain packets +// should be ignored because of their potential for spam +bool Main::isValidPacketScript(std::string script) +{ + static const int invalidPacketScriptsCount = 2; + static const std::string invalidPacketScripts[invalidPacketScriptsCount] = { + "OutsideBanner", + "sleeperScript" + }; + + for (int i = 0; i < invalidPacketScriptsCount; i++) + { + if (Misc::StringUtils::ciEqual(script, invalidPacketScripts[i])) + return false; + } + + return true; +} diff --git a/apps/openmw/mwmp/Main.hpp b/apps/openmw/mwmp/Main.hpp index 10c919344..f145ce7e2 100644 --- a/apps/openmw/mwmp/Main.hpp +++ b/apps/openmw/mwmp/Main.hpp @@ -21,6 +21,8 @@ namespace mwmp static void Frame(float dt); static void PressedKey(int key); + static bool isValidPacketScript(std::string script); + Networking *getNetworking() const; LocalPlayer *getLocalPlayer() const; GUIController *getGUIController() const; @@ -38,7 +40,6 @@ namespace mwmp LocalPlayer *mLocalPlayer; GUIController *mGUIController; - std::string server; unsigned short port; }; diff --git a/apps/openmw/mwscript/interpretercontext.cpp b/apps/openmw/mwscript/interpretercontext.cpp index cfcdbb517..ab4271c37 100644 --- a/apps/openmw/mwscript/interpretercontext.cpp +++ b/apps/openmw/mwscript/interpretercontext.cpp @@ -177,6 +177,10 @@ namespace MWScript throw std::runtime_error ("local variables not available in this context"); mLocals->mShorts.at (index) = value; + + if (sendPackets) + printf("Sending ID_SCRIPT_LOCAL_SHORT for %s\n", + this->mReference.getClass().getScript(mReference)); } void InterpreterContext::setLocalLong (int index, int value) diff --git a/apps/openmw/mwscript/interpretercontext.hpp b/apps/openmw/mwscript/interpretercontext.hpp index fdd5aa55f..50f3648e3 100644 --- a/apps/openmw/mwscript/interpretercontext.hpp +++ b/apps/openmw/mwscript/interpretercontext.hpp @@ -55,6 +55,9 @@ namespace MWScript const std::string& targetId = ""); ///< The ownership of \a locals is not transferred. 0-pointer allowed. + // Added by tes3mp + bool sendPackets = false; + virtual int getLocalShort (int index) const; virtual int getLocalLong (int index) const;