2016-01-12 03:41:44 +00:00
|
|
|
#include <components/openmw-mp/NetworkMessages.hpp>
|
|
|
|
#include <PacketPriority.h>
|
|
|
|
#include <RakPeer.h>
|
2016-10-17 12:54:36 +00:00
|
|
|
#include "PlayerPacket.hpp"
|
2016-01-12 03:41:44 +00:00
|
|
|
|
|
|
|
using namespace mwmp;
|
|
|
|
|
2016-10-17 12:54:36 +00:00
|
|
|
void PlayerPacket::Packet(RakNet::BitStream *bs, BasePlayer *player, bool send)
|
2016-01-12 03:41:44 +00:00
|
|
|
{
|
|
|
|
this->player = player;
|
|
|
|
this->bs = bs;
|
|
|
|
|
2016-08-17 15:20:36 +00:00
|
|
|
if (send)
|
2016-01-12 03:41:44 +00:00
|
|
|
{
|
2016-08-05 19:28:01 +00:00
|
|
|
bs->Write(packetID);
|
2016-01-12 03:41:44 +00:00
|
|
|
bs->Write(player->guid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-17 12:54:36 +00:00
|
|
|
PlayerPacket::PlayerPacket(RakNet::RakPeerInterface *peer)
|
2016-01-12 03:41:44 +00:00
|
|
|
{
|
|
|
|
packetID = 0;
|
|
|
|
priority = HIGH_PRIORITY;
|
|
|
|
reliability = RELIABLE_ORDERED;
|
|
|
|
this->peer = peer;
|
|
|
|
}
|
|
|
|
|
2016-10-17 12:54:36 +00:00
|
|
|
PlayerPacket::~PlayerPacket()
|
2016-01-12 03:41:44 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-10-17 12:54:36 +00:00
|
|
|
void PlayerPacket::Send(BasePlayer *player, RakNet::AddressOrGUID destination)
|
2016-01-12 03:41:44 +00:00
|
|
|
{
|
|
|
|
bsSend->ResetWritePointer();
|
|
|
|
Packet(bsSend, player, true);
|
|
|
|
peer->Send(bsSend, priority, reliability, 0, destination, false);
|
|
|
|
}
|
|
|
|
|
2016-10-17 12:54:36 +00:00
|
|
|
void PlayerPacket::Send(BasePlayer *player, bool toOther)
|
2016-01-12 03:41:44 +00:00
|
|
|
{
|
|
|
|
bsSend->ResetWritePointer();
|
|
|
|
Packet(bsSend, player, true);
|
|
|
|
peer->Send(bsSend, priority, reliability, 0, player->guid, toOther);
|
|
|
|
}
|
|
|
|
|
2016-10-17 12:54:36 +00:00
|
|
|
void PlayerPacket::Read(BasePlayer *player)
|
2016-01-12 03:41:44 +00:00
|
|
|
{
|
|
|
|
Packet(bsRead, player, false);
|
|
|
|
}
|
|
|
|
|
2016-10-17 12:54:36 +00:00
|
|
|
void PlayerPacket::SetReadStream(RakNet::BitStream *bitStream)
|
2016-01-12 03:41:44 +00:00
|
|
|
{
|
|
|
|
bsRead = bitStream;
|
|
|
|
}
|
|
|
|
|
2016-10-17 12:54:36 +00:00
|
|
|
void PlayerPacket::SetSendStream(RakNet::BitStream *bitStream)
|
2016-01-12 03:41:44 +00:00
|
|
|
{
|
|
|
|
bsSend = bitStream;
|
|
|
|
}
|
|
|
|
|
2016-10-17 12:54:36 +00:00
|
|
|
void PlayerPacket::RequestData(RakNet::RakNetGUID player)
|
2016-01-12 03:41:44 +00:00
|
|
|
{
|
|
|
|
bsSend->ResetWritePointer();
|
2016-08-05 19:28:01 +00:00
|
|
|
bsSend->Write(packetID);
|
2016-01-12 03:41:44 +00:00
|
|
|
bsSend->Write(player);
|
|
|
|
peer->Send(bsSend, HIGH_PRIORITY, RELIABLE_ORDERED, 0, player, false);
|
|
|
|
}
|
|
|
|
|
2016-10-17 12:54:36 +00:00
|
|
|
void PlayerPacket::SetStreams(RakNet::BitStream *inStream, RakNet::BitStream *outStream)
|
2016-01-12 03:41:44 +00:00
|
|
|
{
|
2016-08-17 15:20:36 +00:00
|
|
|
if (inStream != 0)
|
2016-01-12 03:41:44 +00:00
|
|
|
bsRead = inStream;
|
2016-08-17 15:20:36 +00:00
|
|
|
if (outStream != 0)
|
2016-01-12 03:41:44 +00:00
|
|
|
bsSend = outStream;
|
|
|
|
}
|