[General] Simplify WorldPackets

0.6.1
Koncord 8 years ago
parent 556bf18535
commit fd8e833d6a

@ -7,49 +7,29 @@ using namespace mwmp;
PacketContainer::PacketContainer(RakNet::RakPeerInterface *peer) : WorldPacket(peer)
{
packetID = ID_CONTAINER;
hasCellData = true;
}
void PacketContainer::Packet(RakNet::BitStream *bs, bool send)
{
WorldPacket::Packet(bs, send);
RW(event->action, send);
if (send)
event->worldObjectCount = (unsigned int)(event->worldObjects.size());
else
event->worldObjects.clear();
RW(event->worldObjectCount, send);
if (event->worldObjectCount > maxObjects)
{
event->isValid = false;
if(!PacketHeader(bs, send))
return;
}
RW(event->cell.mData.mFlags, send);
RW(event->cell.mData.mX, send);
RW(event->cell.mData.mY, send);
RW(event->cell.mName, send);
RW(event->action, send);
WorldObject worldObject;
for (unsigned int i = 0; i < event->worldObjectCount; i++)
{
if (send)
{
worldObject = event->worldObjects.at(i);
worldObject.containerItemCount = (unsigned int)(worldObject.containerItems.size());
worldObject.containerItemCount = (unsigned int) (worldObject.containerItems.size());
}
else
{
worldObject.containerItems.clear();
}
RW(worldObject.refId, send);
RW(worldObject.refNumIndex, send);
RW(worldObject.mpNum, send);
Object(worldObject, send);
RW(worldObject.containerItemCount, send);
if (worldObject.containerItemCount > maxObjects || worldObject.refId.empty() || (worldObject.refNumIndex != 0 && worldObject.mpNum != 0))
@ -63,9 +43,7 @@ void PacketContainer::Packet(RakNet::BitStream *bs, bool send)
for (unsigned int j = 0; j < worldObject.containerItemCount; j++)
{
if (send)
{
containerItem = worldObject.containerItems.at(j);
}
RW(containerItem.refId, send);
RW(containerItem.count, send);
@ -73,14 +51,9 @@ void PacketContainer::Packet(RakNet::BitStream *bs, bool send)
RW(containerItem.actionCount, send);
if (!send)
{
worldObject.containerItems.push_back(containerItem);
}
}
if (!send)
{
event->worldObjects.push_back(worldObject);
}
}
}

@ -6,47 +6,11 @@ using namespace mwmp;
PacketDoorState::PacketDoorState(RakNet::RakPeerInterface *peer) : WorldPacket(peer)
{
packetID = ID_DOOR_STATE;
hasCellData = true;
}
void PacketDoorState::Packet(RakNet::BitStream *bs, bool send)
void PacketDoorState::Object(WorldObject &worldObject, bool send)
{
WorldPacket::Packet(bs, send);
if (send)
event->worldObjectCount = (unsigned int)(event->worldObjects.size());
else
event->worldObjects.clear();
RW(event->worldObjectCount, send);
if (event->worldObjectCount > maxObjects)
{
event->isValid = false;
return;
}
RW(event->cell.mData.mFlags, send);
RW(event->cell.mData.mX, send);
RW(event->cell.mData.mY, send);
RW(event->cell.mName, send);
WorldObject worldObject;
for (unsigned int i = 0; i < event->worldObjectCount; i++)
{
if (send)
{
worldObject = event->worldObjects.at(i);
}
RW(worldObject.refId, send);
RW(worldObject.refNumIndex, send);
RW(worldObject.mpNum, send);
RW(worldObject.doorState, send);
if (!send)
{
event->worldObjects.push_back(worldObject);
}
}
WorldPacket::Object(worldObject, send);
RW(worldObject.doorState, send);
}

@ -10,7 +10,7 @@ namespace mwmp
public:
PacketDoorState(RakNet::RakPeerInterface *peer);
virtual void Packet(RakNet::BitStream *bs, bool send);
virtual void Object(WorldObject &worldObject, bool send);
};
}

@ -8,37 +8,7 @@ PacketMusicPlay::PacketMusicPlay(RakNet::RakPeerInterface *peer) : WorldPacket(p
packetID = ID_MUSIC_PLAY;
}
void PacketMusicPlay::Packet(RakNet::BitStream *bs, bool send)
void PacketMusicPlay::Object(WorldObject &worldObject, bool send)
{
WorldPacket::Packet(bs, send);
if (send)
event->worldObjectCount = (unsigned int)(event->worldObjects.size());
else
event->worldObjects.clear();
RW(event->worldObjectCount, send);
if (event->worldObjectCount > maxObjects)
{
event->isValid = false;
return;
}
WorldObject worldObject;
for (unsigned int i = 0; i < event->worldObjectCount; i++)
{
if (send)
{
worldObject = event->worldObjects.at(i);
}
RW(worldObject.filename, send);
if (!send)
{
event->worldObjects.push_back(worldObject);
}
}
RW(worldObject.filename, send);
}

@ -10,7 +10,7 @@ namespace mwmp
public:
PacketMusicPlay(RakNet::RakPeerInterface *peer);
virtual void Packet(RakNet::BitStream *bs, bool send);
virtual void Object(WorldObject &worldObject, bool send);
};
}

@ -6,48 +6,12 @@ using namespace mwmp;
PacketObjectAnimPlay::PacketObjectAnimPlay(RakNet::RakPeerInterface *peer) : WorldPacket(peer)
{
packetID = ID_OBJECT_ANIM_PLAY;
hasCellData = true;
}
void PacketObjectAnimPlay::Packet(RakNet::BitStream *bs, bool send)
void PacketObjectAnimPlay::Object(WorldObject &worldObject, bool send)
{
WorldPacket::Packet(bs, send);
if (send)
event->worldObjectCount = (unsigned int)(event->worldObjects.size());
else
event->worldObjects.clear();
RW(event->worldObjectCount, send);
if (event->worldObjectCount > maxObjects)
{
event->isValid = false;
return;
}
RW(event->cell.mData.mFlags, send);
RW(event->cell.mData.mX, send);
RW(event->cell.mData.mY, send);
RW(event->cell.mName, send);
WorldObject worldObject;
for (unsigned int i = 0; i < event->worldObjectCount; i++)
{
if (send)
{
worldObject = event->worldObjects.at(i);
}
RW(worldObject.refId, send);
RW(worldObject.refNumIndex, send);
RW(worldObject.mpNum, send);
RW(worldObject.animGroup, send);
RW(worldObject.animMode, send);
if (!send)
{
event->worldObjects.push_back(worldObject);
}
}
WorldPacket::Object(worldObject, send);
RW(worldObject.animGroup, send);
RW(worldObject.animMode, send);
}

@ -10,7 +10,7 @@ namespace mwmp
public:
PacketObjectAnimPlay(RakNet::RakPeerInterface *peer);
virtual void Packet(RakNet::BitStream *bs, bool send);
virtual void Object(WorldObject &worldObject, bool send);
};
}

@ -6,46 +6,5 @@ using namespace mwmp;
PacketObjectDelete::PacketObjectDelete(RakNet::RakPeerInterface *peer) : WorldPacket(peer)
{
packetID = ID_OBJECT_DELETE;
}
void PacketObjectDelete::Packet(RakNet::BitStream *bs, bool send)
{
WorldPacket::Packet(bs, send);
if (send)
event->worldObjectCount = (unsigned int)(event->worldObjects.size());
else
event->worldObjects.clear();
RW(event->worldObjectCount, send);
if (event->worldObjectCount > maxObjects)
{
event->isValid = false;
return;
}
RW(event->cell.mData.mFlags, send);
RW(event->cell.mData.mX, send);
RW(event->cell.mData.mY, send);
RW(event->cell.mName, send);
WorldObject worldObject;
for (unsigned int i = 0; i < event->worldObjectCount; i++)
{
if (send)
{
worldObject = event->worldObjects.at(i);
}
RW(worldObject.refId, send);
RW(worldObject.refNumIndex, send);
RW(worldObject.mpNum, send);
if (!send)
{
event->worldObjects.push_back(worldObject);
}
}
hasCellData = true;
}

@ -9,8 +9,6 @@ namespace mwmp
{
public:
PacketObjectDelete(RakNet::RakPeerInterface *peer);
virtual void Packet(RakNet::BitStream *bs, bool send);
};
}

@ -8,45 +8,8 @@ PacketObjectLock::PacketObjectLock(RakNet::RakPeerInterface *peer) : WorldPacket
packetID = ID_OBJECT_LOCK;
}
void PacketObjectLock::Packet(RakNet::BitStream *bs, bool send)
void PacketObjectLock::Object(WorldObject &worldObject, bool send)
{
WorldPacket::Packet(bs, send);
if (send)
event->worldObjectCount = (unsigned int)(event->worldObjects.size());
else
event->worldObjects.clear();
RW(event->worldObjectCount, send);
if (event->worldObjectCount > maxObjects)
{
event->isValid = false;
return;
}
RW(event->cell.mData.mFlags, send);
RW(event->cell.mData.mX, send);
RW(event->cell.mData.mY, send);
RW(event->cell.mName, send);
WorldObject worldObject;
for (unsigned int i = 0; i < event->worldObjectCount; i++)
{
if (send)
{
worldObject = event->worldObjects.at(i);
}
RW(worldObject.refId, send);
RW(worldObject.refNumIndex, send);
RW(worldObject.mpNum, send);
RW(worldObject.lockLevel, send);
if (!send)
{
event->worldObjects.push_back(worldObject);
}
}
WorldPacket::Object(worldObject, send);
RW(worldObject.lockLevel, send);
}

@ -10,7 +10,7 @@ namespace mwmp
public:
PacketObjectLock(RakNet::RakPeerInterface *peer);
virtual void Packet(RakNet::BitStream *bs, bool send);
virtual void Object(WorldObject &worldObject, bool send);
};
}

@ -6,49 +6,11 @@ using namespace mwmp;
PacketObjectMove::PacketObjectMove(RakNet::RakPeerInterface *peer) : WorldPacket(peer)
{
packetID = ID_OBJECT_MOVE;
hasCellData = true;
}
void PacketObjectMove::Packet(RakNet::BitStream *bs, bool send)
void PacketObjectMove::Object(WorldObject &worldObject, bool send)
{
WorldPacket::Packet(bs, send);
if (send)
event->worldObjectCount = (unsigned int)(event->worldObjects.size());
else
event->worldObjects.clear();
RW(event->worldObjectCount, send);
if (event->worldObjectCount > maxObjects)
{
event->isValid = false;
return;
}
RW(event->cell.mData.mFlags, send);
RW(event->cell.mData.mX, send);
RW(event->cell.mData.mY, send);
RW(event->cell.mName, send);
WorldObject worldObject;
for (unsigned int i = 0; i < event->worldObjectCount; i++)
{
if (send)
{
worldObject = event->worldObjects.at(i);
}
RW(worldObject.refId, send);
RW(worldObject.refNumIndex, send);
RW(worldObject.mpNum, send);
RW(worldObject.position.pos[0], send);
RW(worldObject.position.pos[1], send);
RW(worldObject.position.pos[2], send);
if (!send)
{
event->worldObjects.push_back(worldObject);
}
}
WorldPacket::Object(worldObject, send);
RW(worldObject.position.pos, send);
}

@ -10,7 +10,7 @@ namespace mwmp
public:
PacketObjectMove(RakNet::RakPeerInterface *peer);
virtual void Packet(RakNet::BitStream *bs, bool send);
virtual void Object(WorldObject &worldObject, bool send);
};
}

@ -6,50 +6,14 @@ using namespace mwmp;
PacketObjectPlace::PacketObjectPlace(RakNet::RakPeerInterface *peer) : WorldPacket(peer)
{
packetID = ID_OBJECT_PLACE;
hasCellData = true;
}
void PacketObjectPlace::Packet(RakNet::BitStream *bs, bool send)
void PacketObjectPlace::Object(WorldObject &worldObject, bool send)
{
WorldPacket::Packet(bs, send);
if (send)
event->worldObjectCount = (unsigned int)(event->worldObjects.size());
else
event->worldObjects.clear();
RW(event->worldObjectCount, send);
if (event->worldObjectCount > maxObjects)
{
event->isValid = false;
return;
}
RW(event->cell.mData.mFlags, send);
RW(event->cell.mData.mX, send);
RW(event->cell.mData.mY, send);
RW(event->cell.mName, send);
WorldObject worldObject;
for (unsigned int i = 0; i < event->worldObjectCount; i++)
{
if (send)
{
worldObject = event->worldObjects.at(i);
}
RW(worldObject.refId, send);
RW(worldObject.refNumIndex, send);
RW(worldObject.mpNum, send);
RW(worldObject.count, send);
RW(worldObject.charge, send);
RW(worldObject.goldValue, send);
RW(worldObject.position, send);
if (!send)
{
event->worldObjects.push_back(worldObject);
}
}
WorldPacket::Object(worldObject, send);
RW(worldObject.count, send);
RW(worldObject.charge, send);
RW(worldObject.goldValue, send);
RW(worldObject.position, send);
}

@ -10,7 +10,7 @@ namespace mwmp
public:
PacketObjectPlace(RakNet::RakPeerInterface *peer);
virtual void Packet(RakNet::BitStream *bs, bool send);
virtual void Object(WorldObject &worldObject, bool send);
};
}

@ -6,49 +6,13 @@ using namespace mwmp;
PacketObjectRotate::PacketObjectRotate(RakNet::RakPeerInterface *peer) : WorldPacket(peer)
{
packetID = ID_OBJECT_ROTATE;
hasCellData = true;
}
void PacketObjectRotate::Packet(RakNet::BitStream *bs, bool send)
void PacketObjectRotate::Object(WorldObject &worldObject, bool send)
{
WorldPacket::Packet(bs, send);
if (send)
event->worldObjectCount = (unsigned int)(event->worldObjects.size());
else
event->worldObjects.clear();
RW(event->worldObjectCount, send);
if (event->worldObjectCount > maxObjects)
{
event->isValid = false;
return;
}
RW(event->cell.mData.mFlags, send);
RW(event->cell.mData.mX, send);
RW(event->cell.mData.mY, send);
RW(event->cell.mName, send);
WorldObject worldObject;
for (unsigned int i = 0; i < event->worldObjectCount; i++)
{
if (send)
{
worldObject = event->worldObjects.at(i);
}
RW(worldObject.refId, send);
RW(worldObject.refNumIndex, send);
RW(worldObject.mpNum, send);
RW(worldObject.position.rot[0], send);
RW(worldObject.position.rot[1], send);
RW(worldObject.position.rot[2], send);
if (!send)
{
event->worldObjects.push_back(worldObject);
}
}
WorldPacket::Object(worldObject, send);
RW(worldObject.position.rot[0], send);
RW(worldObject.position.rot[1], send);
RW(worldObject.position.rot[2], send);
}

@ -10,7 +10,7 @@ namespace mwmp
public:
PacketObjectRotate(RakNet::RakPeerInterface *peer);
virtual void Packet(RakNet::BitStream *bs, bool send);
virtual void Object(WorldObject &worldObject, bool send);
};
}

@ -6,47 +6,11 @@ using namespace mwmp;
PacketObjectScale::PacketObjectScale(RakNet::RakPeerInterface *peer) : WorldPacket(peer)
{
packetID = ID_OBJECT_SCALE;
hasCellData = true;
}
void PacketObjectScale::Packet(RakNet::BitStream *bs, bool send)
void PacketObjectScale::Object(WorldObject &worldObject, bool send)
{
WorldPacket::Packet(bs, send);
if (send)
event->worldObjectCount = (unsigned int)(event->worldObjects.size());
else
event->worldObjects.clear();
RW(event->worldObjectCount, send);
if (event->worldObjectCount > maxObjects)
{
event->isValid = false;
return;
}
RW(event->cell.mData.mFlags, send);
RW(event->cell.mData.mX, send);
RW(event->cell.mData.mY, send);
RW(event->cell.mName, send);
WorldObject worldObject;
for (unsigned int i = 0; i < event->worldObjectCount; i++)
{
if (send)
{
worldObject = event->worldObjects.at(i);
}
RW(worldObject.refId, send);
RW(worldObject.refNumIndex, send);
RW(worldObject.mpNum, send);
RW(worldObject.scale, send);
if (!send)
{
event->worldObjects.push_back(worldObject);
}
}
WorldPacket::Object(worldObject, send);
RW(worldObject.scale, send);
}

@ -10,7 +10,7 @@ namespace mwmp
public:
PacketObjectScale(RakNet::RakPeerInterface *peer);
virtual void Packet(RakNet::BitStream *bs, bool send);
virtual void Object(WorldObject &worldObject, bool send);
};
}

@ -6,56 +6,20 @@ using namespace mwmp;
PacketObjectSpawn::PacketObjectSpawn(RakNet::RakPeerInterface *peer) : WorldPacket(peer)
{
packetID = ID_OBJECT_SPAWN;
hasCellData = true;
}
void PacketObjectSpawn::Packet(RakNet::BitStream *bs, bool send)
void PacketObjectSpawn::Object(WorldObject &worldObject, bool send)
{
WorldPacket::Packet(bs, send);
WorldPacket::Object(worldObject, send);
RW(worldObject.position, send);
if (send)
event->worldObjectCount = (unsigned int)(event->worldObjects.size());
else
event->worldObjects.clear();
RW(worldObject.hasMaster, send);
RW(event->worldObjectCount, send);
if (event->worldObjectCount > maxObjects)
if (worldObject.hasMaster)
{
event->isValid = false;
return;
}
RW(event->cell.mData.mFlags, send);
RW(event->cell.mData.mX, send);
RW(event->cell.mData.mY, send);
RW(event->cell.mName, send);
WorldObject worldObject;
for (unsigned int i = 0; i < event->worldObjectCount; i++)
{
if (send)
{
worldObject = event->worldObjects.at(i);
}
RW(worldObject.refId, send);
RW(worldObject.refNumIndex, send);
RW(worldObject.mpNum, send);
RW(worldObject.position, send);
RW(worldObject.hasMaster, send);
if (worldObject.hasMaster)
{
RW(worldObject.master.refNumIndex, send);
RW(worldObject.master.mpNum, send);
RW(worldObject.master.guid, send);
}
if (!send)
{
event->worldObjects.push_back(worldObject);
}
RW(worldObject.master.refNumIndex, send);
RW(worldObject.master.mpNum, send);
RW(worldObject.master.guid, send);
}
}

@ -10,7 +10,7 @@ namespace mwmp
public:
PacketObjectSpawn(RakNet::RakPeerInterface *peer);
virtual void Packet(RakNet::BitStream *bs, bool send);
virtual void Object(WorldObject &worldObject, bool send);
};
}

@ -6,50 +6,14 @@ using namespace mwmp;
PacketObjectTrap::PacketObjectTrap(RakNet::RakPeerInterface *peer) : WorldPacket(peer)
{
packetID = ID_OBJECT_TRAP;
hasCellData = true;
}
void PacketObjectTrap::Packet(RakNet::BitStream *bs, bool send)
void PacketObjectTrap::Object(WorldObject &worldObject, bool send)
{
WorldPacket::Packet(bs, send);
WorldPacket::Object(worldObject, send);
RW(worldObject.isDisarmed, send);
if (send)
event->worldObjectCount = (unsigned int)(event->worldObjects.size());
else
event->worldObjects.clear();
RW(event->worldObjectCount, send);
if (event->worldObjectCount > maxObjects)
{
event->isValid = false;
return;
}
RW(event->cell.mData.mFlags, send);
RW(event->cell.mData.mX, send);
RW(event->cell.mData.mY, send);
RW(event->cell.mName, send);
WorldObject worldObject;
for (unsigned int i = 0; i < event->worldObjectCount; i++)
{
if (send)
{
worldObject = event->worldObjects.at(i);
}
RW(worldObject.refId, send);
RW(worldObject.refNumIndex, send);
RW(worldObject.mpNum, send);
RW(worldObject.isDisarmed, send);
if (!worldObject.isDisarmed)
RW(worldObject.position, send);
if (!send)
{
event->worldObjects.push_back(worldObject);
}
}
if (!worldObject.isDisarmed)
RW(worldObject.position, send);
}

@ -10,7 +10,7 @@ namespace mwmp
public:
PacketObjectTrap(RakNet::RakPeerInterface *peer);
virtual void Packet(RakNet::BitStream *bs, bool send);
virtual void Object(WorldObject &worldObject, bool send);
};
}

@ -8,38 +8,8 @@ PacketScriptGlobalShort::PacketScriptGlobalShort(RakNet::RakPeerInterface *peer)
packetID = ID_SCRIPT_GLOBAL_SHORT;
}
void PacketScriptGlobalShort::Packet(RakNet::BitStream *bs, bool send)
void PacketScriptGlobalShort::Object(WorldObject &worldObject, bool send)
{
WorldPacket::Packet(bs, send);
if (send)
event->worldObjectCount = (unsigned int)(event->worldObjects.size());
else
event->worldObjects.clear();
RW(event->worldObjectCount, send);
if (event->worldObjectCount > maxObjects)
{
event->isValid = false;
return;
}
WorldObject worldObject;
for (unsigned int i = 0; i < event->worldObjectCount; i++)
{
if (send)
{
worldObject = event->worldObjects.at(i);
}
RW(worldObject.varName, send);
RW(worldObject.shortVal, send);
if (!send)
{
event->worldObjects.push_back(worldObject);
}
}
RW(worldObject.varName, send);
RW(worldObject.shortVal, send);
}

@ -10,7 +10,7 @@ namespace mwmp
public:
PacketScriptGlobalShort(RakNet::RakPeerInterface *peer);
virtual void Packet(RakNet::BitStream *bs, bool send);
virtual void Object(WorldObject &worldObject, bool send);
};
}

@ -6,48 +6,12 @@ using namespace mwmp;
PacketScriptLocalFloat::PacketScriptLocalFloat(RakNet::RakPeerInterface *peer) : WorldPacket(peer)
{
packetID = ID_SCRIPT_LOCAL_FLOAT;
hasCellData = true;
}
void PacketScriptLocalFloat::Packet(RakNet::BitStream *bs, bool send)
void PacketScriptLocalFloat::Object(WorldObject &worldObject, bool send)
{
WorldPacket::Packet(bs, send);
if (send)
event->worldObjectCount = (unsigned int)(event->worldObjects.size());
else
event->worldObjects.clear();
RW(event->worldObjectCount, send);
if (event->worldObjectCount > maxObjects)
{
event->isValid = false;
return;
}
RW(event->cell.mData.mFlags, send);
RW(event->cell.mData.mX, send);
RW(event->cell.mData.mY, send);
RW(event->cell.mName, send);
WorldObject worldObject;
for (unsigned int i = 0; i < event->worldObjectCount; i++)
{
if (send)
{
worldObject = event->worldObjects.at(i);
}
RW(worldObject.refId, send);
RW(worldObject.refNumIndex, send);
RW(worldObject.mpNum, send);
RW(worldObject.index, send);
RW(worldObject.floatVal, send);
if (!send)
{
event->worldObjects.push_back(worldObject);
}
}
WorldPacket::Object(worldObject, send);
RW(worldObject.index, send);
RW(worldObject.floatVal, send);
}

@ -10,7 +10,7 @@ namespace mwmp
public:
PacketScriptLocalFloat(RakNet::RakPeerInterface *peer);
virtual void Packet(RakNet::BitStream *bs, bool send);
virtual void Object(WorldObject &worldObject, bool send);
};
}

@ -6,48 +6,12 @@ using namespace mwmp;
PacketScriptLocalShort::PacketScriptLocalShort(RakNet::RakPeerInterface *peer) : WorldPacket(peer)
{
packetID = ID_SCRIPT_LOCAL_SHORT;
hasCellData = true;
}
void PacketScriptLocalShort::Packet(RakNet::BitStream *bs, bool send)
void PacketScriptLocalShort::Object(WorldObject &worldObject, bool send)
{
WorldPacket::Packet(bs, send);
if (send)
event->worldObjectCount = (unsigned int)(event->worldObjects.size());
else
event->worldObjects.clear();
RW(event->worldObjectCount, send);
if (event->worldObjectCount > maxObjects)
{
event->isValid = false;
return;
}
RW(event->cell.mData.mFlags, send);
RW(event->cell.mData.mX, send);
RW(event->cell.mData.mY, send);
RW(event->cell.mName, send);
WorldObject worldObject;
for (unsigned int i = 0; i < event->worldObjectCount; i++)
{
if (send)
{
worldObject = event->worldObjects.at(i);
}
RW(worldObject.refId, send);
RW(worldObject.refNumIndex, send);
RW(worldObject.mpNum, send);
RW(worldObject.index, send);
RW(worldObject.shortVal, send);
if (!send)
{
event->worldObjects.push_back(worldObject);
}
}
WorldPacket::Object(worldObject, send);
RW(worldObject.index, send);
RW(worldObject.shortVal, send);
}

@ -10,7 +10,7 @@ namespace mwmp
public:
PacketScriptLocalShort(RakNet::RakPeerInterface *peer);
virtual void Packet(RakNet::BitStream *bs, bool send);
virtual void Object(WorldObject &obj, bool send);
};
}

@ -8,39 +8,9 @@ PacketScriptMemberShort::PacketScriptMemberShort(RakNet::RakPeerInterface *peer)
packetID = ID_SCRIPT_MEMBER_SHORT;
}
void PacketScriptMemberShort::Packet(RakNet::BitStream *bs, bool send)
void PacketScriptMemberShort::Object(WorldObject &worldObject, bool send)
{
WorldPacket::Packet(bs, send);
if (send)
event->worldObjectCount = (unsigned int)(event->worldObjects.size());
else
event->worldObjects.clear();
RW(event->worldObjectCount, send);
if (event->worldObjectCount > maxObjects)
{
event->isValid = false;
return;
}
WorldObject worldObject;
for (unsigned int i = 0; i < event->worldObjectCount; i++)
{
if (send)
{
worldObject = event->worldObjects.at(i);
}
RW(worldObject.refId, send);
RW(worldObject.index, send);
RW(worldObject.shortVal, send);
if (!send)
{
event->worldObjects.push_back(worldObject);
}
}
RW(worldObject.refId, send);
RW(worldObject.index, send);
RW(worldObject.shortVal, send);
}

@ -10,7 +10,7 @@ namespace mwmp
public:
PacketScriptMemberShort(RakNet::RakPeerInterface *peer);
virtual void Packet(RakNet::BitStream *bs, bool send);
virtual void Object(WorldObject &obj, bool send);
};
}

@ -8,38 +8,8 @@ PacketVideoPlay::PacketVideoPlay(RakNet::RakPeerInterface *peer) : WorldPacket(p
packetID = ID_VIDEO_PLAY;
}
void PacketVideoPlay::Packet(RakNet::BitStream *bs, bool send)
void PacketVideoPlay::Object(WorldObject &worldObject, bool send)
{
WorldPacket::Packet(bs, send);
if (send)
event->worldObjectCount = (unsigned int)(event->worldObjects.size());
else
event->worldObjects.clear();
RW(event->worldObjectCount, send);
if (event->worldObjectCount > maxObjects)
{
event->isValid = false;
return;
}
WorldObject worldObject;
for (unsigned int i = 0; i < event->worldObjectCount; i++)
{
if (send)
{
worldObject = event->worldObjects.at(i);
}
RW(worldObject.filename, send);
RW(worldObject.allowSkipping, send);
if (!send)
{
event->worldObjects.push_back(worldObject);
}
}
RW(worldObject.filename, send);
RW(worldObject.allowSkipping, send);
}

@ -10,7 +10,7 @@ namespace mwmp
public:
PacketVideoPlay(RakNet::RakPeerInterface *peer);
virtual void Packet(RakNet::BitStream *bs, bool send);
virtual void Object(WorldObject &obj, bool send);
};
}

@ -7,6 +7,7 @@ using namespace mwmp;
WorldPacket::WorldPacket(RakNet::RakPeerInterface *peer) : BasePacket(peer)
{
hasCellData = false;
packetID = 0;
priority = HIGH_PRIORITY;
reliability = RELIABLE_ORDERED;
@ -24,3 +25,53 @@ void WorldPacket::setEvent(BaseEvent *event)
this->event = event;
guid = event->guid;
}
void WorldPacket::Packet(RakNet::BitStream *bs, bool send)
{
if(!PacketHeader(bs, send))
return;
WorldObject worldObject;
for (unsigned int i = 0; i < event->worldObjectCount; i++)
{
if (send)
worldObject = event->worldObjects.at(i);
Object(worldObject, send);
if (!send)
event->worldObjects.push_back(worldObject);
}
}
bool WorldPacket::PacketHeader(RakNet::BitStream *bs, bool send)
{
BasePacket::Packet(bs, send);
if (send)
event->worldObjectCount = (unsigned int)(event->worldObjects.size());
else
event->worldObjects.clear();
RW(event->worldObjectCount, send);
if (event->worldObjectCount > maxObjects)
{
event->isValid = false;
return false;
}
if(hasCellData)
{
RW(event->cell.mData, send, 1);
RW(event->cell.mName, send, 1);
}
return true;
}
void WorldPacket::Object(WorldObject &worldObject, bool send)
{
RW(worldObject.refId, send);
RW(worldObject.refNumIndex, send);
RW(worldObject.mpNum, send);
}

@ -21,9 +21,14 @@ namespace mwmp
void setEvent(BaseEvent *event);
virtual void Packet(RakNet::BitStream *bs, bool send);
protected:
virtual void Object(WorldObject &worldObject, bool send);
bool PacketHeader(RakNet::BitStream *bs, bool send);
BaseEvent *event;
static const int maxObjects = 3000;
bool hasCellData;
};
}

Loading…
Cancel
Save