Some minor updates

This commit is contained in:
WolverinDEV 2021-07-23 14:59:43 +02:00
parent 9f03f33a23
commit f127894110
5 changed files with 42 additions and 37 deletions

View File

@ -3,6 +3,23 @@
#include <any> #include <any>
#include <string> #include <string>
#include <cstddef> #include <cstddef>
#include <chrono>
#define DEFINE_CONVERTER_ENUM(class, size_type) \
namespace ts { \
template <> \
struct converter<class> { \
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<class>(val)); \
}; \
static constexpr class(*from_string_view)(const std::string_view&) = [](const std::string_view& val) { \
return ((class(*)(const std::string_view&)) ts::converter<size_type>::from_string_view)(val); \
}; \
}; \
}
namespace ts { namespace ts {
typedef long double long_double; typedef long double long_double;
@ -17,7 +34,7 @@ namespace ts {
static constexpr T(*from_string_view)(const std::string_view&) = nullptr; 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 <> \ template <> \
struct converter<type> { \ struct converter<type> { \
static constexpr bool supported{true}; \ static constexpr bool supported{true}; \
@ -27,11 +44,11 @@ namespace ts {
static constexpr type(*from_string_view)(const std::string_view&) = decode; \ 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_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_ENCODE(type, name) std::string name(const std::any& value)
/* helper for primitive types */ /* helper for primitive types */
#define CONVERTER_PRIMITIVE(type, references) \ #define CONVERTER_PRIMITIVE(type, references) \
namespace impl { \ namespace impl { \
CONVERTER_METHOD_DECODE(type, converter_ ##type ##_decode); \ CONVERTER_METHOD_DECODE(type, converter_ ##type ##_decode); \
CONVERTER_METHOD_ENCODE(type, converter_ ##type ##_encode); \ CONVERTER_METHOD_ENCODE(type, converter_ ##type ##_encode); \
@ -68,27 +85,21 @@ namespace ts {
template <int length> template <int length>
struct converter<char[length]> { struct converter<char[length]> {
using type = char[length]; 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<const char*>(value), length - 1); }; static constexpr std::string(*to_string)(const std::any&) = [](const std::any& value) { return std::string(std::any_cast<const char*>(value), length - 1); };
}; };
#undef CONVERTER_PRIMITIVE /* We're not enabling this since we don't transport the unit
} template <typename Rep, typename Period>
struct converter<std::chrono::duration<Rep, Period>> {
using type = std::chrono::duration<Rep, Period>;
static constexpr bool supported{true};
#define DEFINE_CONVERTER_ENUM(class, size_type) \ static constexpr std::string(*to_string)(const std::any&) = [](const std::any& value) { return std::to_string(std::any_cast<type>(value)); };
namespace ts { \ }
template <> \ */
struct converter<class> { \
static constexpr bool supported{true}; \ #undef CONVERTER_PRIMITIVE
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<class>(val)); \
}; \
static constexpr class(*from_string_view)(const std::string_view&) = [](const std::string_view& val) { \
return ((class(*)(const std::string_view&)) ts::converter<size_type>::from_string_view)(val); \
}; \
}; \
} }
/* DO NOT REMOVE ME (NL warning) */ /* DO NOT REMOVE ME (NL warning) */

View File

@ -84,7 +84,7 @@ namespace ts {
/** /**
* Helper class for tasks which could be executed multiple times. * Helper class for tasks which could be executed multiple times.
* It will avoid execution stacking while the task is executing. * 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. * Note: If the `multi_shot_task` handle gets deleted no enqueued tasks will be executed.
*/ */
struct multi_shot_task { struct multi_shot_task {

View File

@ -6,7 +6,6 @@
#include <mutex> #include <mutex>
#include "./Packet.h" #include "./Packet.h"
#define DEBUG_ACKNOWLEDGE
namespace ts::connection { namespace ts::connection {
class AcknowledgeManager { class AcknowledgeManager {
public: public:

View File

@ -16,11 +16,9 @@ namespace ts::connection {
void reset(); 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 */, 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 */); 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 setupSharedSecretNew(const std::string& alpha, const std::string& beta, const char privateKey[32], const char publicKey[32]);
bool encrypt( bool encrypt(

View File

@ -10,18 +10,15 @@
namespace ts::protocol { namespace ts::protocol {
enum PacketType : uint8_t { enum PacketType : uint8_t {
VOICE = 0x00, VOICE = 0x00,
VOICE_WHISPER = 0x01, VOICE_WHISPER = 0x01,
COMMAND = 0x02, COMMAND = 0x02,
COMMAND_LOW = 0x03, COMMAND_LOW = 0x03,
PING = 0x04, PING = 0x04,
PONG = 0x05, PONG = 0x05,
ACK = 0x06, ACK = 0x06,
ACK_LOW = 0x07, ACK_LOW = 0x07,
INIT1 = 0x08, INIT1 = 0x08,
PACKET_MAX = INIT1,
UNDEFINED = 0xFF
}; };
class PacketIdManager { class PacketIdManager {