Net: handle in-game GC_PHASE like the Windows client
PHASE_SELECT returns the connection to LoginSession (cached roster, SelectReady, later LOGIN_SUCCESS refreshes), PHASE_CLOSE goes to the login phase, LOADING clears the player, GAME refreshes the status and DEAD no longer leaves the game phase. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
189da4c269
commit
40cac5cf52
@@ -119,28 +119,45 @@ void LoginClient::pump() {
|
||||
if(n<0 && (errno==EAGAIN || errno==EWOULDBLOCK)) break;
|
||||
if(n<=0) { fail("server disconnected");return; }
|
||||
session_->feed({buffer,static_cast<std::size_t>(n)});enqueue();if(status_==Status::Failed) return;
|
||||
if(session_->state()==LoginSession::State::Failed) { fail(session_->failure());return; }
|
||||
if(session_->state()==LoginSession::State::Authenticated && !on_game_) {
|
||||
on_game_=true;session_->begin_game();start_endpoint(game_);return;
|
||||
}
|
||||
if(on_game_ && session_->handshake_phase_entered() && !handshake_notified_) { handshake_notified_=true;if(!direct_enter_) notify(EventType::Handshake); }
|
||||
if(on_game_ && session_->game_login_sent() && !login_notified_) { login_notified_=true;if(!direct_enter_) notify(EventType::LoginStart); }
|
||||
if(session_->state()==LoginSession::State::Selecting && !selection_notified_) {
|
||||
selection_notified_=true;status_=Status::Selecting;
|
||||
if(direct_enter_) {
|
||||
select(direct_enter_slot_);
|
||||
// Do not notify DirectEnterReady here before the server actually transitions to Loading!
|
||||
} else {
|
||||
notify(EventType::SelectReady);
|
||||
}
|
||||
}
|
||||
if(session_->state()==LoginSession::State::Loading && !loading_notified_) {
|
||||
loading_notified_=true;status_=Status::Loading;
|
||||
notify(EventType::Loading);return;
|
||||
}
|
||||
if(!advance()) return;
|
||||
flush();if(status_==Status::Failed) return;
|
||||
}
|
||||
}
|
||||
// Session state transitions after new input; false when pump() must stop for this frame.
|
||||
bool LoginClient::advance() {
|
||||
if(session_->state()==LoginSession::State::Failed) { fail(session_->failure());return false; }
|
||||
if(session_->state()==LoginSession::State::Authenticated && !on_game_) {
|
||||
on_game_=true;session_->begin_game();start_endpoint(game_);return false;
|
||||
}
|
||||
if(on_game_ && session_->handshake_phase_entered() && !handshake_notified_) { handshake_notified_=true;if(!direct_enter_) notify(EventType::Handshake); }
|
||||
if(on_game_ && session_->game_login_sent() && !login_notified_) { login_notified_=true;if(!direct_enter_) notify(EventType::LoginStart); }
|
||||
// __RecvLoginSuccessPacket4 in SelectPhase: PHASE_WINDOW_SELECT.Refresh.
|
||||
if(session_->state()==LoginSession::State::Selecting && selection_notified_ && !direct_enter_ && session_->roster_version()!=roster_version_)
|
||||
notify(EventType::SelectRefresh);
|
||||
if(session_->state()==LoginSession::State::Selecting && !selection_notified_) {
|
||||
selection_notified_=true;status_=Status::Selecting;
|
||||
if(direct_enter_) {
|
||||
select(direct_enter_slot_);
|
||||
// Do not notify DirectEnterReady here before the server actually transitions to Loading!
|
||||
} else {
|
||||
notify(EventType::SelectReady);
|
||||
}
|
||||
}
|
||||
roster_version_=session_->roster_version();
|
||||
if(session_->state()==LoginSession::State::Loading && !loading_notified_) {
|
||||
loading_notified_=true;status_=Status::Loading;
|
||||
notify(EventType::Loading);return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
void LoginClient::return_to_select(std::span<const std::uint8_t> leftover) {
|
||||
if(!session_ || status_!=Status::Loading) throw std::logic_error("select phase requires an entered game session");
|
||||
session_->return_to_select(leftover);
|
||||
// The next character choice is a fresh DirectEnter/select from the select window.
|
||||
direct_enter_=warp_=false;selection_notified_=loading_notified_=false;
|
||||
status_=Status::Entering;deadline_=std::chrono::steady_clock::now()+std::chrono::seconds(15);
|
||||
enqueue();advance();flush();
|
||||
}
|
||||
wire::Bytes LoginClient::take_game_input(std::size_t max) { return session_?session_->take_game_input(max):wire::Bytes{}; }
|
||||
void LoginClient::send_game_packet(wire::Bytes packet,bool sequence) {
|
||||
if(status_!=Status::Loading || !session_) throw std::logic_error("game transport is not ready");
|
||||
|
||||
Reference in New Issue
Block a user