Skip to content

Remove PChar from zone on force logout#7459

Merged
zach2good merged 1 commit intoLandSandBoat:basefrom
sruon:send_disconnect
Apr 20, 2025
Merged

Remove PChar from zone on force logout#7459
zach2good merged 1 commit intoLandSandBoat:basefrom
sruon:send_disconnect

Conversation

@sruon
Copy link
Copy Markdown
Contributor

@sruon sruon commented Apr 19, 2025

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?

Steps to reproduce:

  • Logout as GM
  • Watch logs and see DecreaseZoneCounter is not triggered
  • See the session hangs until the cleanup task runs

This change ensures we remove the PChar from their zone when going through any ForceLogout call, such as when GMs logout.

// FIXME: Two GM level checks? visibleGmLevel is the GM level visible to other players, and m_GMLevel is the alway-invisible GM level.
if (PChar->m_moghouseID || PChar->visibleGmLevel >= 3 || PChar->m_GMlevel > 0)
{
charutils::ForceLogout(PChar);
}

Before #7243, removeCharFromZone was always called (when everything was going through SendToZone), this merely reintroduces parity.

void SendToZone(CCharEntity* PChar, ZoningType type, uint64 ipp)
{
TracyZoneScoped;
if (type == ZoningType::Zoning)
{
auto ip = (uint32)ipp;
auto port = (uint32)(ipp >> 32);
_sql->Query("UPDATE accounts_sessions SET server_addr = %u, server_port = %u WHERE charid = %u",
ip, port, PChar->id);
const char* Query = "UPDATE chars "
"SET "
"pos_zone = %u,"
"pos_prevzone = %u,"
"pos_rot = %u,"
"pos_x = %.3f,"
"pos_y = %.3f,"
"pos_z = %.3f,"
"moghouse = %u,"
"boundary = %u "
"WHERE charid = %u";
_sql->Query(Query, PChar->loc.destination,
(PChar->m_moghouseID || PChar->loc.destination == PChar->getZone()) ? PChar->loc.prevzone : PChar->getZone(), PChar->loc.p.rotation,
PChar->loc.p.x, PChar->loc.p.y, PChar->loc.p.z, PChar->m_moghouseID, PChar->loc.boundary, PChar->id);
message::send(ipc::CharZone{
.charId = PChar->id,
.destinationZoneId = PChar->loc.destination,
});
}
else // ZoningType::Logout
{
SaveCharPosition(PChar);
message::send(ipc::CharZone{
.charId = PChar->id,
.destinationZoneId = 0xFFFF, // Clear cache
});
}
if (PChar->shouldPetPersistThroughZoning())
{
PChar->setPetZoningInfo();
}
else
{
PChar->resetPetZoningInfo();
}
// If player somehow gets zoned, force crit fail their synth
if (PChar->CraftContainer && PChar->CraftContainer->getItemsCount() > 0)
{
charutils::forceSynthCritFail("SendToZone", PChar);
}
PChar->pushPacket<CServerIPPacket>(PChar, static_cast<uint8>(type), ipp);
removeCharFromZone(PChar);
}

Closes #7390

Steps to test these changes

Login/logout as GM, see session gets cleaned up immediately

@sruon sruon changed the title Remove PChar from zone on disconnect Remove PChar from zone on force logout Apr 19, 2025
@Xaver-DaRed Xaver-DaRed added the core Gives visibility for reviewers for impacted areas involving cpp label Apr 20, 2025
@zach2good zach2good merged commit bd0bea3 into LandSandBoat:base Apr 20, 2025
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Gives visibility for reviewers for impacted areas involving cpp

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🐛 Sessions not being removed on logout (maybe)

3 participants