forked from mirror/openmw-tes3mp
[General] Minor cleanup of the World Packets
This commit is contained in:
parent
744b8cf168
commit
1841562553
4 changed files with 22 additions and 31 deletions
|
@ -58,7 +58,7 @@ mwmp::WorldPacketController::WorldPacketController(RakNet::RakPeerInterface *pee
|
||||||
|
|
||||||
mwmp::WorldPacket *mwmp::WorldPacketController::GetPacket(RakNet::MessageID id)
|
mwmp::WorldPacket *mwmp::WorldPacketController::GetPacket(RakNet::MessageID id)
|
||||||
{
|
{
|
||||||
return packets[(unsigned char)id].get();
|
return packets[(RakNet::MessageID)id].get();
|
||||||
}
|
}
|
||||||
|
|
||||||
void mwmp::WorldPacketController::SetStream(RakNet::BitStream *inStream, RakNet::BitStream *outStream)
|
void mwmp::WorldPacketController::SetStream(RakNet::BitStream *inStream, RakNet::BitStream *outStream)
|
||||||
|
|
|
@ -18,7 +18,7 @@ namespace mwmp
|
||||||
|
|
||||||
bool ContainsPacket(RakNet::MessageID id);
|
bool ContainsPacket(RakNet::MessageID id);
|
||||||
|
|
||||||
typedef std::unordered_map<unsigned char, std::unique_ptr<WorldPacket> > packets_t;
|
typedef std::unordered_map<RakNet::MessageID, std::unique_ptr<WorldPacket> > packets_t;
|
||||||
private:
|
private:
|
||||||
packets_t packets;
|
packets_t packets;
|
||||||
};
|
};
|
||||||
|
|
|
@ -17,43 +17,36 @@ void PacketContainer::Packet(RakNet::BitStream *bs, bool send)
|
||||||
|
|
||||||
RW(event->action, send);
|
RW(event->action, send);
|
||||||
|
|
||||||
WorldObject worldObject;
|
for (auto &&worldObject : event->worldObjects)
|
||||||
for (unsigned int i = 0; i < event->worldObjectCount; i++)
|
|
||||||
{
|
{
|
||||||
|
Object(worldObject, send);
|
||||||
|
|
||||||
if (send)
|
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();
|
|
||||||
|
|
||||||
Object(worldObject, send);
|
|
||||||
|
|
||||||
RW(worldObject.containerItemCount, send);
|
RW(worldObject.containerItemCount, send);
|
||||||
|
|
||||||
if (worldObject.containerItemCount > maxObjects || worldObject.refId.empty() || (worldObject.refNumIndex != 0 && worldObject.mpNum != 0))
|
if(!send)
|
||||||
|
{
|
||||||
|
worldObject.containerItems.clear();
|
||||||
|
worldObject.containerItems.resize(worldObject.containerItemCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (worldObject.containerItemCount > maxObjects || worldObject.refId.empty()
|
||||||
|
|| (worldObject.refNumIndex != 0 && worldObject.mpNum != 0))
|
||||||
{
|
{
|
||||||
event->isValid = false;
|
event->isValid = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ContainerItem containerItem;
|
for(auto &&containerItem: worldObject.containerItems)
|
||||||
|
|
||||||
for (unsigned int j = 0; j < worldObject.containerItemCount; j++)
|
|
||||||
{
|
{
|
||||||
if (send)
|
|
||||||
containerItem = worldObject.containerItems.at(j);
|
|
||||||
|
|
||||||
RW(containerItem.refId, send);
|
RW(containerItem.refId, send);
|
||||||
RW(containerItem.count, send);
|
RW(containerItem.count, send);
|
||||||
RW(containerItem.charge, send);
|
RW(containerItem.charge, send);
|
||||||
RW(containerItem.actionCount, send);
|
RW(containerItem.actionCount, send);
|
||||||
|
}
|
||||||
if (!send)
|
|
||||||
worldObject.containerItems.push_back(containerItem);
|
|
||||||
}
|
|
||||||
if (!send)
|
|
||||||
event->worldObjects.push_back(worldObject);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,16 +31,9 @@ void WorldPacket::Packet(RakNet::BitStream *bs, bool send)
|
||||||
if (!PacketHeader(bs, send))
|
if (!PacketHeader(bs, send))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
WorldObject worldObject;
|
for (auto &&worldObject : event->worldObjects)
|
||||||
for (unsigned int i = 0; i < event->worldObjectCount; i++)
|
|
||||||
{
|
{
|
||||||
if (send)
|
|
||||||
worldObject = event->worldObjects.at(i);
|
|
||||||
|
|
||||||
Object(worldObject, send);
|
Object(worldObject, send);
|
||||||
|
|
||||||
if (!send)
|
|
||||||
event->worldObjects.push_back(worldObject);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,10 +54,15 @@ bool WorldPacket::PacketHeader(RakNet::BitStream *bs, bool send)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!send)
|
||||||
|
{
|
||||||
|
event->worldObjects.resize(event->worldObjectCount);
|
||||||
|
}
|
||||||
|
|
||||||
if (hasCellData)
|
if (hasCellData)
|
||||||
{
|
{
|
||||||
RW(event->cell.mData, send, 1);
|
RW(event->cell.mData, send, true);
|
||||||
RW(event->cell.mName, send, 1);
|
RW(event->cell.mName, send, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Reference in a new issue