added hash
This commit is contained in:
1 parent
2c1c077611
commit
251a59ddbe
5 files changed
+58
-7
No files matched your search
@@ -9,6 +9,9 @@
|
||||
using std::min;
|
||||
using std::max;
|
||||
|
||||
constexpr auto NET_SECRET = "880b3713b9ff3e7a94b2712d54679e1f";
|
||||
#define ENABLE_NETWORK_CHECKSUM
|
||||
|
||||
constexpr float ANGULAR_ACCEL = 0.005f * 1000.0f;
|
||||
constexpr float SHIP_ACCEL = 1.0f * 1000.0f;
|
||||
constexpr float ROTATION_SENSITIVITY = 0.002f;
|
||||
|
||||
@@ -78,7 +78,23 @@ namespace ZL {
|
||||
void WebSocketClient::Send(const std::string& message) {
|
||||
if (!connected) return;
|
||||
|
||||
auto ss = std::make_shared<std::string>(message);
|
||||
std::string finalMessage = message;
|
||||
|
||||
#ifdef ENABLE_NETWORK_CHECKSUM
|
||||
// Вычисляем хеш. Для примера используем std::hash,
|
||||
// но в продакшене лучше взять быструю реализацию типа MurmurHash3.
|
||||
size_t hashValue = std::hash<std::string>{}(message + NET_SECRET);
|
||||
|
||||
// Преобразуем хеш в hex-строку для передачи
|
||||
std::stringstream ss_hash;
|
||||
ss_hash << std::hex << hashValue;
|
||||
|
||||
// Добавляем хеш в конец сообщения через разделитель
|
||||
// Например: "UPD:12345:pos...#hash:a1b2c3d4"
|
||||
finalMessage += "#hash:" + ss_hash.str();
|
||||
#endif
|
||||
|
||||
auto ss = std::make_shared<std::string>(finalMessage);
|
||||
|
||||
std::lock_guard<std::mutex> lock(writeMutex_);
|
||||
writeQueue_.push(ss);
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
namespace ZL {
|
||||
|
||||
|
||||
class WebSocketClientBase : public INetworkClient {
|
||||
protected:
|
||||
|
||||
|
||||
Reference in new issue
Block a user