diff --git a/src/BasicChannel.cpp b/src/BasicChannel.cpp index b82ec3f..513d351 100644 --- a/src/BasicChannel.cpp +++ b/src/BasicChannel.cpp @@ -147,10 +147,20 @@ bool BasicChannel::verify_password(const std::optional &password, b return base64::encode(digest::sha1(*password)) == channel_password; } -int64_t BasicChannel::emptySince() { - time_point lastLeft = time_point() + milliseconds( - properties()[property::CHANNEL_LAST_LEFT].as_or(0)); - return (int64_t) duration_cast(system_clock::now() - lastLeft).count(); +uint64_t BasicChannel::empty_seconds() { + using std::chrono::system_clock; + using std::chrono::milliseconds; + using std::chrono::seconds; + using std::chrono::floor; + + auto last_channel_leave = system_clock::time_point{} + milliseconds{properties()[property::CHANNEL_LAST_LEFT].as_or(0)}; + auto current_timestamp = system_clock::now(); + if(current_timestamp < last_channel_leave) { + /* clock seems to have gone backwards */ + return 0; + } + + return (uint64_t) floor(current_timestamp - last_channel_leave).count(); } void BasicChannel::setLinkedHandle(const std::weak_ptr &ptr) { diff --git a/src/BasicChannel.h b/src/BasicChannel.h index 08fd2a8..5f00d23 100644 --- a/src/BasicChannel.h +++ b/src/BasicChannel.h @@ -55,7 +55,7 @@ namespace ts { [[nodiscard]] bool verify_password(const std::optional&, bool /* password already hashed */); bool defaultChannel() { return (*this->_properties)[property::CHANNEL_FLAG_DEFAULT]; } - int64_t emptySince(); + uint64_t empty_seconds(); inline std::chrono::system_clock::time_point createdTimestamp() { return std::chrono::system_clock::time_point() + std::chrono::milliseconds( diff --git a/src/Properties.h b/src/Properties.h index adee46a..e2c3c78 100644 --- a/src/Properties.h +++ b/src/Properties.h @@ -326,7 +326,7 @@ namespace ts { CLIENT_LOGIN_NAME, //used for serverquery clients, makes no sense on normal clients currently CLIENT_LOGIN_PASSWORD, //used for serverquery clients, makes no sense on normal clients currently CLIENT_DATABASE_ID, //automatically up-to-date for any client "in view", only valid with PERMISSION feature, holds database client id - CLIENT_ID, //clid! + CLIENT_ID, //clid! CLIENT_HARDWARE_ID, //hwid! CLIENT_CHANNEL_GROUP_ID, //automatically up-to-date for any client "in view", only valid with PERMISSION feature, holds database client id CLIENT_SERVERGROUPS, //automatically up-to-date for any client "in view", only valid with PERMISSION feature, holds all servergroups client belongs too diff --git a/src/log/LogSinks.cpp b/src/log/LogSinks.cpp index ef76cb0..7652248 100644 --- a/src/log/LogSinks.cpp +++ b/src/log/LogSinks.cpp @@ -27,7 +27,7 @@ namespace logger { continue; } - terminal::instance()->writeMessage(std::to_string(length) + "_" + std::to_string(index) + ": " + std::string{line}); + terminal::instance()->writeMessage(std::string{line}); } while(++index); } else { cout << message << std::flush; diff --git a/src/protocol/PacketDecoder.cpp b/src/protocol/PacketDecoder.cpp index d14dc16..d5b31a6 100644 --- a/src/protocol/PacketDecoder.cpp +++ b/src/protocol/PacketDecoder.cpp @@ -51,7 +51,15 @@ PacketProcessResult PacketDecoder::process_incoming_data(PacketParser &packet_pa } #endif #endif - auto result = this->decode_incoming_packet(error, packet_parser); + assert(packet_parser.type() >= 0 && packet_parser.type() < this->incoming_generation_estimators.size()); + + auto& generation_estimator = this->incoming_generation_estimators[packet_parser.type()]; + { + std::lock_guard glock{this->incoming_generation_estimator_lock}; + packet_parser.set_estimated_generation(generation_estimator.visit_packet(packet_parser.packet_id())); + } + + auto result = this->decrypt_incoming_packet(error, packet_parser); if(result != PacketProcessResult::SUCCESS) { return result; } @@ -142,15 +150,7 @@ PacketProcessResult PacketDecoder::process_incoming_data(PacketParser &packet_pa return PacketProcessResult::SUCCESS; } -PacketProcessResult PacketDecoder::decode_incoming_packet(std::string& error, PacketParser &packet_parser) { - assert(packet_parser.type() >= 0 && packet_parser.type() < this->incoming_generation_estimators.size()); - - auto& generation_estimator = this->incoming_generation_estimators[packet_parser.type()]; - { - std::lock_guard glock{this->incoming_generation_estimator_lock}; - packet_parser.set_estimated_generation(generation_estimator.visit_packet(packet_parser.packet_id())); - } - +PacketProcessResult PacketDecoder::decrypt_incoming_packet(std::string& error, PacketParser &packet_parser) { /* decrypt the packet if needed */ if(packet_parser.is_encrypted()) { CryptHandler::key_t crypt_key{}; diff --git a/src/protocol/PacketDecoder.h b/src/protocol/PacketDecoder.h index 10d5060..96870be 100644 --- a/src/protocol/PacketDecoder.h +++ b/src/protocol/PacketDecoder.h @@ -86,7 +86,7 @@ namespace ts::protocol { return packet_index & 0x1U; /* use 0 for command and 1 for command low */ } - PacketProcessResult decode_incoming_packet(std::string &error /* error */, protocol::PacketParser &packet_parser/* packet */); + PacketProcessResult decrypt_incoming_packet(std::string &error /* error */, protocol::PacketParser &packet_parser/* packet */); CommandReassembleResult try_reassemble_ordered_packet(command_fragment_buffer_t& /* buffer */, std::unique_lock& /* buffer lock */, ReassembledCommand*& /* command */); }; }