fixing hash function

This commit is contained in:
Vladislav Khorev committed 2026-11-15 23:10:19 +06:00
1 parent 90669ff333
commit a784da9fb4
4 files changed
+57 -18

No files matched your search

+9 -7
View File
@@ -1,5 +1,6 @@
#include "WebsocketGameClient.h"
#include "NetworkProtocol.h"
#include "../utils/Utils.h"
#ifdef __EMSCRIPTEN__
#include <emscripten/websocket.h>
#else
@@ -525,10 +526,11 @@ void WebsocketGameClient::update(std::int64_t)
std::string error;
InitialStateMessage initial;
if (parseInitialStateMessage(text, initial, error)) {
logger() << text << std::endl;
if (!expectedCompatibilityFingerprint_.empty() &&
initial.compatibilityFingerprint !=
expectedCompatibilityFingerprint_) {
std::cerr << "[network] Incompatible server content: expected "
logger() << "[network] Incompatible server content: expected "
<< expectedCompatibilityFingerprint_ << ", received "
<< initial.compatibilityFingerprint << '\n';
continue;
@@ -541,12 +543,12 @@ void WebsocketGameClient::update(std::int64_t)
std::move(initial.compatibilityFingerprint);
pendingTicks_.clear();
initialized_ = true;
std::cout << "[network] Applied initial state at tick "
logger() << "[network] Applied initial state at tick "
<< initial.snapshotTick << " as player '"
<< initial.assignedPlayerId << "' (delay "
<< initial.inputDelayTicks << " ticks)" << std::endl;
} catch (const std::exception& exception) {
std::cerr << "[network] Invalid initial state: "
logger() << "[network] Invalid initial state: "
<< exception.what() << '\n';
}
continue;
@@ -555,7 +557,7 @@ void WebsocketGameClient::update(std::int64_t)
if (parseTickMessage(text, tick, error)) {
if (initialized_ && tick.tickId >= nextExpectedTick_) {
if (!loggedFirstTick_) {
std::cout << "[network] Received first lockstep tick "
logger() << "[network] Received first lockstep tick "
<< tick.tickId << std::endl;
loggedFirstTick_ = true;
}
@@ -566,14 +568,14 @@ void WebsocketGameClient::update(std::int64_t)
std::string errorCode;
std::string errorDetail;
if (parseErrorMessage(text, errorCode, errorDetail)) {
std::cerr << "[network] Server rejected request (" << errorCode
logger() << "[network] Server rejected request (" << errorCode
<< "): " << errorDetail << '\n';
if (errorCode == "server_full" ||
errorCode == "incompatible")
rejected_ = true;
continue;
}
std::cerr << "[network] Ignoring WebSocket message: "
logger() << "[network] Ignoring WebSocket message: "
<< error << '\n';
}
@@ -619,7 +621,7 @@ void WebsocketGameClient::update(std::int64_t)
replica_.save(state);
const std::string localHash = canonicalStateHash(std::move(state));
if (localHash != tick.stateHash) {
std::cerr << "[network] Lockstep divergence at tick "
logger() << "[network] Lockstep divergence at tick "
<< tick.tickId << ": server=" << tick.stateHash
<< ", client=" << localHash << '\n';
}