diff options
| author | auth <[email protected]> | 2020-07-13 23:05:20 +0200 |
|---|---|---|
| committer | auth <[email protected]> | 2020-07-13 23:05:20 +0200 |
| commit | e177151308cbdfb2b96119389cf5bf7c2659b94e (patch) | |
| tree | 7e5737aca17322bf3d39ee5643b3ae2d5deea8f3 /client/src | |
| parent | Small changes. (diff) | |
| download | loader-e177151308cbdfb2b96119389cf5bf7c2659b94e.tar.xz loader-e177151308cbdfb2b96119389cf5bf7c2659b94e.zip | |
Forum integration.
Added separate packet ids for login request/response.
Added login responses.
Small code changes.
Diffstat (limited to 'client/src')
| -rw-r--r-- | client/src/client/client.h | 15 | ||||
| -rw-r--r-- | client/src/client/packet.h | 4 | ||||
| -rw-r--r-- | client/src/main.cpp | 31 |
3 files changed, 41 insertions, 9 deletions
diff --git a/client/src/client/client.h b/client/src/client/client.h index 7618913..8bf3743 100644 --- a/client/src/client/client.h +++ b/client/src/client/client.h @@ -11,6 +11,17 @@ struct version_t { uint8_t patch; }; +enum client_state { + idle = 0, logged_in, waiting +}; + +enum login_result { + login_fail = 15494, + hwid_mismatch = 11006, + login_success = 61539, + banned = 28618 +}; + class client { int m_socket; std::atomic<bool> m_active; @@ -19,11 +30,13 @@ class client { SSL_CTX* m_ssl_ctx; public: + int state; + std::string session_id; event<packet_t&> receive_event; event<> connect_event; - client() : m_socket{-1}, m_active{false} {} + client() : m_socket{-1}, m_active{false}, state{client_state::idle} {} void start(const std::string_view server_ip, const uint16_t port); diff --git a/client/src/client/packet.h b/client/src/client/packet.h index 5a26ee4..db24ac2 100644 --- a/client/src/client/packet.h +++ b/client/src/client/packet.h @@ -7,9 +7,9 @@ namespace tcp { constexpr size_t session_id_len = 10; constexpr size_t message_len = 512; -enum packet_type : int { write = 0, read }; +enum packet_type { write = 0, read }; -enum packet_id : int { message = 0, hwid, session }; +enum packet_id { message = 0, hwid, session, login_req, login_resp, process_list }; struct packet_t { std::string message; diff --git a/client/src/main.cpp b/client/src/main.cpp index 86a73bf..83804dd 100644 --- a/client/src/main.cpp +++ b/client/src/main.cpp @@ -40,27 +40,46 @@ int main(int argc, char* argv[]) { client.shutdown(); } - int ret = client.write(tcp::packet_t("hwid", tcp::packet_type::write, - client.session_id, - tcp::packet_id::hwid)); + int ret = + client.write(tcp::packet_t("hwid", tcp::packet_type::write, + client.session_id, tcp::packet_id::hwid)); if (ret <= 0) { io::logger->error("failed to send hwid."); client.shutdown(); } } + if (id == tcp::packet_id::login_resp) { + auto j = nlohmann::json::parse(message); + + auto res = j["result"].get<int>(); + if (res == tcp::login_result::banned) { + io::logger->error("your account is banned."); + client.shutdown(); + } + + io::logger->info("res {}", res); + } + io::logger->info("{}:{}->{} {}", packet.seq, packet.session_id, message, id); }); while (client) { + std::string u; + getline(std::cin, u); + std::string p; getline(std::cin, p); - int ret = client.write( - tcp::packet_t(p, tcp::packet_type::write, client.session_id)); + auto l = fmt::format("{},{}", u, p); + + int ret = client.write(tcp::packet_t(l, tcp::packet_type::write, + client.session_id, + tcp::packet_id::login_req)); + if (ret <= 0) { - break; + return 0; } } } |