1 # This file is part of SurrealServices.
3 # SurrealServices is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
8 # SurrealServices is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with SurrealServices; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 use SrSv
::Conf
'main';
28 use Exporter
'import';
29 our @EXPORT = qw
(agent_doconn getAgentRevUuid getAgentUuid setAgentRevUuid setAgentUuid
);
34 # These appear to match the implementations I've seen, but are unspecified in the RFCs.
35 # They may vary by implementation.
36 NICKLEN
=> 30, # some ircds are different. hyperion is 16.
37 IDENTLEN
=> 10, # Sometimes 8 or 9.
38 # hyperion may break this due to it's ident format: [ni]=identhere, like this n=northman
39 HOSTLEN
=> 63, # I think I've seen 64 here before.
40 MASKLEN
=> 30 + 10 + 63 + 2, # 105, or maybe 106. the 2 constant is for !@
42 CHANNELLEN
=> 32, # From 005 reply. hyperion is 30.
50 PREFIXAQ_DISABLE
=> 0,
52 die "NICKIP must be enabled if CLK is\n" if CLK
&& !NICKIP
;
54 use SrSv
::IRCd
::IO
qw(ircd_connect ircsend ircsendimm ircd_flush_queue);
55 use SrSv
::IRCd
::Event
qw(addhandler callfuncs);
56 use SrSv
::IRCd
::State
qw($ircline $remoteserv $ircd_ready synced initial_synced set_server_state set_server_juped get_server_state get_online_servers);
58 use SrSv
::Unreal
::Modes
qw(@opmodes %opmodes $scm $ocm $acm);
59 use SrSv
::Unreal
::Tokens
;
60 use SrSv
::IRCd
::Parse
qw(parse_tkl parse_addline);
61 use SrSv
::Unreal
::Base64
qw(itob64 b64toi);
63 use SrSv
::Text
::Format
qw( wordwrap );
67 use SrSv
::Process
::InParent
qw(update_userkill getAgentRevUuid getAgentUuid setAgentRevUuid setAgentUuid);
70 our %preconnect_defer_mode;
72 our $unreal_protocol_version;
73 our %uuids; #NickServ -> AAAAAA
74 our %reverse_uuids; #AAAAA -> NickServ
75 addhandler
('SEOS', undef(), undef(), 'ircd::eos', 1);
76 addhandler
('NETINFO', undef(), undef(), 'ircd::netinfo', 1);
77 addhandler
('VERSION', undef(), undef(), 'ircd::version', 1);
78 addhandler
('SERVER', undef(), undef(), 'ircd::handle_server', 1);
79 addhandler
('ENDBURST',undef(),undef(),'ircd::endburst',1);
82 if (ref ($user) ne "HASH") {
83 Carp
::confess
("encodeUUID_ called on non-hash " . $user);
86 if (defined ($user->{e_ID
})) {
89 if (!defined($user->{ID
})) {
90 Carp
::confess
("encodeUUID_ called on a user w/o id " , Dumper
($user));
93 my $nick = $user->{NICK
};
94 if (!defined ($nick)) {
95 $nick = get_user_nick
($user);
97 if (is_agent
($nick)) {
98 return $user->{e_ID
} = $user->{ID
};
100 return $user->{e_ID
} = encodeUUID
($user->{ID
});
102 sub getAgentRevUuid
($) {
104 my $nick = $reverse_uuids{$id};
105 $uuids{lc $nick} = $id;
108 sub getAgentUuid
($) {
110 my $id = $uuids{$nick};
113 sub setAgentRevUuid
($$) {
114 my ($id, $nick) = @_;
115 $reverse_uuids{$id} = lc $nick;
117 sub setAgentUuid
($$) {
118 my ($nick, $id) = @_;
119 $uuids{lc $nick} = $id;
122 my $remote = $main_conf{remote
};
123 my $port = $main_conf{port
};
124 ircd_connect
($remote, $port);
125 #ircsendimm('PROTOCTL '.($tkn ? 'TOKEN ' : '').'NICKv2 UMODE2 TKLEXT'.
126 #(CLK ? ' CLK' : ' VHP'). # CLK obsoletes VHP. Plus if you leave VHP on, CLK doesn't work.
127 # (NOQUIT ? ' NOQUIT' : '').(SJ3 ? ' SJOIN SJOIN2 SJ3' : '').
128 # (NICKIP ? ' NICKIP' : '').
129 # (SJB64 ? ' SJB64 NS VL' : ''),
131 ircsendimm
( 'PASS :'.$main_conf{pass
},
132 'SERVER '.$main_conf{local}.' ' . $main_conf{pass
} . ' 0 ' .$main_conf{numeric
} . ' ' .$main_conf{info
} );
133 ircsendimm
('BURST ' .time);
134 %preconnect_defer_mode = %defer_mode;
140 sub handle_server
($$$$;$$$) {
141 # This is mostly a stub function, but we may need the $unreal_protocol_version
142 # at a later date. Plus we may want to maintain a server tree in another module.
143 my ($src_server, $server_name, $num_hops, $info_line, $server_numeric, $protocol_version, $build_flags) = @_;
144 $unreal_protocol_version = $protocol_version if defined $protocol_version;
151 my ($src, $cookie, $dst) = @_;
152 # This will only make sense if you remember that
153 # $src is where it came from, $dst is where it went (us)
154 # we're basically bouncing it back, but changing from PING to PONG.
155 if (defined($dst) and defined($cookie)) {
156 # $dst is always $main_conf{local} anyway...
157 # this is only valid b/c we never have messages routed THROUGH us
158 # we are always an end point.
159 ircsendimm
(":$dst PONG $src :$cookie");
162 ircsendimm
("PONG :$src");
168 flushmodes
(\
%preconnect_defer_mode);
172 ircsendimm
("ENDBURST");
179 #foreach my $k (keys %servers) {
180 # print "Server: $k ircline: ",$servers{$k}[0], " state: ", $servers{$k}[1], "\n";
182 #print "Synced: ", synced(), "\n\n";
185 ircsendimm
(':'.$main_conf{local}.' EOS VERSION');
188 flushmodes
(\
%preconnect_defer_mode);
194 sub netinfo
($$$$$$$$) {
195 ircsendimm
('NETINFO 0 '.time." $_[2] $_[3] 0 0 0 :$_[7]");
196 $main_conf{network
} = $_[7];
200 ircsendimm
((SJB64
? '@'.itob64
($main_conf{numeric
}) : ':'.$main_conf{local})." TSCTL SVSTIME ".time);
203 sub parse_sjoin
($$$$) {
204 my ($server, $ts, $cn, $parms) = @_;
205 my (@users, @bans, @excepts, @invex, @blobs, $blobs, $chmodes, $chmodeparms);
207 $server = '' unless $server;
209 if($parms =~ /^:(.*)/) {
212 ($chmodes, $blobs) = split(/ :/, $parms, 2);
213 ($chmodes, $chmodeparms) = split(/ /, $chmodes, 2);
215 @blobs = split(/ /, $blobs);
217 foreach my $x (@blobs) {
218 if($x =~ /^(\&|\"|\')(.*)$/) {
220 push @bans, $2 if $1 eq '&';
221 push @excepts, $2 if $1 eq '"';
222 push @invex, $2 if $1 eq "\'";
224 $x =~ /^([*~@%+]*)(.*)$/;
225 my ($prefixes, $nick) = ($1, $2);
226 my @prefixes = split(//, $prefixes);
228 foreach my $prefix (@prefixes) {
229 $op |= $opmodes{q
} if ($prefix eq '*');
230 $op |= $opmodes{a
} if ($prefix eq '~');
231 $op |= $opmodes{o
} if ($prefix eq '@');
232 $op |= $opmodes{h
} if ($prefix eq '%');
233 $op |= $opmodes{v
} if ($prefix eq '+');
236 push @users, { NICK
=> $nick, __OP
=> $op };
240 return ($server, $cn, $ts, $chmodes, $chmodeparms, \
@users, \
@bans, \
@excepts, \
@invex);
246 my ($src, $chan, $target, $reason) = @_;
247 $src = $main_conf{numeric
} unless initial_synced
();
249 if (ref($src) eq "HASH") {
250 $srcId = ($src->{ID
}?$src->{ID
}:$src->{NICK
});
255 my $targetId = ($target->{ID
}?encodeUUID_
($target):$target->{NICK
});
256 ircsend
(":$srcId KICK $chan $targetId :$reason");
257 callfuncs
('KICK', 0, 2, [$srcId, $chan, $targetId, $reason]);
261 my ($src, $chan, $target) = @_;
262 my $srcId = ($src->{ID
}?$src->{ID
}:$src->{NICK
});
263 my $targetId = ($target->{ID
}?encodeUUID_
($target):$target->{NICK
});
264 ircsend
(":$srcId INVITE $targetId $chan 0");
269 ircsend
(':'.$main_conf{local}.' PING :'.$main_conf{local});
271 # ircsend(':'.$_[2].' '.$tkn{PONG}[$tkn].' '.$_[0].' :'.$_[1]);
276 my ($src, $dst, @msgs) = @_;
278 foreach my $buf (@msgs) {
279 # 3 spaces, two colons, PRIVMSG=7
280 # Length restrictions are for CLIENT Protocol
281 # hence the (MASKLEN - (NICKLEN + 1))
282 # Technically optimizable if we use $agent{lc $src}'s ident and host
283 my $buflen = length($src) + length($dst) + 12 + (MASKLEN
- (NICKLEN
+ 1));
284 push @bufs, wordwrap
($buf, (MAXBUFLEN
- $buflen));
286 my $srcId = ($src->{ID
}?$src->{ID
}:$src->{NICK
});
288 # submit a list of messages as a single packet to the server
289 ircsend
(":$srcId PRIVMSG $dst :".join("\r\n".":$src PRIVMSG $dst :", @bufs));
290 callfuncs
('LOOP_PRIVMSG', 0, 1, [$src, $dst, \
@bufs]);
295 debug_privmsg
($main_conf{local}, $main_conf{diag
}, @msgs);
296 write_log
('diag', '<'.$main_conf{local}.'>', @msgs);
301 debug_privmsg
($main_conf{local}, $main_conf{diag
}, @msgs);
304 sub debug_privmsg
($$@) {
305 my ($src, $dst, @msgs) = @_;
308 foreach my $buf (@msgs) {
309 # 3 spaces, two colons, PRIVMSG=7
310 # Length restrictions are for CLIENT Protocol
311 # hence the (MASKLEN - (NICKLEN + 1))
312 my $buflen = length($src) + length($dst) + 12 + (MASKLEN
- (NICKLEN
+ 1));
313 push @bufs, wordwrap
($buf, (MAXBUFLEN
- $buflen));
316 # submit a list of messages as a single packet to the server
317 ircsendimm
(":$src PRIVMSG $dst :".join("\r\n".":$src PRIVMSG $dst :", @bufs));
318 callfuncs
('LOOP_PRIVMSG', 0, 1, [$src, $dst, \
@bufs]);
322 my ($src, $dst, @msgs) = @_;
323 my $target = $dst; #lazy erry
325 foreach my $buf (@msgs) {
326 # 3 spaces, two colons, NOTICE=6
327 # Length restrictions are for CLIENT Protocol
328 # hence the (MASKLEN - (NICKLEN + 1))
329 my $buflen = length($src) + length($dst) + 12 + (MASKLEN
- (NICKLEN
+ 1));
330 push @bufs, wordwrap
($buf, (MAXBUFLEN
- $buflen));
332 my $srcId = ($src->{ID
}?$src->{ID
}:$src->{NICK
});
334 if (ref ($dst) eq "HASH") { #User Object
335 $targetId = ($target->{ID
}?encodeUUID_
($target):$target->{NICK
});
337 else { # /notice #channel This probably sucks. Blame erry :(
340 ircsend
(":$srcId NOTICE $targetId :".join("\r\n".":$srcId NOTICE $targetId :", @bufs));
341 callfuncs
('LOOP_NOTICE', 0, 1, [$srcId, $targetId, \
@bufs]);
345 my ($src, $dst, $cmd, @toks) = @_;
346 my $target = $dst; #lazy erry
347 my $srcId = ($src->{ID
}?$src->{ID
}:$src->{NICK
});
348 my $targetId = ($target->{ID
}?encodeUUID_
($target):$target->{NICK
});
349 privmsg
($srcId, $targetId, "\x01".join(' ', ($cmd, @toks))."\x01");
352 sub ctcp_reply
($$@) {
353 my ($src, $dst, $cmd, @toks) = @_;
354 my $target = $dst; #lazy erry
355 my $srcId = ($src->{ID
}?$src->{ID
}:$src->{NICK
});
356 my $targetId = ($target->{ID
}?encodeUUID_
($target):$target->{NICK
});
357 notice
($srcId, $targetId, "\x01".join(' ', ($cmd, @toks))."\x01");
361 my ($src, $dst, $modes) = @_;
362 my $target = $dst; #lazy erry
363 my $srcId = ($src->{ID
}?$src->{ID
}:$src->{NICK
});
364 my $targetId = ($target->{ID
}?encodeUUID_
($target):$target->{NICK
});
365 ircsend
(":$srcId SVSMODE $targetId $modes");
366 callfuncs
('UMODE', 0, undef, [$dst, $modes]);
369 sub setsvsstamp
($$$) {
370 my ($src, $dst, $stamp) = @_;
372 ircsend
(":$src SVS2MODE $dst +d $stamp");
373 # This function basically set the svsstamp to
374 # be the same as the userid. Not all ircd will
375 # support this function.
377 # We obviously already know the userid, so don't
378 # use a callback here.
379 #callfuncs('UMODE', 0, undef, [$dst, $modes]);
382 sub setagent_umode
($$) {
383 my ($src, $modes) = @_;
384 ircsend
(":$src UMODE2 $modes");
388 my ($src, $dst, @modelist) = @_;
389 #debug(" --", "-- ircd::setmode2: ".$_[0], split(/\n/, Carp::longmess($@)), " --");
390 foreach my $modetuple (@modelist) {
391 my $target = $modetuple->[1];
392 setmode
($src, $dst, $modetuple->[0], $modetuple->[1]);
395 sub ban_list
($$$$@) {
396 # Convenience function for lots of bans or excepts.
397 my ($src, $cn, $sign, $mode, @parms) = @_;
399 foreach my $mask (@parms) {
400 push @masklist, [( ($sign >= 1) ? '+' : '-').$mode, $mask];
402 ircd
::setmode2
($src, $cn, @masklist);
406 my ($src, $dst, $modes, $target) = @_;
408 if (initial_synced
()) {
409 if (ref($src) eq "HASH") {
410 if ($src->{NICK
} && !$src->{ID
}) {
413 $srcId = ($src->{ID
}?$src->{ID
}:($src->{UUID
}?$src->{UUID
}:$src->{NICK
}));
420 $src = $main_conf{numeric
};
424 if (ref ($target) eq "HASH") {
425 $targetId = ($target->{UID
}?$target->{UID
}:($target->{ID
}?encodeUUID_
($target):$target->{NICK
}));
430 callfuncs
('MODE', undef, 1, [$srcId, $dst, $modes, $targetId, $target]);
431 print "$ircline -- setmode($srcId, $dst, $modes, $targetId)\n" if DEBUG
;
432 ircsend
(":$srcId MODE $dst $modes $targetId");
435 sub setmode_many
($$$;@) {
436 my ($src, $dst, $modes, @targets) = @_;
438 if (initial_synced
()) {
439 $srcId = ($src->{ID
}?$src->{ID
}:($src->{UUID
}?$src->{UUID
}:$src->{NICK
}));
442 $src = $main_conf{local};
446 foreach my $target (@targets) {
447 my $targetId = ($target->{ID
}?encodeUUID_
($target):$target->{NICK
});
448 $parms .= ($parms eq ""?"":" ") . $targetId;
450 callfuncs
('MODE', undef, 1, [$srcId, $dst, $modes, $parms, @targets]);
451 print "$ircline -- setmode($srcId, $dst, $modes, $parms)\n" if DEBUG
;
452 ircsend
(":$srcId MODE $dst $modes $parms");
457 my $dm = (shift or \
%defer_mode);
458 my @k = keys(%$dm); my @v = values(%$dm);
459 for(my $i; $i<@k; $i++) {
460 my ($src, $dst) = split(/ /, $k[$i]);
463 my ($modes, $parms) = split(/ /, $m, 2);
464 setmode_real
($src, $dst, $modes, $parms);
470 sub setmode_real
($$$;$) {
471 my ($src, $dst, $modes, $parms) = @_;
472 print "$ircline -- setmode_real($src, $dst, $modes, $parms)\n" if DEBUG
;
473 # for server sources, there must be a timestamp. but you can put 0 for unspecified.
474 $parms =~ s/\s+$//; #trim any trailing whitespace, as it might break the simple parser in the ircd.
476 ircsend
(":$src MODE $dst $modes".($parms?" $parms":'').($src =~ /\./ ? ' 0' : ''));
479 sub settopic
($$$$$) {
480 my ($src, $chan, $setter, $time, $topic) = @_;
481 $src = $main_conf{numeric
} unless initial_synced
();
482 #>> 38 :583AAAAAF TOPIC #erry :Welcome to erry(world|net). Have a cookie.
483 my $srcId = ($src->{ID
}?$src->{ID
}:$src->{NICK
});
484 ircsend
(":$srcId TOPIC $chan :$topic");
485 callfuncs
('TOPIC', undef, undef, [$srcId, $chan, $setter, $time, $topic]);
489 my ($src, $message) = @_;
490 ircsend
(":$src WALLOPS :$message");
494 my ($src, $message) = @_;
495 my $srcId = ($src->{ID
}?$src->{ID
}:$src->{NICK
});
496 ircsend
(":$srcId GLOBOPS :$message");
500 my ($setter, $ident, $host, $expiry, $reason) = @_;
501 $setter = $main_conf{local} unless defined($setter);
502 $ident = '*' unless defined($ident);
503 # you need to use ADDLINE for this. GLINE is a user command
505 #>> 47 :583AAAAAA ADDLINE G test@testie inspircd.erry.omg 1308118489 0 :hi
506 #NOTE FOR ALL ADDLINES:
507 #note that you need to provide expiry alone, not expiry +time
508 #otherwise you will end up with insanely long bans
510 if (ref ($setter) eq "HASH") {
511 $setId = $setter->{ID
};
516 my $line = ":$setId ADDLINE G $ident\@$host " . $main_conf{local} . " ". time() . " " . ($expiry)." :$reason";
518 #return ($type, +1, $ident, $host, $setter, $expire, $time, $reason);
519 callfuncs
('TKL', undef, undef, [parse_addline
($line)]);
523 my ($setter, $ident, $host) = @_;
524 my $line = "TKL - G $ident $host $setter";
525 my $setId = getAgentUuid
($setter);
526 if ($setId) { $setter = $setId; }
527 #:583AAAAAE DELLINE G test@test.com
528 my $line = ":$setter DELLINE G $ident\@$host";
530 callfuncs
('TKL', undef, undef, [parse_delline
($line)]);
534 my ($setter, $host, $expiry, $reason) = @_;
535 $setter=$main_conf{local} unless defined($setter);
536 my $setId = getAgentUuid
($setter);
537 if ($setId) { $setter = $setId; }
538 #:583AAAAAE ADDLINE Z test.com inspircd.erry.omg 1308216407 0 :go away
539 my $line = ":$setter ADDLINE Z $host " . $main_conf{local} . " ". time() . " " . ($expiry)." :$reason";
541 callfuncs
('TKL', undef, undef, [parse_addline
($line)]);
545 my ($setter, $host) = @_;
546 my $setId = getAgentUuid
($setter);
547 if ($setId) { $setter = $setId; }
548 my $line = ":$setter DELLINE Z $host";
550 callfuncs
('TKL', undef, undef, [parse_delline
($line)]);
553 sub spamfilter
($$$$$$$) {
554 # Note the hardcoded zero (0).
555 # Looks like theoretically one can have expirable spamfilters.
556 # This is untested however.
557 my ($sign, $tkl_target, $tkl_action, $setter, $bantime, $reason, $regex) = @_;
558 my $tkl = "TKL ".($sign ? '+' : '-' )." F $tkl_target $tkl_action $setter 0 ".time()." $bantime $reason :$regex";
560 callfuncs
('TKL', undef, undef, [parse_tkl
($tkl)]);
563 sub update_userkill
($) {
566 # This is a simple way to do it, that _could_ be defeated
567 # with enough users getting killed at once.
568 # The alternative would require a timer to expire the old entries.
569 return undef if (time() == $userkill[1] and $target eq $userkill[0]);
570 @userkill = ($target, time());
576 my ($src, $target, $reason) = @_;
577 $src = $main_conf{local} unless initial_synced
();
578 my $srcId = ($src->{ID
}?$src->{ID
}:$src->{NICK
});
579 my $targetId = ($target->{ID
}?encodeUUID_
($target):$target->{NICK
});
580 my $srcNick = $target->{NICK
};
581 return 0 unless update_userkill
($targetId);
582 ircsendimm
(":$srcId KILL $targetId :($reason)");
583 callfuncs
('KILL', 0, 1, [$src, $target, $srcNick, $reason]);
587 my ($src, $target, $snomasks) = @_;
588 $src=$main_conf{local} unless defined($src);
590 # None, this doesn't affect us.
592 # SVSSNO is not in tokens.txt nor msg.h
593 ircsend
(":$src ".'SVS2SNO'." $target $snomasks ".time);
597 my ($src, $target, $newnick) = @_;
598 $src=$main_conf{local} unless defined($src);
599 # note: we will get a NICK cmd back after a
600 # successful nick change.
601 # warning, if misused, this can KILL the user
603 my $srcId = ($src->{ID
}?$src->{ID
}:$src->{NICK
});
604 my $targetId = ($target->{ID
}?encodeUUID_
($target):$target->{NICK
});
605 ircsend
(":$srcId SVSNICK $targetId $newnick ".time);
609 my ($targetserver, $bool, $src) = @_;
610 $src = $main_conf{local} unless defined($src);
611 if ($bool > 0) { $bool = '+'; } else { $bool = '-'; }
612 #this is SVS NO-OP not SVS SNOOP
613 ircsend
(":$main_conf{local} SVSNOOP $targetserver $bool");
619 # Changes the WATCH list of a user.
620 # Syntax: SVSWATCH <nick> :<watch parameters>
621 # Example: SVSWATCH Blah :+Blih!*@* -Bluh!*@* +Bleh!*@*.com
622 # *** We do not track this info nor care.
623 my ($src, $target, @watchlist) = @_;
624 my $srcId = ($src->{ID
}?$src->{ID
}:$src->{NICK
});
625 my $targetId = ($target->{ID
}?encodeUUID_
($target):$target->{NICK
});
626 my $base_str = ":$srcId SVSWATCH $targetId ";
627 my $send_str = $base_str;
629 my $watch = shift @watchlist;
630 if (length("$send_str $watch") > MAXBUFLEN
) {
632 $send_str = $base_str;
634 $send_str = "$send_str $watch";
639 sub svssilence
($$@) {
640 # Changes the SILENCE list of a user.
641 # Syntax: SVSSILENCE <nick> :<silence parameters>
642 # Example: SVSSILENCE Blah :+Blih!*@* -Bluh!*@* +Bleh!*@*.com
643 # *** We do not track this info nor care.
644 my ($src, $target, @silencelist) = @_;
645 my $srcId = ($src->{ID
}?$src->{ID
}:$src->{NICK
});
646 my $targetId = ($target->{ID
}?encodeUUID_
($target):$target->{NICK
});
647 my $base_str = ":$srcId SVSSILENCE $targetId ";
648 my $send_str = $base_str;
649 while (@silencelist) {
650 my $silence = shift @silencelist;
651 if (length("$send_str $silence") > MAXBUFLEN
) {
653 $send_str = $base_str;
655 $send_str = "$send_str $silence";
661 # Gives nick Operflags like the ones in O:lines.
662 # SVSO <nick> <+operflags> (Adds the Operflags)
663 # SVSO <nick> - (Removes all O:Line flags)
664 # Example: SVSO SomeNick +bBkK
665 # *** We do not track this info nor care.
666 # *** We will see any umode changes later.
667 # *** this cmd does not change any umodes!
669 my ($src, $target, $oflags) = @_;
670 $src = $main_conf{local} unless defined($src);
671 ircsend
(":$src SVSO $target $oflags");
676 # *** We do not track this info nor care.
677 my ($src, $target, $swhois) = @_;
678 $src = $main_conf{local} unless defined($src);
679 ircsend
(":$src SWHOIS $target :$swhois");
684 my ($src, $target, @chans) = @_;
685 foreach my $chan (@chans) {
686 # insp only allows one at the time.
687 __svsjoin
($src, $target, $chan);
692 my ($src, $target, $chan) = @_;
693 # a note. a JOIN is returned back to us on success
694 # so no need to process this command.
695 # similar for svspart.
696 my $srcId = ($src->{ID
}?$src->{ID
}:$src->{NICK
});
697 my $targetId = ($target->{ID
}?encodeUUID_
($target):$target->{NICK
});
698 ircsend
(($srcId?":$srcId":'')." SVSJOIN $targetId $chan");
702 my ($src, $target, $reason, @chans) = @_;
703 my $srcId = ($src->{ID
}?$src->{ID
}:$src->{NICK
});
704 my $targetId = ($target->{ID
}?encodeUUID_
($target):$target->{NICK
});
705 ircsend
(($srcId ? ":$srcId" : '')." SVSPART $targetId ".join(',', @chans).
706 ($reason ? " :$reason" : ''));
710 # we need to sqline most/all of our agents.
711 # tho whether we want to put it in agent_connect
712 # or leave it to the module to call it...
713 my ($nickmask, $reason) = @_;
714 #ircsend("$tkn{S1QLINE}[$tkn] $nickmask".($reason?" :$reason":''));
715 qline
($nickmask, 0, $reason);
719 my ($nickmask, $expiry, $reason) = @_;
720 #:583AAAAAA ADDLINE Q hell3o inspircd.erry.omg 1308295479 600 :Bye Bye
721 my $line = ':' . $main_conf{numeric
} . ' ADDLINE Q '.$nickmask.' '.$main_conf{local}.' '. time() . ' ' . ($expiry ? $expiry : 0 ) . ' :'.$reason;
723 callfuncs
('TKL', undef, undef, [parse_addline
($line)]);
728 #>> 37 :583AAAAAA DELLINE Q errietta3
729 my $line = ":" . $main_conf{numeric
} . ' DELLINE Q ' . $nickmask . "\n";
731 callfuncs
('TKL', undef, undef, [parse_tkl
($line)]);
735 my ($nickmask, $expiry, $reason) = @_;
736 #:583AAAAAA ADDLINE Q hell3o inspircd.erry.omg 1308295479 600 :Bye Bye
738 my $line = ':' . $main_conf{numeric
} . ' ADDLINE Q '.$nickmask . ' ' . $main_conf{local} . ' '. time() . ' ' . ($expiry ? $expiry : 0).' :'.$reason;
741 # at startup we send these too early,
742 # before the handlers are initialized
743 # so they may be lost.
744 callfuncs
('TKL', undef, undef, [parse_tkl
($line)]);
748 # we need to sqline most/all of our agents.
749 # tho whether we want to put it in agent_connect
750 # or leave it to the module to call it...
758 # TKL - Q * test services.SC.net
759 my $line = 'TKL - Q * '.$nickmask.' '.$main_conf{local};
761 callfuncs
('TKL', undef, undef, [parse_tkl
($line)]);
765 my ($src, $target, $reason) = @_;
766 # SVSKILL requires a src, it will NOT work w/o one.
767 # not sure if it'll accept a servername or not.
768 # consider defaulting to ServServ
769 die('svskill called w/o $src') unless $src;
770 ircsend
(':'.$src.' SVSKILL '.$target.' :'.$reason);
771 callfuncs
('QUIT', 0, undef, [$target, $reason]);
776 #ircsend(":$main_conf{local} 351 $src $main::progname ver $main::version $main_conf{local} ".
777 # $main::extraversion);
782 ircsend
("USERHOST $target");
787 die "We're not supposed to use USERIP anymore!" if DEBUG
and NICKIP
;
788 ircsend
(":$main::rsnick USERIP $target");
792 my ($src, $target, $vhost) = @_;
793 my $srcId = ($src->{ID
}?$src->{ID
}:$src->{NICK
});
794 my $targetId = ($target->{ID
}?encodeUUID_
($target):$target->{NICK
});
795 ircsend
(($srcId?":$srcId ":'')." CHGHOST $targetId $vhost");
796 callfuncs
('CHGHOST', 0, 1, [$srcId, $targetId, $vhost]);
800 my ($src, $target, $ident) = @_;
801 my $srcId = ($src->{ID
}?$src->{ID
}:$src->{NICK
});
802 my $targetId = ($target->{ID
}?encodeUUID_
($target):$target->{NICK
});
803 ircsend
(($src?":$srcId ":'')." CHGIDENT $targetId $ident");
804 callfuncs
('CHGIDENT', 0, 1, [$srcId, $targetId, $ident]);
807 sub jupe_server
($$) {
808 my ($server, $reason) = @_;
810 # :nascent.surrealchat.net SERVER wyvern.surrealchat.net 2 :SurrealChat
811 die "You can't jupe $server"
812 if ((lc($server) eq lc($remoteserv)) or (lc($server) eq lc($main_conf{local})));
813 ircsend
(':'.$main_conf{local}." SQUIT $server :");
814 ircsend
(':'.$main_conf{local}." SERVER $server 2 :$reason");
816 set_server_juped
($server);
818 sub agent_dojoin
($$) {
819 my ($agent, $chan) = @_;
821 if (ref($agent) ne "HASH") {
822 $srcId = getAgentUuid
($agent);
829 $srcId = ($src->{ID
}?$src->{ID
}:($src->{UUID
}?$src->{UUID
}:$src->{NICK
}));
831 ircsend
(":" . $srcId . " JOIN " . $chan);
834 sub agent_dopart
($$$) {
835 my ($agent, $chan, $reason) = @_;
837 if (ref($agent) ne "HASH") {
838 $srcId = getAgentUuid
($agent);
845 $srcId = ($src->{ID
}?$src->{ID
}:($src->{UUID
}?$src->{UUID
}:$src->{NICK
}));
847 ircsend
(":$srcId PART $chan :$reason");
849 sub rehash_all_servers
(;$) {
852 # Validate the type before passing it along.
853 # Very IRCd specific! May be version specific.
854 $type = undef() if(defined($type) && !($type =~ /^\-(motd|botmotd|opermotd|garbage)$/i));
856 foreach my $server (get_online_servers
()) {
857 ircsend
(':'.$main::rsnick
.' REHASH '.$server.(defined($type) ? ' '.$type : '') );
861 sub unban_nick
($$@) {
862 # This is an Unreal-specific server-protocol HACK.
863 # It is not expected to be portable to other ircds.
864 # Similar concepts may exist in other ircd implementations
865 my ($src, $cn, @nicks) = @_;
866 my $srcId = ($src->{ID
}?$src->{ID
}:$src->{NICK
});
867 my $i = 0; my @nicklist = ();
868 while(my $nick = shift @nicks) {
869 push @nicklist, $nick;
871 ircsend
(($src ? ":$src" : '' )." SVSMODE $cn -".'b'x
($i).' '.join(' ', @nicklist));
872 $i = 0; @nicklist = ();
876 ircsend
(($srcId ? ":$srcId " : "SVSMODE $cn -".'b'x
($i).' '.join(' ', @nicklist)));
877 # We don't loopback this, as we'll receive back the list
882 # This is an Unreal-specific server-protocol HACK.
883 # It is not expected to be portable to other ircds.
884 # Similar concepts may exist in other ircd implementations
887 ircsend
(($src ? ":$src " : '' ). "SVSMODE $cn -b");
888 # We don't loopback this, as we'll receive back the list
892 # HostServ OFF would want this.
893 # resets the vhost to be the cloakhost.
894 sub reset_cloakhost
($$) {
895 my ($src, $target) = @_;
896 setumode
($src, $target, '-x+x'); # only works in 3.2.6.
899 # removes the cloakhost, so that vhost matches realhost
900 sub disable_cloakhost
($$) {
901 my ($src, $target) = @_;
902 setumode
($src, $target, '-x'); # only works in 3.2.6.
905 # enables the cloakhost, so that vhost becomes the cloakhost
906 sub enable_cloakhost
($$) {
907 my ($src, $target) = @_;
908 setumode
($src, $target, '+x'); # only works in 3.2.6.
911 sub agent_doconn
($$$$$) {
912 my ($nick, $ident, $host, $modes, $gecos) = @_;
915 if ($startInt == -1) {
916 $uuid = $main_conf{numeric
} . "AAAAAA";
917 $startInt = decodeUUID
($uuid);
920 $uuid = encodeUUID
($startInt);
922 ircsend
(":" . $main_conf{numeric
} . " UID" . " $uuid " . time . " $nick $host $host $ident 127.0.0.1 ". (time+5) . " $modes " . ":$gecos" );
923 setAgentUuid
($nick,$uuid);
924 setAgentRevUuid
($uuid, $nick);
929 my ($src, $sign, @targets) = @_;
930 $src = $main_conf{local} unless $src;
931 foreach my $target (@targets) {
932 ircsend
(':'.$src .' SVSNOLAG '.$sign.' '.$target);