You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
86 lines
1.9 KiB
C++
86 lines
1.9 KiB
C++
#include <components/openmw-mp/NetworkMessages.hpp>
|
|
#include <PacketPriority.h>
|
|
#include <RakPeer.h>
|
|
#include "ObjectPacket.hpp"
|
|
|
|
using namespace mwmp;
|
|
|
|
ObjectPacket::ObjectPacket(RakNet::RakPeerInterface *peer) : BasePacket(peer)
|
|
{
|
|
hasCellData = false;
|
|
packetID = 0;
|
|
priority = HIGH_PRIORITY;
|
|
reliability = RELIABLE_ORDERED;
|
|
orderChannel = CHANNEL_OBJECT;
|
|
this->peer = peer;
|
|
}
|
|
|
|
ObjectPacket::~ObjectPacket()
|
|
{
|
|
|
|
}
|
|
|
|
void ObjectPacket::setObjectList(BaseObjectList *objectList)
|
|
{
|
|
this->objectList = objectList;
|
|
guid = objectList->guid;
|
|
}
|
|
|
|
void ObjectPacket::Packet(RakNet::BitStream *bs, bool send)
|
|
{
|
|
if (!PacketHeader(bs, send))
|
|
return;
|
|
|
|
BaseObject baseObject;
|
|
for (unsigned int i = 0; i < objectList->baseObjectCount; i++)
|
|
{
|
|
if (send)
|
|
baseObject = objectList->baseObjects.at(i);
|
|
|
|
Object(baseObject, send);
|
|
|
|
if (!send)
|
|
objectList->baseObjects.push_back(baseObject);
|
|
}
|
|
}
|
|
|
|
bool ObjectPacket::PacketHeader(RakNet::BitStream *bs, bool send)
|
|
{
|
|
BasePacket::Packet(bs, send);
|
|
|
|
RW(objectList->packetOrigin, send);
|
|
|
|
/* Comment this out until it's implemented properly
|
|
if (objectList->packetOrigin == mwmp::CLIENT_SCRIPT_LOCAL)
|
|
RW(objectList->originClientScript, send, true);
|
|
*/
|
|
|
|
if (send)
|
|
objectList->baseObjectCount = (unsigned int)(objectList->baseObjects.size());
|
|
else
|
|
objectList->baseObjects.clear();
|
|
|
|
RW(objectList->baseObjectCount, send);
|
|
|
|
if (objectList->baseObjectCount > maxObjects)
|
|
{
|
|
objectList->isValid = false;
|
|
return false;
|
|
}
|
|
|
|
if (hasCellData)
|
|
{
|
|
RW(objectList->cell.mData, send, true);
|
|
RW(objectList->cell.mName, send, true);
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
void ObjectPacket::Object(BaseObject &baseObject, bool send)
|
|
{
|
|
RW(baseObject.refId, send);
|
|
RW(baseObject.refNum, send);
|
|
RW(baseObject.mpNum, send);
|
|
}
|