Some general code cleanup
This commit is contained in:
parent
393bc621c0
commit
88158742e8
@ -147,10 +147,20 @@ bool BasicChannel::verify_password(const std::optional<std::string> &password, b
|
||||
return base64::encode(digest::sha1(*password)) == channel_password;
|
||||
}
|
||||
|
||||
int64_t BasicChannel::emptySince() {
|
||||
time_point<system_clock> lastLeft = time_point<system_clock>() + milliseconds(
|
||||
properties()[property::CHANNEL_LAST_LEFT].as_or<uint64_t>(0));
|
||||
return (int64_t) duration_cast<seconds>(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<uint64_t>(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<seconds>(current_timestamp - last_channel_leave).count();
|
||||
}
|
||||
|
||||
void BasicChannel::setLinkedHandle(const std::weak_ptr<TreeView::LinkedTreeEntry> &ptr) {
|
||||
|
@ -55,7 +55,7 @@ namespace ts {
|
||||
[[nodiscard]] bool verify_password(const std::optional<std::string>&, 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(
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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{};
|
||||
|
@ -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<std::mutex>& /* buffer lock */, ReassembledCommand*& /* command */);
|
||||
};
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user