diff --git a/include/ki/protocol/control/ClientHello.h b/include/ki/protocol/control/ClientHello.h index f126d8c..98900a6 100644 --- a/include/ki/protocol/control/ClientHello.h +++ b/include/ki/protocol/control/ClientHello.h @@ -1,7 +1,5 @@ #pragma once #include "../../util/Serializable.h" -#include "../Packet.h" -#include "Opcode.h" #include #include @@ -15,14 +13,14 @@ namespace control { public: ClientHello(uint16_t session_id = 0, - uint32_t timestamp = 0, uint32_t milliseconds = 0); + int32_t timestamp = 0, uint32_t milliseconds = 0); virtual ~ClientHello() = default; uint16_t get_session_id() const; void set_session_id(uint16_t session_id); - uint32_t get_timestamp() const; - void set_timestamp(uint32_t timestamp); + int32_t get_timestamp() const; + void set_timestamp(int32_t timestamp); uint32_t get_milliseconds() const; void set_milliseconds(uint32_t milliseconds); @@ -30,12 +28,9 @@ namespace control void write_to(std::ostream &ostream) const override final; void read_from(std::istream &istream) override final; size_t get_size() const override final; - - static Packet *create_packet(uint16_t session_id = 0, - uint32_t timestamp = 0, uint32_t milliseconds = 0); private: uint16_t m_session_id; - uint32_t m_timestamp; + int32_t m_timestamp; uint32_t m_milliseconds; }; } diff --git a/include/ki/protocol/control/Ping.h b/include/ki/protocol/control/Ping.h index 5ab0b33..1b102c0 100644 --- a/include/ki/protocol/control/Ping.h +++ b/include/ki/protocol/control/Ping.h @@ -1,7 +1,5 @@ #pragma once #include "../../util/Serializable.h" -#include "../Packet.h" -#include "Opcode.h" #include namespace ki @@ -29,10 +27,6 @@ namespace control void write_to(std::ostream &ostream) const override final; void read_from(std::istream &istream) override final; size_t get_size() const override final; - - static Packet *create_packet(uint16_t session_id = 0, - uint16_t milliseconds = 0, uint8_t minutes = 0, - bool response = false); private: uint16_t m_session_id; uint16_t m_milliseconds; diff --git a/include/ki/protocol/control/ServerHello.h b/include/ki/protocol/control/ServerHello.h index f94106b..dd76843 100644 --- a/include/ki/protocol/control/ServerHello.h +++ b/include/ki/protocol/control/ServerHello.h @@ -1,7 +1,5 @@ #pragma once #include "../../util/Serializable.h" -#include "../Packet.h" -#include "Opcode.h" #include #include @@ -15,14 +13,14 @@ namespace control { public: ServerHello(uint16_t session_id = 0, - uint32_t timestamp = 0, uint32_t milliseconds = 0); + int32_t timestamp = 0, uint32_t milliseconds = 0); virtual ~ServerHello() = default; uint16_t get_session_id() const; void set_session_id(uint16_t session_id); - uint32_t get_timestamp() const; - void set_timestamp(uint32_t timestamp); + int32_t get_timestamp() const; + void set_timestamp(int32_t timestamp); uint32_t get_milliseconds() const; void set_milliseconds(uint32_t milliseconds); @@ -30,12 +28,9 @@ namespace control void write_to(std::ostream &ostream) const override final; void read_from(std::istream &istream) override final; size_t get_size() const override final; - - static Packet *create_packet(uint16_t session_id = 0, - uint32_t timestamp = 0, uint32_t milliseconds = 0); private: uint16_t m_session_id; - uint32_t m_timestamp; + int32_t m_timestamp; uint32_t m_milliseconds; }; } diff --git a/src/protocol/control/ClientHello.cpp b/src/protocol/control/ClientHello.cpp index 50b7cd9..6d6e819 100644 --- a/src/protocol/control/ClientHello.cpp +++ b/src/protocol/control/ClientHello.cpp @@ -7,8 +7,8 @@ namespace protocol { namespace control { - ClientHello::ClientHello(uint16_t session_id, - uint32_t timestamp, uint32_t milliseconds) + ClientHello::ClientHello(const uint16_t session_id, + const int32_t timestamp, const uint32_t milliseconds) { m_session_id = session_id; m_timestamp = timestamp; @@ -20,17 +20,17 @@ namespace control return m_session_id; } - void ClientHello::set_session_id(uint16_t session_id) + void ClientHello::set_session_id(const uint16_t session_id) { m_session_id = session_id; } - uint32_t ClientHello::get_timestamp() const + int32_t ClientHello::get_timestamp() const { return m_timestamp; } - void ClientHello::set_timestamp(uint32_t timestamp) + void ClientHello::set_timestamp(const int32_t timestamp) { m_timestamp = timestamp; } @@ -40,7 +40,7 @@ namespace control return m_milliseconds; } - void ClientHello::set_milliseconds(uint32_t milliseconds) + void ClientHello::set_milliseconds(const uint32_t milliseconds) { m_milliseconds = milliseconds; } @@ -50,7 +50,7 @@ namespace control dml::Record record; record.add_field("unknown"); record.add_field("unknown2"); - record.add_field("m_timestamp")->set_value(m_timestamp); + record.add_field("m_timestamp")->set_value(m_timestamp); record.add_field("m_milliseconds")->set_value(m_milliseconds); record.add_field("m_session_id")->set_value(m_session_id); record.write_to(ostream); @@ -61,7 +61,7 @@ namespace control dml::Record record; record.add_field("unknown"); record.add_field("unknown2"); - auto *timestamp = record.add_field("m_timestamp"); + auto *timestamp = record.add_field("m_timestamp"); auto *milliseconds = record.add_field("m_milliseconds"); auto *session_id = record.add_field("m_session_id"); record.read_from(istream); @@ -74,18 +74,9 @@ namespace control size_t ClientHello::get_size() const { return sizeof(dml::USHRT) + sizeof(dml::UINT) + - sizeof(dml::UINT) + sizeof(dml::UINT) + + sizeof(dml::INT) + sizeof(dml::UINT) + sizeof(dml::USHRT); } - - Packet *ClientHello::create_packet(uint16_t session_id, - uint32_t timestamp, uint32_t milliseconds) - { - const ClientHello data(session_id, timestamp, milliseconds); - auto *packet = new Packet(true, (uint8_t)Opcode::CLIENT_HELLO); - packet->set_payload_data(data); - return packet; - } } } } \ No newline at end of file diff --git a/src/protocol/control/Ping.cpp b/src/protocol/control/Ping.cpp index b5a2cd5..6260b6b 100644 --- a/src/protocol/control/Ping.cpp +++ b/src/protocol/control/Ping.cpp @@ -71,16 +71,6 @@ namespace control return sizeof(dml::USHRT) + sizeof(dml::USHRT) + sizeof(dml::UBYT); } - - Packet* Ping::create_packet(uint16_t session_id, - uint16_t milliseconds, uint8_t minutes, bool response) - { - const Ping data(session_id, milliseconds, minutes); - auto *packet = new Packet(true, - (uint8_t)(response ? Opcode::PING_RSP : Opcode::PING)); - packet->set_payload_data(data); - return packet; - } } } } \ No newline at end of file diff --git a/src/protocol/control/ServerHello.cpp b/src/protocol/control/ServerHello.cpp index 4be2c91..5f25d89 100644 --- a/src/protocol/control/ServerHello.cpp +++ b/src/protocol/control/ServerHello.cpp @@ -7,8 +7,8 @@ namespace protocol { namespace control { - ServerHello::ServerHello(uint16_t session_id, - uint32_t timestamp, uint32_t milliseconds) + ServerHello::ServerHello(const uint16_t session_id, + const int32_t timestamp, const uint32_t milliseconds) { m_session_id = session_id; m_timestamp = timestamp; @@ -20,17 +20,17 @@ namespace control return m_session_id; } - void ServerHello::set_session_id(uint16_t session_id) + void ServerHello::set_session_id(const uint16_t session_id) { m_session_id = session_id; } - uint32_t ServerHello::get_timestamp() const + int32_t ServerHello::get_timestamp() const { return m_timestamp; } - void ServerHello::set_timestamp(uint32_t timestamp) + void ServerHello::set_timestamp(const int32_t timestamp) { m_timestamp = timestamp; } @@ -40,7 +40,7 @@ namespace control return m_milliseconds; } - void ServerHello::set_milliseconds(uint32_t milliseconds) + void ServerHello::set_milliseconds(const uint32_t milliseconds) { m_milliseconds = milliseconds; } @@ -50,7 +50,7 @@ namespace control dml::Record record; record.add_field("m_session_id")->set_value(m_session_id); record.add_field("unknown"); - record.add_field("m_timestamp")->set_value(m_timestamp); + record.add_field("m_timestamp")->set_value(m_timestamp); record.add_field("m_milliseconds")->set_value(m_milliseconds); record.write_to(ostream); } @@ -60,7 +60,7 @@ namespace control dml::Record record; auto *session_id = record.add_field("m_session_id"); record.add_field("unknown"); - auto *timestamp = record.add_field("m_timestamp"); + auto *timestamp = record.add_field("m_timestamp"); auto *milliseconds = record.add_field("m_milliseconds"); record.read_from(istream); @@ -71,17 +71,8 @@ namespace control size_t ServerHello::get_size() const { - return sizeof(dml::USHRT) + sizeof(dml::GID) + - sizeof(dml::UINT); - } - - Packet *ServerHello::create_packet(uint16_t session_id, - uint32_t timestamp, uint32_t milliseconds) - { - const ServerHello data(session_id, timestamp, milliseconds); - auto *packet = new Packet(true, (uint8_t)Opcode::SERVER_HELLO); - packet->set_payload_data(data); - return packet; + return sizeof(dml::USHRT) + sizeof(dml::UINT) + + sizeof(dml::INT) + sizeof(dml::UINT); } } }