Skip to content

Commit

Permalink
fix the login info that causes the proxy crash
Browse files Browse the repository at this point in the history
  • Loading branch information
ZTzTopia committed Apr 22, 2023
1 parent 99a22ab commit 3459bc9
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 12 deletions.
19 changes: 12 additions & 7 deletions src/server/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -173,24 +173,21 @@ 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);
// text_parse.set("protocol", m_config->m_server.protocol);
// 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(
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/utils/hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -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--) {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/random.h
Original file line number Diff line number Diff line change
Expand Up @@ -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(':');
}

Expand Down
4 changes: 2 additions & 2 deletions src/utils/text_parse.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 3459bc9

Please sign in to comment.