forgot to commit this at home

This commit is contained in:
malloc 2018-03-05 13:22:16 -06:00
parent 9fe643eb99
commit b2ca8cc142
6 changed files with 41 additions and 28 deletions

View file

@ -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;

View file

@ -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)

View file

@ -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] &
}

View file

@ -4,36 +4,21 @@
#include <sstream>
#include <algorithm>
#include <string>
#include <chrono>
#include <ctime>
#include <mutex>
#include <cstring>
#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<int16_t>(X)
@ -43,18 +28,15 @@
#define HTONL (X) sosc::net::htonv<int32_t>(X)
#define HTONUL(X) sosc::net::htonv<uint32_t>(X)
#define NTOHL (X) sosc::net::ntohv<int32_t>(X)
#define NTOHUL(X) sosc::net::ntohv<uint32_t>(X)
#define NTOHL (X) sosc::net::ntohv<int32_t>(X, 0)
#define NTOHUL(X) sosc::net::ntohv<uint32_t>(X, 0)
#define HTONLL (X) sosc::net::htonv<int64_t>(X)
#define HTONULL(X) sosc::net::htonv<uint64_t>(X)
#define NTOHLL (X) sosc::net::ntohv<int64_t>(X)
#define NTOHULL(X) sosc::net::ntohv<uint64_t>(X)
#define NTOHLL (X) sosc::net::ntohv<int64_t>(X, 0)
#define NTOHULL(X) sosc::net::ntohv<uint64_t>(X, 0)
namespace sosc {
typedef std::chrono::system_clock clock;
typedef std::chrono::time_point<sosc::clock> time;
namespace net {
class IpAddress {
public:
@ -70,6 +52,7 @@ template<typename T = uint32_t>
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();

View file

@ -0,0 +1,2 @@
#include "time.hpp"

21
server/src/utils/time.hpp Normal file
View file

@ -0,0 +1,21 @@
#ifndef SOSC_UTIL_TIME_H
#define SOSC_UTIL_TIME_H
#include <sstream>
#include <algorithm>
#include <string>
#include <cstring>
#include <chrono>
#include <ctime>
#include <mutex>
namespace sosc {
typedef std::chrono::system_clock clock;
typedef std::chrono::time_point<sosc::clock> time;
namespace clk {
}}
#endif