]> jfr.im git - irc/SurrealServices/srsv.git/blob - branches/0.5.0/SrSv/Insp/Parse.pm
Fix a problem with parse & networks w/ more than 1 server.
[irc/SurrealServices/srsv.git] / branches / 0.5.0 / SrSv / Insp / Parse.pm
1 # This file is part of SurrealServices.
2 #
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.
7 #
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.
12 #
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
16
17 package SrSv::IRCd::Parse;
18
19 use strict;
20
21 use Exporter 'import';
22 # parse_sjoin shouldn't get used anywhere else, as we never produce SJOINs
23 # parse_tkl however is used for loopbacks.
24 BEGIN { our @EXPORT_OK = qw(parse_line parse_tkl parse_addline) }
25
26 # FIXME
27 BEGIN { *SJB64 = \&ircd::SJB64; *CLK = \&ircd::CLK; *NICKIP = \&ircd::NICKIP; }
28
29 use SrSv::Conf 'main';
30
31 use SrSv::Debug;
32 use SrSv::IRCd::State qw($ircline $remoteserv create_server get_server_children set_server_state get_server_state %IRCd_capabilities);
33 use SrSv::IRCd::Queue qw(queue_size);
34 use SrSv::IRCd::IO qw( ircsend ircsendimm);
35 use SrSv::IRCd::Send qw (getRevUuid getUuid setRevUuid setUuid);
36 use SrSv::Unreal::Modes qw(%opmodes);
37 use SrSv::RunLevel 'main_shutdown';
38 # Unreal uses its own modified base64 for everything except NICKIP
39 use SrSv::Unreal::Base64 qw(b64toi itob64);
40 use SrSv::User '/./';
41 # Unreal uses unmodified base64 for NICKIP.
42 # Consider private implementation,
43 # tho MIME's is probably faster
44 use MIME::Base64;
45 use Data::Dumper;
46 use SrSv::Insp::UUID;
47 # FIXME
48 use constant {
49 # Wait For
50 WF_NONE => 0,
51 WF_NICK => 1,
52 WF_CHAN => 2,
53 WF_ALL => 3,
54 };
55
56 use SrSv::Shared qw(@servernum);
57
58 our %cmdhash;
59
60 sub parse_line($) {
61 my ($in) = @_;
62 if (!$in) {
63 return;
64 }
65 my $cmd;
66
67 if($in =~ /^(?:@|:)(\S+) (\S+)/) {
68 $cmd = $2;
69 }
70 elsif ($in =~ /^(\S+)/) {
71 $cmd = $1;
72 }
73 my $sub = $cmdhash{$cmd};
74 unless (defined($sub)) {
75 print "Bailing out from $ircline:$cmd for lack of cmdhash\n" if DEBUG();
76 return undef();
77 }
78 my ($event, $src, $dst, $wf, @args) = &$sub($in);
79 unless (defined($event)) {
80 print "Bailing out from $ircline:$cmd for lack of event\n" if DEBUG;
81 return undef();
82 }
83 #return unless defined $event;
84
85 my (@recipients, @out);
86 if(defined($dst)) {
87 #$args[$dst] = lc $args[$dst];
88 @recipients = split(/\,/, $args[$dst]);
89 }
90 #if(defined($src)) { $args[$src] = lc $args[$src]; }
91
92 if(@recipients > 1) {
93 foreach my $rcpt (@recipients) {
94 $args[$dst] = $rcpt;
95 push @out, [$event, $src, $dst, $wf, [@args]];
96 }
97 } else {
98 @out = [$event, $src, $dst, $wf, [@args]];
99 }
100
101 return @out;
102 }
103 #parse_fjoin($server, $channel, $ts, $modes, @nicks, @status)
104 sub parse_fjoin ($$$$$$) {
105 my ($server, $channel, $ts, $modes, $idsr, $statusref) = @_;
106 my @status = @$statusref;
107 my @ids = @$idsr;
108 my $i = 0;
109 my @users;
110 foreach my $id (@ids) {
111 my $op = 0;
112 my @ops = split ("",$status[$i]);
113 foreach my $prefix (@ops) {
114 $op |= $opmodes{$prefix};
115 }
116 my $user = {ID => $id, __OP=>$op}; #ID'S are _already_ decoded in FJOIN!
117 get_user_nick ($user);
118 push @users, $user;
119 $i++;
120 }
121 return ($server, $channel, $ts, $modes, undef, \@users, undef, undef, undef); #bans etc are got from FMODE..
122 }
123 sub parse_sjoin($$$$) {
124 my ($server, $ts, $cn, $parms) = @_;
125 my (@users, @bans, @excepts, @invex, @blobs, $blobs, $chmodes, $chmodeparms);
126
127 $server = '' unless $server;
128
129 if($parms =~ /^:(.*)/) {
130 $blobs = $1;
131 } else {
132 ($chmodes, $blobs) = split(/ :/, $parms, 2);
133 ($chmodes, $chmodeparms) = split(/ /, $chmodes, 2);
134 }
135 @blobs = split(/ /, $blobs);
136
137 foreach my $x (@blobs) {
138 if($x =~ /^(\&|\"|\')(.*)$/) {
139 my $type;
140 push @bans, $2 if $1 eq '&';
141 push @excepts, $2 if $1 eq '"';
142 push @invex, $2 if $1 eq "\'";
143 } else {
144 $x =~ /^([*~@%+]*)(.*)$/;
145 my ($prefixes, $nick) = ($1, $2);
146 my @prefixes = split(//, $prefixes);
147 my $op = 0;
148 foreach my $prefix (@prefixes) {
149 $op |= $opmodes{q} if ($prefix eq '*');
150 $op |= $opmodes{a} if ($prefix eq '~');
151 $op |= $opmodes{o} if ($prefix eq '@');
152 $op |= $opmodes{h} if ($prefix eq '%');
153 $op |= $opmodes{v} if ($prefix eq '+');
154 }
155
156 push @users, { NICK => $nick, __OP => $op };
157 }
158 }
159
160 return ($server, $cn, $ts, $chmodes, $chmodeparms, \@users, \@bans, \@excepts, \@invex);
161 }
162 sub parse_addline ($) {
163 my ($line) = @_;
164 #return ($type, +1, $ident, $host, $setter, $expire, $time, $reason);
165 #>> 47 :583AAAAAA ADDLINE G test@testie inspircd.erry.omg 1308118489 0 :hi
166 my ($setter, undef, $type, $mask, $server, $time, $expiry, $reason) = split (/ /, $line, 7);
167 $reason =~ /:(.*)/;
168 $reason = $1;
169 $setter =~ /:(.*)/;
170 $setter = $1;
171 my @masks = split (/@/,$mask, 1);
172 my $ident = $masks[0];
173 my $host = $masks[1];
174 #return ($type, +1, $ident, $host, $setter, $expire, $time, $reason);
175 return ($type, +1, $ident, $host, $setter, $expiry, $time, $reason);
176 }
177 sub parse_tkl ($) {
178 my ($in) = @_;
179 # This function is intended to accept ALL tkl types,
180 # tho maybe not parse all of them in the first version.
181
182 # Discard first token, 'TKL'
183 my (undef, $sign, $type, $params) = split(/ /, $in, 4);
184
185 # Yes, TKL types are case sensitive!
186 # also be aware (and this applies to the net.pm generator functions too)
187 # This implementation may appear naiive, but Unreal assumes that, for a given
188 # TKL type, that all parameters are non-null.
189 # Thus, if any parameters ARE null, Unreal WILL segfault.
190 ## Update: this problem may have been fixed since Unreal 3.2.2 or so.
191 if ($type eq 'G' or $type eq 'Z' or $type eq 's' or $type eq 'Q') {
192 # format is
193 # TKL + type ident host setter expiretime settime :reason
194 # TKL - type ident host setter
195 # for Q, ident is always '*' or 'h' (Services HOLDs)
196 if ($sign eq '+') {
197 my ($ident, $host, $setter, $expire, $time, $reason) = split(/ /, $params, 6);
198
199 $reason =~ s/^\://;
200 return ($type, +1, $ident, $host, $setter, $expire, $time, $reason);
201 }
202 elsif($sign eq '-') {
203 my ($ident, $host, $setter) = split(/ /, $params, 3);
204 return ($type, -1, $ident, $host, $setter);
205 }
206 }
207 elsif($type eq 'F') {
208 # TKL + F cpnNPq b saturn!attitude@netadmin.SCnet.ops 0 1099959668 86400 Possible_mIRC_DNS_exploit :\/dns (\d+\.){3}\d
209 # TKL + F u g saturn!attitude@saturn.netadmin.SCnet.ops 0 1102273855 604800 sploogatheunbreakable:_Excessively_offensive_behavior,_ban_evasion. :.*!imleetnig@.*\.dsl\.mindspring\.com
210 # TKL - F u Z tabris!northman@tabris.netadmin.SCnet.ops 0 0 :do_not!use@mask
211 if ($sign eq '+') {
212 my ($target, $action, $setter, $expire, $time, $bantime, $reason, $mask) = split(/ /, $params, 8);
213 $mask =~ s/^\://;
214 return ($type, +1, $target, $action, $setter, $expire, $time, $bantime, $reason, $mask);
215 }
216 elsif($sign eq '-') {
217 my ($target, $action, $setter, $expire, $time, $mask) = split(/ /, $params, 6);
218 $mask =~ s/^\://;
219 return ($type, -1, $target, $action, $setter, $mask);
220 }
221 }
222 }
223
224 sub PING($) {
225 my ($event, $src, $dst, @args);
226 $_[0] =~ /^(?:8|PING) :(\S+)$/;
227 # ($event, $src, $dst, $args)
228 return ('PING', undef, undef, WF_NONE, $1);
229 }
230 sub UID ($) {
231 if ($_[0] =~ /^(:\S+) UID (\S+) (\d+) (\S+) (\S+) (\S+) (\S+) (\S+) (\d+) (\S+) :(.*)$/) {
232 print "1111111111111\n";
233 #:583 UID 583AAAAAJ 1307703236 erry__ localhost localhost errietta 127.0.0.1 1307703241 + :errietta
234 my ($server, $uid, $stamp, $nick, $host, $vhost, $ident, $IP, $ts, $modes, $gecos) = ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12);
235 print "UID $uid " . decodeUUID($uid) . "\n";
236 my $user = { NICK => $nick, ID => decodeUUID($uid) };
237 return ('NICKCONN', undef, undef, WF_NICK, $user, 0, $ts, $ident, $host, $server, $stamp, $modes, $vhost, $gecos,
238 join('.', unpack('C4', MIME::Base64::decode($IP))));
239 }
240 elsif ($_[0] =~ /^(:\S+) UID (\S+) (\d+) (\S+) (\S+) (\S+) (\S+) (\S+) (\d+) (\S+) (\S+) :(.*)$/) {
241 print "2222222\n";
242 #:965 UID 965AAAAAG 1311863295 erry arceus.pokemonlake.com IceFyre/NetAdmin/erry ~erry 216.14.116.138 1311863255 +IWhiosw +ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz :erry
243 my ($server, $uid, $stamp, $nick, $host, $vhost, $ident, $IP, $ts, $modes, $snomasks, $gecos) = ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12);
244 $modes .= $snomasks;
245 print "UID $uid " . decodeUUID($uid) . "\n";
246 my $user = { NICK => $nick, ID => decodeUUID($uid) };
247 return ('NICKCONN', undef, undef, WF_NICK, $user, 0, $ts, $ident, $host, $server, $stamp, $modes, $vhost, $gecos,
248 join('.', unpack('C4', MIME::Base64::decode($IP))));
249 }
250 }
251 sub EOS($) {
252 my $event;
253 if ($_[1] != "ENDBURST") {
254 $_[0] =~ /^(@|:)(\S+) (?:EOS|ES)/; # Sometimes there's extra crap on the end?
255 my $server;
256 if ($1 eq '@') {
257 $server = $servernum[b64toi($2)];
258 }
259 else {
260 $server = $2;
261 }
262 print "SERVER $server\n";
263 set_server_state($server, 1);
264 return undef() unless get_server_state($remoteserv);
265 if($server eq $remoteserv) { $event = 'SEOS' } else { $event = 'EOS' }
266 print "Ok. we had EOS\n";
267 return ($event, undef, undef, WF_ALL, $server);
268 }
269 else {
270 print "wot\n";
271 $_[0] =~ /^:(\S+) ENDBURST/;
272 my $server = $1;
273 set_server_state($server, 1);
274 print "server $server remote $remoteserv\n";
275 return undef() unless get_server_state($remoteserv);
276 print "This be it! Got endbrust!\n";
277 return ("ENDBURST", undef, undef, WF_ALL, $1);
278 }
279 }
280 our %servIds;
281 sub SERVER($) {
282 #ircd::debug($_[0]) if $debug;
283
284 if($_[0] =~ /^(?:SERVER|\') (\S+) (\S+) :(U[0-9]+)-([A-Za-z0-9]+)-([0-9]+) (.*)$/) {
285 # SERVER test-tab.surrealchat.net 1 :U2307-FhinXeOoZEmM-200 SurrealChat
286 # cmd, servername, hopCount, U<protocol>-<buildflags>-<numeric> infoLine
287 $remoteserv = $1;
288 create_server($1);
289 $servernum[$5] = $1;
290
291 return ('SERVER', undef, undef, WF_ALL, undef, $1, $2, $6, $5, $3, $4);
292 # src, serverName, numHops, infoLine, serverNumeric, protocolVersion, buildFlags
293 }
294 elsif($_[0] =~ /^(:|@)(\S+) (?:SERVER|\') (\S+) (\d+) (\d+) :(.*)$/) {
295 # @38 SERVER test-hermes.surrealchat.net 2 100 :SurrealChat
296 # source, cmd, new server, hopCount, serverNumeric, infoLine
297 my ($numeric, $name);
298 if ($1 eq '@') {
299 $name = $servernum[b64toi($2)];
300 }
301 else {
302 $name = $2;
303 }
304 create_server($3, $name);
305 $servernum[$5] = $3;
306
307 return ('SERVER', undef, undef, WF_ALL, $name, $3, $4, $6, $5);
308 # src, serverName, numHops, infoLine, serverNumeric
309 }
310 if($_[0] =~ /^(?:SERVER|\') (\S+) (\S+) :(.*)$/) {
311 $remoteserv = $1;
312 create_server($1);
313 return ('SERVER', undef, undef, WF_ALL, undef, $1, $2, $3);
314 # src, serverName, numHops, infoLine
315 }
316 elsif($_[0] =~ /^:(\S+) (?:SERVER|\') (\S+) (\d+) :(.*)$/) {
317 # source, new server, hop count, description
318 create_server($2, $1);
319 return ('SERVER', undef, undef, WF_ALL, $1, $2, $3, $4);
320 # src, serverName, numHops, infoLine
321 }
322 elsif ($_[0] =~ /^:(\S+) SERVER (\S+) (\S+) (\d+) (\S+) :(.*)$/) {
323 #:irc.icefyre.org SERVER Services.IceFyre.Org * 1 00B :IceFyre IRC Services
324 my $id = $servIds{$1};
325 create_server($5, $id);
326 return ('SERVER', undef, undef, WF_ALL, $1, $5, $4, $6);
327 }
328 elsif ($_[0] =~ /^SERVER (\S+) (\S+) (\d+) (\S+) :(.*)$/) {
329 print "RIGHT ONE WHOO\n";
330 #SERVER inspircd.erry.omg mypass 0 583 :erry World
331 #SERVER irc.icefyre.org mypass 0 965 :IceFyre IRC Hub
332
333 #SERVER servername password hopcount SID :Server Desc
334 $remoteserv = $4;
335 create_server ($4);
336 #since from now on we'll be getting commands as sent from the SID it's much wiser to keep that than the name.
337 $servIds{$1} = $4;
338 return ("SERVER", undef, undef, WF_ALL, undef, $1, $3, $5, $4);
339 }
340 }
341
342 sub SQUIT($) {
343 if($_[0] =~ /^(?:SQUIT|-) (\S+) :(.*)$/) {
344 my $list = [get_server_children($1)];
345 set_server_state($1, undef());
346 return ('SQUIT', undef, undef, WF_ALL, undef, $list, $2);
347 }
348 elsif($_[0] =~ /^(:|@)(\S+) (?:SQUIT|-) (\S+) :(.*)$/) {
349 my $name;
350 if ($1 eq '@') {
351 $name = $servernum[b64toi($2)];
352 }
353 else {
354 $name = $2;
355 }
356 my $list = [get_server_children($3)];
357 set_server_state($3, undef());
358 return ('SQUIT', undef, undef, WF_ALL, $name, $list, $4);
359 }
360 }
361
362 sub NETINFO($) {
363 $_[0] =~ /^(?:NETINFO|AO) (\S+) (\S+) (\S+) (\S+) (\S+) (\S+) (\S+) :(.*)$/;
364 return ('NETINFO', undef, undef, WF_NONE, $1, $2, $3, $4, $5, $6, $7, $8);
365 }
366
367 sub PROTOCTL($) {
368 $_[0] =~ /^PROTOCTL (.*)$/;
369 return ('PROTOCTL', undef, undef, WF_NONE, $1);
370 }
371
372 sub JOIN($) {
373 $_[0] =~ /^:(\S+) (?:C|JOIN) (\S+)$/;
374 my $user = { ID => decodeUUID($1) };
375 get_user_nick ($user);
376 return ('JOIN', undef, 1, WF_CHAN, $user, $2);
377 }
378
379 sub FJOIN ($) {
380 #>> 13 :97K FJOIN #erry 1307879417 +nt :o,97KAAAAAA ,97KAAAAAB
381 if ($_[0] =~ m"^(:\S+) FJOIN (\S+) (\d+) (\S+) (:?)(.*)$") {
382 my ($server, $channel, $ts, $modes, $userstring) = ($1, $2, $3, $4, $6);
383 my @users = split (" ", $userstring);
384 my (@ids, @status);
385 foreach my $user (@users) {
386 my @params = split (",",$user);
387 push (@status, $params[0]);
388 push (@ids, decodeUUID($params[1]));
389 }
390 return ('SJOIN', undef, undef, WF_CHAN, parse_fjoin($server, $channel, $ts, $modes, \@ids, \@status));
391 }
392 #>> 15 :583 FJOIN #opers 1310128904 +Pis :
393 #CHANNELS CONFIGURED TO STAY OPEN WITH CHMODE +P (INSP)
394 elsif ($_[0] =~ m"^(:\S+) FJOIN (\S+) (\d+) (\S+) :$") {
395 print "WHOOOOOOF";
396 #FIXME - Update channel modes.
397 }
398 }
399 sub SJOIN($) {
400 if ($_[0] =~ /^(?:\~|SJOIN) (\S+) (\S+) (.*)$/) {
401 my ($ts, $cn, $payload) = ($1, $2, $3);
402 if ($ts =~ s/^!//) {
403 $ts = b64toi($ts);
404 }
405 return ('SJOIN', undef, undef, WF_CHAN, parse_sjoin($remoteserv, $ts, $cn, $payload));
406 }
407 elsif($_[0] =~ /^(@|:)(\S+) (?:\~|SJOIN) (\S+) (\S+) (.*)$/) {
408 my ($server, $ts, $cn, $payload) = ($2, $3, $4, $5);
409 if ($1 eq '@') {
410 $server = $servernum[b64toi($2)];
411 }
412 else {
413 $server = $2;
414 }
415 if ($ts =~ s/^!//) {
416 $ts = b64toi($ts);
417 }
418 return ('SJOIN', undef, undef, WF_CHAN, parse_sjoin($server, $ts, $cn, $payload));
419 }
420 }
421
422 sub PART($) {
423 my $user;
424
425 if($_[0] =~ /^:(\S+) (?:D|PART) (\S+) :(.*)$/) {
426 $user = {ID => decodeUUID($1)};
427 get_user_nick ($user);
428 return ('PART', undef, 0, WF_CHAN, $user, $2, $3);
429 }
430 elsif($_[0] =~ /^:(\S+) (?:D|PART) (\S+)$/) {
431 $user = {ID => decodeUUID($1)};
432 get_user_nick ($user);
433 return ('PART', undef, 0, WF_CHAN, $user, $2, undef);
434 }
435 }
436 sub FMODE($) {
437 #:583AAAAAR FMODE #erry 1308214721 +ib test!*@* When any mode in the channel is set.
438 #:583 FMODE #erry 1308214721 +b test1!*@* At server connect. Note that the rest of the channel modes are not there but rather at FJOIN. So this will only have bans and the like.
439 if($_[0] =~ /^:(\S+) FMODE (#\S+) (\d+) (\S+) ?(.*)$/) {
440 my $id = $1;
441 my $user;
442 print "FMODE ID $id " . length($id);
443 if (length($id) > 3) { #UID
444 print "FFFFFFFFFFF\n";
445 $user = {ID => decodeUUID($id)};
446 get_user_nick ($user);
447 }
448 else { #SID
449 $user = $id;
450 }
451 my $name;
452 my $argz = $5;
453 my @args = split(/ /, $argz);
454 my $modes = $4;
455 print "============MODES $modes=================\n";
456 print "5: $4\n";
457 print "6: $5\n";
458 my @modes = split(//, $modes);
459 my @userargs;
460 foreach my $mode (@modes) {
461 if($mode eq '+' or $mode eq '-') { next; }
462 if ($mode !~ /^[vhoaq]$/) { next; }
463 my $arg = shift (@args);
464 next if $arg eq '';
465 my $id = decodeUUID($arg);
466 my $tuser = {ID=>$id};
467 get_user_nick ($tuser);
468 push @userargs, $tuser;
469 }
470 return ('MODE', undef, 1, WF_ALL, $user, $2, $4, $5, @userargs);
471 }
472 }
473 sub MODE($) {
474 my $user;
475 if($_[0] =~ /^(@|:)(\S+) (?:G|MODE) (#\S+) (.*)(?: \d+)?$/) {
476 my $name;
477 if ($1 eq '@') {
478 $name = $servernum[b64toi($2)];
479 $user = {NICK => $name};
480 }
481 else {
482 $name = $2;
483 $user = { ID=>decodeUUID($name)};
484 get_user_nick ($user);
485 }
486 my $argz = $6;
487 my @args = split(/ /, $argz);
488 my $modes = $5;
489 print "============MODES $modes=================\n";
490 print "5: $5\n";
491 print "6: $6\n";
492 my @modes = split(//, $modes);
493 my $newargs = "";
494 foreach my $mode (@modes) {
495 if($mode eq '+' or $mode eq '-') { next; }
496 my $arg = shift (@args);
497 next if $arg eq '';
498 my $id = encodeUUID($arg);
499 my $tuser = {ID=>$id};
500 my $nick = get_user_nick ($tuser);
501 print "!!!!!!!!!!!1!!!!!$nick\n";
502 $newargs .= ($newargs eq ""?$nick:" $nick"); # what an awful way to do it.
503 }
504 my $arguements;
505 if ($newargs eq "") {
506 $arguements = $argz;
507 }
508 else {
509 $arguements = $newargs;
510 }
511 return ('MODE', undef, 1, WF_ALL, $user, $3, $4, $arguements);
512 }
513 elsif($_[0] =~ /^:(\S+) (?:G|MODE) (\S+) :(\S+)$/) {
514 # We shouldn't ever get this, as UMODE2 is preferred
515 $user = { ID => decodeUUID($1) };
516 get_user_nick ($user);
517 return ('UMODE', 0, 0, WF_ALL, $user, $3);
518 }
519
520 }
521
522
523 sub MESSAGE($) {
524 my ($event, @args);
525 if($_[0] =~ /^(@|:)(\S+) (?:\!|PRIVMSG) (\S+) :(.*)$/) {
526
527 my ($name, $srcUser, $dstUser) ;
528 if ($1 eq '@') {
529 $name = $servernum[b64toi($2)];
530 $srcUser = {NICK=>$name};
531 }
532 else {
533 $name = $2;
534 $srcUser = {ID=>decodeUUID($name)};
535 unless (get_user_nick ($srcUser)) {
536 $srcUser = {NICK=>$name};
537 get_user_id ($name);
538 }
539 }
540 my $dest = $3;
541 $dstUser = {ID=>($dest)};
542 unless (get_user_nick ($dstUser)) {
543 $dstUser = {NICK=>$dest};
544 }
545 $event = 'PRIVMSG'; @args = ($srcUser, $dstUser, $4);
546 }
547 elsif($_[0] =~ /^(@|:)(\S+) (?:B|NOTICE) (\S+) :(.*)$/) {
548 my $name;
549 if ($1 eq '@') {
550 $name = $servernum[b64toi($2)];
551 }
552 else {
553 $name = $2;
554 }
555 $event = 'NOTICE'; @args = ($name, $3, $4);
556 }
557 $args[1] =~ s/\@${main_conf{local}}.*//io;
558
559 if(queue_size > 50 and $event eq 'PRIVMSG' and $args[1] !~ /^#/ and $args[2] =~ /^\w/) {
560 ircd::notice($args[1], $args[0], "It looks like the system is busy. You don't need to do your command again, just hold on a minute...");
561 }
562
563 return ($event, 0, 1, WF_ALL, @args);
564 }
565
566 sub AWAY($) {
567 if($_[0] =~ /^:(\S+) (?:6|AWAY) :(.*)$/) {
568 my $user = {ID=>decodeUUID($1)};
569 get_user_nick($user);
570 return ('AWAY', undef, undef, WF_ALL, $user, $2);
571 }
572 elsif($_[0] =~ /^:(\S+) (?:6|AWAY)$/) {
573 my $user = {ID => decodeUUID($1)};
574 get_user_nick ($user);
575 return ('BACK', undef, undef, WF_ALL, $user);
576 }
577 }
578
579 sub NICK($) {
580 my ($event, @args);
581 #:97KAAAAAA NICK erry_ 1307878528
582 if($_[0] =~ /^:(\S+) (?:NICK|\&) (\S+) :?(\S+)$/) {
583 my $user = {ID => decodeUUID($1)};
584 get_user_nick ($user);
585 set_user_nick (decodeUUID($1), $2);
586 set_user_id ($2, decodeUUID($1));
587 return ('NICKCHANGE', undef, undef, WF_NICK, $user, $2, $3);
588 }
589 }
590
591 sub QUIT($) {
592 if ($_[0] =~ /^:(\S+) QUIT :Killed \((\S+) \((.*)\)\)$/) {
593 #:583AAAAAH QUIT :Killed (erry (die))
594 my $victim = {ID=>decodeUUID($1)};
595 get_user_nick ($victim);
596 my $murderer = {NICK=>$2};
597 get_user_id ($murderer);
598 my $reason = $3;
599 return ('KILL', 0, 1, WF_NICK, $murderer, $victim, $reason, undef);
600 }
601 elsif ($_[0] =~ /^:(\S+) QUIT :(.*)$/) {
602 my $user = {ID=>decodeUUID($1)};
603 get_user_nick ($user);
604 return ('QUIT', 0, undef, WF_NICK, $user, $2);
605 }
606 }
607 sub OPERQUIT ($) {
608 if ($_[0] =~ /^:(\S+) QUIT :(.*)$/) {
609 my $user = {ID=>decodeUUID($1)};
610 get_user_nick ($user);
611 return ('QUIT', 0, undef, WF_NICK, $user, $2);
612 }
613 }
614
615 sub KILL($) {
616 #All insp sends is :583AAAAAH QUIT :Killed (erry (die))
617 #_VERY_ helpful.
618 #UNLESS you kill someone who's in the services server:
619 #:583AAAAAA KILL 123AAAAAA :Killed (erry (die))
620 #:123AAAAAA OPERQUIT :Killed (erry (die))
621 #And yes, for (some?) opers it's OPERQUIT not QUIT
622 #Joy, JOY, JOY!
623 $_[0] =~ /^:(\S+) KILL (\S+) :(.*)$/;
624 my $murderer = {ID=>decodeUUID($1)};
625 get_user_nick ($murderer);
626 my $victim = {ID=>decodeUUID($2)};
627 get_user_nick ($victim);
628 return ("KILL", 0, 1, WF_NICK, $murderer, $victim, $3, undef);
629 }
630 sub KICK($) {
631 #:tabris KICK #diagnostics SurrealBot :i know you don't like this. but it's for science!
632 $_[0] =~ /^(@|:)(\S+) (?:KICK|H) (\S+) (\S+) :(.*)$/;
633 # source, chan, target, reason
634 #$src = 0; #$dst = 2;
635 my $name;
636 if ($1 eq '@') {
637 $name = $servernum[b64toi($2)];
638 }
639 else {
640 $name = $2;
641 }
642 my $user = {ID => decodeUUID($name)};
643 unless (get_user_nick ($user)) {
644 $user = {NICK => $name};
645 get_user_id ($user);
646 }
647 return ('KICK', 0, undef, WF_CHAN, $user, $3, $4, $5);
648 }
649
650 sub HOST($) {
651 if($_[0] =~ /^:(\S+) (?:CHGHOST|AL) (\S+) (\S+)$/) {
652 #:Agent CHGHOST tabris tabris.netadmin.SCnet.ops
653 return ('CHGHOST', 0, 1, WF_CHAN, $1, $2, $3);
654 #setter, target, vhost
655 }
656 elsif($_[0] =~ /^:(\S+) (?:SETHOST|AA) (\S+)$/) {
657 #:tabris SETHOST tabris.netadmin.SCnet.ops
658 return ('CHGHOST', 0, 1, WF_CHAN, $1, $1, $2);
659 }
660
661 elsif ($_[0] =~ /^:(?:\S* )?302 (\S+) :(\S+?)\*?=[+-].*?\@(.*)/) {
662 #:serebii.razorville.co.uk 302 leif :Jesture=+~Jesture00@buzz-3F604D09.sympatico.ca
663 return ('CHGHOST', 0, 1, WF_CHAN, $1, $2, $3);
664 }
665 }
666
667
668 sub USERIP($) {
669 $_[0] =~ /^:(?:\S* )?340 (\S+) :(\S+?)\*?=[+-].*?\@((?:\.|\d)*)/;
670 return ('USERIP', 0, 1, WF_CHAN, $1, $2, $3);
671 }
672
673 sub IDENT($) {
674 if($_[0] =~ /^:(\S+) (?:CHGIDENT|AL) (\S+) (\S+)$/) {
675 return ('CHGIDENT', 0, 1, WF_ALL, $1, $2, $3);
676 #setter, target, IDENT
677 }
678 elsif($_[0] =~ /^:(\S+) (?:SETIDENT|AD) (\S+)$/) {
679 return ('CHGIDENT', 0, 1, WF_ALL, $1, $1, $2);
680 #setter, target, ident
681 }
682 }
683
684
685 sub TOPIC($) {
686 if ($_[0] =~ /^:(\S+) TOPIC (\S+) :(.*)$/) {
687 #:583AAAAAF TOPIC #erry :Welcome to erry(world|net). Have a cookie.
688 my $setter = { ID => decodeUUID($1) };
689 get_user_nick ($setter);
690 return ('TOPIC', 0, 1, WF_ALL, $setter, $2, $setter, 0, $3);
691 }
692 }
693
694 sub UMODE($) {
695 #:tabris | +oghaANWt
696 $_[0] =~ /^:(\S+) (?:UMODE2|\|) (\S+)$/;
697 # src, umodes
698 # a note, not all umodes are passed
699 # +s, +O, and +t are not passed. possibly others
700 # also not all umodes do we care about.
701 # umodes we need care about:
702 # oper modes: hoaACN,O oper-only modes: HSq
703 # regular modes: rxB,izV (V is only somewhat, as the ircd
704 # does the conversions from NOTICE to PRIVSMG for us).
705
706 # Yes, I'm changing the event type on this
707 # It's better called UMODE, and easily emulated
708 # on IRCds with only MODE.
709 return ('UMODE', 0, 0, WF_ALL, $1, $2);
710 }
711 sub OPERTYPE ($) {
712 #:583AAAAAB OPERTYPE SuperNetAdmin
713 #Every OPERTYPE will get +o, so it's safe to assume they're opers,
714 #even if we don't give them privs (either in inspircd or srsv)
715 $_[0] =~ /^:(\S+) OPERTYPE (\S+)$/;
716 my $user = { ID => decodeUUID($1) };
717 get_user_nick ($user);
718 return ("OPERUP", 0, 0, WF_ALL, $user);
719 }
720 sub SVSMODE($) {
721 #:tabris | +oghaANWt
722 $_[0] =~ /^:(\S+) (?:SVS2?MODE|n|v) (\S+) (\S+)$/;
723 # src, umodes
724 # a note, not all umodes are passed
725 # +s, +O, and +t are not passed. possibly others
726 # also not all umodes do we care about.
727 # umodes we need care about:
728 # oper modes: hoaACN,O oper-only modes: HSq
729 # regular modes: rxB,izV (V is only somewhat, as the ircd
730 # does the conversions from NOTICE to PRIVSMG for us).
731
732 return ('UMODE', 0, 0, WF_ALL, $2, $3);
733 }
734
735 sub WHOIS($) {
736 # :tab WHOIS ConnectServ :ConnectServ
737 if($_[0] =~ /^:(\S+) (?:WHOIS|\#) (\S+)$/) {
738 return ('WHOIS', 0, undef, WF_NONE, $1, $2);
739 }
740 elsif($_[0] =~ /^:(\S+) (?:WHOIS|\#) (\S+) :(\S+)$/) {
741 return ('WHOIS', 0, undef, WF_NONE, $1, $3);
742 }
743 }
744
745 sub TSCTL($) {
746 $_[0] =~ /^:(\S+) (?:TSCTL|AW) alltime$/;
747 ircsend(":$main_conf{local} NOTICE $1 *** Server=$main_conf{local} TSTime=".
748 time." time()=".time." TSOffset=0");
749 return;
750 }
751
752 sub VERSION($) {
753 $_[0] =~ /^:(\S+) (?:VERSION|\+).*$/;
754 return ('VERSION', 0, undef, WF_NONE, $1);
755 }
756
757 sub TKL($) {
758 if ($_[0] =~ /^(@|:)(\S+) (?:TKL|BD) (.*)$/) {
759 # We discard the source anyway.
760 #my $server;
761 #if ($1 eq '@') {
762 # $server = $servernum[b64toi($2)];
763 #}
764 #else {
765 # $server = $2;
766 #}
767 return ('TKL', undef, undef, WF_NONE, parse_tkl("TKL $3"));
768 }
769 elsif ($_[0] =~ /^(?:TKL|BD) (.*)$/) {
770 return ('TKL', undef, undef, WF_NONE, parse_tkl("TKL $1"));
771 }
772 }
773
774 sub SNOTICE($) {
775 $_[0] =~ /^(@|:)(\S+) (SENDSNO|Ss|SMO|AU) ([A-Za-z]) :(.*)$/;
776 #@servernumeric Ss snomask :message
777 my $name;
778 if ($1 eq '@') {
779 $name = $servernum[b64toi($2)];
780 }
781 else {
782 $name = $2;
783 }
784 my $event;
785 $event = 'SENDSNO' if(($3 eq 'SENDSNO' or $3 eq 'Ss'));
786 $event = 'SMO' if(($3 eq 'SMO' or $3 eq 'AU'));
787 return ($event, 0, undef, WF_NONE, $name, $4, $5);
788 }
789
790 sub GLOBOPS($) {
791 $_[0] =~ /^(@|:)(\S+) (?:GLOBOPS|\]) :(.*)$/;
792 #@servernumeric [ :message
793 my $name;
794 if ($1 eq '@') {
795 $name = $servernum[b64toi($2)];
796 }
797 else {
798 $name = $2;
799 }
800 return ('GLOBOPS', 0, undef, WF_NONE, $name, $3);
801 }
802
803 sub ISUPPORT($) {
804 $_[0] =~ /^:(\S+) (?:105|005) (\S+) (.+) :are supported by this server$/;
805 # :test-tab.surrealchat.net 105 services.SC.net CMDS=KNOCK,MAP,DCCALLOW,USERIP :are supported by this server
806 foreach my $token (split(/\s+/, $3)) {
807 my ($key, $value) = split('=', $token);
808 $IRCd_capabilities{$key} = ($value ? $value : 1);
809 }
810 }
811
812 sub CAPAB {
813 #CAPAB MODULES :m_botmode.so,m_chanprotect.so,m_chghost.so,m_chgident.so,m_cloaking.so,m_deaf.so,m_delayjoin.so,m_delaymsg.so,m_gecosban.so,m_globops.so,m_helpop.so,m_messageflood.so,m_muteban.so,m_nokicks.so,m_nonicks.so,m_nonotice.so,m_nopartmsg.so,m_ojoin.so,m_operchans.so,m_operinvex.so,m_permchannels.so,m_redirect.so,m_regex_glob.so,m_remove.so,m_sajoin.so,m_sakick.so,m_sanick.so,m_sapart.so,m_saquit.so,m_serverban.so,m_services_account.so,m_servprotect.so,m_setident.so,m_showwhois.so,m_shun.so
814 #CAPAB MODULES :m_silence.so,m_watch.so
815 #CAPAB MODSUPPORT :m_chghost.so,m_chgident.so,m_gecosban.so,m_muteban.so,m_nopartmsg.so,m_remove.so,m_sajoin.so,m_sakick.so,m_sanick.so,m_sapart.so,m_saquit.so,m_serverban.so,m_services_account.so,m_showwhois.so,m_silence.so,m_watch.so
816 #CAPAB CHANMODES :admin=&a ban=b c_registered=r delayjoin=D delaymsg=d flood=f founder=~q halfop=%h inviteonly=i key=k limit=l moderated=m noextmsg=n nokick=Q nonick=N nonotice=T official-join=!Y op=@o operonly=O permanent=P private=p redirect=L reginvite=R regmoderated=M secret=s topiclock=t voice=+v
817 #6 CAPAB USERMODES :bot=B cloak=x deaf=d helpop=h invisible=i oper=o regdeaf=R servprotect=k showwhois=W snomask=s u_registered=r wallops=w
818 #CAPAB CAPABILITIES :NICKMAX=32 CHANMAX=65 MAXMODES=20 IDENTMAX=12 MAXQUIT=256 MAXTOPIC=308 MAXKICK=256 MAXGECOS=129 MAXAWAY=201 IP6SUPPORT=1 PROTOCOL=1202 HALFOP=1 PREFIX=(Yqaohv)!~&@%+ CHANMODES=b,k,Ldfl,DMNOPQRTimnprst USERMODES=,,s,BRWdhikorwx SVSPART=1
819 #---
820 #What we care about: CHANMODES :admin=&a founder=~q Determines if we can set +a and +q on people, halfop %h: likewise... cloak=x determines if we can have cloaks or vhosts. in the modules we care about chghost, chgident, cloaking for vhosts, m_silence and m_watch for silence and watch respectively. Also c_registered, we can _NOT_ continue w/o it.
821 #I HAVE NO IDEA where to get the watch/silence list limit!!!
822 #let's do this the lame way!
823 #FIXME this is so ugly
824 my $capab = $_[0];
825 print "CAPAB $_[0]\n";
826 $capab =~ /CAPAB (\S+)/;
827 my $type = $1;
828 if ($type eq "END" && $IRCd_capabilities {"REG"} eq "") {
829 ircd::debug ("WARNING: SurrealServices requires m_services_account.so to be loaded in Inspircd.");
830 ircd::debug ("m_services_account.so not loaded! Shutting down NOW!");
831 print "m_services_account.so not loaded! Shutting down NOW!\n";
832 main_shutdown;
833 }
834 if ($capab =~ /m_chghost/ && $type eq "MODSUPPORT") {
835 $IRCd_capabilities{"CHGHOST"} = 1;
836 }
837 if ($capab =~ /m_chgident/ && $type eq "MODSUPPORT") {
838 $IRCd_capabilities{"CHGIDENT"} = 1;
839 }
840 if ($capab =~ /m_cloaking/ ) {
841 $IRCd_capabilities{"CLOAKHOST"} = 1;
842 }
843 if ($capab =~ /cloak=(\S)/ ) {
844 $IRCd_capabilities{"CLOAK"} = $1;
845 }
846 if ($capab =~ /admin=(\S)(\S)/) {
847 $IRCd_capabilities{"ADMIN"} = $2;
848 }
849 if ($capab =~ /founder=(\S)(\S)/) {
850 $IRCd_capabilities{"FOUNDER"} = $2;
851 }
852 if ($capab =~ /halfop=(\S)(\S)/) {
853 $IRCd_capabilities{"HALFOP"} = $2;
854 }
855 if ($capab =~ /silence/) {
856 $IRCd_capabilities{"SILENCE"} = 32; #unless we can make it TELL US
857 }
858 if ($capab =~ /watch/) {
859 $IRCd_capabilities{"WATCH"} = 32; #unless we can make it TELL US
860 }
861 if ($capab =~ /registered/) {
862 $IRCd_capabilities{"REG"} = 1;
863 }
864 $IRCd_capabilities {"INSP"} = 1; #this is _horrible_
865
866 }
867 sub STATS($) {
868 $_[0] =~ /^:(\S+) (?:STATS|2) (\S) :(.+)$/;
869 return ('STATS', undef, undef, WF_NONE, $1, $2, $3)
870 }
871
872 BEGIN {
873 %cmdhash = (
874 PING => \&PING,
875 '8' => \&PING,
876
877 EOS => \&EOS,
878 ES => \&EOS,
879 ENDBURST => \&EOS,
880 SERVER => \&SERVER,
881 "\'" => \&SERVER,
882
883 SQUIT => \&SQUIT,
884 '-' => \&SQUIT,
885
886 NETINFO => \&NETINFO,
887 AO => \&NETINFO,
888
889 PROTOCTL => \&PROTOCTL,
890
891 JOIN => \&JOIN,
892 C => \&JOIN,
893
894 PART => \&PART,
895 D => \&PART,
896
897 SJOIN => \&SJOIN,
898 '~' => \&SJOIN,
899 FJOIN => \&FJOIN,
900 FMODE => \&FMODE,
901 MODE => \&MODE,
902 G => \&MODE,
903
904 PRIVMSG => \&MESSAGE,
905 '!' => \&MESSAGE,
906 NOTICE => \&MESSAGE,
907 B => \&MESSAGE,
908
909 AWAY => \&AWAY,
910 '6' => \&AWAY,
911
912 NICK => \&NICK,
913 '&' => \&NICK,
914
915 QUIT => \&QUIT,
916 ',' => \&QUIT,
917
918 KILL => \&KILL,
919 '.' => \&KILL,
920
921 KICK => \&KICK,
922 H => \&KICK,
923
924 CHGHOST => \&HOST,
925 AL => \&HOST,
926 SETHOST => \&HOST,
927 AA => \&HOST,
928 '302' => \&HOST,
929
930 '340' => \&USERIP,
931
932 CHGIDENT => \&IDENT,
933 AZ => \&IDENT,
934 SETIDENT => \&IDENT,
935 AD => \&IDENT,
936
937 TOPIC => \&TOPIC,
938 ')' => \&TOPIC,
939
940 UMODE2 => \&UMODE,
941 '|' => \&UMODE,
942
943 TSCTL => \&TSCTL,
944 AW => \&TSCTL,
945
946 VERSION => \&VERSION,
947 '+' => \&VERSION,
948
949 TKL => \&TKL,
950 BD => \&TKL,
951
952 WHOIS => \&WHOIS,
953 '#' => \&WHOIS,
954
955 SENDSNO => \&SNOTICE,
956 Ss => \&SNOTICE,
957
958 SMO => \&SNOTICE,
959 AU => \&SNOTICE,
960
961 GLOBOPS => \&GLOBOPS,
962 ']' => \&GLOBOPS,
963
964 '105' => \&ISUPPORT,
965 '005' => \&ISUPPORT,
966
967 SVSMODE => \&SVSMODE,
968 'n' => \&SVSMODE,
969 SVS2MODE => \&SVSMODE,
970 'v' => \&SVSMODE,
971
972 STATS => \&STATS,
973 '2' => \&STATS,
974 UID => \&UID,
975 OPERTYPE => \&OPERTYPE,
976 OPERQUIT => \&OPERQUIT, #Opers are so special, they get their own QUIT. SOme of the time.
977 CAPAB => \&CAPAB,
978 FMODE => \&FMODE
979 );
980 }
981
982 1;