diff options
Diffstat (limited to 'lib/ASM')
| -rw-r--r-- | lib/ASM/Event.pm | 51 | ||||
| -rw-r--r-- | lib/ASM/Statsp.pm | 78 |
2 files changed, 79 insertions, 50 deletions
diff --git a/lib/ASM/Event.pm b/lib/ASM/Event.pm index ca48f7e..a5e1083 100644 --- a/lib/ASM/Event.pm +++ b/lib/ASM/Event.pm @@ -59,8 +59,6 @@ sub new $conn->add_handler('channelmodeis', \&on_channelmodeis); $conn->add_handler('quietlist', \&on_quietlist); $conn->add_handler('pong', \&on_pong); - $conn->add_handler('statsdebug', \&on_statsdebug); - $conn->add_handler('endofstats', \&on_endofstats); $conn->add_handler('channelurlis', \&on_channelurlis); $conn->add_handler('480', \&on_jointhrottled); $conn->add_handler('invite', \&blah); # This doesn't need to be fancy; I just need it to go through inspect @@ -71,9 +69,6 @@ sub new return $self; } -my $clearstatsp = 1; -my %statsp = (); -my %oldstatsp = (); sub on_jointhrottled { @@ -85,46 +80,7 @@ sub on_jointhrottled } } -sub on_statsdebug -{ - my ($conn, $event) = @_; - my ($char, $line) = ($event->{args}->[1], $event->{args}->[2]); - if ($char eq 'p') { - if ($clearstatsp) { - $clearstatsp = 0; - %oldstatsp = %statsp; - %statsp = (); - } - if ($line =~ /^(\d+) staff members$/) { - #this is the end of the report - } else { - my ($nick, $userhost) = split(" ", $line); - $userhost =~ s/\((.*)\)/$1/; - my ($user, $host) = split("@", $userhost); - $statsp{$nick}= [$user, $host]; - } - } -} - -sub on_endofstats -{ - my ($conn, $event) = @_; - if ($event->{args}->[1] eq 'p') { - $clearstatsp=1; - my $tmp = Dumper(\%statsp); chomp $tmp; - if ( join(',', sort(keys %oldstatsp)) ne join(',', sort(keys %statsp)) ) { - open(FH, '>>', 'statsplog.txt'); - say FH strftime('%F %T ', gmtime) . join(',', sort(keys %statsp)); - close(FH); - ASM::Util->dprint(join(",", keys %statsp), 'statsp'); - } - # $event->{args}->[2] == "End of /STATS report" - #end of /stats p - } -} - my $lagcycles = 0; -my $pongcount = 0; sub on_pong { @@ -145,9 +101,6 @@ sub on_pong if ($lag > 1) { ASM::Util->dprint("Latency: $lag", 'latency'); } - if (($pongcount++ % 3) == 0) { #easiest way to do something roughly every 90 seconds - $conn->sl('STATS p'); - } if ( @::syncqueue || $::netsplit_ignore_lag || $::pendingsync) { return; #we don't worry about lag if we've just started up and are still syncing, or just experienced a netsplit } @@ -905,9 +858,7 @@ sub on_whofuckedup { my ($conn, $event) = @_; if ($event->{args}->[1] eq "STATS") { -#most likely this is getting called because we did stats p too often. -#unfortunately the server doesn't let us know what exactly we called stats for. -#anyways, we don't need to do anything for this + #we don't need to do anything for this } else { #dunno why it got called, print the data and I'll add a handler for it. ASM::Util->dprint('on_whofuckedup called!', 'sync'); ASM::Util->dprint(Dumper($event), 'sync'); diff --git a/lib/ASM/Statsp.pm b/lib/ASM/Statsp.pm new file mode 100644 index 0000000..a462844 --- /dev/null +++ b/lib/ASM/Statsp.pm @@ -0,0 +1,78 @@ +package ASM::Statsp; +no autovivification; +use warnings; +use strict; + +use Data::Dumper; +use IO::All; +use POSIX qw(strftime); +use ASM::Util; + +no if $] >= 5.017011, warnings => 'experimental::smartmatch'; + +sub new +{ + my $module = shift; + my ($conn) = @_; + my $self = {}; + $self->{CONN} = $conn; + bless($self); + $conn->add_handler('statsdebug', \&on_statsdebug, 'after'); + $conn->add_handler('endofstats', \&on_endofstats, 'after'); + $conn->add_handler('263', \&on_whofuckedup, 'after'); + $conn->schedule(180, sub { $conn->sl('STATS p'); }); + return $self; +} + +my $clearstatsp = 1; +my %statsp = (); +my %oldstatsp = (); + +sub on_statsdebug +{ + my ($conn, $event) = @_; + my ($char, $line) = ($event->{args}->[1], $event->{args}->[2]); + if ($char eq 'p') { + if ($clearstatsp) { + $clearstatsp = 0; + %oldstatsp = %statsp; + %statsp = (); + } + if ($line =~ /^(\d+) staff members$/) { + #this is the end of the report + } else { + my ($nick, $userhost) = split(" ", $line); + $userhost =~ s/\((.*)\)/$1/; + my ($user, $host) = split("@", $userhost); + $statsp{$nick}= [$user, $host]; + } + } +} + +sub on_endofstats +{ + my ($conn, $event) = @_; + if ($event->{args}->[1] eq 'p') { + $clearstatsp=1; + my $tmp = Dumper(\%statsp); chomp $tmp; + if ( join(',', sort(keys %oldstatsp)) ne join(',', sort(keys %statsp)) ) { + open(FH, '>>', 'statsplog.txt'); + say FH strftime('%F %T ', gmtime) . join(',', sort(keys %statsp)); + close(FH); + ASM::Util->dprint(join(",", keys %statsp), 'statsp'); + } + # $event->{args}->[2] == "End of /STATS report" + #end of /stats p + $conn->schedule( 90, sub { $conn->sl('STATS p') } ); + } +} + +sub on_whofuckedup +{ + my ($conn, $event) = @_; + if ($event->{args}->[1] eq "STATS") { + $conn->schedule(30, sub { $conn->sl('STATS p') } ); + } +} + +1; |
