feat(gameplay): add player logout and disconnect handling

This commit is contained in:
2026-06-26 17:05:09 +08:00
parent 25e9b0e0d3
commit e5e84848a9
11 changed files with 110 additions and 13 deletions

View File

@@ -200,6 +200,18 @@ void ClientWorld::receive_other_player(const PlayerInfoRsp& rsp) {
}
}
void ClientWorld::receive_player_logout(const LogoutRsp& rsp) {
{
std::lock_guard lock(m_other_players_mutex);
int sum = m_other_players.erase(rsp.uuid());
if (sum == 0) {
Logger::warn("Player {} not find", rsp.uuid());
} else {
Logger::info("Player {} erase", rsp.uuid());
}
}
}
void ClientWorld::init(std::string_view player_name,
std::shared_ptr<NetworkClient> client) {
m_chunks.reserve(MAX_DISTANCE * MAX_DISTANCE * 4);
@@ -405,6 +417,12 @@ void ClientWorld::receive_chunk(const ChunkDataRsp& data) {
});
}
void ClientWorld::exit() {
LogoutReq req;
req.set_uuid(m_player.get_uuid());
m_client->send(make_packet(req));
}
void ClientWorld::update(float delta_time) {
m_player.update(delta_time);
{