Add and implement ID_SCRIPT_MEMBER_SHORT

coverity_scan^2
David Cernat 8 years ago
parent c91e240664
commit c205e793cb

@ -596,6 +596,21 @@ void Networking::ProcessWorldPacket(RakNet::Packet *packet)
break;
}
case ID_SCRIPT_MEMBER_SHORT:
{
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_SCRIPT_MEMBER_SHORT from %s",
player->Npc()->mName.c_str());
myPacket->Read(event);
LOG_APPEND(Log::LOG_WARN, "- cellRef: %s",
event->cellRef.mRefID.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",
@ -603,8 +618,8 @@ void Networking::ProcessWorldPacket(RakNet::Packet *packet)
myPacket->Read(event);
LOG_APPEND(Log::LOG_WARN, "- globalName: %s\n- shortVal: %i",
event->globalName.c_str(),
LOG_APPEND(Log::LOG_WARN, "- varName: %s\n- shortVal: %i",
event->varName.c_str(),
event->shortVal);
myPacket->Send(event, true);

@ -230,7 +230,7 @@ void Main::PressedKey(int key)
// should be ignored because of their potential for spam
bool Main::isValidPacketScript(std::string script)
{
static const int invalidPacketScriptsCount = 16;
static const int invalidPacketScriptsCount = 17;
static const std::string invalidPacketScripts[invalidPacketScriptsCount] = {
// Spammy shorts
"OutsideBanner",
@ -238,11 +238,12 @@ bool Main::isValidPacketScript(std::string script)
"dreamer_talkerEnable",
"drenSlaveOwners",
"ahnassiScript",
"FaluraScript",
"hlormarScript",
// Spammy floats
"Float",
"SignRotate",
"FaluraScript",
"jsaddhaScript",
// Spammy globals
"wraithguardScript",
// Spammy globals leading to crashes

@ -12,9 +12,11 @@
#include <apps/openmw/mwbase/windowmanager.hpp>
#include <apps/openmw/mwworld/cellstore.hpp>
#include <apps/openmw/mwworld/esmstore.hpp>
#include <apps/openmw/mwworld/inventorystore.hpp>
#include <apps/openmw/mwclass/npc.hpp>
#include <apps/openmw/mwmechanics/npcstats.hpp>
#include <apps/openmw/mwworld/inventorystore.hpp>
#include <apps/openmw/mwmechanics/combat.hpp>
#include <SDL_messagebox.h>
@ -914,14 +916,42 @@ void Networking::ProcessWorldPacket(RakNet::Packet *packet)
break;
}
case ID_SCRIPT_MEMBER_SHORT:
{
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "%s", "Received ID_SCRIPT_MEMBER_SHORT");
LOG_APPEND(Log::LOG_WARN, "- cellRef: %s\n- index: %i\n- shortVal: %i\n",
event->cellRef.mRefID.c_str(),
event->index,
event->shortVal);
// Mimic the way a Ptr is fetched in InterpreterContext for similar situations
MWWorld::Ptr ptrFound = MWBase::Environment::get().getWorld()->getPtr(event->cellRef.mRefID, false);
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;
std::string scriptId = ptrFound.getClass().getScript(ptrFound);
ptrFound.getRefData().setLocals(
*MWBase::Environment::get().getWorld()->getStore().get<ESM::Script>().find(scriptId));
ptrFound.getRefData().getLocals().mShorts[event->index] = event->shortVal;;
}
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(),
LOG_APPEND(Log::LOG_WARN, "- varName: %s\n- shortVal: %i",
event->varName.c_str(),
event->shortVal);
MWBase::Environment::get().getWorld()->setGlobalInt(event->globalName, event->shortVal);
MWBase::Environment::get().getWorld()->setGlobalInt(event->varName, event->shortVal);
break;
}

@ -164,7 +164,8 @@ add_component_dir (openmw-mp
Packets/World/PacketContainerAdd Packets/World/PacketContainerRemove Packets/World/PacketDoorActivate
Packets/World/PacketVideoPlay
Packets/World/PacketScriptLocalShort Packets/World/PacketScriptLocalFloat Packets/World/PacketScriptGlobalShort)
Packets/World/PacketScriptLocalShort Packets/World/PacketScriptLocalFloat Packets/World/PacketScriptMemberShort
Packets/World/PacketScriptGlobalShort)
add_component_dir (fallback
fallback validate

@ -38,7 +38,7 @@ namespace mwmp
int index;
int shortVal;
float floatVal;
std::string globalName;
std::string varName;
};
}

@ -17,6 +17,7 @@
#include "../Packets/World/PacketScriptLocalShort.hpp"
#include "../Packets/World/PacketScriptLocalFloat.hpp"
#include "../Packets/World/PacketScriptMemberShort.hpp"
#include "../Packets/World/PacketScriptGlobalShort.hpp"
#include "WorldPacketController.hpp"
@ -46,6 +47,7 @@ mwmp::WorldPacketController::WorldPacketController(RakNet::RakPeerInterface *pee
AddPacket<PacketScriptLocalShort>(&packets, peer);
AddPacket<PacketScriptLocalFloat>(&packets, peer);
AddPacket<PacketScriptMemberShort>(&packets, peer);
AddPacket<PacketScriptGlobalShort>(&packets, peer);
}

@ -48,6 +48,7 @@ enum GameMessages
ID_SCRIPT_LOCAL_SHORT,
ID_SCRIPT_LOCAL_FLOAT,
ID_SCRIPT_MEMBER_SHORT,
ID_SCRIPT_GLOBAL_SHORT
};

@ -12,6 +12,6 @@ void PacketScriptGlobalShort::Packet(RakNet::BitStream *bs, WorldEvent *event, b
{
WorldPacket::Packet(bs, event, send);
RW(event->globalName, send);
RW(event->varName, send);
RW(event->shortVal, send);
}

@ -0,0 +1,19 @@
#include <components/openmw-mp/NetworkMessages.hpp>
#include "PacketScriptMemberShort.hpp"
using namespace mwmp;
PacketScriptMemberShort::PacketScriptMemberShort(RakNet::RakPeerInterface *peer) : WorldPacket(peer)
{
packetID = ID_SCRIPT_MEMBER_SHORT;
}
void PacketScriptMemberShort::Packet(RakNet::BitStream *bs, WorldEvent *event, bool send)
{
WorldPacket::Packet(bs, event, send);
RW(event->cellRef.mRefID, send);
RW(event->index, send);
RW(event->shortVal, send);
}

@ -0,0 +1,17 @@
#ifndef OPENMW_PACKETSCRIPTMEMBERSHORT_HPP
#define OPENMW_PACKETSCRIPTMEMBERSHORT_HPP
#include <components/openmw-mp/Packets/World/WorldPacket.hpp>
namespace mwmp
{
class PacketScriptMemberShort : public WorldPacket
{
public:
PacketScriptMemberShort(RakNet::RakPeerInterface *peer);
virtual void Packet(RakNet::BitStream *bs, WorldEvent *event, bool send);
};
}
#endif //OPENMW_PACKETSCRIPTMEMBERSHORT_HPP
Loading…
Cancel
Save