Create placeholders for WorldPacket classes
parent
790d41e278
commit
285f89573d
@ -0,0 +1,32 @@
|
|||||||
|
#include <boost/shared_ptr.hpp>
|
||||||
|
#include <boost/foreach.hpp>
|
||||||
|
#include <boost/make_shared.hpp>
|
||||||
|
|
||||||
|
#include "../Packets/World/PacketObjectRemoval.hpp"
|
||||||
|
|
||||||
|
#include "WorldPacketController.hpp"
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
inline void AddPacket(mwmp::WorldPacketController::packets_t *packets, RakNet::RakPeerInterface *peer)
|
||||||
|
{
|
||||||
|
T *packet = new T(peer);
|
||||||
|
typedef mwmp::WorldPacketController::packets_t::value_type value_t;
|
||||||
|
packets->insert(value_t(packet->GetPacketID(), value_t::second_type(packet)));
|
||||||
|
}
|
||||||
|
|
||||||
|
mwmp::WorldPacketController::WorldPacketController(RakNet::RakPeerInterface *peer)
|
||||||
|
{
|
||||||
|
AddPacket<PacketObjectRemoval>(&packets, peer);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
mwmp::WorldPacket *mwmp::WorldPacketController::GetPacket(RakNet::MessageID id)
|
||||||
|
{
|
||||||
|
return packets[(unsigned char)id].get();
|
||||||
|
}
|
||||||
|
|
||||||
|
void mwmp::WorldPacketController::SetStream(RakNet::BitStream *inStream, RakNet::BitStream *outStream)
|
||||||
|
{
|
||||||
|
BOOST_FOREACH( packets_t::value_type &packet, packets )
|
||||||
|
packet.second->SetStreams(inStream, outStream);
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
#ifndef OPENMW_WORLDPACKETCONTROLLER_HPP
|
||||||
|
#define OPENMW_WORLDPACKETCONTROLLER_HPP
|
||||||
|
|
||||||
|
|
||||||
|
#include <RakPeerInterface.h>
|
||||||
|
#include "../Packets/World/WorldPacket.hpp"
|
||||||
|
#include <map>
|
||||||
|
#include <boost/shared_ptr.hpp>
|
||||||
|
|
||||||
|
namespace mwmp
|
||||||
|
{
|
||||||
|
class WorldPacketController
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
WorldPacketController(RakNet::RakPeerInterface *peer);
|
||||||
|
WorldPacket *GetPacket(RakNet::MessageID id);
|
||||||
|
void SetStream(RakNet::BitStream *inStream, RakNet::BitStream *outStream);
|
||||||
|
|
||||||
|
typedef std::map<unsigned char, boost::shared_ptr<WorldPacket> > packets_t;
|
||||||
|
private:
|
||||||
|
packets_t packets;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif //OPENMW_WORLDPACKETCONTROLLER_HPP
|
@ -0,0 +1,14 @@
|
|||||||
|
#include <components/openmw-mp/NetworkMessages.hpp>
|
||||||
|
#include "PacketObjectRemoval.hpp"
|
||||||
|
|
||||||
|
using namespace mwmp;
|
||||||
|
|
||||||
|
PacketObjectRemoval::PacketObjectRemoval(RakNet::RakPeerInterface *peer) : WorldPacket(peer)
|
||||||
|
{
|
||||||
|
packetID = ID_WORLD_OBJECT_REMOVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PacketObjectRemoval::Packet(RakNet::BitStream *bs, BasePlayer *player, bool send)
|
||||||
|
{
|
||||||
|
WorldPacket::Packet(bs, player, send);
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
#ifndef OPENMW_PACKETOBJECTREMOVAL_HPP
|
||||||
|
#define OPENMW_PACKETOBJECTREMOVAL_HPP
|
||||||
|
|
||||||
|
#include <components/openmw-mp/Packets/World/WorldPacket.hpp>
|
||||||
|
|
||||||
|
namespace mwmp
|
||||||
|
{
|
||||||
|
class PacketObjectRemoval : public WorldPacket
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
PacketObjectRemoval(RakNet::RakPeerInterface *peer);
|
||||||
|
|
||||||
|
virtual void Packet(RakNet::BitStream *bs, BasePlayer *player, bool send);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif //OPENMW_PACKETOBJECTREMOVAL_HPP
|
@ -0,0 +1,58 @@
|
|||||||
|
#include <components/openmw-mp/NetworkMessages.hpp>
|
||||||
|
#include <PacketPriority.h>
|
||||||
|
#include <RakPeer.h>
|
||||||
|
#include "WorldPacket.hpp"
|
||||||
|
|
||||||
|
using namespace mwmp;
|
||||||
|
|
||||||
|
void WorldPacket::Packet(RakNet::BitStream *bs, BasePlayer *player, bool send)
|
||||||
|
{
|
||||||
|
this->player = player;
|
||||||
|
this->bs = bs;
|
||||||
|
|
||||||
|
if (send)
|
||||||
|
{
|
||||||
|
bs->Write(packetID);
|
||||||
|
bs->Write(player->guid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
WorldPacket::WorldPacket(RakNet::RakPeerInterface *peer) : BasePacket(peer)
|
||||||
|
{
|
||||||
|
packetID = 0;
|
||||||
|
priority = HIGH_PRIORITY;
|
||||||
|
reliability = RELIABLE_ORDERED;
|
||||||
|
this->peer = peer;
|
||||||
|
}
|
||||||
|
|
||||||
|
WorldPacket::~WorldPacket()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void WorldPacket::Send(BasePlayer *player, RakNet::AddressOrGUID destination)
|
||||||
|
{
|
||||||
|
bsSend->ResetWritePointer();
|
||||||
|
Packet(bsSend, player, true);
|
||||||
|
peer->Send(bsSend, priority, reliability, 0, destination, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void WorldPacket::Send(BasePlayer *player, bool toOther)
|
||||||
|
{
|
||||||
|
bsSend->ResetWritePointer();
|
||||||
|
Packet(bsSend, player, true);
|
||||||
|
peer->Send(bsSend, priority, reliability, 0, player->guid, toOther);
|
||||||
|
}
|
||||||
|
|
||||||
|
void WorldPacket::Read(BasePlayer *player)
|
||||||
|
{
|
||||||
|
Packet(bsRead, player, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void WorldPacket::RequestData(RakNet::RakNetGUID guid)
|
||||||
|
{
|
||||||
|
bsSend->ResetWritePointer();
|
||||||
|
bsSend->Write(packetID);
|
||||||
|
bsSend->Write(guid);
|
||||||
|
peer->Send(bsSend, HIGH_PRIORITY, RELIABLE_ORDERED, 0, guid, false);
|
||||||
|
}
|
@ -0,0 +1,46 @@
|
|||||||
|
#ifndef OPENMW_WORLDPACKET_HPP
|
||||||
|
#define OPENMW_WORLDPACKET_HPP
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <RakNetTypes.h>
|
||||||
|
#include <BitStream.h>
|
||||||
|
#include <PacketPriority.h>
|
||||||
|
#include <components/openmw-mp/Base/BasePlayer.hpp>
|
||||||
|
|
||||||
|
#include <components/openmw-mp/Packets/BasePacket.hpp>
|
||||||
|
|
||||||
|
|
||||||
|
namespace mwmp
|
||||||
|
{
|
||||||
|
class WorldPacket : public BasePacket
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
WorldPacket(RakNet::RakPeerInterface *peer);
|
||||||
|
|
||||||
|
~WorldPacket();
|
||||||
|
|
||||||
|
virtual void Packet(RakNet::BitStream *bs, BasePlayer *player, bool send);
|
||||||
|
|
||||||
|
virtual void Send(BasePlayer *player, bool toOtherPlayers = true);
|
||||||
|
virtual void Send(BasePlayer *player, RakNet::AddressOrGUID destination);
|
||||||
|
virtual void Read(BasePlayer *player);
|
||||||
|
|
||||||
|
virtual void RequestData(RakNet::RakNetGUID player);
|
||||||
|
|
||||||
|
static size_t headerSize()
|
||||||
|
{
|
||||||
|
return (size_t)(1 + RakNet::RakNetGUID::size()); // packetID + RakNetGUID (uint64_t)
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned char GetPacketID()
|
||||||
|
{
|
||||||
|
return packetID;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
BasePlayer *player;
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif //OPENMW_WORLDPACKET_HPP
|
Loading…
Reference in New Issue