openmw-tes3coop/components/openmw-mp/Packets/PlayerPacket.cpp

76 lines
1.7 KiB
C++
Raw Normal View History

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