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; }
}