diff options
author | louiz’ <louiz@louiz.org> | 2017-01-22 21:31:50 +0100 |
---|---|---|
committer | louiz’ <louiz@louiz.org> | 2017-01-22 21:31:50 +0100 |
commit | 5d801ddcd025f68d2ec91edf0462091a32c779c1 (patch) | |
tree | 25aa1b7c66ada9a98e3027743c9552492689abf8 /src/bridge | |
parent | dd129366575f371bcec51b7303bfb273d6edc8a2 (diff) | |
download | biboumi-5d801ddcd025f68d2ec91edf0462091a32c779c1.tar.gz biboumi-5d801ddcd025f68d2ec91edf0462091a32c779c1.tar.bz2 biboumi-5d801ddcd025f68d2ec91edf0462091a32c779c1.tar.xz biboumi-5d801ddcd025f68d2ec91edf0462091a32c779c1.zip |
Add a linger_time configuration option on IRC servers
Diffstat (limited to 'src/bridge')
-rw-r--r-- | src/bridge/bridge.cpp | 22 | ||||
-rw-r--r-- | src/bridge/bridge.hpp | 5 |
2 files changed, 26 insertions, 1 deletions
diff --git a/src/bridge/bridge.cpp b/src/bridge/bridge.cpp index 16b1c68..ca9c9fa 100644 --- a/src/bridge/bridge.cpp +++ b/src/bridge/bridge.cpp @@ -11,6 +11,7 @@ #include <database/database.hpp> #include "result_set_management.hpp" #include <algorithm> +#include <utils/timed_events.hpp> using namespace std::string_literals; @@ -865,7 +866,7 @@ void Bridge::send_muc_leave(Iid&& iid, std::string&& nick, const std::string& me this->user_jid + "/" + res, self); IrcClient* irc = this->find_irc_client(iid.get_server()); if (irc && irc->number_of_joined_channels() == 0) - irc->send_quit_command(""); + this->quit_or_start_linger_timer(iid.get_server()); } void Bridge::send_nick_change(Iid&& iid, @@ -1212,3 +1213,22 @@ void Bridge::set_record_history(const bool val) this->record_history = val; } #endif + +void Bridge::quit_or_start_linger_timer(const std::string& irc_hostname) +{ +#ifdef USE_DATABASE + auto options = Database::get_irc_server_options(this->get_bare_jid(), + irc_hostname); + const auto timeout = std::chrono::seconds(options.lingerTime.value()); +#else + const auto timeout = 0s; +#endif + + const auto event_name = "IRCLINGER:" + irc_hostname + ".." + this->get_bare_jid(); + TimedEvent event(std::chrono::steady_clock::now() + timeout, [this, irc_hostname]() { + IrcClient* irc = this->find_irc_client(irc_hostname); + if (irc) + irc->send_quit_command(""); + }, event_name); + TimedEventsManager::instance().add_event(std::move(event)); +} diff --git a/src/bridge/bridge.hpp b/src/bridge/bridge.hpp index fc839b4..7d0166c 100644 --- a/src/bridge/bridge.hpp +++ b/src/bridge/bridge.hpp @@ -236,6 +236,11 @@ public: #ifdef USE_DATABASE void set_record_history(const bool val); #endif + /** + * Start a timer that will send a QUIT command after the + * configured linger time is expired. + */ + void quit_or_start_linger_timer(const std::string& irc_hostname); private: /** |