From acd95709476bd8cee21203c0e4b16bdc89f0056b Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Mon, 5 Jul 2021 09:38:37 -0700 Subject: [PATCH] Rename `pbot.output_queue_flushed` to `pbot.output_queue_empty` --- PBot/IRC.pm | 8 ++++++++ PBot/IRC/Connection.pm | 1 - PBot/PBot.pm | 2 +- Plugins/Battleship.pm | 11 +++++++---- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/PBot/IRC.pm b/PBot/IRC.pm index cdc95b2c..e8ec8e6c 100644 --- a/PBot/IRC.pm +++ b/PBot/IRC.pm @@ -34,6 +34,11 @@ $VERSION = "0.79"; sub new { my $proto = shift; + my %args = @_; + + if (not $args{pbot}) { + Carp::croak("Missing pbot reference to " . __PACKAGE__); + } my $self = { '_conn' => [], @@ -45,6 +50,7 @@ sub new { '_read' => IO::Select->new(), '_timeout' => 0, '_write' => IO::Select->new(), + '_pbot' => $args{pbot}, }; bless $self, $proto; @@ -123,6 +129,8 @@ sub do_one_loop { $outputevent->content->{coderef}->(@{$outputevent->content->{args}}); } $nexttimer = $self->outputqueue->head->time if !$self->outputqueue->is_empty(); + } else { + $self->{_pbot}->{event_dispatcher}->dispatch_event('pbot.output_queue_empty'); } # we don't want to bother waiting on input or running diff --git a/PBot/IRC/Connection.pm b/PBot/IRC/Connection.pm index c26361c5..ed29a7f1 100644 --- a/PBot/IRC/Connection.pm +++ b/PBot/IRC/Connection.pm @@ -1382,7 +1382,6 @@ sub sl { if ($seconds == 0) { $self->{_slcount} = 0; - $self->pbot->{event_dispatcher}->dispatch_event('pbot.output_queue_flushed'); } ### DEBUG DEBUG DEBUG diff --git a/PBot/PBot.pm b/PBot/PBot.pm index 41abf3f0..da2ebd55 100644 --- a/PBot/PBot.pm +++ b/PBot/PBot.pm @@ -172,7 +172,7 @@ sub initialize { } # prepare the IRC engine - $self->{irc} = PBot::IRC->new; + $self->{irc} = PBot::IRC->new(pbot => $self); # prepare remaining core PBot modules -- do not change this order $self->{event_queue} = PBot::EventQueue->new(pbot => $self, name => 'PBot event queue', %conf); diff --git a/Plugins/Battleship.pm b/Plugins/Battleship.pm index 6d7eeca1..f72472c2 100644 --- a/Plugins/Battleship.pm +++ b/Plugins/Battleship.pm @@ -117,7 +117,7 @@ sub initialize { # receive notification when all messages in IRC output queue have been sent $self->{pbot}->{event_dispatcher}->register_handler( - 'pbot.output_queue_flushed', sub { $self->on_output_queue_flushed(@_) } + 'pbot.output_queue_empty', sub { $self->on_output_queue_empty(@_) } ); } @@ -129,6 +129,9 @@ sub unload { # remove battleship loop event from event queue $self->end_game_loop; + + # remove event handler + $self->{pbot}->{event_dispatcher}->remove_handler('pbot.output_queue_empty'); } # the game is paused at the beginning when sending the player boards to all @@ -138,7 +141,7 @@ sub unload { # disconnected with 'excess flood'). this event handler resumes the game once # the boards have finished transmitting, unless the game was manually paused # by a player. -sub on_output_queue_flushed { +sub on_output_queue_empty { my ($self) = @_; # we don't care about the other event arguments # unless paused by a player, resume the game @@ -312,7 +315,7 @@ sub cmd_battleship { $self->{state_data}->{paused} = 1; # this pause was set by a player. - # this is used by on_output_queue_flushed() to know if it's okay to unpause automatically + # this is used by on_output_queue_empty() to know if it's okay to unpause automatically $self->{state_data}->{paused_by_player} = 1; } else { $self->{state_data}->{paused} = 0; @@ -1394,7 +1397,7 @@ sub state_showboard { # this is due to output pacing; the messages are trickled out slowly # to avoid overflowing the ircd's receive queue. we do not want the # game state to advance while the messages are being sent out. the - # game will resume when the `pbot.output_queue_flushed` notification + # game will resume when the `pbot.output_queue_empty` notification # is received. $state->{paused} = 1;