From a685b5af7ad225d56bd47ebddbb9849c29acb7a6 Mon Sep 17 00:00:00 2001 From: deutor Date: Thu, 25 Aug 2016 11:34:54 +0200 Subject: [PATCH 1/5] IRC bot - detect lost communication Force reconnect if no data received from server for config['irc_conn_timeout'] seconds (that may happen when network/VPN goes down - in such case IRC bot won't get immediately notification that connection was lost, at least till it tries to send anything). --- irc.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/irc.php b/irc.php index 44093ed068..62d9ce45e7 100755 --- a/irc.php +++ b/irc.php @@ -28,7 +28,8 @@ require_once 'includes/discovery/functions.inc.php'; error_reporting(E_ERROR); class ircbot { - + private $last_activity = ''; + private $data = ''; private $authd = array(); @@ -149,6 +150,8 @@ class ircbot { $this->connect_alert(); } + $this->last_activity = time(); + $this->j = 2; $this->connect(); @@ -170,6 +173,17 @@ class ircbot { if ($this->config['irc_alert']) { $this->alertData(); } + + if($this->config['irc_conn_timeout']) { + $inactive_seconds = time() - $this->last_activity; + $max_inactive = $this->config['irc_conn_timeout']; + + if( $inactive_seconds > $max_inactive) { + $this->log("No data from server since " . $max_inactive . " seconds. Restarting."); + break; + } + } + usleep($this->tick); } @@ -267,6 +281,7 @@ class ircbot { private function getData() { if (($data = $this->read('irc')) !== false) { + $this->last_activity = time(); $this->data = $data; $ex = explode(' ', $this->data); if ($ex[0] == 'PING') { From f69954e29fbeda49524afb8f43af720f4db0962b Mon Sep 17 00:00:00 2001 From: deutor Date: Thu, 25 Aug 2016 11:38:32 +0200 Subject: [PATCH 2/5] Update irc.php --- irc.php | 1 + 1 file changed, 1 insertion(+) diff --git a/irc.php b/irc.php index 62d9ce45e7..5b50cc61ad 100755 --- a/irc.php +++ b/irc.php @@ -28,6 +28,7 @@ require_once 'includes/discovery/functions.inc.php'; error_reporting(E_ERROR); class ircbot { + private $last_activity = ''; private $data = ''; From 7c9a176d639d849eebc546263244b5f8df80c767 Mon Sep 17 00:00:00 2001 From: deutor Date: Thu, 25 Aug 2016 11:42:05 +0200 Subject: [PATCH 3/5] Update irc.php --- irc.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/irc.php b/irc.php index 5b50cc61ad..b857914cb7 100755 --- a/irc.php +++ b/irc.php @@ -28,9 +28,9 @@ require_once 'includes/discovery/functions.inc.php'; error_reporting(E_ERROR); class ircbot { - + private $last_activity = ''; - + private $data = ''; private $authd = array(); From 55a962e02fdb9d0b411e27c2e1ac5f672eec6321 Mon Sep 17 00:00:00 2001 From: deutor Date: Thu, 25 Aug 2016 11:44:04 +0200 Subject: [PATCH 4/5] Update irc.php --- irc.php | 1 - 1 file changed, 1 deletion(-) diff --git a/irc.php b/irc.php index b857914cb7..6694a17af0 100755 --- a/irc.php +++ b/irc.php @@ -178,7 +178,6 @@ class ircbot { if($this->config['irc_conn_timeout']) { $inactive_seconds = time() - $this->last_activity; $max_inactive = $this->config['irc_conn_timeout']; - if( $inactive_seconds > $max_inactive) { $this->log("No data from server since " . $max_inactive . " seconds. Restarting."); break; From 7547f4905c78a1087b5c7238ce9774a42f922740 Mon Sep 17 00:00:00 2001 From: deutor Date: Thu, 25 Aug 2016 11:48:20 +0200 Subject: [PATCH 5/5] Update irc.php --- irc.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/irc.php b/irc.php index 6694a17af0..a916d595c1 100755 --- a/irc.php +++ b/irc.php @@ -175,10 +175,10 @@ class ircbot { $this->alertData(); } - if($this->config['irc_conn_timeout']) { + if ($this->config['irc_conn_timeout']) { $inactive_seconds = time() - $this->last_activity; $max_inactive = $this->config['irc_conn_timeout']; - if( $inactive_seconds > $max_inactive) { + if ($inactive_seconds > $max_inactive) { $this->log("No data from server since " . $max_inactive . " seconds. Restarting."); break; }