2016-10-17 15:47:16 +00:00
|
|
|
#ifndef OPENMW_BASEPACKET_HPP
|
|
|
|
#define OPENMW_BASEPACKET_HPP
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <RakNetTypes.h>
|
|
|
|
#include <BitStream.h>
|
|
|
|
#include <PacketPriority.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace mwmp
|
|
|
|
{
|
|
|
|
class BasePacket
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
BasePacket(RakNet::RakPeerInterface *peer);
|
|
|
|
|
2017-03-06 09:44:08 +00:00
|
|
|
virtual ~BasePacket();
|
2016-10-17 15:47:16 +00:00
|
|
|
|
2017-03-06 09:44:08 +00:00
|
|
|
virtual void Packet(RakNet::BitStream *bs, bool send);
|
2017-07-31 10:57:57 +00:00
|
|
|
virtual uint32_t Send(bool toOtherPlayers = true);
|
|
|
|
virtual uint32_t Send(RakNet::AddressOrGUID destination);
|
2017-03-06 09:44:08 +00:00
|
|
|
virtual void Read();
|
|
|
|
|
|
|
|
void setGUID(RakNet::RakNetGUID guid);
|
|
|
|
RakNet::RakNetGUID getGUID();
|
2017-03-05 08:01:42 +00:00
|
|
|
|
2016-10-17 15:47:16 +00:00
|
|
|
void SetReadStream(RakNet::BitStream *bitStream);
|
|
|
|
void SetSendStream(RakNet::BitStream *bitStream);
|
|
|
|
void SetStreams(RakNet::BitStream *inStream, RakNet::BitStream *outStream);
|
2017-07-31 10:57:57 +00:00
|
|
|
virtual uint32_t RequestData(RakNet::RakNetGUID guid);
|
2016-10-17 15:47:16 +00:00
|
|
|
|
|
|
|
static size_t headerSize()
|
|
|
|
{
|
|
|
|
return (size_t)(1 + RakNet::RakNetGUID::size()); // packetID + RakNetGUID (uint64_t)
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned char GetPacketID()
|
|
|
|
{
|
|
|
|
return packetID;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
template<class templateType>
|
|
|
|
void RW(templateType &data, unsigned int size, bool write)
|
|
|
|
{
|
|
|
|
if (write)
|
|
|
|
bs->Write(data, size);
|
|
|
|
else
|
|
|
|
bs->Read(data, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class templateType>
|
2017-05-28 06:56:51 +00:00
|
|
|
void RW(templateType &data, bool write, bool compress = 0)
|
2016-10-17 15:47:16 +00:00
|
|
|
{
|
|
|
|
if (write)
|
2017-05-28 06:56:51 +00:00
|
|
|
{
|
2017-05-31 05:37:11 +00:00
|
|
|
if (compress)
|
2017-05-28 06:56:51 +00:00
|
|
|
bs->WriteCompressed(data);
|
|
|
|
else
|
|
|
|
bs->Write(data);
|
|
|
|
}
|
2016-10-17 15:47:16 +00:00
|
|
|
else
|
2017-05-28 06:56:51 +00:00
|
|
|
{
|
2017-05-31 05:37:11 +00:00
|
|
|
if (compress)
|
2017-05-28 06:56:51 +00:00
|
|
|
bs->ReadCompressed(data);
|
|
|
|
else
|
|
|
|
bs->Read(data);
|
|
|
|
}
|
2016-10-17 15:47:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RW(bool &data, bool write)
|
|
|
|
{
|
|
|
|
if (write)
|
2017-06-02 13:03:29 +00:00
|
|
|
bs->Write(data);
|
2016-10-17 15:47:16 +00:00
|
|
|
else
|
2017-06-02 13:03:29 +00:00
|
|
|
bs->Read(data);
|
2016-10-17 15:47:16 +00:00
|
|
|
}
|
|
|
|
|
2017-05-28 06:56:51 +00:00
|
|
|
void RW(std::string &str, bool write, bool compress = 0)
|
2016-10-17 15:47:16 +00:00
|
|
|
{
|
|
|
|
if (write)
|
|
|
|
{
|
2017-05-31 05:37:11 +00:00
|
|
|
if (compress)
|
2017-09-03 20:03:02 +00:00
|
|
|
RakNet::RakString::SerializeCompressed(str.c_str(), bs);
|
2017-05-28 06:56:51 +00:00
|
|
|
else
|
2017-09-03 10:53:45 +00:00
|
|
|
{
|
|
|
|
RakNet::RakString rstr;
|
|
|
|
rstr = str.c_str();
|
2017-05-28 06:56:51 +00:00
|
|
|
bs->Write(rstr);
|
2017-09-03 10:53:45 +00:00
|
|
|
}
|
2016-10-17 15:47:16 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
RakNet::RakString rstr;
|
2017-05-31 05:37:11 +00:00
|
|
|
if (compress)
|
2017-05-28 06:56:51 +00:00
|
|
|
rstr.DeserializeCompressed(bs);
|
|
|
|
else
|
|
|
|
bs->Read(rstr);
|
2016-10-17 15:47:16 +00:00
|
|
|
str = rstr.C_String();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
unsigned char packetID;
|
|
|
|
PacketReliability reliability;
|
|
|
|
PacketPriority priority;
|
2017-04-23 05:31:01 +00:00
|
|
|
int orderChannel;
|
2016-10-17 15:47:16 +00:00
|
|
|
RakNet::BitStream *bsRead, *bsSend, *bs;
|
|
|
|
RakNet::RakPeerInterface *peer;
|
2017-03-06 09:44:08 +00:00
|
|
|
RakNet::RakNetGUID guid;
|
2016-10-17 15:47:16 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif //OPENMW_BASEPACKET_HPP
|