[Client] Send ConsoleCommand packets when console is used

This commit is contained in:
David Cernat 2019-12-07 10:11:45 +02:00
parent 18cd3d1ea1
commit eeb77f80d2
3 changed files with 68 additions and 0 deletions

View File

@ -7,6 +7,20 @@
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.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/exception.hpp>
#include <components/compiler/extensions0.hpp> #include <components/compiler/extensions0.hpp>
@ -195,11 +209,28 @@ namespace MWGui
/* /*
Start of tes3mp addition 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, Mark this InterpreterContext as having a CONSOLE context,
so that packets sent by the Interpreter can have their so that packets sent by the Interpreter can have their
origin determined by serverside scripts origin determined by serverside scripts
*/ */
interpreterContext.setContextType(Interpreter::Context::CONSOLE); 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 End of tes3mp addition
*/ */

View File

@ -1147,6 +1147,33 @@ void ObjectList::addVideoPlay(std::string filename, bool allowSkipping)
addObject(baseObject); 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) void ObjectList::addScriptLocalShort(const MWWorld::Ptr& ptr, int index, int shortVal)
{ {
cell = *ptr.getCell()->getCell(); 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)->setObjectList(this);
mwmp::Main::get().getNetworking()->getObjectPacket(ID_CONTAINER)->Send(); 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();
}

View File

@ -64,6 +64,7 @@ namespace mwmp
void addDoorState(const MWWorld::Ptr& ptr, MWWorld::DoorState state); void addDoorState(const MWWorld::Ptr& ptr, MWWorld::DoorState state);
void addMusicPlay(std::string filename); void addMusicPlay(std::string filename);
void addVideoPlay(std::string filename, bool allowSkipping); void addVideoPlay(std::string filename, bool allowSkipping);
void addConsoleCommandObject(const MWWorld::Ptr& ptr);
void addScriptLocalShort(const MWWorld::Ptr& ptr, int index, int shortVal); void addScriptLocalShort(const MWWorld::Ptr& ptr, int index, int shortVal);
void addScriptLocalFloat(const MWWorld::Ptr& ptr, int index, float floatVal); void addScriptLocalFloat(const MWWorld::Ptr& ptr, int index, float floatVal);
void addScriptMemberShort(std::string refId, int index, int shortVal); void addScriptMemberShort(std::string refId, int index, int shortVal);
@ -86,6 +87,7 @@ namespace mwmp
void sendScriptMemberShort(); void sendScriptMemberShort();
void sendScriptGlobalShort(); void sendScriptGlobalShort();
void sendContainer(); void sendContainer();
void sendConsoleCommand();
private: private:
Networking *getNetworking(); Networking *getNetworking();