Skip to content

Commit

Permalink
12.13: implemented JELP MODEREQ. #63. added outgoing JELP MODEREQ and…
Browse files Browse the repository at this point in the history
… MODEREP. update Evented::Object.
  • Loading branch information
cooper committed Dec 6, 2016
1 parent 971517c commit 73ded1c
Show file tree
Hide file tree
Showing 9 changed files with 120 additions and 7 deletions.
4 changes: 4 additions & 0 deletions INDEV
Expand Up @@ -3737,3 +3737,7 @@ CHANGES:
12. don't fire user_mask_change oper notice for cloaks applied to new users.
closes #111.
actually always do it for remote users. #111.

13. implemented JELP MODEREQ. #63.
added outgoing JELP MODEREQ and MODEREP.
update Evented::Object.
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
12.12
12.13
2 changes: 1 addition & 1 deletion modules/Channel/ModeSync.module/JELP.module/JELP.json
Expand Up @@ -6,5 +6,5 @@
"description" : "JELP mode synchronization",
"name" : "Channel::ModeSync::JELP",
"package" : "M::Channel::ModeSync::JELP",
"version" : "0.1"
"version" : "0.3"
}
62 changes: 60 additions & 2 deletions modules/Channel/ModeSync.module/JELP.module/JELP.pm
Expand Up @@ -15,7 +15,65 @@ use 5.010;

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

our %jelp_incoming_commands = ();
our %jelp_outgoing_commands = ();
our %jelp_incoming_commands = (
MODEREQ => {
# :<SID> MODEREQ <channel>|* <target SID>|* <modes>|*
params => '-source(server) * * *',
code => \&in_modereq
},
MODEREP => {
# :<SID> MODEREP <channel> <target SID>|* :<mode string>
params => '-source(server) channel * *',
code => \&in_moderep
}
);

our %jelp_outgoing_commands = (
MODEREQ => \&out_modereq,
MODEREP => \&out_moderep
);

my $handle_modereq;

sub init {
$handle_modereq = M::Channel::ModeSync->can('handle_modereq') or return;
return 1;
}

sub in_modereq {
my ($server, $msg, $source_serv, $ch_name, $target, $modes) = @_;
undef $ch_name if $ch_name eq '*';
undef $target if $target eq '*';
undef $modes if $modes eq '*';

# find a channel maybe.
# abort if a name was provided and we can't find it.
my $ch_maybe = $pool->lookup_channel($ch_name) or return
if defined $ch_name;

return $handle_modereq->($msg, $source_serv, $ch_maybe, $target, $modes);
}

sub in_moderep {

}

sub out_modereq {
my ($to_server, $source_serv, $ch_maybe, $serv_maybe, $modes_maybe) = @_;
sprintf ':%s MODEREQ %s %s %s',
$source_serv->id,
$ch_maybe ? $ch_maybe->name : '*',
$serv_maybe ? $serv_maybe->id : '*',
length $modes_maybe ? $modes_maybe : '*';
}

sub out_moderep {
my ($to_server, $source_serv, $channel, $serv_maybe, $mode_str) = @_;
sprintf ':%s MODEREP %s %s :%s',
$source_serv->id,
$channel->name,
$serv_maybe ? $serv_maybe->id : '*',
$mode_str;
}

$mod
2 changes: 1 addition & 1 deletion modules/Channel/ModeSync.module/ModeSync.json
Expand Up @@ -6,5 +6,5 @@
"description" : "improves channel mode synchronization",
"name" : "Channel::ModeSync",
"package" : "M::Channel::ModeSync",
"version" : "0.4"
"version" : "0.6"
}
48 changes: 48 additions & 0 deletions modules/Channel/ModeSync.module/ModeSync.pm
Expand Up @@ -62,4 +62,52 @@ sub cmodes_changed {

}

# handle_modereq()
#
# $source_serv server object source
#
# $ch_maybe channel object or undef if it is for all channels
#
# $target server object target or undef if it is network-wide
#
# $modes string of mode letters in the perspective of the source server
# or undef if requesting all modes
#
sub handle_modereq {
my ($msg, $source_serv, $ch_maybe, $target, $modes) = @_;

# if the modes are missing, a channel must be present.
# this indicates a network-wide sync of all modes on a channel.
return if !$ch_maybe && !defined $modes;

my @forward_args = (modereq => $source_serv, $ch_maybe, $target, $modes);

# this is not for me; forward.
if (defined $target && $target ne $me->id) {
$target = $pool->lookup_server($target) or return;
return $msg->forward_to($target, @forward_args);
}

# Safe point - we will handle this request.
my @channels = $ch_maybe ? $ch_maybe : $pool->channels;
foreach my $channel (@channels) {

# map mode letters in the perspective of $source_serv to names.
my @mode_names = map $source_serv->cmode_name($_), split //, $modes;

# construct a mode string in the perspective of $me with these modes.
my $mode_str = $channel->mode_string_with($me, @mode_names);
next if !length $mode_str;

$source_serv->{location}->fire_command(moderep =>
$me, $channel, $target, $mode_str
);
}

# unless this was addressed specifically to me, forward.
$msg->forward(@forward_args) if !defined $target;

return 1;
}

$mod
2 changes: 1 addition & 1 deletion modules/ircd.module/channel.module/channel.json
Expand Up @@ -8,5 +8,5 @@
"no_bless" : 1,
"package" : "channel",
"preserve_sym" : 1,
"version" : "12.09"
"version" : "12.12"
}
3 changes: 3 additions & 0 deletions modules/ircd.module/channel.module/channel.pm
Expand Up @@ -431,6 +431,9 @@ sub handle_mode_string {

}

sub modes_with { ... }
sub mode_string_with { ... }

# returns a +modes string.
sub mode_string { _mode_string(0, @_) }
sub mode_string_hidden { _mode_string(1, @_) }
Expand Down

0 comments on commit 73ded1c

Please sign in to comment.