From e1ca40bf09255ea74602a6b31e0e17ae611e3e3b Mon Sep 17 00:00:00 2001 From: auth Date: Sun, 5 Jul 2020 11:25:10 +0200 Subject: Added support for packet actions. Added support for client hwid handling. Removed timeout client message. --- client/src/main.cpp | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) (limited to 'client/src/main.cpp') 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) { -- cgit v1.2.3