Skip to content

Commit

Permalink
10.99: fixed #74 where the forward channel could be the same as the o…
Browse files Browse the repository at this point in the history
…riginal one. removed old, unsued 'do_not_set' mode block options. added some extra santity checks to Forward module.
  • Loading branch information
cooper committed Jul 3, 2016
1 parent 6173911 commit d947218
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 48 deletions.
4 changes: 4 additions & 0 deletions INDEV
Original file line number Diff line number Diff line change
Expand Up @@ -3177,3 +3177,7 @@ CHANGES:

98. fixed incorrect CASEMAPPING in RPL_ISUPPORT. thx @GLolol.
renamed repository to "juno."

99. fixed #74 where the forward channel could be the same as the original one.
removed old, unsued 'do_not_set' mode block options.
added some extra santity checks to Forward module.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
10.98
10.99
2 changes: 1 addition & 1 deletion modules/Channel/Forward.module/Forward.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
"description" : "adds channel forwarding abilities",
"name" : "Channel::Forward",
"package" : "M::Channel::Forward",
"version" : "1.9"
"version" : "2"
}
23 changes: 19 additions & 4 deletions modules/Channel/Forward.module/Forward.pm
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ sub cmode_forward {

# no length, don't set
if (!length $mode->{param}) {
$mode->{do_not_set} = 1;
return;
}

Expand All @@ -89,8 +88,19 @@ sub cmode_forward {
# to be forwarded to can forward.
my $f_channel = $pool->lookup_channel($mode->{param});
my $source = $mode->{source};
$source->numeric(ERR_NOSUCHCHANNEL => $mode->{param}) and return
if (!$f_channel && $source->isa('user'));

# channel does not exist.
if (!$f_channel) {
$source->numeric(ERR_NOSUCHCHANNEL => $mode->{param})
if $source->isa('user');
return;
}

# forwarding to the same channel.
if ($f_channel == $channel) {
# TODO: add a numeric?
return;
}

# is the channel free forward or is the user opped?
if (!$source->isa('user') || $f_channel->is_mode('free_forward')
Expand Down Expand Up @@ -119,7 +129,12 @@ sub on_user_join_failed {
return unless $channel->is_mode('forward');
my $f_ch_name = $channel->mode_parameter('forward');

# FIXME: wouldn't hurt to double-check that the channel name is valid here
# this was already checked once, but this is just in case it was
# set by a pseudoserver or something and is invalid.
if (!utils::validchan($f_ch_name)) {
L("Invalid forward channel name for $$channel{name}: $f_ch_name");
return;
}

# We need the channel object, unfortunately it is not always the case that
# we are being forwarded to a channel that already exists.
Expand Down
12 changes: 6 additions & 6 deletions modules/Channel/Key.module/Key.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"version" : "1.7",
"author" : {
"name" : "Matthew Barksdale",
"website" : "https://github.com/mattwb65"
},
"depends" : {
"modules" : [
"Base::ChannelModes",
Expand All @@ -8,9 +11,6 @@
},
"description" : "adds channel key mode",
"name" : "Channel::Key",
"author" : {
"website" : "https://github.com/mattwb65",
"name" : "Matthew Barksdale"
},
"package" : "M::Channel::Key"
"package" : "M::Channel::Key",
"version" : "1.8"
}
26 changes: 12 additions & 14 deletions modules/Channel/Key.module/Key.pm
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ use utils qw(cut_to_limit cols);
our ($api, $mod, $pool);

sub init {

# register key mode block.
$mod->register_channel_mode_block(
name => 'key',
code => \&cmode_key
) or return;

# register ERR_BADCHANNELKEY
$mod->register_user_numeric(
name => shift @$_,
Expand All @@ -40,44 +40,43 @@ sub init {
[ ERR_BADCHANNELKEY => 481, '%s :Invalid channel key' ],
[ ERR_KEYSET => 467, '%s :Channel key already set' ]
);

# Hook on the can_join event to prevent joining a channel without valid key
$pool->on('user.can_join' => \&on_user_can_join, with_eo => 1, name => 'has.key');

return 1;
}

sub cmode_key {
my ($channel, $mode) = @_;
$mode->{has_basic_status} or return;

# if we're unsetting...
if (!$mode->{setting}) {
return unless $channel->is_mode('key');

# if we unset without a parameter (the key),
# we need to push the current key to params
push @{ $mode->{params} }, $channel->mode_parameter('key')
if !defined $mode->{param};

$channel->unset_mode('key');
}

# setting.
else {

# sanity checking
$mode->{param} = cols(cut_to_limit('key', $mode->{param}));

# no length; don't set.
if (!length $mode->{param}) {
$mode->{do_not_set} = 1;
return;
}

$channel->set_mode('key', $mode->{param});
}

return 1;
}

Expand All @@ -90,4 +89,3 @@ sub on_user_can_join {
}

$mod

2 changes: 1 addition & 1 deletion modules/Core/ChannelModes.module/ChannelModes.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
"description" : "the core set of channel modes",
"name" : "Core::ChannelModes",
"package" : "M::Core::ChannelModes",
"version" : "9.86"
"version" : "10.99"
}
41 changes: 20 additions & 21 deletions modules/Core/ChannelModes.module/ChannelModes.pm
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ sub init {
# register status channel modes.
register_statuses($_) or return foreach
sort { $b <=> $a } keys %ircd::channel_mode_prefixes;

# add multi-prefix capability.
$mod->register_capability('multi-prefix');

# add channel message restrictions.
add_message_restrictions();

return 1;
}

Expand All @@ -54,7 +54,7 @@ sub register_statuses {
$mod->register_channel_mode_block( name => $name, code => sub {
my ($channel, $mode) = @_;
my $source = $mode->{source};

# find the target.
my $t_user = $mode->{user_lookup}($mode->{param});

Expand Down Expand Up @@ -85,7 +85,7 @@ sub register_statuses {

return 1;
};

my $check2 = sub {

# the source's highest status is not enough.
Expand All @@ -99,7 +99,7 @@ sub register_statuses {
$mode->{send_no_privs} = 1;
return;
}

}

# [USER RESPONSE, SERVER RESPONSE]
Expand All @@ -108,9 +108,9 @@ sub register_statuses {
# add or remove from the list.
my $do = $mode->{state} ? 'add_to_list' : 'remove_from_list';
$channel->$do($name, $t_user);

return 1;

}) or return;

return 1
Expand Down Expand Up @@ -148,7 +148,7 @@ sub _cmode_banlike {

# view list.
if (!length $mode->{param} && $mode->{source}->isa('user')) {

# send each list item.
my $name = uc($reply).q(LIST);
my $letter = $me->cmode_letter($list);
Expand All @@ -159,10 +159,10 @@ sub _cmode_banlike {
$_->[1]{setby},
$_->[1]{time}
) foreach $channel->list_elements($list, 1);

# end of list.
$mode->{source}->numeric("RPL_ENDOF$name" => $channel->name);

return;
}

Expand All @@ -171,11 +171,10 @@ sub _cmode_banlike {
$mode->{send_no_privs} = 1;
return;
}

# remove prefixing colon.
$mode->{param} = cols($mode->{param});
if (!length $mode->{param}) {
$mode->{do_not_set} = 1;
return;
}

Expand All @@ -191,7 +190,7 @@ sub _cmode_banlike {
else {
$channel->remove_from_list($list, $mode->{param});
}

return 1;
}

Expand All @@ -200,29 +199,29 @@ sub add_message_restrictions {
# not in channel and no external messages?
$pool->on('user.can_message' => sub {
my ($user, $event, $channel, $message, $type) = @_;

# not internal only, or user is in channel.
return unless $channel->is_mode('no_ext');
return if $channel->has_user($user);

# no external messages.
$user->numeric(ERR_CANNOTSENDTOCHAN => $channel->name, 'No external messages');
$event->stop('no_ext');

}, name => 'no.external.messages', with_eo => 1, priority => 30);

# moderation and no voice?
$pool->on('user.can_message' => sub {
my ($user, $event, $channel, $message, $type) = @_;

# not moderated, or the user has proper status.
return unless $channel->is_mode('moderated');
return if $channel->user_get_highest_level($user) >= -2;

# no external messages.
$user->numeric(ERR_CANNOTSENDTOCHAN => $channel->name, 'Channel is moderated');
$event->stop('moderated');

}, name => 'moderated', with_eo => 1, priority => 20);

# banned and no voice?
Expand All @@ -238,7 +237,7 @@ sub add_message_restrictions {
$event->stop('banned');

}, name => 'stop.banned.users', with_eo => 1, priority => 10);

}

$mod

0 comments on commit d947218

Please sign in to comment.