forgot to commit this at home
This commit is contained in:
parent
9fe643eb99
commit
b2ca8cc142
6 changed files with 41 additions and 28 deletions
|
@ -19,8 +19,9 @@ class Connection {
|
||||||
return this._isOpen;
|
return this._isOpen;
|
||||||
}
|
}
|
||||||
|
|
||||||
public constructor(address: string, handles: PacketHandle[], useCipher: boolean = false,
|
public constructor(address: string, handles: PacketHandle[],
|
||||||
onOpen: ConnEvent = null, onClose: ConnEvent = null, onError: ConnErrorEvent = null)
|
useCipher: boolean = false, onOpen: ConnEvent = null,
|
||||||
|
onClose: ConnEvent = null, onError: ConnErrorEvent = null)
|
||||||
{
|
{
|
||||||
this.address = address;
|
this.address = address;
|
||||||
this.useCipher = useCipher;
|
this.useCipher = useCipher;
|
||||||
|
@ -63,8 +64,9 @@ class Connection {
|
||||||
var raw = new Uint8Array(event.data);
|
var raw = new Uint8Array(event.data);
|
||||||
var msg: Packet;
|
var msg: Packet;
|
||||||
try {
|
try {
|
||||||
msg = !this.useCipher || !Cipher.ready ? Packet.fromBytes(raw)
|
msg = (!this.useCipher || !Cipher.ready)
|
||||||
: Packet.fromBytes(Cipher.parse(raw));
|
? Packet.fromBytes(raw)
|
||||||
|
: Packet.fromBytes(Cipher.parse(raw));
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
close();
|
close();
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -82,6 +82,11 @@ std::string sosc::net::pack_error_time() {
|
||||||
return std::string(6, 0);
|
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] &
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,36 +4,21 @@
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <chrono>
|
|
||||||
#include <ctime>
|
|
||||||
#include <mutex>
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
#undef htons
|
|
||||||
#undef HTONS
|
#undef HTONS
|
||||||
#undef htonus
|
|
||||||
#undef HTONUS
|
#undef HTONUS
|
||||||
#undef ntohs
|
|
||||||
#undef NTOHS
|
#undef NTOHS
|
||||||
#undef ntohus
|
|
||||||
#undef NTOHUS
|
#undef NTOHUS
|
||||||
|
|
||||||
#undef htonl
|
|
||||||
#undef HTONL
|
#undef HTONL
|
||||||
#undef htonul
|
|
||||||
#undef HTONUL
|
#undef HTONUL
|
||||||
#undef ntohl
|
|
||||||
#undef NTOHL
|
#undef NTOHL
|
||||||
#undef ntohul
|
|
||||||
#undef NTOHUL
|
#undef NTOHUL
|
||||||
|
|
||||||
#undef htonll
|
|
||||||
#undef HTONLL
|
#undef HTONLL
|
||||||
#undef htonull
|
|
||||||
#undef HTONULL
|
#undef HTONULL
|
||||||
#undef ntohll
|
|
||||||
#undef NTOHLL
|
#undef NTOHLL
|
||||||
#undef ntohull
|
|
||||||
#undef NTOHULL
|
#undef NTOHULL
|
||||||
|
|
||||||
#define HTONS (X) sosc::net::htonv<int16_t>(X)
|
#define HTONS (X) sosc::net::htonv<int16_t>(X)
|
||||||
|
@ -43,18 +28,15 @@
|
||||||
|
|
||||||
#define HTONL (X) sosc::net::htonv<int32_t>(X)
|
#define HTONL (X) sosc::net::htonv<int32_t>(X)
|
||||||
#define HTONUL(X) sosc::net::htonv<uint32_t>(X)
|
#define HTONUL(X) sosc::net::htonv<uint32_t>(X)
|
||||||
#define NTOHL (X) sosc::net::ntohv<int32_t>(X)
|
#define NTOHL (X) sosc::net::ntohv<int32_t>(X, 0)
|
||||||
#define NTOHUL(X) sosc::net::ntohv<uint32_t>(X)
|
#define NTOHUL(X) sosc::net::ntohv<uint32_t>(X, 0)
|
||||||
|
|
||||||
#define HTONLL (X) sosc::net::htonv<int64_t>(X)
|
#define HTONLL (X) sosc::net::htonv<int64_t>(X)
|
||||||
#define HTONULL(X) sosc::net::htonv<uint64_t>(X)
|
#define HTONULL(X) sosc::net::htonv<uint64_t>(X)
|
||||||
#define NTOHLL (X) sosc::net::ntohv<int64_t>(X)
|
#define NTOHLL (X) sosc::net::ntohv<int64_t>(X, 0)
|
||||||
#define NTOHULL(X) sosc::net::ntohv<uint64_t>(X)
|
#define NTOHULL(X) sosc::net::ntohv<uint64_t>(X, 0)
|
||||||
|
|
||||||
namespace sosc {
|
namespace sosc {
|
||||||
typedef std::chrono::system_clock clock;
|
|
||||||
typedef std::chrono::time_point<sosc::clock> time;
|
|
||||||
|
|
||||||
namespace net {
|
namespace net {
|
||||||
class IpAddress {
|
class IpAddress {
|
||||||
public:
|
public:
|
||||||
|
@ -70,6 +52,7 @@ template<typename T = uint32_t>
|
||||||
T ntohv(std::string net_var, size_t offset = 0);
|
T ntohv(std::string net_var, size_t offset = 0);
|
||||||
|
|
||||||
std::tm to_utc(const time_t* time);
|
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(std::string data, size_t offset = 0);
|
||||||
bool is_error_time(sosc::time time);
|
bool is_error_time(sosc::time time);
|
||||||
std::string pack_time();
|
std::string pack_time();
|
||||||
|
|
2
server/src/utils/time.cpp
Normal file
2
server/src/utils/time.cpp
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
#include "time.hpp"
|
||||||
|
|
21
server/src/utils/time.hpp
Normal file
21
server/src/utils/time.hpp
Normal 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
|
Loading…
Reference in a new issue