diff --git a/src/server/server.cpp b/src/server/server.cpp index 9175195..54e0271 100644 --- a/src/server/server.cpp +++ b/src/server/server.cpp @@ -135,8 +135,8 @@ bool Server::process_packet(ENetPeer* peer, ENetPacket* packet) std::string md5_string{}; md5_string.reserve(32); - for (unsigned char b : digest) { - md5_string += fmt::format("{:02x}", b); + for (int i{ 0 }; i < 16; i++) { + md5_string += fmt::format("{:02X}", digest[i]); } return md5_string; @@ -173,12 +173,11 @@ bool Server::process_packet(ENetPeer* peer, ENetPacket* packet) static randutils::pcg_rng gen{ utils::random::get_generator_local() }; static std::string mac{ utils::random::generate_mac(gen) }; - static std::uint32_t mac_hash{ utils::proton_hash(fmt::format("{}RT", mac).c_str()) }; + static std::int32_t mac_hash{ utils::proton_hash(fmt::format("{}RT", mac).c_str()) }; static std::string rid{ utils::random::generate_hex(gen, 32, true) }; - static std::string gid{ utils::random::generate_hex(gen, 32, true) }; static std::string wk{ utils::random::generate_hex(gen, 32, true) }; static std::string device_id{ utils::random::generate_hex(gen, 16, true) }; - static std::uint32_t device_id_hash{ utils::proton_hash(fmt::format("{}RT", device_id).c_str()) }; + static std::int32_t device_id_hash{ utils::proton_hash(fmt::format("{}RT", device_id).c_str()) }; utils::TextParse text_parse{ message_data }; // text_parse.set("game_version", m_config->m_server.game_version); @@ -186,11 +185,9 @@ bool Server::process_packet(ENetPeer* peer, ENetPacket* packet) // text_parse.set("platformID", m_config->m_server.platformID); text_parse.set("mac", mac); text_parse.set("rid", rid); - text_parse.set("gid", gid); text_parse.set("wk", wk); text_parse.set("hash", device_id_hash); text_parse.set("hash2", mac_hash); - text_parse.set( "klv", generate_klv( @@ -201,12 +198,20 @@ bool Server::process_packet(ENetPeer* peer, ENetPacket* packet) ) ); + spdlog::debug("{}", text_parse.get_all_raw()); m_peer.m_gt_server->send_packet(message_type, text_parse.get_all_raw()); return false; } break; } + case player::NET_MESSAGE_GAME_MESSAGE: { + if (message_data.find("action|quit") != std::string::npos) { + m_peer.m_gt_client->disconnect(); + } + + break; + } case player::NET_MESSAGE_GAME_PACKET: { player::GameUpdatePacket* game_update_packet{ player::get_struct(packet) }; return process_tank_update_packet(peer, game_update_packet); diff --git a/src/utils/hash.h b/src/utils/hash.h index ca6ff74..5cfe42e 100644 --- a/src/utils/hash.h +++ b/src/utils/hash.h @@ -23,9 +23,9 @@ constexpr std::size_t fnv1a_hash(const std::string_view& data) return hash; } -constexpr std::uint32_t proton_hash(const char* data, std::size_t length = 0) +constexpr std::int32_t proton_hash(const char* data, std::size_t length = 0) { - std::uint32_t hash{ 0x55555555 }; + std::int32_t hash{ 0x55555555 }; if (data) { if (length > 0) { while (length--) { diff --git a/src/utils/random.h b/src/utils/random.h index 6c19c9c..060cd51 100644 --- a/src/utils/random.h +++ b/src/utils/random.h @@ -95,7 +95,7 @@ inline std::string generate_mac(T gen, bool zero_two = true) } for (std::size_t i{ 0 }; i < (zero_two ? 5 : 6); i++) { - result.append(generate_hex(gen, 1, false)); + result.append(generate_hex(gen, 2, false)); result.push_back(':'); } diff --git a/src/utils/text_parse.h b/src/utils/text_parse.h index 50bc6de..4c99d2f 100644 --- a/src/utils/text_parse.h +++ b/src/utils/text_parse.h @@ -145,9 +145,9 @@ class TextParse { std::string string{}; for (auto it = m_data.cbegin(); it != m_data.cend(); ++it) { string += *it; - if (std::next(it) != m_data.cend() && !std::next(it)->empty()) { + // if (std::next(it) != m_data.cend() && !std::next(it)->empty()) { string += "\r\n"; - } + // } } return string;