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:
co-authored by
Claude Opus 5.5
parent
ce6d457808
commit
189da4c269
@@ -1715,6 +1715,7 @@ Outstanding, most severe first:
|
||||
|
||||
P0, the real-server flow stops:
|
||||
1. `RecvWarpPacket` reads and drops GC_WARP. Windows sets DirectEnter for the selected slot and reconnects to `lAddr:wPort`. Map teleports and channel moves hang.
|
||||
- **Fixed:** `RecvWarpPacket` stops processing the old socket and `pump_python_net` calls `LoginClient::warp`. It reconnects like DirectEnter: same login key, the remembered selected slot, a new generation so the server clock is re-synced, and `SetNewLoadingPhase` (ENABLE_NEW_LOADING). A connect failure under DirectEnter is ClosePhase (`SetLoginPhase`). Covered in `login_oracle_test`.
|
||||
2. In-game `RecvPhasePacket` only stores the phase. Windows calls `SetSelectPhase` (plus `__DownloadMark`), `SetLoginPhase`, `SetLoadingPhase`, `SetGamePhase` or `ClosePhase`. Going back to character select and reloading after a warp do not work.
|
||||
3. `LoginSession` (select phase) only accepts headers 0/7/32/44/90/150-153/253-255 and drops the connection on anything else. The following are missing:
|
||||
- GC 6 LOGIN_SUCCESS3;
|
||||
|
||||
@@ -88,7 +88,7 @@ void PythonNetworkStream::StartGame() {
|
||||
}
|
||||
|
||||
void PythonNetworkStream::ResetConnection() {
|
||||
m_recvBuffer.clear();m_unportedPackets.clear();m_unknownPacketQuit=false;m_isObserverMode=m_bMobileFlag=false;std::memset(m_lastPacket,0,sizeof(m_lastPacket));ClearSendQueue();m_startGameRequested=m_refreshInventory=m_refreshStatus=m_refreshSkill=m_refreshCharacter=m_refreshShopSearch=m_stopGamePhase=false;
|
||||
m_recvBuffer.clear();m_unportedPackets.clear();m_unknownPacketQuit=false;m_isObserverMode=m_bMobileFlag=false;std::memset(m_lastPacket,0,sizeof(m_lastPacket));ClearSendQueue();m_startGameRequested=m_refreshInventory=m_refreshStatus=m_refreshSkill=m_refreshCharacter=m_refreshShopSearch=m_stopGamePhase=m_warpRequested=false;
|
||||
m_refreshGuildInfo=m_refreshGuildBoard=m_refreshGuildMember=m_refreshGuildCombo=m_refreshGuildSkill=m_refreshGuildGrade=m_refreshMessenger=false;
|
||||
m_guildID=0;
|
||||
m_changeServerTime=m_changeClientTime=0;m_dungeonDestination={};
|
||||
@@ -1058,6 +1058,9 @@ bool PythonNetworkStream::RecvCreateFlyPacket() {
|
||||
bool PythonNetworkStream::RecvWarpPacket() {
|
||||
TPacketGCWarp p;
|
||||
if (!Read(sizeof(p), &p)) return false;
|
||||
// CNetworkStream::Connect disconnects first: nothing after GC_WARP on the old socket is processed.
|
||||
m_warpRequested=true;m_warpAddress=uint32_t(p.lAddr);m_warpPort=p.wPort;
|
||||
m_recvBuffer.clear();m_stopGamePhase=true;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -216,6 +216,12 @@ public:
|
||||
using FlyCallback = std::function<void(uint8_t flyType, uint32_t startVID, uint32_t endVID)>;
|
||||
void SetFlyCallback(FlyCallback cb) { m_flyCallback = cb; }
|
||||
|
||||
// GC_WARP: the transport (LoginClient::warp) performs CNetworkStream::Connect(lAddr, wPort).
|
||||
bool TakeWarpRequest(uint32_t& address,uint16_t& port) {
|
||||
if(!m_warpRequested) return false;
|
||||
m_warpRequested=false;address=m_warpAddress;port=m_warpPort;return true;
|
||||
}
|
||||
|
||||
private:
|
||||
bool CheckPacket(uint8_t* retHeader);
|
||||
bool DispatchGamePhasePacket(uint8_t header,bool& ret);
|
||||
@@ -260,6 +266,9 @@ private:
|
||||
std::vector<bool> m_sendSequence;
|
||||
// Handshake/HandshakeOK/HybridCrypt return from GamePhase() before the refresh block.
|
||||
bool m_stopGamePhase=false;
|
||||
bool m_warpRequested=false;
|
||||
uint32_t m_warpAddress=0;
|
||||
uint16_t m_warpPort=0;
|
||||
uint32_t m_changeServerTime=0,m_changeClientTime=0; // CPythonNetworkStream::m_kServerTimeSync
|
||||
std::pair<int32_t,int32_t> m_dungeonDestination{};
|
||||
bool RecvItemSetPacket();
|
||||
|
||||
@@ -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; }
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -1412,7 +1412,12 @@ void pump_python_net() {
|
||||
} else if(event.type == LoginClient::EventType::DirectEnterReady) callback(handler, "SetLoadingPhase");
|
||||
else if(event.type == LoginClient::EventType::Loading) {
|
||||
PythonNetworkStream::Instance().SetPhase(PHASE_LOADING);
|
||||
callback(handler,"SetLoadingPhase");
|
||||
// SetSelectPhase under DirectEnter: ENABLE_NEW_LOADING picks SetNewLoadingPhase for a warp.
|
||||
callback(handler,client.is_warp()?"SetNewLoadingPhase":"SetLoadingPhase");
|
||||
}
|
||||
else if(client.is_direct_enter() && event.connection_failure) {
|
||||
// OnConnectFailure under DirectEnter: ClosePhase -> handler.SetLoginPhase.
|
||||
client.cancel();PythonNetworkStream::Instance().ResetConnection();callback(handler,"SetLoginPhase");
|
||||
}
|
||||
else {
|
||||
auto* target = account_handler ? account_handler : phases[1];
|
||||
@@ -1422,6 +1427,15 @@ void pump_python_net() {
|
||||
auto& stream=PythonNetworkStream::Instance();
|
||||
stream.PushRecvData(client.take_game_input(stream.RecvBufferSpace()));
|
||||
stream.ProcessRecvData();
|
||||
uint32_t warpAddress=0;uint16_t warpPort=0;
|
||||
if(stream.TakeWarpRequest(warpAddress,warpPort) && client.status()==LoginClient::Status::Loading) {
|
||||
// RecvWarpPacket: __DirectEnterMode_Set(selected slot, true) + Connect. Leaving the game phase
|
||||
// (__LeaveGamePhase) and SetLoadingPhase clear actors, items and the player before the new map.
|
||||
try { client.warp(warpAddress,warpPort); }
|
||||
catch(const std::exception& e) { SDL_Log("Warp failed: %s",e.what());client.cancel();stream.ResetConnection();callback(handler,"SetLoginPhase");return; }
|
||||
stream.ResetConnection();
|
||||
return;
|
||||
}
|
||||
if(client.status()==LoginClient::Status::Loading) {
|
||||
for(auto& [packet,sequence]:stream.PopSendPacketsWithSequence()) client.send_game_packet(std::move(packet),sequence);
|
||||
}
|
||||
|
||||
@@ -59,5 +59,16 @@ int main() {
|
||||
if(valid.state()!=ava2::LoginSession::State::Loading || valid.receive_space()!=ava2::LoginSession::kRecvBufferSize-14) return 8;
|
||||
if(valid.take_game_input(0).size()!=0 || valid.take_game_input(5)!=ava2::wire::Bytes{0,1,2,3,4}) return 9;
|
||||
if(valid.take_game_input()!=ava2::wire::Bytes{5,6,7,8,9,10,11,12,13} || valid.receive_space()!=ava2::LoginSession::kRecvBufferSize) return 10;
|
||||
// GC_WARP (RecvWarpPacket -> DirectEnter + Connect): the entered session logs in again on the new
|
||||
// core with the same login key, re-reads the roster and re-selects the character.
|
||||
valid.reconnect_game();
|
||||
if(valid.state()!=ava2::LoginSession::State::Handshake || valid.server_milliseconds(serverMS)) return 13;
|
||||
valid.feed(handshake);valid.take_output();valid.feed(login_phase);sent=valid.take_output();
|
||||
if(sent.size()!=1 || ava2::wire::decrypt(sent[0],ava2::wire::locale_key())[0]!=109 || ava2::wire::read32(ava2::wire::decrypt(sent[0],ava2::wire::locale_key()),32)!=123) return 14;
|
||||
valid.feed(ava2::wire::encrypt(payload,rx));
|
||||
if(valid.state()!=ava2::LoginSession::State::Selecting) return 15;
|
||||
valid.select(0);valid.take_output();
|
||||
ava2::wire::Bytes warped{253,5};valid.feed(ava2::wire::encrypt(warped,rx));
|
||||
if(valid.state()!=ava2::LoginSession::State::Loading) return 16;
|
||||
std::cout<<"Original AVA2 client/server layout, cipher and character selection oracle passed\n";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user