From 6c79fe43fe2d6bbbb2808777e5553a7360b37d22 Mon Sep 17 00:00:00 2001 From: hovertank3d Date: Mon, 23 Feb 2026 03:05:12 +0100 Subject: revert to being a raw proxy --- include/net/conn.hpp | 63 ++++++++++++++-------------------------------------- 1 file changed, 17 insertions(+), 46 deletions(-) (limited to 'include/net/conn.hpp') diff --git a/include/net/conn.hpp b/include/net/conn.hpp index 9755f88..6cd6024 100644 --- a/include/net/conn.hpp +++ b/include/net/conn.hpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include @@ -20,6 +21,7 @@ class conn { using handler = std::function)>; using handler_list = std::vector; + std::array handlers; std::map netmodule_handlers; @@ -56,12 +58,6 @@ public: } } - template - void reg_handler(int id, H h) - { - handlers[id].push_back(h); - } - template void reg_handler(H h) { @@ -107,55 +103,30 @@ public: send_packet(T::packet_id, payload); } - bool handle_netmodule(std::span payload) + template + void handle(T unk_handler) { - uint16_t id; - std::memcpy(&id, payload.data(), sizeof(id)); - id = to_little(id); - - if (netmodule_handlers[id].size() <= 0) { - // currently i won't bother implementing netmodules - // FIXME: return false - return true; + auto [id, len] = read_header(); + if (id == 0) { + throw std::runtime_error("invalid message id"); } + std::vector payload(len); + rw.read(payload); + if (handlers[id].size() <= 0) { + unk_handler(id, payload); + } for (auto& h : handlers[id]) { - if (h(payload.subspan(2)) == true) { - return false; + if (h(payload) == true) { + return; } } - return true; } - bool handle() - { - try { - auto [id, len] = read_header(); - if (id == 0) { - return false; - } - - std::vector payload(len); - rw.read(payload); - // got netmodule - if (id == 82) { - return handle_netmodule(payload); - } - - if (handlers[id].size() <= 0) { - return false; - } - - for (auto& h : handlers[id]) { - if (h(payload) == true) { - break; - } - } - return true; - } catch (io::file_io::eof e) { - return false; - } + void handle() + { + handle([](int, std::vector) {}); } }; } \ No newline at end of file -- cgit v1.2.3