Skip to content

Commit

Permalink
Merge pull request #6848 from cocosolos/packetlistrollback
Browse files Browse the repository at this point in the history
Packet handling fixes
  • Loading branch information
zach2good authored Jan 26, 2025
2 parents 0d90318 + d1f3326 commit e6e34bb
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 7 deletions.
10 changes: 10 additions & 0 deletions src/map/entities/charentity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,16 @@ auto CCharEntity::getPacketList() const -> const std::deque<std::unique_ptr<CBas
return PacketList;
}

auto CCharEntity::getPacketListCopy() -> std::deque<std::unique_ptr<CBasicPacket>>
{
std::deque<std::unique_ptr<CBasicPacket>> PacketListCopy;
for (const auto& packet : PacketList)
{
PacketListCopy.emplace_back(std::make_unique<CBasicPacket>(packet));
}
return PacketListCopy;
}

void CCharEntity::clearPacketList()
{
while (!PacketList.empty())
Expand Down
1 change: 1 addition & 0 deletions src/map/entities/charentity.h
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@ class CCharEntity : public CBattleEntity
uint8 GetGender();

auto getPacketList() const -> const std::deque<std::unique_ptr<CBasicPacket>>&;
auto getPacketListCopy() -> std::deque<std::unique_ptr<CBasicPacket>>; // Return a COPY of packet list
void clearPacketList();

template <typename T, typename... Args>
Expand Down
12 changes: 7 additions & 5 deletions src/map/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1049,13 +1049,14 @@ int32 send_parse(int8* buff, size_t* buffsize, sockaddr_in* from, map_session_da
{
do
{
*buffsize = FFXI_HEADER_SIZE;
auto& packetList = PChar->getPacketList();
packets = 0;
*buffsize = FFXI_HEADER_SIZE;
auto packetList = PChar->getPacketListCopy();
packets = 0;

while (!PChar->isPacketListEmpty() && *buffsize + packetList.front()->getSize() < MAX_BUFFER_SIZE && static_cast<size_t>(packets) < PacketCount)
while (!packetList.empty() && *buffsize + packetList.front()->getSize() < MAX_BUFFER_SIZE && static_cast<size_t>(packets) < PacketCount)
{
PSmallPacket = PChar->popPacket();
PSmallPacket = std::move(packetList.front());
packetList.pop_front();

PSmallPacket->setSequence(map_session_data->server_packet_id);
auto type = PSmallPacket->getType();
Expand Down Expand Up @@ -1130,6 +1131,7 @@ int32 send_parse(int8* buff, size_t* buffsize, sockaddr_in* from, map_session_da
}
}
} while (PacketSize == static_cast<uint32>(-1));
PChar->erasePackets(packets);
TotalPacketsSentPerTick += packets;
TracyZoneString(fmt::format("Sending {} packets", packets));

Expand Down
2 changes: 1 addition & 1 deletion src/map/packet_guard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ namespace PacketGuard
{
// Count packets in queue
std::map<std::string, uint32> packetCounterMap;
for (auto& entry : PChar->getPacketList())
for (auto& entry : PChar->getPacketListCopy())
{
auto packetStr = fmt::format("0x{:4X}", entry->getType());
packetCounterMap[packetStr]++;
Expand Down
2 changes: 1 addition & 1 deletion src/map/zone_entities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ void CZoneEntities::TryAddToNearbySpawnLists(CBaseEntity* PEntity)
case TYPE_PC:
{
PCurrentChar->SpawnPCList[PEntity->id] = PEntity;
PCurrentChar->updateEntityPacket(PEntity, ENTITY_SPAWN, UPDATE_ALL_CHAR);
PCurrentChar->updateCharPacket(static_cast<CCharEntity*>(PEntity), ENTITY_SPAWN, UPDATE_ALL_CHAR);
break;
}
case TYPE_NPC:
Expand Down

0 comments on commit e6e34bb

Please sign in to comment.