Skip to content

Commit b7022e3

Browse files
committed
misc. cleanup server.pm.
1 parent df688f8 commit b7022e3

File tree

3 files changed

+77
-42
lines changed

3 files changed

+77
-42
lines changed

INDEV

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4027,3 +4027,4 @@ CHANGES:
40274027
92. fix mixmatched 'throttle' vs 'join_throttle' mode names.
40284028
fix bug that allowed zero for joins per second in join throttle.
40294029
misc. cleanup channel.pm.
4030+
misc. cleanup server.pm.

modules/ircd.module/channel.module/channel.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2009-16, Mitchell Cooper
1+
# Copyright (c) 2009-17, Mitchell Cooper
22
#
33
# @name: "ircd::channel"
44
# @package: "channel"

modules/ircd.module/server.module/server.pm

Lines changed: 75 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
2-
# Copyright (c) 2009-16, Mitchell Cooper
1+
# Copyright (c) 2009-17, Mitchell Cooper
32
#
43
# @name: "ircd::server"
54
# @package: "server"
@@ -31,6 +30,7 @@ sub init {
3130
return 1;
3231
}
3332

33+
# creates a server
3434
sub new {
3535
my ($class, %opts) = @_;
3636

@@ -51,34 +51,37 @@ sub new {
5151
# handle a server quit.
5252
# does not close a connection; use $server->conn->done() for that.
5353
#
54-
# $reason = the actual reason to log and show to opers
55-
# $why = the reason to send in user quit messages
56-
# $quiet = do not send out notices
54+
# $reason = the actual reason to log and show to opers
55+
# $why = the reason to send in user quit messages
56+
# $quiet = if true, do not send out notices
5757
#
5858
sub quit {
5959
my ($server, $reason, $why, $quiet) = @_;
6060
$why //= "$$server{parent}{name} $$server{name}";
6161

62+
# tell ppl
6263
notice(server_quit =>
6364
$server->notice_info,
6465
$server->{parent}->notice_info,
6566
$reason
6667
) unless $quiet;
6768

68-
# all children must be disposed of.
69+
# all children must be disposed of
6970
foreach my $serv ($server->children) {
7071
next if $serv == $server;
7172
$serv->quit('parent server has disconnected', $why);
7273
}
7374

74-
# delete all of the server's users.
75+
# delete all of the server's users
7576
my @users = $server->all_users;
7677
foreach my $user (@users) {
7778
$user->quit($why, 1);
7879
}
7980

81+
# remove from pool
8082
$pool->delete_server($server) if $server->{pool};
8183
$server->delete_all_events();
84+
8285
return 1;
8386
}
8487

@@ -90,6 +93,7 @@ sub add_umode {
9093
return 1;
9194
}
9295

96+
# remove a umode association
9397
sub remove_umode {
9498
my ($server, $name) = @_;
9599
my $u = delete $server->{umodes}{$name} or return;
@@ -179,8 +183,9 @@ sub cmode_name {
179183
my ($server, $mode) = @_;
180184
return unless defined $mode;
181185
foreach my $name (keys %{ $server->{cmodes} }) {
182-
next unless defined $server->{cmodes}{$name}{letter};
183-
return $name if $mode eq $server->{cmodes}{$name}{letter};
186+
my $ref = $server->{cmodes}{$name};
187+
next unless length $ref->{letter};
188+
return $name if $mode eq $ref->{letter};
184189
}
185190
return;
186191
}
@@ -193,6 +198,7 @@ sub cmode_letter {
193198
}
194199

195200
# get cmode type.
201+
# returns -1 on failure (since 0, a false value, is a valid type)
196202
sub cmode_type {
197203
my ($server, $name) = @_;
198204
return -1 if !defined $name;
@@ -231,13 +237,15 @@ sub cmode_takes_parameter {
231237
return $params{ $server->{cmodes}{$name}{type} || -1 };
232238
}
233239

240+
# true only for the local server
234241
sub is_local { shift == $me }
235242

236243
# sub DESTROY {
237244
# my $server = shift;
238245
# L("$server destroyed");
239246
# }
240247

248+
# servers which are direct children of this one
241249
sub children {
242250
my $server = shift;
243251
my @a;
@@ -249,7 +257,7 @@ sub children {
249257
return @a;
250258
}
251259

252-
# hops to server.
260+
# number of hops to another server
253261
sub hops_to {
254262
my ($server1, $server2) = @_;
255263
my $hops = 0;
@@ -262,90 +270,111 @@ sub hops_to {
262270
return $hops;
263271
}
264272

273+
# UID to user object
265274
sub uid_to_user {
266275
my ($server, $uid) = @_;
267276
return $server->{uid_to_user}($uid) if $server->{uid_to_user};
268277
return $pool->lookup_user($uid);
269278
}
270279

280+
# user object to UID
271281
sub user_to_uid {
272282
my ($server, $user) = @_;
273283
return $server->{user_to_uid}($user) if $server->{user_to_uid};
274284
return $user->{uid};
275285
}
276286

287+
# SID to server object
277288
sub sid_to_server {
278289
my ($server, $sid) = @_;
279290
return $server->{sid_to_server}($sid) if $server->{sid_to_server};
280291
return $pool->lookup_server($sid);
281292
}
282293

294+
# server object to SID
283295
sub server_to_sid {
284296
my ($server, $serv) = @_;
285297
return $server->{server_to_sid}($serv) if $server->{server_to_sid};
286298
return $serv->{sid};
287299
}
288300

301+
# set the above conversion functions
289302
sub set_functions {
290303
my ($server, %functions) = @_;
291304
@$server{ keys %functions } = values %functions;
292305
}
293306

294307
# shortcuts
295308

296-
sub id { shift->{sid} }
297-
sub full { shift->{name} }
298-
sub fullreal { shift->{name} }
299-
sub name { shift->{name} }
300-
sub conn { shift->{conn} }
301-
sub user { undef }
302-
sub users { @{ shift->{users} } }
303-
sub server { shift }
304-
sub parent { shift->{parent} }
305-
sub location { shift->{location} }
306-
309+
sub id { shift->{sid} } # server ID (SID)
310+
sub full { shift->{name} } # server name
311+
sub fullreal { shift->{name} } # server name
312+
sub name { shift->{name} } # server name
313+
sub conn { shift->{conn} } # for uplinks, the connection object
314+
sub user { undef } # false for servers
315+
sub users { @{ shift->{users} } } # list of users belonging to this server
316+
sub server { shift } # the server itself
317+
sub parent { shift->{parent} } # parent server
318+
sub location { shift->{location} } # uplink this server is reached through
319+
320+
# ->all_users every single user on the server
321+
#
322+
# ->real_users all REAL users on the server (those which are not
323+
# created via IRCd modules)
324+
#
325+
# ->all_local_users all LOCAL users (those belonging to the local server).
326+
# for servers, this method is not particularly useful,
327+
# but it is consistent with the pool method.
328+
#
329+
# ->real_local_users all REAL, LOCAL users on the server
330+
#
331+
# ->global_users all users on the server which are NOT local-only
332+
# fake users created via IRCd modules
333+
#
307334
sub all_users { @{ shift->{users} } }
308335
sub real_users { grep { !$_->{fake} } shift->all_users }
309336
sub all_local_users { grep { $_->is_local } shift->all_users }
310337
sub real_local_users { grep { $_->is_local && !$_->{fake} } shift->all_users }
311338
sub global_users { grep { !$_->{fake_local} } shift->all_users }
312339

313-
############
314-
### MINE ###
315-
############
316-
317340
# handle incoming server data.
318-
sub handle {}
341+
sub handle { L("Server ->handle() is deprecated!") }
319342

320-
# send burst to a connected server.
343+
# send the local server's burst to an uplink
344+
# uplinks only!
321345
sub send_burst {
322346
my $server = shift;
323347
return if $server->{i_sent_burst};
324348

349+
# mark the server as bursting
325350
my $time = time;
326351
$server->{i_am_burst} = $time;
327352

328-
# fire burst events.
353+
# fire burst events
329354
my $proto = $server->{link_type};
330355
$server->prepare(
331-
[ send_burst => $time ],
332-
[ "send_${proto}_burst" => $time ]
356+
[ send_burst => $time ], # generic burst
357+
[ "send_${proto}_burst" => $time ] # proto-specific burst
333358
)->fire;
334359

360+
# remove burst state
335361
delete $server->{i_am_burst};
336362
$server->{i_sent_burst} = time;
363+
337364
return 1;
338365
}
339366

367+
# called when a remote server burst is ending
340368
sub end_burst {
341369
my $server = shift;
342370
my $time = delete $server->{is_burst};
343371
my $elapsed = time - $time;
344372
$server->{sent_burst} = time;
345373

374+
# tell ppl
346375
notice(server_endburst => $server->notice_info, $elapsed);
347376

348-
# fire end burst events.
377+
# fire end burst events
349378
my $proto = $server->{link_type};
350379
$server->prepare(
351380
[ end_burst => $time ],
@@ -355,12 +384,10 @@ sub end_burst {
355384
return 1;
356385
}
357386

358-
# send data to all of my children.
359-
# this actually sends it to all connected servers.
360-
# it is only intended to be called with this server object.
387+
# send data to all of my uplinks.
388+
# local server only!
361389
sub send_children {
362390
my $ignore = shift;
363-
364391
foreach my $server ($pool->servers) {
365392

366393
# don't send to ignored
@@ -376,17 +403,20 @@ sub send_children {
376403

377404
$server->send(@_);
378405
}
379-
380-
return 1
406+
return 1;
381407
}
382408

409+
# like ->send_children, but each passed string will be prefixed
410+
# with the initial argument as its source.
411+
# local server only!
383412
sub sendfrom_children {
384413
my ($ignore, $from) = (shift, shift);
385414
send_children($ignore, map { ":$from $_" } @_);
386415
return 1;
387416
}
388417

389-
# send data to MY servers.
418+
# send data to a server.
419+
# uplinks only!
390420
sub send {
391421
my $server = shift;
392422
if (!$server->conn) {
@@ -397,19 +427,22 @@ sub send {
397427
$server->conn->send(@_);
398428
}
399429

400-
# send data to a server from THIS server.
430+
# send data to an uplink with the local server as the source.
431+
# uplinks only!
401432
sub sendme {
402433
my $server = shift;
403434
$server->sendfrom($me->{sid}, @_);
404435
}
405436

406-
# send data from a UID or SID.
437+
# send data to an uplink from a UID or SID.
438+
# uplinks only!
407439
sub sendfrom {
408440
my ($server, $from) = (shift, shift);
409441
$server->send(map { ":$from $_" } @_);
410442
}
411443

412-
# convenient for $server->fire_command
444+
# forward a server command to a specific server.
445+
# it may be an uplink or a descendant of an uplink.
413446
sub forward {
414447
my $server = shift;
415448
return $pool->fire_command($server->location, @_);
@@ -430,6 +463,7 @@ sub ircd_opt {
430463
}
431464

432465
# CAP shortcuts.
466+
# uplinks only!
433467
*has_cap = *connection::has_cap;
434468
*add_cap = *connection::add_cap;
435469
*remove_cap = *connection::remove_cap;

0 commit comments

Comments
 (0)