From f1278941102e71b160f45f439da8c0a400d907d4 Mon Sep 17 00:00:00 2001 From: WolverinDEV Date: Fri, 23 Jul 2021 14:59:43 +0200 Subject: [PATCH] Some minor updates --- src/converters/converter.h | 53 +++++++++++++++++++------------ src/misc/task_executor.h | 2 +- src/protocol/AcknowledgeManager.h | 1 - src/protocol/CryptHandler.h | 2 -- src/protocol/Packet.h | 21 ++++++------ 5 files changed, 42 insertions(+), 37 deletions(-) diff --git a/src/converters/converter.h b/src/converters/converter.h index 21a8c25..0406c9c 100644 --- a/src/converters/converter.h +++ b/src/converters/converter.h @@ -3,6 +3,23 @@ #include #include #include +#include + +#define DEFINE_CONVERTER_ENUM(class, size_type) \ +namespace ts { \ + template <> \ + struct converter { \ + static constexpr bool supported{true}; \ + static constexpr bool references{false}; \ + \ + static constexpr std::string(*to_string)(const std::any&) = [](const std::any& val) { \ + return std::to_string(std::any_cast(val)); \ + }; \ + static constexpr class(*from_string_view)(const std::string_view&) = [](const std::string_view& val) { \ + return ((class(*)(const std::string_view&)) ts::converter::from_string_view)(val); \ + }; \ + }; \ +} namespace ts { typedef long double long_double; @@ -17,7 +34,7 @@ namespace ts { static constexpr T(*from_string_view)(const std::string_view&) = nullptr; }; - #define DECLARE_CONVERTER(type, decode, encode, references_) \ +#define DECLARE_CONVERTER(type, decode, encode, references_) \ template <> \ struct converter { \ static constexpr bool supported{true}; \ @@ -27,11 +44,11 @@ namespace ts { static constexpr type(*from_string_view)(const std::string_view&) = decode; \ }; - #define CONVERTER_METHOD_DECODE(type, name) type name(const std::string_view& str) - #define CONVERTER_METHOD_ENCODE(type, name) std::string name(const std::any& value) +#define CONVERTER_METHOD_DECODE(type, name) type name(const std::string_view& str) +#define CONVERTER_METHOD_ENCODE(type, name) std::string name(const std::any& value) /* helper for primitive types */ - #define CONVERTER_PRIMITIVE(type, references) \ +#define CONVERTER_PRIMITIVE(type, references) \ namespace impl { \ CONVERTER_METHOD_DECODE(type, converter_ ##type ##_decode); \ CONVERTER_METHOD_ENCODE(type, converter_ ##type ##_encode); \ @@ -68,27 +85,21 @@ namespace ts { template struct converter { using type = char[length]; - static constexpr bool supported = true; + static constexpr bool supported{true}; static constexpr std::string(*to_string)(const std::any&) = [](const std::any& value) { return std::string(std::any_cast(value), length - 1); }; }; - #undef CONVERTER_PRIMITIVE -} + /* We're not enabling this since we don't transport the unit + template + struct converter> { + using type = std::chrono::duration; + static constexpr bool supported{true}; -#define DEFINE_CONVERTER_ENUM(class, size_type) \ -namespace ts { \ - template <> \ - struct converter { \ - static constexpr bool supported{true}; \ - static constexpr bool references{false}; \ - \ - static constexpr std::string(*to_string)(const std::any&) = [](const std::any& val) { \ - return std::to_string(std::any_cast(val)); \ - }; \ - static constexpr class(*from_string_view)(const std::string_view&) = [](const std::string_view& val) { \ - return ((class(*)(const std::string_view&)) ts::converter::from_string_view)(val); \ - }; \ - }; \ + static constexpr std::string(*to_string)(const std::any&) = [](const std::any& value) { return std::to_string(std::any_cast(value)); }; + } + */ + +#undef CONVERTER_PRIMITIVE } /* DO NOT REMOVE ME (NL warning) */ \ No newline at end of file diff --git a/src/misc/task_executor.h b/src/misc/task_executor.h index cef41ae..f38dfde 100644 --- a/src/misc/task_executor.h +++ b/src/misc/task_executor.h @@ -84,7 +84,7 @@ namespace ts { /** * Helper class for tasks which could be executed multiple times. * It will avoid execution stacking while the task is executing. - * The task will never be executed twice only sequential. + * The task will never be executed twice, only sequential. * Note: If the `multi_shot_task` handle gets deleted no enqueued tasks will be executed. */ struct multi_shot_task { diff --git a/src/protocol/AcknowledgeManager.h b/src/protocol/AcknowledgeManager.h index 68cd70e..4503d2f 100644 --- a/src/protocol/AcknowledgeManager.h +++ b/src/protocol/AcknowledgeManager.h @@ -6,7 +6,6 @@ #include #include "./Packet.h" -#define DEBUG_ACKNOWLEDGE namespace ts::connection { class AcknowledgeManager { public: diff --git a/src/protocol/CryptHandler.h b/src/protocol/CryptHandler.h index 4fbd840..7ae070a 100644 --- a/src/protocol/CryptHandler.h +++ b/src/protocol/CryptHandler.h @@ -16,11 +16,9 @@ namespace ts::connection { void reset(); - //TeamSpeak old bool setupSharedSecret(const std::string& /* alpha */, const std::string& /* beta */, ecc_key* /* remote_public_key */, ecc_key* /* own_private_key */, std::string &/* error */); bool setupSharedSecret(const std::string& /* alpha */, const std::string& /* beta */, const std::string& /* shared_key */, std::string &/* error */); - //TeamSpeak new bool setupSharedSecretNew(const std::string& alpha, const std::string& beta, const char privateKey[32], const char publicKey[32]); bool encrypt( diff --git a/src/protocol/Packet.h b/src/protocol/Packet.h index fd517c0..167972a 100644 --- a/src/protocol/Packet.h +++ b/src/protocol/Packet.h @@ -10,18 +10,15 @@ namespace ts::protocol { enum PacketType : uint8_t { - VOICE = 0x00, - VOICE_WHISPER = 0x01, - COMMAND = 0x02, - COMMAND_LOW = 0x03, - PING = 0x04, - PONG = 0x05, - ACK = 0x06, - ACK_LOW = 0x07, - INIT1 = 0x08, - - PACKET_MAX = INIT1, - UNDEFINED = 0xFF + VOICE = 0x00, + VOICE_WHISPER = 0x01, + COMMAND = 0x02, + COMMAND_LOW = 0x03, + PING = 0x04, + PONG = 0x05, + ACK = 0x06, + ACK_LOW = 0x07, + INIT1 = 0x08, }; class PacketIdManager {