diff --git a/client/src/sock/Connection.ts b/client/src/sock/Connection.ts index b303ec9..6903f01 100644 --- a/client/src/sock/Connection.ts +++ b/client/src/sock/Connection.ts @@ -19,8 +19,9 @@ class Connection { return this._isOpen; } - public constructor(address: string, handles: PacketHandle[], useCipher: boolean = false, - onOpen: ConnEvent = null, onClose: ConnEvent = null, onError: ConnErrorEvent = null) + public constructor(address: string, handles: PacketHandle[], + useCipher: boolean = false, onOpen: ConnEvent = null, + onClose: ConnEvent = null, onError: ConnErrorEvent = null) { this.address = address; this.useCipher = useCipher; @@ -63,8 +64,9 @@ class Connection { var raw = new Uint8Array(event.data); var msg: Packet; try { - msg = !this.useCipher || !Cipher.ready ? Packet.fromBytes(raw) - : Packet.fromBytes(Cipher.parse(raw)); + msg = (!this.useCipher || !Cipher.ready) + ? Packet.fromBytes(raw) + : Packet.fromBytes(Cipher.parse(raw)); } catch(e) { close(); return; diff --git a/server/CMakeLists.txt b/server/CMakeLists.txt index 37e2350..8ecdb37 100644 --- a/server/CMakeLists.txt +++ b/server/CMakeLists.txt @@ -9,5 +9,5 @@ file(GLOB_RECURSE server_src set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -static -g") add_executable(server ${server_src}) -install(TARGETS server RUNTIME DESTINATION bin) +install(TARGETS server RUNTIME DESTINATION bin) diff --git a/server/src/utils/net.cpp b/server/src/utils/net.cpp index 3ff1f0b..894b3d5 100644 --- a/server/src/utils/net.cpp +++ b/server/src/utils/net.cpp @@ -82,6 +82,11 @@ std::string sosc::net::pack_error_time() { return std::string(6, 0); } -sosc::time unpack_time(std::string data, size_t offset = 0) { +sosc::time unpack_time(std::string data, size_t offset) { + if(offset + 6 >= data.length()) + return pack_error_time(); + struct tm time = tm(); + time.tm_year = ((data[offset] & } + diff --git a/server/src/utils/net.hpp b/server/src/utils/net.hpp index 593aa70..490dddc 100644 --- a/server/src/utils/net.hpp +++ b/server/src/utils/net.hpp @@ -4,36 +4,21 @@ #include #include #include -#include -#include -#include #include -#undef htons #undef HTONS -#undef htonus #undef HTONUS -#undef ntohs #undef NTOHS -#undef ntohus #undef NTOHUS -#undef htonl #undef HTONL -#undef htonul #undef HTONUL -#undef ntohl #undef NTOHL -#undef ntohul #undef NTOHUL -#undef htonll #undef HTONLL -#undef htonull #undef HTONULL -#undef ntohll #undef NTOHLL -#undef ntohull #undef NTOHULL #define HTONS (X) sosc::net::htonv(X) @@ -43,18 +28,15 @@ #define HTONL (X) sosc::net::htonv(X) #define HTONUL(X) sosc::net::htonv(X) -#define NTOHL (X) sosc::net::ntohv(X) -#define NTOHUL(X) sosc::net::ntohv(X) +#define NTOHL (X) sosc::net::ntohv(X, 0) +#define NTOHUL(X) sosc::net::ntohv(X, 0) #define HTONLL (X) sosc::net::htonv(X) #define HTONULL(X) sosc::net::htonv(X) -#define NTOHLL (X) sosc::net::ntohv(X) -#define NTOHULL(X) sosc::net::ntohv(X) +#define NTOHLL (X) sosc::net::ntohv(X, 0) +#define NTOHULL(X) sosc::net::ntohv(X, 0) namespace sosc { -typedef std::chrono::system_clock clock; -typedef std::chrono::time_point time; - namespace net { class IpAddress { public: @@ -70,6 +52,7 @@ template T ntohv(std::string net_var, size_t offset = 0); std::tm to_utc(const time_t* time); +sosc::time error_time(); bool is_error_time(std::string data, size_t offset = 0); bool is_error_time(sosc::time time); std::string pack_time(); diff --git a/server/src/utils/time.cpp b/server/src/utils/time.cpp new file mode 100644 index 0000000..52085a7 --- /dev/null +++ b/server/src/utils/time.cpp @@ -0,0 +1,2 @@ +#include "time.hpp" + diff --git a/server/src/utils/time.hpp b/server/src/utils/time.hpp new file mode 100644 index 0000000..2cdcd7b --- /dev/null +++ b/server/src/utils/time.hpp @@ -0,0 +1,21 @@ +#ifndef SOSC_UTIL_TIME_H +#define SOSC_UTIL_TIME_H + +#include +#include +#include +#include +#include +#include +#include + +namespace sosc { +typedef std::chrono::system_clock clock; +typedef std::chrono::time_point time; + +namespace clk { + +}} + + +#endif