diff options
| author | auth <[email protected]> | 2020-07-05 11:25:10 +0200 |
|---|---|---|
| committer | auth <[email protected]> | 2020-07-05 11:25:10 +0200 |
| commit | e1ca40bf09255ea74602a6b31e0e17ae611e3e3b (patch) | |
| tree | d163ae07461108a2667107153b72180f69981a9c /client/src/main.cpp | |
| parent | Replaced std::byte by uint8_t (diff) | |
| download | loader-e1ca40bf09255ea74602a6b31e0e17ae611e3e3b.tar.xz loader-e1ca40bf09255ea74602a6b31e0e17ae611e3e3b.zip | |
Added support for packet actions.
Added support for client hwid handling.
Removed timeout client message.
Diffstat (limited to 'client/src/main.cpp')
| -rw-r--r-- | client/src/main.cpp | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/client/src/main.cpp b/client/src/main.cpp index f0508ce..727e3a0 100644 --- a/client/src/main.cpp +++ b/client/src/main.cpp @@ -6,15 +6,14 @@ int main(int argc, char* argv[]) { io::init(); - assembler::assembler a; + /*assembler::assembler a; a.push({1, 2, 3, 7, 9}); a.end(); for(auto &b : a()) { io::logger->info("{:x}", b); } + std::cin.get();*/ - - std::cin.get(); tcp::client client; std::thread t{tcp::client::monitor, std::ref(client)}; @@ -22,35 +21,36 @@ int main(int argc, char* argv[]) { client.start("127.0.0.1", 6666); + client.connect_event.add([&]() { io::logger->info("connected."); }); + client.receive_event.add([&](tcp::packet_t& packet) { if (!packet) return; auto message = packet(); + auto action = packet.act; + + // move ? + int ret = -1; - // first packet is the session id and current version - if (packet.id == 1) { + if (action == tcp::packet_action::session) { client.session_id = packet.session_id; tcp::version_t v{0, 1, 0}; auto version = fmt::format("{}.{}.{}", v.major, v.minor, v.patch); - if(version != message) { - io::logger->error("please update your client"); + if (version != message) { + io::logger->error("please update your client."); client.shutdown(); } - return; - } - if (message == "timedout") { - io::logger->warn("connection timeout."); - client.shutdown(); + int ret = client.write(tcp::packet_t("hwid", tcp::packet_type::write, + client.session_id, + tcp::packet_action::hwid)); + if (ret <= 0) { + io::logger->error("failed to send hwid."); + client.shutdown(); + } } - io::logger->info("{}:{}->{}", packet.id, packet.session_id, message); - - std::string imports; - client.read_stream(imports); - - auto json = nlohmann::json::parse(imports); - std::ofstream o("o"); - o << std::setw(4) << json; + io::logger->info("{}:{}->{} {}", packet.id, packet.session_id, message, + packet.act); }); while (client) { |