Skip to content

Commit 4512ebc

Browse files
committed
8.99: $user->events_for_message($msg) returns events for user handlers.
fixed $user->handle() and $user->handle_unsafe() for use with the new system. registration commands now utilize the new parameter parser. other cleanup.
1 parent 40dbd62 commit 4512ebc

File tree

13 files changed

+81
-59
lines changed

13 files changed

+81
-59
lines changed

INDEV

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2523,6 +2523,11 @@ CHANGES:
25232523
numerics are no longer sent to servers (not with the server as the target anyway).
25242524
servers now do not send ERR_UNKNOWNCOMMAND to other registered servers, and all incoming numerics are ignored.
25252525

2526+
99. $user->events_for_message($msg) returns events for user handlers.
2527+
fixed $user->handle() and $user->handle_unsafe() for use with the new system.
2528+
registration commands now utilize the new parameter parser.
2529+
other cleanup.
2530+
25262531

25272532

25282533

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8.98
1+
8.99

modules/Base/RegistrationCommands.module/RegistrationCommands.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version" : "8.94",
2+
"version" : "8.99",
33
"name" : "Base::RegistrationCommands",
44
"author" : {
55
"website" : "https://github.com/cooper",

modules/Base/RegistrationCommands.module/RegistrationCommands.pm

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,14 @@ sub register_registration_command {
4040
}
4141

4242
# parameter check callback.
43-
my $command = uc delete $opts{name};
44-
my $params = $opts{parameters};
45-
$pool->on("connection.command_$command" => sub {
46-
my ($event, @args) = @_;
43+
my $command = uc delete $opts{name};
44+
my $event_name = "connection.message_$command";
45+
my $params = $opts{parameters};
46+
$pool->on($event_name => sub {
47+
my ($event, $msg) = @_;
4748

4849
# there are enough.
49-
return 1 if @args >= $params;
50+
return 1 if $msg->params >= $params;
5051

5152
# not enough.
5253
my $conn = $event->object;
@@ -59,17 +60,24 @@ sub register_registration_command {
5960
_caller => $mod->package
6061
) or return if $params;
6162

62-
# wrapper that prevents execution after registration.
63+
# wrapper.
6364
my $code = sub {
64-
my ($conn, $event) = @_;
65+
my ($conn, $event, $msg) = @_;
66+
67+
# prevent execution after registration.
6568
return if $conn->{type} && !$opts{after_reg};
66-
$opts{code}(@_);
69+
70+
# arguments.
71+
my @args = $msg->params;
72+
unshift @args, $msg if $opts{with_msg};
73+
unshift @args, $msg->data if $opts{with_data};
74+
75+
$opts{code}($conn, $event, @args);
6776
$event->cancel('ERR_UNKNOWNCOMMAND');
6877
$event->stop unless $opts{continue_handlers}; # prevent later user/server handlers.
6978
};
7079

7180
# attach the callback.
72-
my $event_name = 'connection.command_'.$command.($opts{with_data} ? '_raw' : '');
7381
my $result = $pool->on($event_name => $code,
7482
name => $opts{cb_name},
7583
with_eo => 1,

modules/Core/RegistrationCommands.module/RegistrationCommands.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version" : "6.1",
2+
"version" : "6.3",
33
"name" : "Core::RegistrationCommands",
44
"author" : {
55
"website" : "https://github.com/cooper",

modules/Core/RegistrationCommands.module/RegistrationCommands.pm

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,25 +30,23 @@ sub init {
3030
);
3131

3232
$mod->register_registration_command(
33-
name => shift @$_, code => shift @$_,
34-
parameters => shift @$_, with_data => shift @$_,
35-
after_reg => shift @$_
33+
name => shift @$_, code => shift @$_,
34+
parameters => shift @$_, after_reg => shift @$_
3635
) or return foreach (
3736
#
3837
# PARAMS = number of parameters
39-
# DATA = true if include $data string
4038
# LATER = true if the command should be handled even after registration
4139
#
42-
# [ NAME => \&sub PARAMS DATA LATER
43-
[ PING => \&rcmd_ping, 1, undef, 1 ],
44-
[ PONG => sub { 1 }, undef, undef, 1 ],
45-
[ CAP => \&rcmd_cap, 1, undef, 1 ],
46-
[ NICK => \&rcmd_nick, 1, undef, ],
47-
[ USER => \&rcmd_user, 4, 1, 1 ],
48-
[ SERVER => \&rcmd_server, 5, undef, ],
49-
[ PASS => \&rcmd_pass, 1, undef, ],
50-
[ QUIT => \&rcmd_quit, undef, 1, ],
51-
[ ERROR => \&rcmd_error, 1, undef, 1 ],
40+
# [ NAME => \&sub PARAMS LATER
41+
[ PING => \&rcmd_ping, 1, 1 ],
42+
[ PONG => sub { 1 }, undef, 1 ],
43+
[ CAP => \&rcmd_cap, 1, 1 ],
44+
[ NICK => \&rcmd_nick, 1, ],
45+
[ USER => \&rcmd_user, 4, 1 ],
46+
[ SERVER => \&rcmd_server, 5, ],
47+
[ PASS => \&rcmd_pass, 1, ],
48+
[ QUIT => \&rcmd_quit, undef, ],
49+
[ ERROR => \&rcmd_error, 1, 1 ],
5250
);
5351

5452
return 1;
@@ -199,7 +197,7 @@ sub rcmd_nick {
199197
}
200198

201199
sub rcmd_user {
202-
my ($connection, $event, $data, @args) = @_;
200+
my ($connection, $event, @args) = @_;
203201

204202
# already registered.
205203
if ($connection->{type}) {
@@ -208,8 +206,8 @@ sub rcmd_user {
208206
}
209207

210208
$connection->{ident} = $args[0];
211-
$connection->{real} = col((split /\s+/, $data, 5)[4]);
212-
$connection->fire_event(reg_user => @$connection{ qw(ident real) });
209+
$connection->{real} = $args[3];
210+
$connection->fire_event(reg_user => @args[0,3]);
213211
$connection->reg_continue('id2');
214212
}
215213

@@ -264,8 +262,8 @@ sub rcmd_pass {
264262

265263
# not used for registered users.
266264
sub rcmd_quit {
267-
my ($connection, $event, $data, $arg) = @_;
268-
my $reason = defined $arg ? col((split /\s+/, $data, 2)[1]) : 'leaving';
265+
my ($connection, $event, $arg) = @_;
266+
my $reason = $arg // 'leaving';
269267
$connection->done("~ $reason");
270268
}
271269

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
2-
"version" : "8.78",
2+
"version" : "8.99",
33
"name" : "Core::UserNumerics",
44
"author" : {
55
"website" : "https://github.com/cooper",
66
"name" : "Mitchell Cooper"
77
},
88
"description" : "the core set of user numerics",
9-
"package" : "M::Core::UserNumerics",
109
"depends" : {
1110
"modules" : "Base::UserNumerics"
12-
}
11+
},
12+
"package" : "M::Core::UserNumerics"
1313
}

modules/Core/UserNumerics.module/UserNumerics.pm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ sub rpl_isupport {
158158
$lines[$curr] .= $val eq 'YES' ? "$param " : "$param=$val ";
159159
}
160160

161-
return map { "$_:are supported by this server" } @lines
161+
return map { "$_:are supported by this server" } @lines;
162162
}
163163

164164
# CHANMODES in RPL_ISUPPORT.
@@ -170,7 +170,7 @@ sub isp_chanmodes {
170170
# status (4)
171171
# key (5)
172172
my %m;
173-
my @a = ('', '', '', '', '');
173+
my @a = ('') x 5;
174174

175175
# find each mode letter.
176176
foreach my $name ($ircd::conf->keys_of_block(['modes', 'channel'])) {
@@ -188,7 +188,7 @@ sub isp_chanmodes {
188188
# alphabetize each group.
189189
foreach my $type (keys %m) {
190190
my @alphabetized = sort { $a cmp $b } @{ $m{$type} };
191-
$a[$type] = join '', @alphabetized
191+
$a[$type] = join '', @alphabetized;
192192
}
193193

194194
return "$a[3],$a[1],$a[2],$a[0]";

modules/ircd.module/connection.module/connection.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version" : "8.98",
2+
"version" : "8.99",
33
"name" : "ircd::connection",
44
"no_bless" : 1,
55
"author" : {

modules/ircd.module/connection.module/connection.pm

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,7 @@ sub handle {
109109

110110
# user events.
111111
my $user = $connection->user;
112-
push @events,
113-
[ $user, message => $msg ],
114-
[ $user, "message_${cmd}" => $msg ]
115-
if $user;
112+
push @events, $user->events_for_message($msg) if $user;
116113

117114
# fire with safe option.
118115
my $fire = $connection->prepare(@events)->fire('safe');

0 commit comments

Comments
 (0)