Detect server disconnect during character loading and show error

GameHandler::update() now detects when the socket closes mid-session
(e.g. Warden rejection) and transitions to DISCONNECTED state.
Character screen shows a disconnect message instead of hanging on
"Loading characters..." forever. Reverted SHA1(seed+module) fallback
to SHA1(seed) since neither is correct without module execution.
This commit is contained in:
Kelsi 2026-02-14 18:46:54 -08:00
parent 0ef4af9c99
commit f4f23eab7a
2 changed files with 24 additions and 6 deletions

View file

@ -253,6 +253,13 @@ void GameHandler::update(float deltaTime) {
auto socketEnd = std::chrono::high_resolution_clock::now();
socketTime += std::chrono::duration<float, std::milli>(socketEnd - socketStart).count();
// Detect server-side disconnect (socket closed during update)
if (socket && !socket->isConnected() && state != WorldState::DISCONNECTED) {
LOG_WARNING("Server closed connection in state: ", worldStateName(state));
disconnect();
return;
}
// Post-gate visibility: determine whether server goes silent or closes after Warden requirement.
if (wardenGateSeen_ && socket && socket->isConnected()) {
wardenGateElapsed_ += deltaTime;
@ -2281,13 +2288,12 @@ void GameHandler::handleWardenData(network::Packet& packet) {
break;
}
// SHA1(seed + moduleImage) — the server verifies this against its own copy
// SHA1(seed) fallback — wrong answer but sends a response to avoid silent hang.
// Correct answer requires executing the Warden module via emulator (not yet functional).
// Server will likely disconnect, but GameHandler::update() now detects that gracefully.
{
std::vector<uint8_t> hashInput;
hashInput.insert(hashInput.end(), seed.begin(), seed.end());
hashInput.insert(hashInput.end(), wardenModuleData_.begin(), wardenModuleData_.end());
auto hash = auth::Crypto::sha1(hashInput);
LOG_INFO("Warden: SHA1 fallback hash over ", hashInput.size(), " bytes (seed+module)");
auto hash = auth::Crypto::sha1(seed);
LOG_WARNING("Warden: Sending SHA1(seed) fallback — server will likely reject");
std::vector<uint8_t> resp;
resp.push_back(0x04);
resp.insert(resp.end(), hash.begin(), hash.end());