Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use PacketList directly when sending #6831

Merged
merged 1 commit into from
Jan 25, 2025

Conversation

cocosolos
Copy link
Contributor

I affirm:

  • I understand that if I do not agree to the following points by completing the checkboxes my PR will be ignored.
  • I understand I should leave resolving conversations to the LandSandBoat team so that reviewers won't miss what was said.
  • I have read and understood the Contributing Guide and the Code of Conduct.
  • I have tested my code and the things my code has changed since the last commit in the PR and will test after any later commits.

What does this pull request do?

Couple edge case fixes if a pending packet ends up being null. Mainly though this makes it so we use the PacketList directly when preparing packets to send instead of making a copy and using that. We currently make a copy of the packet list, process those copies, then delete the real packets. This apparently causes some sync issues (#6829) that should be fixed now.

I'm not sure why exactly this issue seems to be consistent, so this may require some further review, but this seems to fix it.

Steps to test these changes

Log in with 2 characters, go to the same zone, both characters can see each other.

Copy link
Contributor

@zach2good zach2good left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logically seems fine, I'd just like it to be made as clear and obvious about what's going on at every step as possible

@@ -439,40 +439,34 @@ void CCharEntity::pushPacket(std::unique_ptr<CBasicPacket>&& packet)
void CCharEntity::updateCharPacket(CCharEntity* PChar, ENTITYUPDATE type, uint8 updatemask)
{
auto existing = PendingCharPackets.find(PChar->id);
if (existing == PendingCharPackets.end())
if (existing == PendingCharPackets.end() || !existing->second)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find this logical block quite hard to reason about, can you break these up even if it ends up with nested conditions?

I think it would also help to rename existing to itr, and break out conditions like:

const bool hasPendingPacket = itr != PendingCharPackets.end();

and to not use the itr pair directly, but to use:

auto& pendingPacket = existing->second;
pendingPacket ->updateWith...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the logic here, hopefully more clear.

@@ -542,8 +541,7 @@ class CCharEntity : public CBattleEntity

CItemEquipment* getEquip(SLOTTYPE slot);

// TODO: Don't use raw ptrs for this, but don't duplicate whole packets with unique_ptr either.
CBasicPacket* PendingPositionPacket = nullptr;
std::deque<std::unique_ptr<CBasicPacket>> PacketList; // The list of packets to be sent to the character during the next network cycle
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of making this public, can you keep it private and access it with: auto getPacketList() -> std::deque<std::unique_ptr<CBasicPacket>>&

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, made it const too.

src/map/map.cpp Outdated

while (!packetList.empty() && *buffsize + packetList.front()->getSize() < MAX_BUFFER_SIZE && static_cast<size_t>(packets) < PacketCount)
while (!PChar->PacketList.empty() && *buffsize + PChar->PacketList.front()->getSize() < MAX_BUFFER_SIZE && static_cast<size_t>(packets) < PacketCount)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isPacketListEmpty

@zach2good zach2good merged commit 6204a23 into LandSandBoat:base Jan 25, 2025
13 checks passed
@cocosolos cocosolos deleted the packetlist branch January 25, 2025 14:53
@BoundingS
Copy link

This seems to cause a very game breaking bug if items get out of sync between mog house and player inventory, gil etc. Would you take a look at the issue I posted and see what you think?

@zach2good
Copy link
Contributor

Please stop commenting on closed PRs, it's very hard for us to track. Open new issues and link prs you want to talk about

@cocosolos cocosolos mentioned this pull request Jan 26, 2025
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants