diff options
| author | auth <[email protected]> | 2020-07-11 23:19:24 +0200 |
|---|---|---|
| committer | auth <[email protected]> | 2020-07-11 23:19:24 +0200 |
| commit | 883aafaf87ec22aa4c9142ac5c836040a0f531b4 (patch) | |
| tree | 38a73a202d815719991efeecfd3769dea7d20984 /client/src | |
| parent | Added blacklist implementation on server. (diff) | |
| download | loader-883aafaf87ec22aa4c9142ac5c836040a0f531b4.tar.xz loader-883aafaf87ec22aa4c9142ac5c836040a0f531b4.zip | |
Small changes.
Diffstat (limited to 'client/src')
| -rw-r--r-- | client/src/client/packet.h | 19 | ||||
| -rw-r--r-- | client/src/main.cpp | 12 |
2 files changed, 16 insertions, 15 deletions
diff --git a/client/src/client/packet.h b/client/src/client/packet.h index f574625..5a26ee4 100644 --- a/client/src/client/packet.h +++ b/client/src/client/packet.h @@ -9,37 +9,38 @@ constexpr size_t message_len = 512; enum packet_type : int { write = 0, read }; -enum packet_action : uint8_t { message = 0, hwid = 1, session }; +enum packet_id : int { message = 0, hwid, session }; struct packet_t { std::string message; std::string session_id; - uint8_t act; int id; + int seq; packet_t() {} packet_t(const std::string_view msg, const packet_type &type, std::string_view session = "", - const packet_action &action = packet_action::message) { + const packet_id &action = packet_id::message) { if (type == read) { - ++id; + ++seq; message = msg; enc::decrypt_message(message); auto json = nlohmann::json::parse(message); + + id = json["id"]; message = json["message"]; session_id = json["session_id"]; - act = json["action"]; } else { nlohmann::json json; - json["action"] = action; + json["id"] = action; json["session_id"] = session; json["message"] = msg.data(); message = json.dump(); session_id = session; - act = action; + id = action; enc::encrypt_message(message); } @@ -48,11 +49,11 @@ struct packet_t { ~packet_t() { message.clear(); session_id.clear(); - act = -1; + id = -1; } operator bool() const { - return !message.empty() && !session_id.empty() && act != -1; + return !message.empty() && !session_id.empty() && id != -1; } auto &operator()() { return message; } }; diff --git a/client/src/main.cpp b/client/src/main.cpp index 8a1aca0..86a73bf 100644 --- a/client/src/main.cpp +++ b/client/src/main.cpp @@ -26,11 +26,11 @@ int main(int argc, char* argv[]) { client.receive_event.add([&](tcp::packet_t& packet) { if (!packet) return; auto message = packet(); - auto action = packet.act; + auto id = packet.id; - if (action == tcp::packet_action::session) { + if (id == tcp::packet_id::session) { client.session_id = packet.session_id; - + tcp::version_t v{0, 1, 0}; auto version = fmt::format("{}.{}.{}", v.major, v.minor, v.patch); io::logger->info("current server version {}", message); @@ -42,15 +42,15 @@ int main(int argc, char* argv[]) { int ret = client.write(tcp::packet_t("hwid", tcp::packet_type::write, client.session_id, - tcp::packet_action::hwid)); + tcp::packet_id::hwid)); if (ret <= 0) { io::logger->error("failed to send hwid."); client.shutdown(); } } - io::logger->info("{}:{}->{} {}", packet.id, packet.session_id, message, - action); + io::logger->info("{}:{}->{} {}", packet.seq, packet.session_id, message, + id); }); while (client) { |