diff --git a/apps/openmw/mwgui/console.cpp b/apps/openmw/mwgui/console.cpp index df3c2cb49..30714e97f 100644 --- a/apps/openmw/mwgui/console.cpp +++ b/apps/openmw/mwgui/console.cpp @@ -7,6 +7,20 @@ #include <boost/filesystem.hpp> #include <boost/filesystem/fstream.hpp> +/* + Start of tes3mp addition + + Include additional headers for multiplayer purposes +*/ +#include <components/openmw-mp/TimedLog.hpp> +#include "../mwmp/Main.hpp" +#include "../mwmp/Networking.hpp" +#include "../mwmp/LocalPlayer.hpp" +#include "../mwmp/ObjectList.hpp" +/* + End of tes3mp addition +*/ + #include <components/compiler/exception.hpp> #include <components/compiler/extensions0.hpp> @@ -195,11 +209,28 @@ namespace MWGui /* Start of tes3mp addition + Send an ID_CONSOLE_COMMAND packet to the server with the + command and target used + Mark this InterpreterContext as having a CONSOLE context, so that packets sent by the Interpreter can have their origin determined by serverside scripts */ interpreterContext.setContextType(Interpreter::Context::CONSOLE); + + mwmp::ObjectList *objectList = mwmp::Main::get().getNetworking()->getObjectList(); + objectList->reset(); + objectList->packetOrigin = mwmp::CLIENT_CONSOLE; + objectList->consoleCommand = command; + + if (mPtr.isEmpty()) + objectList->cell = mwmp::Main::get().getLocalPlayer()->cell; + else + { + objectList->addConsoleCommandObject(mPtr); + } + + objectList->sendConsoleCommand(); /* End of tes3mp addition */ diff --git a/apps/openmw/mwmp/ObjectList.cpp b/apps/openmw/mwmp/ObjectList.cpp index c94de9d46..84c3c6f2e 100644 --- a/apps/openmw/mwmp/ObjectList.cpp +++ b/apps/openmw/mwmp/ObjectList.cpp @@ -1147,6 +1147,33 @@ void ObjectList::addVideoPlay(std::string filename, bool allowSkipping) addObject(baseObject); } +void ObjectList::addConsoleCommandObject(const MWWorld::Ptr& ptr) +{ + cell = *ptr.getCell()->getCell(); + + mwmp::BaseObject baseObject; + + if (ptr == MWBase::Environment::get().getWorld()->getPlayerPtr()) + { + baseObject.isPlayer = true; + baseObject.guid = mwmp::Main::get().getNetworking()->getLocalPlayer()->guid; + } + else if (mwmp::PlayerList::isDedicatedPlayer(ptr)) + { + baseObject.isPlayer = true; + baseObject.guid = mwmp::PlayerList::getPlayer(ptr)->guid; + } + else + { + baseObject.isPlayer = false; + baseObject.refId = ptr.getCellRef().getRefId(); + baseObject.refNum = ptr.getCellRef().getRefNum().mIndex; + baseObject.mpNum = ptr.getCellRef().getMpNum(); + } + + addObject(baseObject); +} + void ObjectList::addScriptLocalShort(const MWWorld::Ptr& ptr, int index, int shortVal) { cell = *ptr.getCell()->getCell(); @@ -1338,3 +1365,11 @@ void ObjectList::sendContainer() mwmp::Main::get().getNetworking()->getObjectPacket(ID_CONTAINER)->setObjectList(this); mwmp::Main::get().getNetworking()->getObjectPacket(ID_CONTAINER)->Send(); } + +void ObjectList::sendConsoleCommand() +{ + LOG_MESSAGE_SIMPLE(TimedLog::LOG_VERBOSE, "Sending ID_CONSOLE_COMMAND"); + + mwmp::Main::get().getNetworking()->getObjectPacket(ID_CONSOLE_COMMAND)->setObjectList(this); + mwmp::Main::get().getNetworking()->getObjectPacket(ID_CONSOLE_COMMAND)->Send(); +} diff --git a/apps/openmw/mwmp/ObjectList.hpp b/apps/openmw/mwmp/ObjectList.hpp index 0a122cfc6..bd28f8878 100644 --- a/apps/openmw/mwmp/ObjectList.hpp +++ b/apps/openmw/mwmp/ObjectList.hpp @@ -64,6 +64,7 @@ namespace mwmp void addDoorState(const MWWorld::Ptr& ptr, MWWorld::DoorState state); void addMusicPlay(std::string filename); void addVideoPlay(std::string filename, bool allowSkipping); + void addConsoleCommandObject(const MWWorld::Ptr& ptr); 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); @@ -86,6 +87,7 @@ namespace mwmp void sendScriptMemberShort(); void sendScriptGlobalShort(); void sendContainer(); + void sendConsoleCommand(); private: Networking *getNetworking();