From 30eb23ffe5f7b9e8c3b4267457d0aa3bd02665e7 Mon Sep 17 00:00:00 2001 From: hovertank3d Date: Mon, 23 Feb 2026 23:17:56 +0100 Subject: implement `connect`, `disconnect` and `accept` --- include/net/types.hpp | 21 +++++++++++++++++++++ include/util/io.hpp | 9 ++++----- 2 files changed, 25 insertions(+), 5 deletions(-) (limited to 'include') diff --git a/include/net/types.hpp b/include/net/types.hpp index b9453d6..5301021 100644 --- a/include/net/types.hpp +++ b/include/net/types.hpp @@ -72,6 +72,25 @@ struct vec2 { T y; }; +// NetMessages + +struct connect { + static constexpr uint8_t packet_id = 1; + + std::string version; +}; + +struct disconnect { + static constexpr uint8_t packet_id = 2; + + nstring reason; +}; + +struct accept { + uint8_t slot; + uint8_t server_flags = 0; +}; + inline nstring operator""_ns(const char* str, std::size_t) { return nstring{nstring::Literal, str}; @@ -79,3 +98,5 @@ inline nstring operator""_ns(const char* str, std::size_t) } } + +using net::packet::operator""_ns; diff --git a/include/util/io.hpp b/include/util/io.hpp index 629bf59..9131a96 100644 --- a/include/util/io.hpp +++ b/include/util/io.hpp @@ -16,11 +16,11 @@ namespace io { template -concept custom_write = requires(T t) { - { t.write(K()) } -> std::same_as; +concept custom_write = requires(T t, K &k) { + { t.write(k) } -> std::same_as; }; template -concept custom_read = requires(T& t, K& k) { +concept custom_read = requires(T& t, K &k) { { t.read(k) } -> std::same_as; }; @@ -108,7 +108,6 @@ public: template class serialized_io { I io; - public: serialized_io(I io) : io(io) @@ -193,7 +192,7 @@ public: } template > T> - ssize_t write(T& f) + ssize_t write(T f) { return f.write(*this); } -- cgit v1.2.3