Skip to content

Commit

Permalink
12.64: prevent knocking on private channels. closes #34.
Browse files Browse the repository at this point in the history
  • Loading branch information
cooper committed Jan 7, 2017
1 parent 12114d4 commit 4ad8529
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 7 deletions.
2 changes: 2 additions & 0 deletions INDEV
Expand Up @@ -3927,3 +3927,5 @@ CHANGES:
called on ->take_lower_time() and in SJOIN. closes #162.

63. added Channel::Knock. closes #39.

64. prevent knocking on private channels. closes #34.
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
12.63
12.64
2 changes: 1 addition & 1 deletion modules/Channel/Knock.module/Knock.json
Expand Up @@ -12,5 +12,5 @@
"description" : "request to join a restricted channel",
"name" : "Channel::Knock",
"package" : "M::Channel::Knock",
"version" : "0.6"
"version" : "0.8"
}
3 changes: 2 additions & 1 deletion modules/Channel/Knock.module/Knock.pm
Expand Up @@ -16,6 +16,7 @@ use strict;
use 5.010;

use List::Util qw(first);
use utils qw(ref_to_list);

our ($api, $mod, $me, $pool);

Expand All @@ -42,7 +43,7 @@ sub init {

# knock events
$pool->on('user.can_knock' => \&on_user_can_knock, 'check.banned');
$pool->on('channel.knock' => \&on_channel_knock, 'notify.channel');
$pool->on('channel.knock' => \&on_channel_knock, 'notify.channel');

return 1;
}
Expand Down
2 changes: 1 addition & 1 deletion modules/Channel/Secret.module/Secret.json
Expand Up @@ -11,5 +11,5 @@
"description" : "allows a channel to be marked secret or private",
"name" : "Channel::Secret",
"package" : "M::Channel::Secret",
"version" : "2.6"
"version" : "2.7"
}
17 changes: 14 additions & 3 deletions modules/Channel/Secret.module/Secret.pm
Expand Up @@ -21,9 +21,6 @@ use 5.010;

our ($api, $mod, $pool);

# TODO: (#34) once KNOCKing is implemented, make sure it's not permitted
# for channels with +p set (ERR_CANNOTSENDTOCHAN) but is for +s

# channel mode blocks
our %channel_modes = (
secret => { type => 'normal' },
Expand All @@ -50,6 +47,12 @@ sub init {
'channel.secret.names_character'
);

# prevent users from knocking on private channels.
$pool->on('user.can_knock' =>
\&on_user_can_knock,
'private.channel'
);

return 1;
}

Expand Down Expand Up @@ -120,4 +123,12 @@ sub names_character {
$$c = "@" if $channel->is_mode('secret'); # more important than private
}

sub on_user_can_knock {
my ($user, $event, $channel) = @_;
return unless $channel->is_mode('private');
$event->{error_reply} =
[ ERR_CANNOTSENDTOCHAN => $channel->name, 'Channel is private' ];
$event->stop('banned');
}

$mod

0 comments on commit 4ad8529

Please sign in to comment.