mirror of
https://github.com/pragma-/pbot.git
synced 2025-09-27 06:37:23 +02:00

- wait until fully connected (irc.welcome) before sending PING - do not send another PING until PONG is received These changes prevent the bot from sending multiple PINGs when the ircd is heavily lagging. The multiple PINGs would queue up and then get sent all at once when the ircd unlagged, potentially causing an excess-flood disconnection.
55 lines
1.6 KiB
Perl
55 lines
1.6 KiB
Perl
# File: LagChecker.pm
|
|
#
|
|
# Purpose: Registers command to query lag history.
|
|
|
|
# SPDX-FileCopyrightText: 2010-2023 Pragmatic Software <pragma78@gmail.com>
|
|
# SPDX-License-Identifier: MIT
|
|
|
|
package PBot::Core::Commands::LagChecker;
|
|
use parent 'PBot::Core::Class';
|
|
|
|
use PBot::Imports;
|
|
|
|
use Time::Duration qw/concise ago/;
|
|
use Time::HiRes qw/gettimeofday tv_interval/;
|
|
|
|
sub initialize($self, %conf) {
|
|
$self->{pbot}->{commands}->register(sub { $self->cmd_lagcheck(@_) }, "lagcheck", 0);
|
|
}
|
|
|
|
sub cmd_lagcheck($self, $context) {
|
|
if (defined $self->{pbot}->{lagchecker}->{pong_received} and $self->{pbot}->{lagchecker}->{pong_received} == 0) {
|
|
# a ping has been sent (pong_received is not undef) and no pong has been received yet
|
|
my $elapsed = tv_interval($self->{pbot}->{lagchecker}->{ping_send_time}) * 1000;
|
|
my $lag_total = $elapsed;
|
|
my $len = @{$self->{pbot}->{lagchecker}->{lag_history}};
|
|
|
|
my @entries;
|
|
|
|
foreach my $entry (@{$self->{pbot}->{lagchecker}->{lag_history}}) {
|
|
my ($send_time, $lag_result) = @$entry;
|
|
|
|
$lag_total += $lag_result;
|
|
|
|
my $ago = concise ago(gettimeofday - $send_time);
|
|
|
|
push @entries, "[$ago] " . sprintf "%.1f ms", $lag_result;
|
|
}
|
|
|
|
push @entries, "[waiting for pong] $elapsed";
|
|
|
|
my $lagstring = join '; ', @entries;
|
|
|
|
my $average = $lag_total / ($len + 1);
|
|
|
|
$lagstring .= "; average: " . sprintf "%.1f ms", $average;
|
|
|
|
return $lagstring;
|
|
}
|
|
|
|
return "My lag: " . $self->{pbot}->{lagchecker}->lagstring;
|
|
}
|
|
|
|
|
|
1;
|