From 1c448ed41cac523f28e37c6e6b4e850090582c90 Mon Sep 17 00:00:00 2001 From: WolverinDEV Date: Sat, 6 Feb 2021 22:35:43 +0100 Subject: [PATCH] Fixed windows --- CMakeLists.txt | 3 +- src/PermissionManager.h | 1 - src/Properties.h | 1 - src/bbcode/bbcodes.cpp | 20 +++++++---- src/lookup/ipv4.h | 58 +++++++++++++------------------ src/lookup/ipv6.h | 64 ++++++++++++++--------------------- src/protocol/CryptHandler.cpp | 21 +++++++----- src/protocol/Packet.h | 1 + src/protocol/buffers.h | 4 --- src/query/Command.h | 25 +++++++------- 10 files changed, 88 insertions(+), 110 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4eb9c3e..1b8e645 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -138,8 +138,6 @@ set(SOURCE_FILES src/protocol/ringbuffer.cpp src/protocol/AcknowledgeManager.cpp src/protocol/PacketLossCalculator.cpp - - src/lookup/ip.cpp ) set(HEADER_FILES @@ -219,6 +217,7 @@ if (TEASPEAK_SERVER) set(SOURCE_FILES ${SOURCE_FILES} src/BasicChannel.cpp + src/lookup/ip.cpp ) set(HEADER_FILES ${HEADER_FILES} diff --git a/src/PermissionManager.h b/src/PermissionManager.h index 26d1533..3a7ba39 100644 --- a/src/PermissionManager.h +++ b/src/PermissionManager.h @@ -15,7 +15,6 @@ #include "misc/spin_mutex.h" #include "Definitions.h" #include "Variable.h" -#include "spdlog/fmt/ostr.h" // must be included #define permNotGranted (-2) #define PERM_ID_GRANT ((ts::permission::PermissionType) (1U << 15U)) diff --git a/src/Properties.h b/src/Properties.h index 88cd413..a2a9b35 100644 --- a/src/Properties.h +++ b/src/Properties.h @@ -2,7 +2,6 @@ #include #include "misc/memtracker.h" -#include #include "Variable.h" #include #include diff --git a/src/bbcode/bbcodes.cpp b/src/bbcode/bbcodes.cpp index 90e0f9e..2bb294d 100644 --- a/src/bbcode/bbcodes.cpp +++ b/src/bbcode/bbcodes.cpp @@ -1,5 +1,6 @@ #include #include +#include #include "bbcodes.h" using namespace std; @@ -7,8 +8,9 @@ using namespace bbcode; bool bbcode::sloppy::has_tag(std::string message, std::deque tag) { std::transform(message.begin(), message.end(), message.begin(), ::tolower); - for(auto& entry : tag) + for(auto& entry : tag) { std::transform(entry.begin(), entry.end(), entry.begin(), ::tolower); + } std::deque begins; size_t index = 0, found, length = 0; @@ -17,17 +19,23 @@ bool bbcode::sloppy::has_tag(std::string message, std::deque tag) { for(auto it = tag.begin(); it != tag.end() && found == string::npos; it++) { found = message.find(*it, index); length = it->length(); - }; + } + if(found > 0 && found + length < message.length()) { if(message[found + length] == ']' || (message[found + length] == '=' && message.find(']', found + length) != string::npos)) { if(message[found - 1] == '/') { auto found_tag = message.substr(found, length); - for(const auto& entry : begins) - if(entry == found_tag) return true; - } else if(message[found - 1] == '[' && (found < 2 || message[found - 2] != '\\')) + for(const auto& entry : begins) { + if(entry == found_tag) { + return true; + } + } + } else if(message[found - 1] == '[' && (found < 2 || message[found - 2] != '\\')) { begins.push_back(message.substr(found, length)); - if(message[found + length] != ']') + } + if(message[found + length] != ']') { found = message.find(']', found + length); + } } } index = found + 1; diff --git a/src/lookup/ipv4.h b/src/lookup/ipv4.h index ca51ad9..f174f2e 100644 --- a/src/lookup/ipv4.h +++ b/src/lookup/ipv4.h @@ -3,44 +3,32 @@ #include #include "./ip.h" -namespace lookup { - namespace ipv4_impl { - union uaddress_t { - struct { - uint32_t address{0}; - uint16_t port{0}; - }; - - uint64_t value; +namespace lookup::ipv4_impl { + union uaddress_t { + struct { + uint32_t address; + uint16_t port; }; - struct converter { - constexpr inline void operator()(uaddress_t& result, const sockaddr_in& addr) { - result.address = addr.sin_addr.s_addr; - result.port = addr.sin_port; - } - }; + uint64_t value; + }; - struct comparator { - constexpr inline bool operator()(const uaddress_t& a, const uaddress_t& b) { - return a.value == b.value; - } - }; + struct converter { + constexpr inline void operator()(uaddress_t& result, const sockaddr_in& addr) { + result.address = addr.sin_addr.s_addr; + result.port = addr.sin_port; + } + }; - struct hash { - constexpr inline uint8_t operator()(const sockaddr_in& address) { - return (address.sin_addr.s_addr & 0xFFU) ^ (address.sin_port); - } - }; - } + struct comparator { + constexpr inline bool operator()(const uaddress_t& a, const uaddress_t& b) { + return a.value == b.value; + } + }; - template - using ip_v4 = ip_vx< - T, - sockaddr_in, - ipv4_impl::uaddress_t, - ipv4_impl::converter, - ipv4_impl::comparator, - ipv4_impl::hash - >; + struct hash { + constexpr inline uint8_t operator()(const sockaddr_in& address) { + return (address.sin_addr.s_addr & 0xFFU) ^ (address.sin_port); + } + }; } \ No newline at end of file diff --git a/src/lookup/ipv6.h b/src/lookup/ipv6.h index 611cdc6..30c61a9 100644 --- a/src/lookup/ipv6.h +++ b/src/lookup/ipv6.h @@ -1,53 +1,39 @@ #pragma once -#include #include - #include "./ip.h" -namespace lookup { - namespace ipv6_impl { - struct address_t { - union { - uint64_t address_u64[ 2]; - }; - - uint16_t port; +namespace lookup::ipv6_impl { + struct address_t { + union { + uint64_t address_u64[ 2]; }; - struct converter { - constexpr inline void operator()(address_t& result, const sockaddr_in6& addr) { - auto addr_ptr = (uint64_t*) &addr.sin6_addr; + uint16_t port; + }; - result.address_u64[0] = addr_ptr[0]; - result.address_u64[1] = addr_ptr[1]; + struct converter { + constexpr inline void operator()(address_t& result, const sockaddr_in6& addr) { + auto addr_ptr = (uint64_t*) &addr.sin6_addr; - result.port = addr.sin6_port; - } - }; + result.address_u64[0] = addr_ptr[0]; + result.address_u64[1] = addr_ptr[1]; - struct comparator { - constexpr inline bool operator()(const address_t& a, const address_t& b) { - return a.address_u64[0] == b.address_u64[0] && a.address_u64[1] == b.address_u64[1] && a.port == b.port; - } - }; + result.port = addr.sin6_port; + } + }; - struct hash { - constexpr inline uint8_t operator()(const sockaddr_in6& address) { - auto addr_ptr = (uint8_t*) &address.sin6_addr; + struct comparator { + constexpr inline bool operator()(const address_t& a, const address_t& b) { + return a.address_u64[0] == b.address_u64[0] && a.address_u64[1] == b.address_u64[1] && a.port == b.port; + } + }; - return (uint8_t) (addr_ptr[8] ^ addr_ptr[9]) ^ (uint8_t) (addr_ptr[15] ^ address.sin6_port); - } - }; - } + struct hash { + constexpr inline uint8_t operator()(const sockaddr_in6& address) { + auto addr_ptr = (uint8_t*) &address.sin6_addr; - template - using ip_v6 = ip_vx< - T, - sockaddr_in6, - ipv6_impl::address_t, - ipv6_impl::converter, - ipv6_impl::comparator, - ipv6_impl::hash - >; + return (uint8_t) (addr_ptr[8] ^ addr_ptr[9]) ^ (uint8_t) (addr_ptr[15] ^ address.sin6_port); + } + }; } \ No newline at end of file diff --git a/src/protocol/CryptHandler.cpp b/src/protocol/CryptHandler.cpp index d2adb62..b7bd050 100644 --- a/src/protocol/CryptHandler.cpp +++ b/src/protocol/CryptHandler.cpp @@ -1,13 +1,14 @@ //#define NO_OPEN_SSL /* because we're lazy and dont want to build this lib extra for the TeaClient */ #define FIXEDINT_H_INCLUDED /* else it will be included by ge */ - -#include "misc/endianness.h" -#include +#include #include -#include -#include "misc/memtracker.h" -#include "misc/digest.h" -#include "CryptHandler.h" +#include +#include + +#include "./CryptHandler.h" +#include "../misc/endianness.h" +#include "../misc/memtracker.h" +#include "../misc/digest.h" #include "../misc/sassert.h" using namespace std; @@ -69,7 +70,7 @@ bool CryptHandler::setupSharedSecret(const std::string& alpha, const std::string } { - lock_guard lock(this->cache_key_lock); + std::lock_guard lock(this->cache_key_lock); memcpy(this->iv_struct, iv_buffer, SHA_DIGEST_LENGTH); this->iv_struct_length = SHA_DIGEST_LENGTH; @@ -171,7 +172,9 @@ bool CryptHandler::generate_key_nonce( ) { auto& key_cache_array = to_server ? this->cache_key_client : this->cache_key_server; if(type < 0 || type >= key_cache_array.max_size()) { +#if 0 logError(0, "Tried to generate a crypt key with invalid type ({})!", type); +#endif return false; } @@ -180,7 +183,7 @@ bool CryptHandler::generate_key_nonce( auto& key_cache = key_cache_array[type]; if(key_cache.generation != generation) { const size_t buffer_length = 6 + this->iv_struct_length; - sassert(buffer_length < GENERATE_BUFFER_LENGTH); + assert(buffer_length < GENERATE_BUFFER_LENGTH); char buffer[GENERATE_BUFFER_LENGTH]; memset(buffer, 0, buffer_length); diff --git a/src/protocol/Packet.h b/src/protocol/Packet.h index 0d7a5e5..2bb8caa 100644 --- a/src/protocol/Packet.h +++ b/src/protocol/Packet.h @@ -4,6 +4,7 @@ #include #include #include +#include #include #include "../query/Command.h" diff --git a/src/protocol/buffers.h b/src/protocol/buffers.h index 8075a67..55e48e9 100644 --- a/src/protocol/buffers.h +++ b/src/protocol/buffers.h @@ -11,10 +11,6 @@ #include "./Packet.h" #include "../misc/queue.h" -#ifndef NO_LOG - #include -#endif - namespace ts::buffer { struct RawBuffer { public: diff --git a/src/query/Command.h b/src/query/Command.h index 8a3a146..633d314 100644 --- a/src/query/Command.h +++ b/src/query/Command.h @@ -1,7 +1,6 @@ #pragma once #ifdef byte - #define byte asdd #ifndef WIN32 #warning The byte macro is already defined! Undefining it! #endif @@ -18,17 +17,18 @@ #include "../Variable.h" namespace ts { -#define PARM_TYPE(type, fromString, toString) \ - BaseCommandParm(std::string key, type value) : BaseCommandParm(std::pair(key, "")) {\ - toString; \ - } \ -BaseCommandParm& operator=(type value){ \ - toString; \ - return *this; \ -} \ - \ -operator type(){ \ - fromString; \ +#define PARM_TYPE(type, fromString, toString) \ +BaseCommandParm(std::string key, type value) : BaseCommandParm(std::pair(key, "")) { \ + toString; \ +} \ + \ +BaseCommandParm& operator=(type value){ \ + toString; \ + return *this; \ +} \ + \ +operator type() { \ + fromString; \ } class Command; @@ -43,7 +43,6 @@ operator type(){ \ public: ParameterBulk(const ParameterBulk& ref) : parms(ref.parms) {} - variable operator[](size_t index){ if(parms.size() > index) return parms[index]; return variable{"", "", VARTYPE_NULL};