Raw hooks now take hook names and support multiple hooks. This changes rchook_add and rchook_del.

This commit is contained in:
Elijah Perrault committed 2011-03-04 19:14:18 -07:00
1 parent f4448302e2
commit d4ff35a5f9
4 files changed
+31 -17

No files matched your search

+14 -8
View File
@@ -9,7 +9,7 @@ use Exporter;
use base qw(Exporter);
our (%LANGE, %MODULE, %EVENTS, %HOOKS, %CMDS);
our (%LANGE, %MODULE, %EVENTS, %HOOKS, %CMDS, %RAWHOOKS);
our @EXPORT_OK = qw(conf_get trans err awarn timer_add timer_del cmd_add
cmd_del hook_add hook_del rchook_add rchook_del match_user
has_priv mod_exists ratelimit_check fpfmt);
@@ -263,12 +263,16 @@ sub timer_del
# Hook onto a raw command.
sub rchook_add
{
my ($cmd, $sub) = @_;
my ($cmd, $name, $sub) = @_;
$cmd = uc $cmd;
if (defined $Proto::IRC::RAWC{$cmd}) { return; }
$Proto::IRC::RAWC{$cmd} = $sub;
# Make sure core doesn't already handle this.
if (defined $Proto::IRC::RAWC{$cmd}) { return }
# If the hook already exists, ignore it.
if (defined $RAWHOOKS{$cmd}{$name}) { return }
# Create the hook.
$RAWHOOKS{$cmd}{$name} = $sub;
return 1;
}
@@ -276,12 +280,14 @@ sub rchook_add
# Delete a raw command hook.
sub rchook_del
{
my ($cmd) = @_;
my ($cmd, $name) = @_;
$cmd = uc $cmd;
if (!defined $Proto::IRC::RAWC{$cmd}) { return; }
# Make sure the hook exists.
if (!defined $RAWHOOKS{$cmd}{$name}) { return }
delete $Proto::IRC::RAWC{$cmd};
# Delete it.
delete $RAWHOOKS{$cmd}{$name};
return 1;
}
+9 -3
View File
@@ -78,10 +78,16 @@ sub ircparse
M::SASLAuth::handle_authenticate($svr, @ex);
}
}
# Check if it's handled by core.
elsif (defined $RAWC{$ex[1]}) {
&{ $RAWC{$ex[1]} }($svr, @ex);
}
else {
# otherwise, check %RAWC for ex[1].
if (defined $RAWC{$ex[1]}) {
&{ $RAWC{$ex[1]} }($svr, @ex);
# otherwise, check for a raw hook.
if (defined $API::Std::RAWHOOKS{$ex[1]}) {
foreach (keys %{$API::Std::RAWHOOKS{$ex[1]}}) {
&{ $API::Std::RAWHOOKS{$ex[1]}{$_} }($svr, @ex);
}
}
}
}