Add and implement 3 new WorldPackets for ingame script variable values

coverity_scan^2
David Cernat 8 years ago
parent e7ebeb8eec
commit 97468980af

@ -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]);

@ -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]);

@ -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

@ -34,6 +34,11 @@ namespace mwmp
std::string video;
bool allowSkipping;
int index;
int shortVal;
float floatVal;
std::string globalName;
};
}

@ -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 <typename T>
@ -39,6 +43,10 @@ mwmp::WorldPacketController::WorldPacketController(RakNet::RakPeerInterface *pee
AddPacket<PacketContainerRemove>(&packets, peer);
AddPacket<PacketDoorActivate>(&packets, peer);
AddPacket<PacketVideoPlay>(&packets, peer);
AddPacket<PacketScriptLocalShort>(&packets, peer);
AddPacket<PacketScriptLocalFloat>(&packets, peer);
AddPacket<PacketScriptGlobalShort>(&packets, peer);
}

@ -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
};

@ -0,0 +1,17 @@
#include <components/openmw-mp/NetworkMessages.hpp>
#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);
}

@ -0,0 +1,17 @@
#ifndef OPENMW_PACKETSCRIPTGLOBALSHORT_HPP
#define OPENMW_PACKETSCRIPTGLOBALSHORT_HPP
#include <components/openmw-mp/Packets/World/WorldPacket.hpp>
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

@ -0,0 +1,25 @@
#include <components/openmw-mp/NetworkMessages.hpp>
#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);
}

@ -0,0 +1,17 @@
#ifndef OPENMW_PACKETSCRIPTLOCALFLOAT_HPP
#define OPENMW_PACKETSCRIPTLOCALFLOAT_HPP
#include <components/openmw-mp/Packets/World/WorldPacket.hpp>
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

@ -0,0 +1,25 @@
#include <components/openmw-mp/NetworkMessages.hpp>
#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);
}

@ -0,0 +1,17 @@
#ifndef OPENMW_PACKETSCRIPTLOCALSHORT_HPP
#define OPENMW_PACKETSCRIPTLOCALSHORT_HPP
#include <components/openmw-mp/Packets/World/WorldPacket.hpp>
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
Loading…
Cancel
Save