Net: reconnect to the new core on GC_WARP

RecvWarpPacket now matches Windows: DirectEnter for the selected slot
(warp flavour, SetNewLoadingPhase) and Connect(lAddr, wPort) through
LoginClient::warp, discarding what is left on the old socket.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shenlei
2026-10-13 13:20:47 +09:00
co-authored by Claude Opus 5.5
parent ce6d457808
commit 189da4c269
8 changed files with 63 additions and 11 deletions
+16 -7
View File
@@ -24,7 +24,7 @@ LoginClient::~LoginClient() {
}
void LoginClient::close_socket() { if(fd_>=0) close(fd_);fd_=-1; }
void LoginClient::cancel() {
++generation_;close_socket();resolution_.reset();session_.reset();outgoing_.clear();events_.clear();send_offset_=0;status_=Status::Idle;direct_enter_=false;
++generation_;close_socket();resolution_.reset();session_.reset();outgoing_.clear();events_.clear();send_offset_=0;status_=Status::Idle;direct_enter_=warp_=false;
}
void LoginClient::notify(EventType type,std::string reason,bool connection_failure) { events_.push_back({type,std::move(reason),connection_failure,generation_}); }
void LoginClient::fail(std::string reason,bool connection_failure) {
@@ -149,19 +149,28 @@ void LoginClient::send_game_packet(wire::Bytes packet,bool sequence) {
void LoginClient::direct_enter(std::uint8_t slot) {
if(!session_ || status_!=Status::Selecting || slot>=session_->characters().size() || !session_->characters()[slot].id)
throw std::invalid_argument("DirectEnter requires an occupied character slot");
const auto character=session_->characters()[slot];
const auto& character=session_->characters()[slot];
reconnect(character.address,character.port,slot,false);
}
void LoginClient::warp(std::uint32_t address,std::uint16_t port) {
if(!session_ || status_!=Status::Loading) throw std::logic_error("warp requires an entered game session");
reconnect(address,port,selected_slot_,true);
}
void LoginClient::reconnect(std::uint32_t wire_address,std::uint16_t port,std::uint8_t slot,bool warp) {
// Windows CNetworkAddress::Set(DWORD) copies the little-endian wire DWORD to sin_addr.
in_addr address{};address.s_addr=character.address;
in_addr address{};address.s_addr=wire_address;
char host[INET_ADDRSTRLEN]{};
if(!character.address || !character.port || !inet_ntop(AF_INET,&address,host,sizeof(host)))
if(!wire_address || !port || !inet_ntop(AF_INET,&address,host,sizeof(host)))
throw std::invalid_argument("character server endpoint is missing");
session_->reconnect_game();
direct_enter_=true;direct_enter_slot_=slot;handshake_notified_=false;login_notified_=selection_notified_=loading_notified_=false;
// A new game connection: stale events are dropped and the handshake clock is re-synchronized.
++generation_;events_.clear();
direct_enter_=true;warp_=warp;direct_enter_slot_=slot;handshake_notified_=false;login_notified_=selection_notified_=loading_notified_=false;
deadline_=std::chrono::steady_clock::now()+std::chrono::seconds(15);
start_endpoint({host,character.port});
start_endpoint({host,port});
}
void LoginClient::select(std::uint8_t slot) {
if(!session_) throw std::logic_error("not connected");session_->select(slot);status_=Status::Entering;deadline_=std::chrono::steady_clock::now()+std::chrono::seconds(15);enqueue();
if(!session_) throw std::logic_error("not connected");session_->select(slot);selected_slot_=slot;status_=Status::Entering;deadline_=std::chrono::steady_clock::now()+std::chrono::seconds(15);enqueue();
}
std::vector<LoginClient::Event> LoginClient::take_events() { auto events=std::move(events_);events_.clear();return events; }
}
+6 -1
View File
@@ -21,6 +21,8 @@ public:
void update_player_guild(const std::string& player,uint32_t id,const std::string& name) {if(session_)session_->update_player_guild(player,id,name);}
void select(std::uint8_t slot);
void direct_enter(std::uint8_t slot);
// CPythonNetworkStream::RecvWarpPacket: __DirectEnterMode_Set(m_dwSelectedCharacterIndex, true) + Connect(lAddr, wPort).
void warp(std::uint32_t address,std::uint16_t port);
wire::Bytes take_game_input(std::size_t max=LoginSession::kRecvBufferSize);
void send_game_packet(wire::Bytes packet,bool sequence=true);
std::vector<Event> take_events();
@@ -28,10 +30,12 @@ public:
const LoginSession* session() const { return session_.get(); }
bool is_connected() const { return on_game_ && fd_>=0 && (status_==Status::Authenticating || status_==Status::Selecting || status_==Status::Entering || status_==Status::Loading); }
bool is_direct_enter() const { return direct_enter_; }
bool is_warp() const { return direct_enter_ && warp_; } // __DirectEnterMode_IsWarp (ENABLE_NEW_LOADING)
std::uint64_t generation() const { return generation_; }
private:
struct Resolution;
void start_endpoint(const Endpoint& endpoint);
void reconnect(std::uint32_t address,std::uint16_t port,std::uint8_t slot,bool warp);
bool try_next_address();
void close_socket();
void flush();
@@ -44,7 +48,8 @@ private:
std::shared_ptr<Resolution> resolution_;
Endpoint game_;
bool direct_enter_=false;
std::uint8_t direct_enter_slot_=0;
std::uint8_t direct_enter_slot_=0, selected_slot_=0;
bool warp_=false;
bool handshake_notified_=false;
bool on_game_=false, login_notified_=false, selection_notified_=false, loading_notified_=false;
std::uint64_t generation_=0;
+1 -1
View File
@@ -27,7 +27,7 @@ void LoginSession::begin_game() {
game_=true; server_clock_ready_=false; handshake_phase_entered_=false; encrypted_=false; sequence_=0; raw_.clear(); plain_.clear(); output_.clear(); tx_=rx_=locale_key(); state_=State::Handshake;
}
void LoginSession::reconnect_game() {
if(state_!=State::Selecting) throw std::logic_error("DirectEnter requires a selected account session");
if(state_!=State::Selecting && state_!=State::Loading) throw std::logic_error("DirectEnter/warp requires a selected account session");
server_clock_ready_=false;handshake_phase_entered_=false;encrypted_=false; sequence_=0; raw_.clear(); plain_.clear(); output_.clear();
tx_=rx_=locale_key(); state_=State::Handshake;
roster_received_=select_phase_received_=game_login_sent_=false;