From 4cb122df85843049828507eff7b776b98c0f5e9f Mon Sep 17 00:00:00 2001 From: Elijah Perrault Date: Tue, 1 Feb 2011 23:48:14 -0700 Subject: [PATCH] Added core command SHUTDOWN. --- bin/auto | 3 ++- doc/CHANGELOG | 1 + src/Core/IRC.pm | 35 ++++++++++++++++++++++++++++++++++- 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/bin/auto b/bin/auto index de7d076..fa8c364 100755 --- a/bin/auto +++ b/bin/auto @@ -246,7 +246,7 @@ dbug "* Connecting to servers..."; # Get servers from config. my %cservers = conf_get("server"); # Set the hashes and processes hashes. -my (%SOCKET, %SOCKETH, $SELECT); +our (%SOCKET, $SELECT); $SELECT = IO::Select->new(); my $it = 0; # Iterate through each configured server. @@ -294,6 +294,7 @@ API::Std::hook_add("on_uprivmsg", "ctcp_version_reply", \&Core::IRC::version_rep API::Std::cmd_add("MODLOAD", 1, \%Core::IRC::SHELP_MODLOAD, \%Core::IRC::FHELP_MODLOAD, \&Core::IRC::cmd_modload); API::Std::cmd_add("MODUNLOAD", 1, \%Core::IRC::SHELP_MODUNLOAD, \%Core::IRC::FHELP_MODUNLOAD, \&Core::IRC::cmd_modunload); API::Std::cmd_add("MODRELOAD", 1, \%Core::IRC::SHELP_MODRELOAD, \%Core::IRC::FHELP_MODRELOAD, \&Core::IRC::cmd_modreload); +API::Std::cmd_add("SHUTDOWN", 2, \%Core::IRC::SHELP_SHUTDOWN, \%Core::IRC::FHELP_SHUTDOWN, \&Core::IRC::cmd_shutdown); # Infinite while loop. while (1) { diff --git a/doc/CHANGELOG b/doc/CHANGELOG index 0833132..d2f2215 100644 --- a/doc/CHANGELOG +++ b/doc/CHANGELOG @@ -3,6 +3,7 @@ Auto IRC Bot 3.0: Change Log 3.0 Indev ================================================================== + * Added core command SHUTDOWN. * Added core command MODRELOAD. * Added core command MODUNLOAD. * Added core command MODLOAD. diff --git a/src/Core/IRC.pm b/src/Core/IRC.pm index e98fae0..ff145b9 100644 --- a/src/Core/IRC.pm +++ b/src/Core/IRC.pm @@ -8,7 +8,8 @@ use strict; use warnings; use English; use API::Std qw(trans has_priv match_user); -use API::IRC qw(notice usrc); +use API::Log qw(dbug alog); +use API::IRC qw(notice quit usrc); sub version_reply { @@ -166,5 +167,37 @@ sub cmd_modreload return 1; } +# Help hashes for SHUTDOWN. Spanish, French and German needed. +our %SHELP_SHUTDOWN = ( + 'en' => 'Shutdown Auto.', +); +our %FHELP_SHUTDOWN = ( + 'en' => 'This will send out shutdown notifications, quit all networks, flush the database then exit the program.', +); +# SHUTDOWN callback. +sub cmd_shutdown +{ + my (%data) = @_; + + # Check for the appropriate privilege. + if (!has_priv(match_user(%data), "cmd.shutdown")) { + notice($data{svr}, $data{nick}, trans("Permission denied")."."); + return 0; + } + + # Goodbye world! + notice($data{svr}, $data{nick}, "Shutting down."); + dbug "Got SHUTDOWN from ".$data{nick}."!".$data{user}."@".$data{host}."! Shutting down. . ."; + alog "Got SHUTDOWN from ".$data{nick}."!".$data{user}."@".$data{host}."! Shutting down. . ."; + quit($_, "SHUTDOWN from ".$data{nick}) foreach (keys %Auto::SOCKET); + sleep 1; + DB::flush(); + sleep 1; + exit; + + # To appease PerlCritic. + return 1; +} + 1;