]>
Commit | Line | Data |
---|---|---|
431b229b LP |
1 | /** |
2 | # | |
3 | # BorkNet Services Core | |
4 | # | |
5 | ||
6 | # | |
7 | # Copyright (C) 2004 Ozafy - ozafy@borknet.org - http://www.borknet.org | |
8 | # | |
9 | # This program is free software; you can redistribute it and/or | |
10 | # modify it under the terms of the GNU General Public License | |
11 | # as published by the Free Software Foundation; either version 2 | |
12 | # of the License, or (at your option) any later version. | |
13 | # | |
14 | # This program is distributed in the hope that it will be useful, | |
15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | # GNU General Public License for more details. | |
18 | # | |
19 | # You should have received a copy of the GNU General Public License | |
20 | # along with this program; if not, write to the Free Software | |
21 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
22 | # | |
23 | */ | |
24 | package borknet_services.core; | |
25 | import java.util.*; | |
26 | import java.net.*; | |
27 | import borknet_services.core.*; | |
28 | ||
29 | /** | |
30 | * The server communication class of the Q IRC Bot. | |
31 | * @author Ozafy - ozafy@borknet.org - http://www.borknet.org | |
32 | */ | |
33 | public class CoreServer | |
34 | { | |
35 | /** the main bot */ | |
36 | private Core C; | |
37 | /** the connection to the database */ | |
38 | private CoreDBControl dbc; | |
39 | /** Core commands */ | |
40 | private CoreCommands CC; | |
41 | /** the bot's nick */ | |
42 | private String nick; | |
43 | /** the bot's host */ | |
44 | private String host; | |
45 | /** the server's numeric */ | |
46 | private String numeric; | |
47 | /** the bot's numeric */ | |
48 | private String corenum; | |
49 | /** the channel we report to */ | |
50 | private String reportchan; | |
51 | /** Report connections? */ | |
52 | private boolean reportconn = false; | |
53 | /** ip's to ignore */ | |
54 | private ArrayList<String> reportignore = new ArrayList<String>(); | |
55 | /** our version reply */ | |
56 | private String version; | |
57 | ||
58 | private boolean EA = false; | |
59 | private boolean EB = false; | |
60 | ||
61 | /** | |
62 | * Constructs a Server communicator. | |
63 | * @param B The main bot | |
64 | * @param dbc The connection to the database | |
65 | */ | |
66 | public CoreServer(Core C, CoreDBControl dbc) | |
67 | { | |
68 | this.C = C; | |
69 | this.dbc = dbc; | |
70 | CC = new CoreCommands(C); | |
71 | nick = C.get_nick(); | |
72 | host = C.get_host(); | |
73 | numeric = C.get_numeric(); | |
74 | corenum = C.get_corenum(); | |
75 | version = C.get_version(); | |
76 | reportchan = C.get_reportchan(); | |
77 | reportconn = C.get_reportconn(); | |
78 | String[] ignore = C.get_reportignore().split(","); | |
79 | reportignore = new ArrayList<String>(Arrays.asList(ignore)); | |
80 | } | |
81 | ||
82 | public void setEA(boolean EA) | |
83 | { | |
84 | this.EA = EA; | |
85 | } | |
86 | ||
87 | public void setEB(boolean EB) | |
88 | { | |
89 | this.EB = EB; | |
90 | } | |
91 | ||
92 | public void parseLine(String line) | |
93 | { | |
94 | ArrayList<String> params = splitLine(line); | |
95 | String source = params.get(0); | |
96 | String command = params.get(1); | |
97 | //parse all server commands (that i needed) | |
98 | //bursts | |
99 | //AB G !1123885135.436177 releases.borknet.org 1123885135.436177 | |
100 | if(command.equals("G")) | |
101 | { | |
102 | C.cmd_pong(); | |
103 | return; | |
104 | } | |
105 | if(source.equals("SERVER")) | |
106 | { | |
107 | mserver(params); | |
108 | } | |
109 | else if(source.equals("PASS")) | |
110 | { | |
111 | //ignored not like we accept connections anyway | |
112 | } | |
113 | else if(source.equals("ERROR")) | |
114 | { | |
115 | C.die("ERROR from other server, trying to die gracefully."); | |
116 | } | |
117 | else | |
118 | { | |
119 | if(command.equals("EA")) | |
120 | { | |
121 | if(!EA) | |
122 | { | |
123 | C.printDebug("[>---<] >> *** Completed net.burst..."); | |
124 | EA = true; | |
125 | } | |
126 | } | |
127 | else if(command.equals("EB")) | |
128 | { | |
129 | if(!EB) | |
130 | { | |
131 | C.cmd_EB(); | |
132 | EB = true; | |
133 | } | |
134 | } | |
135 | else if(command.equals("P")) | |
136 | { | |
137 | //OzDFD P ]OAAA :showcommands | |
138 | privmsg(params); | |
139 | } | |
140 | else if(command.equals("N")) | |
141 | { | |
142 | //AB N Ozafy 1 1119649303 ozafy bob.be.borknet.org +oiwkgrxXnIh Ozafy Darth@Vader B]AAAB ABAXs :Laurens Panier | |
143 | nickchange(params); | |
144 | } | |
145 | else if(command.equals("Q")) | |
146 | { | |
147 | //ACAAF Q :Quit: [SearchIRC] Indexed 16 channels in 3 secs @ Aug 12th, 2005, 6:46 pm | |
148 | quit(params); | |
149 | } | |
150 | else if(command.equals("D")) | |
151 | { | |
152 | //ACAAF D ABBRC :hub.uk.borknet.org!hub.uk.borknet.org!xirtwons (Now I've done a kill :p) | |
153 | kill(params); | |
154 | } | |
155 | else if(command.equals("SQ")) | |
156 | { | |
157 | //AB SQ eclipse.il.us.borknet.org 1123885086 :Read error: Broken pipe | |
158 | squit(params); | |
159 | } | |
160 | else if(command.equals("S")) | |
161 | { | |
162 | //AB S lightweight.borknet.org 2 0 1123847781 P10 [lAAD +s :The lean, mean opping machine. | |
163 | server(params); | |
164 | } | |
165 | else if(command.equals("J")) | |
166 | { | |
167 | //[>in <] >> ABAXs J #BorkNet 949217470 | |
168 | //[>in <] >> ABARL J 0 | |
169 | if(params.get(2).equals("0")) | |
170 | { | |
171 | partAll(params); | |
172 | } | |
173 | else | |
174 | { | |
175 | join(params); | |
176 | } | |
177 | } | |
178 | else if(command.equals("L")) | |
179 | { | |
180 | //ABBRG L #404forums | |
181 | //[>in <] >> ABCVC L #advice :Leaving | |
182 | //[>in <] >> ADABd L #lol,#zomg | |
183 | //[>in <] >> ADABd L #lol,#zomg :Leaving | |
184 | part(params); | |
185 | } | |
186 | else if(command.equals("K")) | |
187 | { | |
188 | //[>in <] >> ABAXs K #BorkNet ABBrj :bleh OC12B?O63C12B?O | |
189 | kick(params); | |
190 | } | |
191 | else if(command.equals("C")) | |
192 | { | |
193 | //ABAAA C #Feds 1119880843 | |
194 | //[>in <] >> ABAXs C #bla,#bli,#blo 1125181542 | |
195 | create(params); | |
196 | } | |
197 | else if(command.equals("B")) | |
198 | { | |
199 | //[>in <] >> AB B #BorkNet 949217470 +tncCNu ABBh8,ABBhz,ABBhn:v,ACAAT:o,ACAAV,ABAXs :%InsanitySane!*@sexplay.dk *!juliusjule@sexplay.dk naimex!*@sexplay.dk | |
200 | //[>in <] >> AB B #BorkNet 949217470 ABBh8,ABBhz,ABBhn:v,ACAAT:o,ACAAV,ABAXs :%InsanitySane!*@sexplay.dk *!juliusjule@sexplay.dk naimex!*@sexplay.dk | |
201 | //wtf at these: | |
202 | //[>in <] >> AD B #Tutorial 0 +mtinDCN ADAAA | |
203 | //[>in <] >> AD B #avpoe 0 ADATI | |
204 | //[>in <] >> AD B #help 1 ADAAA:o | |
205 | /* a problem arises if a server splits, services (Q) get restarted during the split, | |
206 | and they join a (now) empty channel (because of the split). the TS on our link will be | |
207 | younger then the ts on the rejoining server, so we lose our modes. | |
208 | Possible solutions: | |
209 | a) if this happens, the B line will have a mode string, so we can find the channels that way, | |
210 | we parse the users/modes, and rejoin the channel. | |
211 | b) we save the timestamps of known channels, and if we get one that doesn't equal ours, we | |
212 | parse it like p10 discribes. | |
213 | c) we trust services not to get restarted during splits ;p | |
214 | ||
215 | a would be the simple dirty solution, b would require more work, and slow us down a bit more | |
216 | but be correct | |
217 | ||
218 | ||
219 | We're going for a. | |
220 | ||
221 | another problem surfaced where the timestamp being burst was a 0 or a 1. I have no idea why, however | |
222 | this causes deops aswell. another fix was put inplace. | |
223 | if(EA && (params.get(4).startsWith("+") || params.get(3).length() < 2)) | |
224 | { | |
225 | reop(chan); | |
226 | } | |
227 | */ | |
228 | bline(params); | |
229 | } | |
230 | else if(command.equals("M")) | |
231 | { | |
232 | //[>in <] >> ABAXs M #BorkNet -ov+ov ABBlK ABBli ABBly ABBlb | |
233 | //[>in <] >> ABASv M Ozafy +h moo@moop | |
234 | mode(params); | |
235 | } | |
236 | else if(command.equals("OM")) | |
237 | { | |
238 | //AW OM #coder-com +ov AWAAA AWAAA | |
239 | omode(params); | |
240 | } | |
241 | else if(command.equals("CM")) | |
242 | { | |
243 | //AQ CM #BorkNet ovpsmikblrcCNDu | |
244 | cmode(params); | |
245 | } | |
246 | else if(command.equals("AC")) | |
247 | { | |
248 | //AQ AC ABBRG Froberg | |
249 | auth(params); | |
250 | } | |
251 | } | |
252 | if(EA) | |
253 | { | |
254 | C.getCoreModControl().parse(params); | |
255 | } | |
256 | /* | |
257 | AC ACCOUNT | |
258 | AD ADMIN | |
259 | LL ASLL | |
260 | A AWAY | |
261 | B BURST | |
262 | CM CLEARMODE | |
263 | CLOSE CLOSE | |
264 | CN CNOTICE | |
265 | CO CONNECT | |
266 | CP CPRIVMSG | |
267 | C CREATE | |
268 | DE DESTRUCT | |
269 | DS DESYNCH | |
270 | DIE DIE | |
271 | DNS DNS | |
272 | EB END_OF_BURST | |
273 | EA EOB_ACK | |
274 | Y ERROR | |
275 | GET GET | |
276 | GL GLINE | |
277 | HASH HASH | |
278 | HELP HELP | |
279 | F INFO | |
280 | I INVITE | |
281 | ISON ISON | |
282 | J JOIN | |
283 | JU JUPE | |
284 | K KICK | |
285 | D KILL | |
286 | LI LINKS | |
287 | LIST LIST | |
288 | LU LUSERS | |
289 | MAP MAP | |
290 | M MODE | |
291 | MO MOTD | |
292 | E NAMES | |
293 | N NICK | |
294 | O NOTICE | |
295 | OPER OPER | |
296 | OM OPMODE | |
297 | L PART | |
298 | PA PASS | |
299 | G PING | |
300 | Z PONG | |
301 | POST POST | |
302 | P PRIVMSG | |
303 | PRIVS PRIVS | |
304 | PROTO PROTO | |
305 | Q QUIT | |
306 | REHASH REHASH | |
307 | RESET RESET | |
308 | RESTART RESTART | |
309 | RI RPING | |
310 | RO RPONG | |
311 | S SERVER | |
312 | SET SET | |
313 | SE SETTIME | |
314 | U SILENCE | |
315 | SQ SQUIT | |
316 | R STATS | |
317 | TI TIME | |
318 | T TOPIC | |
319 | TR TRACE | |
320 | UP UPING | |
321 | USER USER | |
322 | USERHOST USERHOST | |
323 | USERIP USERIP | |
324 | V VERSION | |
325 | WC WALLCHOPS | |
326 | WA WALLOPS | |
327 | WU WALLUSERS | |
328 | WV WALLVOICES | |
329 | H WHO | |
330 | W WHOIS | |
331 | X WHOWAS | |
332 | SN SVSNICK | |
333 | SJ SVSJOIN | |
334 | */ | |
335 | } | |
336 | ||
337 | private ArrayList<String> splitLine(String msg) | |
338 | { | |
339 | /* | |
340 | * This function splits lines on each space | |
341 | * a parameter beginning with ':' will be treated as the last. | |
342 | * The inevitable exception to this is the _first_ parameter... | |
343 | */ | |
344 | ArrayList<String> params = new ArrayList<String>(); | |
345 | String[] result = msg.split("\\s"); | |
346 | for(int i=0; i<result.length; i++) | |
347 | { | |
348 | if(i>0 && result[i].startsWith(":")) | |
349 | { | |
350 | //rest is one param | |
351 | String param = result[i].substring(1); | |
352 | i++; | |
353 | for(; i<result.length; i++) | |
354 | { | |
355 | param += " " + result[i]; | |
356 | } | |
357 | params.add(param); | |
358 | } | |
359 | else | |
360 | { | |
361 | params.add(result[i]); | |
362 | } | |
363 | } | |
364 | return params; | |
365 | } | |
366 | ||
367 | public void privmsg(ArrayList<String> params) | |
368 | { | |
369 | CC.privmsg(params); | |
370 | } | |
371 | ||
372 | /** | |
373 | * Handles a clearmode | |
374 | * @param chan channel that get's cleared | |
375 | * @param modes modes that get cleared | |
376 | */ | |
377 | public void cmode(ArrayList<String> params) | |
378 | { | |
379 | try | |
380 | { | |
381 | //clear all usermodes | |
382 | //AQ CM #BorkNet ovpsmikblrcCNDu | |
383 | //find users and remove o/v | |
384 | String target = params.get(2); | |
385 | String modes = params.get(3); | |
386 | if(target.startsWith("#")) | |
387 | { | |
388 | boolean v = modes.contains("v"); | |
389 | boolean o = modes.contains("o"); | |
390 | Channel channel = dbc.getChannel(target); | |
391 | ArrayList<String> users = channel.getUserlist(); | |
392 | for(String user : users) | |
393 | { | |
394 | if(v) | |
395 | { | |
396 | dbc.setUserChanMode(user, target, "-v"); | |
397 | } | |
398 | if(o) | |
399 | { | |
400 | dbc.setUserChanMode(user, target, "-o"); | |
401 | } | |
402 | } | |
403 | } | |
404 | } | |
405 | catch(ArrayIndexOutOfBoundsException e) | |
406 | { | |
407 | C.printDebug("ArrayIndexOutOfBoundsException in cmode!\n"); | |
408 | C.debug(e); | |
409 | C.report("ArrayIndexOutOfBoundsException in cmode!"); | |
410 | } | |
411 | } | |
412 | ||
413 | /** | |
414 | * Handles a clearmode | |
415 | * @param opernume numeric of the operator that clears the channel | |
416 | * @param params channel and modes that changed | |
417 | */ | |
418 | public void omode(ArrayList<String> params) | |
419 | { | |
420 | //[>in <] >> ABAXs OM #BorkNet -ov+ov ABBlK ABBli ABBly ABBlb | |
421 | try | |
422 | { | |
423 | String source = params.get(0); | |
424 | String target = params.get(2); | |
425 | String modes = params.get(3); | |
426 | if(target.startsWith("#")) | |
427 | { | |
428 | chanMode(params, source, target, modes); | |
429 | } | |
430 | } | |
431 | catch(ArrayIndexOutOfBoundsException e) | |
432 | { | |
433 | C.printDebug("ArrayIndexOutOfBoundsException in srv_omode!\n"); | |
434 | C.debug(e); | |
435 | C.report("ArrayIndexOutOfBoundsException in srv_mode!"); | |
436 | } | |
437 | } | |
438 | ||
439 | public void mode(ArrayList<String> params) | |
440 | { | |
441 | //[>in <] >> ABAXs M #BorkNet -ov+ov ABBlK ABBli ABBly ABBlb | |
442 | //or a mode hack fix | |
443 | //[>in <] >> AB M #programming.help -oo ABAyJ AQAAA 1134578560 | |
444 | //[>in <] >> ABArk M #FLE +oo ABAvx ABAv0 | |
445 | //[>in <] >> ADACf M #elitesabbers +tnCN | |
446 | ||
447 | //usermodes | |
448 | //[>in <] >> ABASv M Ozafy +h moo@moop | |
449 | //[>in <] >> OzDc] M WebBorker553 +x | |
450 | try | |
451 | { | |
452 | String source = params.get(0); | |
453 | String target = params.get(2); | |
454 | String modes = params.get(3); | |
455 | if(target.startsWith("#")) | |
456 | { | |
457 | chanMode(params, source, target, modes); | |
458 | } | |
459 | else | |
460 | { | |
461 | if(modes.contains("+")) | |
462 | { | |
463 | String flags = plus_flags(modes); | |
464 | User user = dbc.getUser(source); | |
465 | String usermodes = user.getModes(); | |
466 | if(usermodes.equals("")) | |
467 | { | |
468 | dbc.setUserField(source,3, "+"+flags); | |
469 | } | |
470 | else | |
471 | { | |
472 | if(flags.equals("h")) | |
473 | { | |
474 | if (!usermodes.contains("h")) | |
475 | { | |
476 | dbc.setUserField(source,3 , usermodes + flags); | |
477 | } | |
478 | } | |
479 | else | |
480 | { | |
481 | dbc.setUserField(source,3 , usermodes + flags); | |
482 | } | |
483 | } | |
484 | if(flags.contains("o")) | |
485 | { | |
486 | dbc.setUserField(source,5 , "true"); | |
487 | } | |
488 | if(flags.contains("h")) | |
489 | { | |
490 | dbc.setUserField(source,8,params.get(4)); | |
491 | } | |
492 | } | |
493 | if(modes.contains("-")) | |
494 | { | |
495 | String flags = min_flags(modes); | |
496 | User user = dbc.getUser(source); | |
497 | if(flags.contains("o")) | |
498 | { | |
499 | dbc.setUserField(source, 5 , "false"); | |
500 | } | |
501 | if(flags.contains("h")) | |
502 | { | |
503 | dbc.setUserField(source,8,"0"); | |
504 | } | |
505 | char c[] = flags.toCharArray(); | |
506 | String usermodes = user.getModes(); | |
507 | for(int i =0; i < c.length; i++) | |
508 | { | |
509 | usermodes = usermodes.replace(c[i],' '); | |
510 | } | |
511 | String[] mod = usermodes.split("\\s"); | |
512 | String mods = ""; | |
513 | for(int i =0; i < mod.length; i++) | |
514 | { | |
515 | mods += mod[i]; | |
516 | } | |
517 | dbc.setUserField(source, 3, mods); | |
518 | } | |
519 | } | |
520 | } | |
521 | catch(ArrayIndexOutOfBoundsException e) | |
522 | { | |
523 | C.printDebug("ArrayIndexOutOfBoundsException in srv_mode!\n"); | |
524 | C.debug(e); | |
525 | C.report("ArrayIndexOutOfBoundsException in srv_mode!"); | |
526 | } | |
527 | } | |
528 | ||
529 | private void chanMode(ArrayList<String> params, String source, String target, String modes) | |
530 | { | |
531 | String change[] = mode_array(modes); | |
532 | if(params.size() > 4) | |
533 | { | |
534 | if(source.equals(numeric + corenum) || params.get(4).equals(numeric + corenum)) | |
535 | { | |
536 | return; | |
537 | } | |
538 | dbc.setUserChanMode(params.get(4), target, change[0]); | |
539 | } | |
540 | if(params.size() > 5 && change.length > 1) | |
541 | { | |
542 | dbc.setUserChanMode(params.get(5), target, change[1]); | |
543 | } | |
544 | if(params.size() > 6 && change.length > 2) | |
545 | { | |
546 | dbc.setUserChanMode(params.get(6), target, change[2]); | |
547 | } | |
548 | if(params.size() > 7 && change.length > 3) | |
549 | { | |
550 | dbc.setUserChanMode(params.get(7), target, change[3]); | |
551 | } | |
552 | if(params.size() > 8 && change.length > 4) | |
553 | { | |
554 | dbc.setUserChanMode(params.get(8), target, change[4]); | |
555 | } | |
556 | if(params.size() > 9 && change.length > 5) | |
557 | { | |
558 | dbc.setUserChanMode(params.get(9), target, change[5]); | |
559 | } | |
560 | } | |
561 | ||
562 | /** | |
563 | * Creates an array of mode flags for easy parsing | |
564 | * @param fl set of flags | |
565 | * | |
566 | * @return an array of seperate flags | |
567 | */ | |
568 | private String[] mode_array(String fl) | |
569 | { | |
570 | String plus = plus_flags(fl); | |
571 | String min = min_flags(fl); | |
572 | ArrayList<String> flags = new ArrayList<String>(); | |
573 | if(min.length()>0) | |
574 | { | |
575 | char c[] = min.toCharArray(); | |
576 | for(int i =0; i < c.length; i++) | |
577 | { | |
578 | if(c[i] == 'o' || c[i] == 'v') | |
579 | { | |
580 | flags.add("-"+c[i]); | |
581 | } | |
582 | } | |
583 | } | |
584 | if(plus.length()>0) | |
585 | { | |
586 | char c[] = plus.toCharArray(); | |
587 | for(int i =0; i < c.length; i++) | |
588 | { | |
589 | if(c[i] == 'o' || c[i] == 'v') | |
590 | { | |
591 | flags.add("+"+c[i]); | |
592 | } | |
593 | } | |
594 | } | |
595 | if(flags.size()>0) | |
596 | { | |
597 | String[] r = (String[]) flags.toArray(new String[ flags.size() ]); | |
598 | return r; | |
599 | } | |
600 | else | |
601 | { | |
602 | return new String[]{"0","0","0","0","0","0","0","0","0","0"}; | |
603 | } | |
604 | } | |
605 | ||
606 | /** | |
607 | * returns the gained flags of a flag list | |
608 | * @param flags set of flags | |
609 | * | |
610 | * @return the gained flags | |
611 | */ | |
612 | private String plus_flags(String flags) | |
613 | { | |
614 | String rflags = ""; | |
615 | if(flags.startsWith("+")) | |
616 | { | |
617 | if(flags.contains("-")) | |
618 | { | |
619 | rflags += flags.substring(1, flags.indexOf("-")) + plus_flags(flags.substring(flags.indexOf("-"))); | |
620 | } | |
621 | else | |
622 | { | |
623 | rflags += flags.substring(1); | |
624 | } | |
625 | } | |
626 | else if(flags.contains("+")) | |
627 | { | |
628 | rflags+= plus_flags(flags.substring(flags.indexOf("+"))); | |
629 | } | |
630 | return rflags; | |
631 | } | |
632 | ||
633 | /** | |
634 | * returns the lost flags of a flag list | |
635 | * @param flags set of flags | |
636 | * | |
637 | * @return the lost flags | |
638 | */ | |
639 | private static String min_flags(String flags) | |
640 | { | |
641 | String rflags = ""; | |
642 | if(flags.startsWith("-")) | |
643 | { | |
644 | if(flags.contains("+")) | |
645 | { | |
646 | rflags += flags.substring(1, flags.indexOf("+")) + min_flags(flags.substring(flags.indexOf("+"))); | |
647 | } | |
648 | else | |
649 | { | |
650 | rflags += flags.substring(1); | |
651 | } | |
652 | } | |
653 | else if(flags.contains("-")) | |
654 | { | |
655 | rflags+= min_flags(flags.substring(flags.indexOf("-"))); | |
656 | } | |
657 | return rflags; | |
658 | } | |
659 | ||
660 | /** | |
661 | * handles the mother server connection | |
662 | * | |
663 | * @param msg raw data gotten from the SERVER line | |
664 | */ | |
665 | public void mserver(ArrayList<String> params) | |
666 | { | |
667 | //add the server or cry | |
668 | //SERVER mooses.fr.borknet.org 1 1362604614 1386544050 J10 OzAP] +h6n :BorkNet IRC Server | |
669 | try | |
670 | { | |
671 | dbc.addServer(params.get(6).substring(0,2),params.get(1),numeric,false); | |
672 | return; | |
673 | } | |
674 | catch(ArrayIndexOutOfBoundsException e) | |
675 | { | |
676 | C.printDebug("ArrayIndexOutOfBoundsException in srv_mserver!"); | |
677 | C.debug(e); | |
678 | C.report("ArrayIndexOutOfBoundsException in srv_mserver!"); | |
679 | } | |
680 | } | |
681 | ||
682 | /** | |
683 | * handles a new server connection | |
684 | * | |
685 | * @param msg raw data gotten from the S line | |
686 | */ | |
687 | public void server(ArrayList<String> params) | |
688 | { | |
689 | //add the server or cry | |
690 | //AB S lightweight.borknet.org 2 0 1123847781 P10 [lAAD +s :The lean, mean opping machine. | |
691 | try | |
692 | { | |
693 | boolean service = false; | |
694 | if(params.get(8).contains("s")) | |
695 | { | |
696 | service = true; | |
697 | } | |
698 | dbc.addServer(params.get(7).substring(0,2),params.get(2),params.get(0),service); | |
699 | C.del_split(params.get(2)); | |
700 | return; | |
701 | } | |
702 | catch(ArrayIndexOutOfBoundsException e) | |
703 | { | |
704 | C.printDebug("ArrayIndexOutOfBoundsException in srv_server!"); | |
705 | C.debug(e); | |
706 | C.report("ArrayIndexOutOfBoundsException in srv_server!"); | |
707 | } | |
708 | } | |
709 | ||
710 | /** | |
711 | * Handles user quits | |
712 | * | |
713 | * @param params raw irc data | |
714 | */ | |
715 | public void quit(ArrayList<String> params) | |
716 | { | |
717 | removeUser(params.get(0),params.get(params.size()-1)); | |
718 | } | |
719 | ||
720 | public void kill(ArrayList<String> params) | |
721 | { | |
722 | removeUser(params.get(2),params.get(params.size()-1)); | |
723 | } | |
724 | ||
725 | private void removeUser(String numeric, String message) | |
726 | { | |
727 | if(reportconn && EA) | |
728 | { | |
729 | User user = dbc.getUser(numeric); | |
730 | String ipv4 = C.longToIp(C.base64Decode(user.getIp())); | |
731 | if(!reportignore.contains(ipv4)) | |
732 | { | |
733 | C.report("User: [" + user.getNick() + "] ["+user.getIdent()+"@"+user.getHost()+"] has quit ["+message+"]"); | |
734 | } | |
735 | } | |
736 | //remove the disconnected user and deauth him | |
737 | dbc.delUser(numeric); | |
738 | } | |
739 | ||
740 | /** | |
741 | * Handles server quits | |
742 | * | |
743 | * @param quit raw irc data | |
744 | */ | |
745 | public void squit(ArrayList<String> params) | |
746 | { | |
747 | try | |
748 | { | |
749 | String host = params.get(2); | |
750 | dbc.delServer(host); | |
751 | C.add_split(host); | |
752 | } | |
753 | catch(ArrayIndexOutOfBoundsException e) | |
754 | { | |
755 | C.printDebug("ArrayIndexOutOfBoundsException in srv_squit!"); | |
756 | C.debug(e); | |
757 | C.report("ArrayIndexOutOfBoundsException in srv_squit!"); | |
758 | } | |
759 | } | |
760 | ||
761 | /** | |
762 | * Handles N lines, these can be a user nickchange, or new clients connecting | |
763 | * | |
764 | * @param usernumeric the user's numeric | |
765 | * @param params raw irc data | |
766 | */ | |
767 | public void nickchange(ArrayList<String> params) | |
768 | { | |
769 | //AB N Ozafy 1 1119649303 ozafy bob.be.borknet.org +oiwkgrxXnIh Ozafy Darth@Vader B]AAAB ABAXs :Laurens Panier | |
770 | //Oz N Ozafy 1 1383584965 ozafy 91.121.106.220 +oiwkgrXnIhP Ozafy:1383586003:1 Gaius@Julius.Caesar BbeWrc OzDFD :Laurens Panier | |
771 | //NN N P 2 1383901011 P proxyscan.borknet.org +odk B]AAED NNAAC :Proxyscan | |
772 | //NN N N 2 1383901011 control services.borknet.org +oidkr C:1383901011 B]AAEE NNAAD :NewServ Control Service | |
773 | ||
774 | //Oz N Ozafy- 1 1386625413 ~ozafy 78.21.219.243 +i BOFdvz OzDdp :Laurens Panier | |
775 | //Oz N WebBorker197 1 1386625506 ~4e15dbf3 91.121.106.220 +i BbeWrc OzDdq :http://webchat.borknet.org/ | |
776 | ||
777 | String source = params.get(0); | |
778 | //new user | |
779 | if(source.length() < 3) | |
780 | { | |
781 | try | |
782 | { | |
783 | boolean isop = false; | |
784 | String nickname = params.get(2); | |
785 | String modes = params.get(7); | |
786 | if(!modes.startsWith("+")) | |
787 | { | |
788 | //doesn't start with a + so he/she had no modes set | |
789 | modes = ""; | |
790 | } | |
791 | String host = params.get(5) + "@" + params.get(6); | |
792 | String ip = params.get(params.size()-3); | |
793 | String ipv4 = C.longToIp(C.base64Decode(ip)); | |
794 | String numeric = params.get(params.size()-2); | |
795 | //it's an oper | |
796 | if(modes.contains("o")) | |
797 | { | |
798 | isop = true; | |
799 | } | |
800 | String auth = "0"; | |
801 | String fake = "0"; | |
802 | if(modes.contains("r")) | |
803 | { | |
804 | auth = params.get(8); | |
805 | if(auth.contains(":")) | |
806 | { | |
807 | auth = auth.split(":")[0]; | |
808 | } | |
809 | } | |
810 | if(modes.contains("h")) | |
811 | { | |
812 | if(modes.contains("r")) | |
813 | { | |
814 | fake = params.get(9); | |
815 | } | |
816 | else | |
817 | { | |
818 | fake = params.get(8); | |
819 | } | |
820 | } | |
821 | dbc.addUser(numeric,nickname,host,modes,auth,isop,numeric.substring(0,2),ip,fake); | |
822 | if(reportconn && EA ) | |
823 | { | |
824 | //user [scrawl43] [dwelabbric@data.searchirc.org] has connected on [hub.webbirc.se] | |
825 | //72.64.145.20 searchirc | |
826 | //85.25.141.52 netsplit | |
827 | if(!reportignore.contains(ipv4)) | |
828 | { | |
829 | C.report("User: [" + nickname + "] ["+host+"] has connected on ["+dbc.getServer(numeric)+"]"); | |
830 | } | |
831 | } | |
832 | return; | |
833 | } | |
834 | catch(ArrayIndexOutOfBoundsException e) | |
835 | { | |
836 | C.printDebug("ArrayIndexOutOfBoundsException in srv_nickchange! (1)"); | |
837 | C.debug(e); | |
838 | C.report("ArrayIndexOutOfBoundsException in srv_nickchange! (1)"); | |
839 | } | |
840 | } | |
841 | //an actual nickchange and not a server sinc | |
842 | else | |
843 | { | |
844 | try | |
845 | { | |
846 | dbc.setUserField(source,1, params.get(2)); | |
847 | return; | |
848 | } | |
849 | catch(ArrayIndexOutOfBoundsException e) | |
850 | { | |
851 | C.printDebug("ArrayIndexOutOfBoundsException in srv_nickchange! (2)"); | |
852 | C.debug(e); | |
853 | C.report("ArrayIndexOutOfBoundsException in srv_nickchange! (2)"); | |
854 | } | |
855 | } | |
856 | } | |
857 | ||
858 | /** | |
859 | * Handles channeljoins | |
860 | * | |
861 | * @param username the user's numeric | |
862 | * @param channel the channel getting joined | |
863 | */ | |
864 | public void join(ArrayList<String> params) | |
865 | { | |
866 | String numeric = params.get(0); | |
867 | String[] channellist = params.get(2).split(","); | |
868 | String timestamp = params.get(3); | |
869 | for(String channel : channellist) | |
870 | { | |
871 | dbc.addUserChan(channel, numeric, timestamp, false, false); | |
872 | } | |
873 | } | |
874 | ||
875 | /** | |
876 | * Handles channel burst lines | |
877 | * | |
878 | * @param channel channel getting bursted | |
879 | * @param users the users currently on the channel, with their modes | |
880 | */ | |
881 | public void bline(ArrayList<String> params) | |
882 | { | |
883 | /* | |
884 | [>in <] >> AB B #BorkNet 949217470 +tncCNul 14 ABBly,ABBlb,ABAXs:ov,ABBli:v,ABBjL,ACAAi:o,ABBlK,ACAAT | |
885 | [>in <] >> Oz B #fle 1362604640 +tnCNul 10 OzDd7,OzAAC:v,OzDd9:o,NCAAC,OzDFD :%*!*@212.29.194.253 | |
886 | ABBly,ABBlb == no modes | |
887 | ABAXs:ov == +ov | |
888 | ABBli:v,ABBjL == +v | |
889 | ACAAi:o,ABBlK,ACAAT == +o | |
890 | <wiebe> modes are only once in burst | |
891 | <wiebe> and apply to all users after it | |
892 | ||
893 | bans start with :%! so filter the % of the first ban if ever need be | |
894 | */ | |
895 | try | |
896 | { | |
897 | String channel = params.get(2); | |
898 | String timestamp = params.get(3); | |
899 | String lastparam = params.get(params.size()-1); | |
900 | if(lastparam.startsWith("%")) | |
901 | { | |
902 | lastparam = params.get(params.size()-2); | |
903 | } | |
904 | String[] userlist = lastparam.split(","); | |
905 | String lastfound = ""; | |
906 | for(String user : userlist) | |
907 | { | |
908 | if(user.contains(":ov") || user.contains(":vo") || lastfound.equals(":ov")) | |
909 | { | |
910 | lastfound=":ov"; | |
911 | String usernumeric = user; | |
912 | if(usernumeric.indexOf(":")>0) | |
913 | { | |
914 | usernumeric = usernumeric.substring(0,(usernumeric.indexOf(":"))); | |
915 | } | |
916 | dbc.addUserChan(channel, usernumeric, timestamp, true, true); | |
917 | } | |
918 | else if(user.contains(":o") || lastfound.equals(":o")) | |
919 | { | |
920 | lastfound=":o"; | |
921 | String usernumeric = user; | |
922 | if(usernumeric.indexOf(":")>0) | |
923 | { | |
924 | usernumeric = usernumeric.substring(0,(usernumeric.indexOf(":"))); | |
925 | } | |
926 | dbc.addUserChan(channel, usernumeric,timestamp, true, false); | |
927 | } | |
928 | else if(user.contains(":v") || lastfound.equals(":v")) | |
929 | { | |
930 | lastfound=":v"; | |
931 | String usernumeric = user; | |
932 | if(usernumeric.indexOf(":")>0) | |
933 | { | |
934 | usernumeric = usernumeric.substring(0,(usernumeric.indexOf(":"))); | |
935 | } | |
936 | dbc.addUserChan(channel, usernumeric,timestamp, false, true); | |
937 | } | |
938 | else | |
939 | { | |
940 | lastfound=""; | |
941 | dbc.addUserChan(channel, user,timestamp, false, false); | |
942 | } | |
943 | } | |
944 | } | |
945 | catch(ArrayIndexOutOfBoundsException e) | |
946 | { | |
947 | C.printDebug("ArrayIndexOutOfBoundsException in bline!"); | |
948 | C.debug(e); | |
949 | C.report("ArrayIndexOutOfBoundsException in bline!"); | |
950 | } | |
951 | } | |
952 | ||
953 | /** | |
954 | * Handles channel creations | |
955 | * | |
956 | * @param channel channel getting created | |
957 | * @param user the user who created it | |
958 | */ | |
959 | public void create(ArrayList<String> params) | |
960 | { | |
961 | String numeric = params.get(0); | |
962 | String[] channellist = params.get(2).split(","); | |
963 | String timestamp = params.get(3); | |
964 | for(String channel : channellist) | |
965 | { | |
966 | dbc.addUserChan(channel, numeric, timestamp, true, false); | |
967 | } | |
968 | } | |
969 | ||
970 | /** | |
971 | * Handles channel parts | |
972 | * | |
973 | * @param chan channel getting parted | |
974 | * @param user the user parting | |
975 | */ | |
976 | public void part(ArrayList<String> params) | |
977 | { | |
978 | String numeric = params.get(0); | |
979 | String[] channellist = params.get(2).split(","); | |
980 | for(String channel : channellist) | |
981 | { | |
982 | dbc.delUserChan(channel, numeric); | |
983 | } | |
984 | } | |
985 | ||
986 | /** | |
987 | * Handles channel parts | |
988 | * | |
989 | * @param chan channel getting parted | |
990 | * @param user the user parting | |
991 | */ | |
992 | public void partAll(ArrayList<String> params) | |
993 | { | |
994 | String numeric = params.get(0); | |
995 | ArrayList<String> channels = new ArrayList<String>(); | |
996 | channels.addAll(dbc.getUserChans(numeric)); | |
997 | for(String channel : channels) | |
998 | { | |
999 | dbc.delUserChan(channel, numeric); | |
1000 | } | |
1001 | } | |
1002 | ||
1003 | /** | |
1004 | * Handles channel kicks | |
1005 | * | |
1006 | * @param chan channel where the kick occurs | |
1007 | * @param user the user getting kicked | |
1008 | */ | |
1009 | public void kick(ArrayList<String> params) | |
1010 | { | |
1011 | String numeric = params.get(0); | |
1012 | String channel = params.get(2); | |
1013 | dbc.delUserChan(channel, numeric); | |
1014 | } | |
1015 | ||
1016 | public void auth(ArrayList<String> params) | |
1017 | { | |
1018 | //[>out<] >> ]Q AC ABAlA Nesjamag | |
1019 | try | |
1020 | { | |
1021 | String numeric = params.get(2); | |
1022 | User user = dbc.getUser(numeric); | |
1023 | String auth = params.get(3); | |
1024 | if(auth.contains(":")) | |
1025 | { | |
1026 | auth = auth.split(":")[0]; | |
1027 | } | |
1028 | dbc.setUserField(numeric,4, auth); | |
1029 | //add the authed flag (r) to his saved umodes | |
1030 | dbc.setUserField(numeric,3,user.getModes()+"r"); | |
1031 | } | |
1032 | catch(ArrayIndexOutOfBoundsException e) | |
1033 | { | |
1034 | C.printDebug("ArrayIndexOutOfBoundsException in srv_auth!"); | |
1035 | C.debug(e); | |
1036 | C.report("ArrayIndexOutOfBoundsException in srv_auth!"); | |
1037 | } | |
1038 | } | |
1039 | } |