Merge pull request #430 from TES3MP/0.6.3 while resolving conflicts
# Conflicts: # apps/openmw-mp/Networking.cpp # apps/openmw-mp/Networking.hpp # components/CMakeLists.txtpull/431/head
commit
8a393d2984
@ -0,0 +1,40 @@
|
||||
#include "WorldstateProcessor.hpp"
|
||||
#include "Networking.hpp"
|
||||
|
||||
using namespace mwmp;
|
||||
|
||||
template<class T>
|
||||
typename BasePacketProcessor<T>::processors_t BasePacketProcessor<T>::processors;
|
||||
|
||||
void WorldstateProcessor::Do(WorldstatePacket &packet, Player &player, BaseWorldstate &worldstate)
|
||||
{
|
||||
packet.Send(true);
|
||||
}
|
||||
|
||||
bool WorldstateProcessor::Process(RakNet::Packet &packet, BaseWorldstate &worldstate) noexcept
|
||||
{
|
||||
worldstate.guid = packet.guid;
|
||||
|
||||
for (auto &processor : processors)
|
||||
{
|
||||
if (processor.first == packet.data[0])
|
||||
{
|
||||
auto player = Players::getPlayerByGUID(packet.guid);
|
||||
WorldstatePacket *myPacket = Networking::get().getWorldstatePacketController()->GetPacket(packet.data[0]);
|
||||
|
||||
myPacket->setWorldstate(&worldstate);
|
||||
worldstate.isValid = true;
|
||||
|
||||
if (!processor.second->avoidReading)
|
||||
myPacket->Read();
|
||||
|
||||
if (worldstate.isValid)
|
||||
processor.second->Do(*myPacket, *player, worldstate);
|
||||
else
|
||||
LOG_MESSAGE_SIMPLE(Log::LOG_ERROR, "Received %s that failed integrity check and was ignored!", processor.second->strPacketID.c_str());
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
#ifndef OPENMW_BASEWORLDSTATEPROCESSOR_HPP
|
||||
#define OPENMW_BASEWORLDSTATEPROCESSOR_HPP
|
||||
|
||||
#include <components/openmw-mp/Base/BasePacketProcessor.hpp>
|
||||
#include <components/openmw-mp/Packets/BasePacket.hpp>
|
||||
#include <components/openmw-mp/Packets/Worldstate/WorldstatePacket.hpp>
|
||||
#include <components/openmw-mp/NetworkMessages.hpp>
|
||||
#include "Players.hpp"
|
||||
|
||||
namespace mwmp
|
||||
{
|
||||
class WorldstateProcessor : public BasePacketProcessor<WorldstateProcessor>
|
||||
{
|
||||
public:
|
||||
|
||||
virtual void Do(WorldstatePacket &packet, Player &player, BaseWorldstate &worldstate);
|
||||
|
||||
static bool Process(RakNet::Packet &packet, BaseWorldstate &worldstate) noexcept;
|
||||
};
|
||||
}
|
||||
|
||||
#endif //OPENMW_BASEWORLDSTATEPROCESSOR_HPP
|
@ -0,0 +1,40 @@
|
||||
#include "../Networking.hpp"
|
||||
#include "WorldstateProcessor.hpp"
|
||||
#include "../Main.hpp"
|
||||
|
||||
using namespace mwmp;
|
||||
|
||||
template<class T>
|
||||
typename BasePacketProcessor<T>::processors_t BasePacketProcessor<T>::processors;
|
||||
|
||||
bool WorldstateProcessor::Process(RakNet::Packet &packet, BaseWorldstate &worldstate)
|
||||
{
|
||||
RakNet::BitStream bsIn(&packet.data[1], packet.length, false);
|
||||
bsIn.Read(guid);
|
||||
worldstate.guid = guid;
|
||||
|
||||
WorldstatePacket *myPacket = Main::get().getNetworking()->getWorldstatePacket(packet.data[0]);
|
||||
myPacket->SetReadStream(&bsIn);
|
||||
|
||||
for (auto &processor : processors)
|
||||
{
|
||||
if (processor.first == packet.data[0])
|
||||
{
|
||||
myGuid = Main::get().getLocalPlayer()->guid;
|
||||
request = packet.length == myPacket->headerSize();
|
||||
|
||||
worldstate.isValid = true;
|
||||
|
||||
if (!request && !processor.second->avoidReading)
|
||||
myPacket->Read();
|
||||
|
||||
if (worldstate.isValid)
|
||||
processor.second->Do(*myPacket, worldstate);
|
||||
else
|
||||
LOG_MESSAGE_SIMPLE(Log::LOG_ERROR, "Received %s that failed integrity check and was ignored!", processor.second->strPacketID.c_str());
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
#ifndef OPENMW_WORLDSTATEPROCESSOR_HPP
|
||||
#define OPENMW_WORLDSTATEPROCESSOR_HPP
|
||||
|
||||
#include <components/openmw-mp/Log.hpp>
|
||||
#include <components/openmw-mp/NetworkMessages.hpp>
|
||||
#include <components/openmw-mp/Packets/Worldstate/WorldstatePacket.hpp>
|
||||
#include "BaseClientPacketProcessor.hpp"
|
||||
|
||||
namespace mwmp
|
||||
{
|
||||
class WorldstateProcessor : public BasePacketProcessor<WorldstateProcessor>, public BaseClientPacketProcessor
|
||||
{
|
||||
public:
|
||||
virtual void Do(WorldstatePacket &packet, BaseWorldstate &worldstate) = 0;
|
||||
|
||||
static bool Process(RakNet::Packet &packet, BaseWorldstate &worldstate);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif //OPENMW_WORLDSTATEPROCESSOR_HPP
|
@ -0,0 +1,26 @@
|
||||
#ifndef OPENMW_BASEWORLDSTATE_HPP
|
||||
#define OPENMW_BASEWORLDSTATE_HPP
|
||||
|
||||
#include <components/openmw-mp/Base/BaseStructs.hpp>
|
||||
|
||||
#include <RakNetTypes.h>
|
||||
|
||||
namespace mwmp
|
||||
{
|
||||
|
||||
class BaseWorldstate
|
||||
{
|
||||
public:
|
||||
|
||||
BaseWorldstate()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
RakNet::RakNetGUID guid;
|
||||
|
||||
bool isValid;
|
||||
};
|
||||
}
|
||||
|
||||
#endif //OPENMW_BASEWORLDSTATE_HPP
|
@ -0,0 +1,6 @@
|
||||
#include "WorldstatePacketController.hpp"
|
||||
|
||||
mwmp::WorldstatePacketController::WorldstatePacketController(RakNet::RakPeerInterface *peer)
|
||||
{
|
||||
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
#ifndef OPENMW_WORLDSTATEPACKETCONTROLLER_HPP
|
||||
#define OPENMW_WORLDSTATEPACKETCONTROLLER_HPP
|
||||
|
||||
|
||||
#include "../Packets/Worldstate/WorldstatePacket.hpp"
|
||||
#include "BasePacketController.hpp"
|
||||
|
||||
namespace mwmp
|
||||
{
|
||||
class WorldstatePacketController: public BasePacketController<WorldstatePacket>
|
||||
{
|
||||
public:
|
||||
WorldstatePacketController(RakNet::RakPeerInterface *peer);
|
||||
};
|
||||
}
|
||||
|
||||
#endif //OPENMW_WORLDSTATEPACKETCONTROLLER_HPP
|
@ -0,0 +1,26 @@
|
||||
#include <components/openmw-mp/NetworkMessages.hpp>
|
||||
#include <PacketPriority.h>
|
||||
#include <RakPeer.h>
|
||||
#include "WorldstatePacket.hpp"
|
||||
|
||||
using namespace mwmp;
|
||||
|
||||
WorldstatePacket::WorldstatePacket(RakNet::RakPeerInterface *peer) : BasePacket(peer)
|
||||
{
|
||||
packetID = 0;
|
||||
priority = HIGH_PRIORITY;
|
||||
reliability = RELIABLE_ORDERED;
|
||||
orderChannel = CHANNEL_WORLDSTATE;
|
||||
this->peer = peer;
|
||||
}
|
||||
|
||||
void WorldstatePacket::setWorldstate(BaseWorldstate *worldstate)
|
||||
{
|
||||
this->worldstate = worldstate;
|
||||
guid = worldstate->guid;
|
||||
}
|
||||
|
||||
BaseWorldstate *WorldstatePacket::getWorldstate()
|
||||
{
|
||||
return worldstate;
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
#ifndef OPENMW_WORLDSTATEPACKET_HPP
|
||||
#define OPENMW_WORLDSTATEPACKET_HPP
|
||||
|
||||
#include <string>
|
||||
#include <RakNetTypes.h>
|
||||
#include <BitStream.h>
|
||||
#include <PacketPriority.h>
|
||||
#include <components/openmw-mp/Base/BaseWorldstate.hpp>
|
||||
|
||||
#include <components/openmw-mp/Packets/BasePacket.hpp>
|
||||
|
||||
namespace mwmp
|
||||
{
|
||||
class WorldstatePacket : public BasePacket
|
||||
{
|
||||
public:
|
||||
WorldstatePacket(RakNet::RakPeerInterface *peer);
|
||||
|
||||
~WorldstatePacket() override = default;
|
||||
|
||||
void setWorldstate(BaseWorldstate *worldstate);
|
||||
BaseWorldstate *getWorldstate();
|
||||
|
||||
protected:
|
||||
BaseWorldstate *worldstate;
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
#endif //OPENMW_WORLDSTATEPACKET_HPP
|
Loading…
Reference in New Issue