diff --git a/apps/openmw-mp/Networking.cpp b/apps/openmw-mp/Networking.cpp index f50de7524..2cec1eb41 100644 --- a/apps/openmw-mp/Networking.cpp +++ b/apps/openmw-mp/Networking.cpp @@ -562,6 +562,56 @@ void Networking::ProcessWorldPacket(RakNet::Packet *packet) break; } + case ID_SCRIPT_LOCAL_SHORT: + { + LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_SCRIPT_LOCAL_SHORT from %s", + player->Npc()->mName.c_str()); + + myPacket->Read(event); + + LOG_APPEND(Log::LOG_WARN, "- cellRef: %s, %i\n- cell: %s", + event->cellRef.mRefID.c_str(), + event->cellRef.mRefNum.mIndex, + event->cell.getDescription().c_str()); + + myPacket->Send(event, true); + + break; + } + + case ID_SCRIPT_LOCAL_FLOAT: + { + LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_SCRIPT_LOCAL_FLOAT from %s", + player->Npc()->mName.c_str()); + + myPacket->Read(event); + + LOG_APPEND(Log::LOG_WARN, "- cellRef: %s, %i\n- cell: %s", + event->cellRef.mRefID.c_str(), + event->cellRef.mRefNum.mIndex, + event->cell.getDescription().c_str()); + + myPacket->Send(event, true); + + break; + } + + case ID_SCRIPT_GLOBAL_SHORT: + { + LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_SCRIPT_GLOBAL_SHORT from %s", + player->Npc()->mName.c_str()); + + myPacket->Read(event); + + LOG_APPEND(Log::LOG_WARN, "- globalName: %s\n- shortVal: %i", + event->globalName.c_str(), + event->shortVal); + + myPacket->Send(event, true); + + break; + } + default: LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Unhandled WorldPacket with identifier %i has arrived", packet->data[0]); diff --git a/apps/openmw/mwmp/Networking.cpp b/apps/openmw/mwmp/Networking.cpp index 5d9e294d6..3c86b0a4e 100644 --- a/apps/openmw/mwmp/Networking.cpp +++ b/apps/openmw/mwmp/Networking.cpp @@ -691,7 +691,7 @@ void Networking::ProcessWorldPacket(RakNet::Packet *packet) if (event->cell.isExterior()) ptrCellStore = MWBase::Environment::get().getWorld()->getExterior(event->cell.mData.mX, event->cell.mData.mY); - else + else if (!event->cell.mName.empty()) ptrCellStore = MWBase::Environment::get().getWorld()->getInterior(event->cell.mName); switch (packet->data[0]) @@ -868,6 +868,63 @@ void Networking::ProcessWorldPacket(RakNet::Packet *packet) break; } + case ID_SCRIPT_LOCAL_SHORT: + { + LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "%s", "Received ID_SCRIPT_LOCAL_SHORT"); + LOG_APPEND(Log::LOG_WARN, "- cellRef: %s, %i\n- cell: %s\n- index: %i\n- shortVal: %i", + event->cellRef.mRefID.c_str(), + event->cellRef.mRefNum.mIndex, + event->cell.getDescription().c_str(), + event->index, + event->shortVal); + + MWWorld::Ptr ptrFound = ptrCellStore->searchByRefNum(event->cellRef.mRefNum); + + if (ptrFound) + { + LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Found %s, %i", + ptrFound.getCellRef().getRefId().c_str(), + ptrFound.getCellRef().getRefNum()); + + ptrFound.getRefData().getLocals().mShorts.at(event->index) = event->shortVal; + } + + break; + } + case ID_SCRIPT_LOCAL_FLOAT: + { + LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "%s", "Received ID_SCRIPT_LOCAL_FLOAT"); + LOG_APPEND(Log::LOG_WARN, "- cellRef: %s, %i\n- cell: %s\n- index: %i\n- floatVal: %f", + event->cellRef.mRefID.c_str(), + event->cellRef.mRefNum.mIndex, + event->cell.getDescription().c_str(), + event->index, + event->floatVal); + + MWWorld::Ptr ptrFound = ptrCellStore->searchByRefNum(event->cellRef.mRefNum); + + if (ptrFound) + { + LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Found %s, %i", + ptrFound.getCellRef().getRefId().c_str(), + ptrFound.getCellRef().getRefNum()); + + ptrFound.getRefData().getLocals().mFloats.at(event->index) = event->floatVal; + } + + break; + } + case ID_SCRIPT_GLOBAL_SHORT: + { + LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "%s", "Received ID_SCRIPT_GLOBAL_SHORT"); + LOG_APPEND(Log::LOG_WARN, "- globalName: %s\n- shortVal: %i", + event->globalName.c_str(), + event->shortVal); + + MWBase::Environment::get().getWorld()->setGlobalInt(event->globalName, event->shortVal); + + break; + } default: LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Unhandled WorldPacket with identifier %i has arrived", packet->data[0]); diff --git a/components/CMakeLists.txt b/components/CMakeLists.txt index 91f4b42a0..d61c206e7 100644 --- a/components/CMakeLists.txt +++ b/components/CMakeLists.txt @@ -162,7 +162,9 @@ add_component_dir (openmw-mp Packets/World/PacketObjectRotate Packets/World/PacketContainerAdd Packets/World/PacketContainerRemove Packets/World/PacketDoorActivate - Packets/World/PacketVideoPlay) + Packets/World/PacketVideoPlay + + Packets/World/PacketScriptLocalShort Packets/World/PacketScriptLocalFloat Packets/World/PacketScriptGlobalShort) add_component_dir (fallback fallback validate diff --git a/components/openmw-mp/Base/WorldEvent.hpp b/components/openmw-mp/Base/WorldEvent.hpp index 4961cf1a2..89c803792 100644 --- a/components/openmw-mp/Base/WorldEvent.hpp +++ b/components/openmw-mp/Base/WorldEvent.hpp @@ -34,6 +34,11 @@ namespace mwmp std::string video; bool allowSkipping; + + int index; + int shortVal; + float floatVal; + std::string globalName; }; } diff --git a/components/openmw-mp/Controllers/WorldPacketController.cpp b/components/openmw-mp/Controllers/WorldPacketController.cpp index 2f4f9735c..1fe200de1 100644 --- a/components/openmw-mp/Controllers/WorldPacketController.cpp +++ b/components/openmw-mp/Controllers/WorldPacketController.cpp @@ -15,6 +15,10 @@ #include "../Packets/World/PacketDoorActivate.hpp" #include "../Packets/World/PacketVideoPlay.hpp" +#include "../Packets/World/PacketScriptLocalShort.hpp" +#include "../Packets/World/PacketScriptLocalFloat.hpp" +#include "../Packets/World/PacketScriptGlobalShort.hpp" + #include "WorldPacketController.hpp" template @@ -39,6 +43,10 @@ mwmp::WorldPacketController::WorldPacketController(RakNet::RakPeerInterface *pee AddPacket(&packets, peer); AddPacket(&packets, peer); AddPacket(&packets, peer); + + AddPacket(&packets, peer); + AddPacket(&packets, peer); + AddPacket(&packets, peer); } diff --git a/components/openmw-mp/NetworkMessages.hpp b/components/openmw-mp/NetworkMessages.hpp index d0935d566..1386641b0 100644 --- a/components/openmw-mp/NetworkMessages.hpp +++ b/components/openmw-mp/NetworkMessages.hpp @@ -44,7 +44,11 @@ enum GameMessages ID_CONTAINER_ADD, ID_CONTAINER_REMOVE, ID_DOOR_ACTIVATE, - ID_VIDEO_PLAY + ID_VIDEO_PLAY, + + ID_SCRIPT_LOCAL_SHORT, + ID_SCRIPT_LOCAL_FLOAT, + ID_SCRIPT_GLOBAL_SHORT }; diff --git a/components/openmw-mp/Packets/World/PacketScriptGlobalShort.cpp b/components/openmw-mp/Packets/World/PacketScriptGlobalShort.cpp new file mode 100644 index 000000000..e0b9f4f83 --- /dev/null +++ b/components/openmw-mp/Packets/World/PacketScriptGlobalShort.cpp @@ -0,0 +1,17 @@ +#include +#include "PacketScriptGlobalShort.hpp" + +using namespace mwmp; + +PacketScriptGlobalShort::PacketScriptGlobalShort(RakNet::RakPeerInterface *peer) : WorldPacket(peer) +{ + packetID = ID_SCRIPT_GLOBAL_SHORT; +} + +void PacketScriptGlobalShort::Packet(RakNet::BitStream *bs, WorldEvent *event, bool send) +{ + WorldPacket::Packet(bs, event, send); + + RW(event->globalName, send); + RW(event->shortVal, send); +} diff --git a/components/openmw-mp/Packets/World/PacketScriptGlobalShort.hpp b/components/openmw-mp/Packets/World/PacketScriptGlobalShort.hpp new file mode 100644 index 000000000..27d3df662 --- /dev/null +++ b/components/openmw-mp/Packets/World/PacketScriptGlobalShort.hpp @@ -0,0 +1,17 @@ +#ifndef OPENMW_PACKETSCRIPTGLOBALSHORT_HPP +#define OPENMW_PACKETSCRIPTGLOBALSHORT_HPP + +#include + +namespace mwmp +{ + class PacketScriptGlobalShort : public WorldPacket + { + public: + PacketScriptGlobalShort(RakNet::RakPeerInterface *peer); + + virtual void Packet(RakNet::BitStream *bs, WorldEvent *event, bool send); + }; +} + +#endif //OPENMW_PACKETSCRIPTGLOBALSHORT_HPP diff --git a/components/openmw-mp/Packets/World/PacketScriptLocalFloat.cpp b/components/openmw-mp/Packets/World/PacketScriptLocalFloat.cpp new file mode 100644 index 000000000..cef324a89 --- /dev/null +++ b/components/openmw-mp/Packets/World/PacketScriptLocalFloat.cpp @@ -0,0 +1,25 @@ +#include +#include "PacketScriptLocalFloat.hpp" + +using namespace mwmp; + +PacketScriptLocalFloat::PacketScriptLocalFloat(RakNet::RakPeerInterface *peer) : WorldPacket(peer) +{ + packetID = ID_SCRIPT_LOCAL_FLOAT; +} + +void PacketScriptLocalFloat::Packet(RakNet::BitStream *bs, WorldEvent *event, bool send) +{ + WorldPacket::Packet(bs, event, send); + + RW(event->cellRef.mRefID, send); + RW(event->cellRef.mRefNum.mIndex, send); + + RW(event->cell.mData.mFlags, send); + RW(event->cell.mData.mX, send); + RW(event->cell.mData.mY, send); + RW(event->cell.mName, send); + + RW(event->index, send); + RW(event->floatVal, send); +} diff --git a/components/openmw-mp/Packets/World/PacketScriptLocalFloat.hpp b/components/openmw-mp/Packets/World/PacketScriptLocalFloat.hpp new file mode 100644 index 000000000..c5f28f4b1 --- /dev/null +++ b/components/openmw-mp/Packets/World/PacketScriptLocalFloat.hpp @@ -0,0 +1,17 @@ +#ifndef OPENMW_PACKETSCRIPTLOCALFLOAT_HPP +#define OPENMW_PACKETSCRIPTLOCALFLOAT_HPP + +#include + +namespace mwmp +{ + class PacketScriptLocalFloat : public WorldPacket + { + public: + PacketScriptLocalFloat(RakNet::RakPeerInterface *peer); + + virtual void Packet(RakNet::BitStream *bs, WorldEvent *event, bool send); + }; +} + +#endif //OPENMW_PACKETSCRIPTLOCALFLOAT_HPP diff --git a/components/openmw-mp/Packets/World/PacketScriptLocalShort.cpp b/components/openmw-mp/Packets/World/PacketScriptLocalShort.cpp new file mode 100644 index 000000000..769888af6 --- /dev/null +++ b/components/openmw-mp/Packets/World/PacketScriptLocalShort.cpp @@ -0,0 +1,25 @@ +#include +#include "PacketScriptLocalShort.hpp" + +using namespace mwmp; + +PacketScriptLocalShort::PacketScriptLocalShort(RakNet::RakPeerInterface *peer) : WorldPacket(peer) +{ + packetID = ID_SCRIPT_LOCAL_SHORT; +} + +void PacketScriptLocalShort::Packet(RakNet::BitStream *bs, WorldEvent *event, bool send) +{ + WorldPacket::Packet(bs, event, send); + + RW(event->cellRef.mRefID, send); + RW(event->cellRef.mRefNum.mIndex, send); + + RW(event->cell.mData.mFlags, send); + RW(event->cell.mData.mX, send); + RW(event->cell.mData.mY, send); + RW(event->cell.mName, send); + + RW(event->index, send); + RW(event->shortVal, send); +} diff --git a/components/openmw-mp/Packets/World/PacketScriptLocalShort.hpp b/components/openmw-mp/Packets/World/PacketScriptLocalShort.hpp new file mode 100644 index 000000000..746bf9c47 --- /dev/null +++ b/components/openmw-mp/Packets/World/PacketScriptLocalShort.hpp @@ -0,0 +1,17 @@ +#ifndef OPENMW_PACKETSCRIPTLOCALSHORT_HPP +#define OPENMW_PACKETSCRIPTLOCALSHORT_HPP + +#include + +namespace mwmp +{ + class PacketScriptLocalShort : public WorldPacket + { + public: + PacketScriptLocalShort(RakNet::RakPeerInterface *peer); + + virtual void Packet(RakNet::BitStream *bs, WorldEvent *event, bool send); + }; +} + +#endif //OPENMW_PACKETSCRIPTLOCALSHORT_HPP