From 62551dc6c982346881ba788c720267d4251d7308 Mon Sep 17 00:00:00 2001 From: Elijah Perrault Date: Wed, 2 Mar 2011 22:02:24 -0700 Subject: [PATCH] Added hook on_disconnect. --- bin/auto | 1 + doc/CHANGELOG | 2 ++ lib/Core/IRC.pm | 16 ++++++++++++++++ 3 files changed, 19 insertions(+) diff --git a/bin/auto b/bin/auto index b5b6827..7dda784 100755 --- a/bin/auto +++ b/bin/auto @@ -471,6 +471,7 @@ while (1) { err(2, "Lost connection to $sockid!", 0); $SELECT->remove($sock); delete $SOCKET{$sockid}; + API::Std::event_run('on_disconnect', $sockid); if (!keys %SOCKET) { # No more connections, stop the program. API::Std::event_run('on_shutdown'); diff --git a/doc/CHANGELOG b/doc/CHANGELOG index a6bf193..488a0e6 100644 --- a/doc/CHANGELOG +++ b/doc/CHANGELOG @@ -3,6 +3,8 @@ Auto IRC Bot 3.0: Change Log 3.0 Indev =============================================================================== + * All data related to a network is now deleted on disconnect. + * Added hook on_disconnect. * Added various options to bin/auto, including support for multiple config files. See bin/auto -h for details. * Changed on_nick, on_quit, on_part, and on_kick source hashrefs to include diff --git a/lib/Core/IRC.pm b/lib/Core/IRC.pm index 9c6a714..6054ee5 100644 --- a/lib/Core/IRC.pm +++ b/lib/Core/IRC.pm @@ -188,6 +188,22 @@ sub clear_usercmd_timer return 1; } +# Server data deletion on disconnect. +hook_add('on_disconnect', 'core.irc.deldata', sub { + my ($svr) = @_; + + # Delete all data related to the server. + if (defined $Proto::IRC::got_001{$svr}) { delete $Proto::IRC::got_001{$svr} } + if (defined $Proto::IRC::botinfo{$svr}) { delete $Proto::IRC::botinfo{$svr} } + if (defined $Proto::IRC::botchans{$svr}) { delete $Proto::IRC::botchans{$svr} } + if (defined $Proto::IRC::chanusers{$svr}) { delete $Proto::IRC::chanusers{$svr} } + if (defined $Proto::IRC::csprefix{$svr}) { delete $Proto::IRC::csprefix{$svr} } + if (defined $Proto::IRC::chanmodes{$svr}) { delete $Proto::IRC::chanmodes{$svr} } + if (defined $Proto::IRC::cap{$svr}) { delete $Proto::IRC::cap{$svr} } + + return 1; +}); + 1; # vim: set ai et sw=4 ts=4: