summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFlorent Le Coz <louiz@louiz.org>2014-05-30 16:08:23 +0200
committerFlorent Le Coz <louiz@louiz.org>2014-05-30 16:08:23 +0200
commitc2311b2893f3db755b67c43e5ad60cef66b10ab2 (patch)
treec9f3199474597dbd0c1deb4b5f91144c5f4c4eb5 /src
parent5c9d2c23ba6a401bc9494a6023491bbf3ade8d34 (diff)
downloadbiboumi-c2311b2893f3db755b67c43e5ad60cef66b10ab2.tar.gz
biboumi-c2311b2893f3db755b67c43e5ad60cef66b10ab2.tar.bz2
biboumi-c2311b2893f3db755b67c43e5ad60cef66b10ab2.tar.xz
biboumi-c2311b2893f3db755b67c43e5ad60cef66b10ab2.zip
Send (every 240s) a PING command to all connected irc servers
fix #2452
Diffstat (limited to 'src')
-rw-r--r--src/bridge/bridge.cpp5
-rw-r--r--src/bridge/bridge.hpp4
-rw-r--r--src/irc/irc_client.cpp15
-rw-r--r--src/irc/irc_client.hpp1
4 files changed, 25 insertions, 0 deletions
diff --git a/src/bridge/bridge.cpp b/src/bridge/bridge.cpp
index 70650a5..3377135 100644
--- a/src/bridge/bridge.cpp
+++ b/src/bridge/bridge.cpp
@@ -63,6 +63,11 @@ void Bridge::clean()
}
}
+const std::string& Bridge::get_jid() const
+{
+ return this->user_jid;
+}
+
Xmpp::body Bridge::make_xmpp_body(const std::string& str)
{
std::string res;
diff --git a/src/bridge/bridge.hpp b/src/bridge/bridge.hpp
index 2618ca6..9c06947 100644
--- a/src/bridge/bridge.hpp
+++ b/src/bridge/bridge.hpp
@@ -32,6 +32,10 @@ public:
* Remove all inactive IrcClients
*/
void clean();
+ /**
+ * Return the jid of the XMPP user using this bridge
+ */
+ const std::string& get_jid() const;
static Xmpp::body make_xmpp_body(const std::string& str);
/***
diff --git a/src/irc/irc_client.cpp b/src/irc/irc_client.cpp
index f08e9d6..01bf569 100644
--- a/src/irc/irc_client.cpp
+++ b/src/irc/irc_client.cpp
@@ -1,3 +1,4 @@
+#include <utils/timed_events.hpp>
#include <irc/irc_message.hpp>
#include <irc/irc_client.hpp>
#include <bridge/bridge.hpp>
@@ -10,8 +11,11 @@
#include <iostream>
#include <stdexcept>
+#include <chrono>
#include <string>
+
using namespace std::string_literals;
+using namespace std::chrono_literals;
IrcClient::IrcClient(std::shared_ptr<Poller> poller, const std::string& hostname, const std::string& username, Bridge* bridge):
SocketHandler(poller),
@@ -35,6 +39,9 @@ IrcClient::IrcClient(std::shared_ptr<Poller> poller, const std::string& hostname
IrcClient::~IrcClient()
{
+ // This event may or may not exist (if we never got connected, it
+ // doesn't), but it's ok
+ TimedEventsManager::instance().cancel("PING"s + this->hostname + this->bridge->get_jid());
}
void IrcClient::start()
@@ -238,6 +245,11 @@ void IrcClient::send_pong_command(const IrcMessage& message)
this->send_message(IrcMessage("PONG", {id}));
}
+void IrcClient::send_ping_command()
+{
+ this->send_message(IrcMessage("PING", {"biboumi"}));
+}
+
void IrcClient::forward_server_message(const IrcMessage& message)
{
const std::string from = message.prefix;
@@ -447,6 +459,9 @@ void IrcClient::on_welcome_message(const IrcMessage& message)
{
this->current_nick = message.arguments[0];
this->welcomed = true;
+ // Install a repeated events to regularly send a PING
+ TimedEventsManager::instance().add_event(TimedEvent(240s, std::bind(&IrcClient::send_ping_command, this),
+ "PING"s + this->hostname + this->bridge->get_jid()));
for (const std::string& chan_name: this->channels_to_join)
this->send_join_command(chan_name);
this->channels_to_join.clear();
diff --git a/src/irc/irc_client.hpp b/src/irc/irc_client.hpp
index e6fb393..2f28c95 100644
--- a/src/irc/irc_client.hpp
+++ b/src/irc/irc_client.hpp
@@ -70,6 +70,7 @@ public:
* Send the PONG irc command
*/
void send_pong_command(const IrcMessage& message);
+ void send_ping_command();
/**
* Send the USER irc command
*/