]> jfr.im git - irc/borknet/trunk.git/blame - core/Core.java
14/03/2011 REV 89
[irc/borknet/trunk.git] / core / Core.java
CommitLineData
b1d4498c 1/**\r
2#\r
3# BorkNet Services Core\r
4#\r
5\r
6#\r
7# Copyright (C) 2004 Ozafy - ozafy@borknet.org - http://www.borknet.org\r
8#\r
9# This program is free software; you can redistribute it and/or\r
10# modify it under the terms of the GNU General Public License\r
11# as published by the Free Software Foundation; either version 2\r
12# of the License, or (at your option) any later version.\r
13#\r
14# This program is distributed in the hope that it will be useful,\r
15# but WITHOUT ANY WARRANTY; without even the implied warranty of\r
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
17# GNU General Public License for more details.\r
18#\r
19# You should have received a copy of the GNU General Public License\r
20# along with this program; if not, write to the Free Software\r
21# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
22#\r
b1d4498c 23*/\r
24package borknet_services.core;\r
25import java.io.*;\r
26import java.net.*;\r
27import java.util.*;\r
28import java.text.*;\r
29import java.util.logging.*;\r
30import java.util.regex.*;\r
31import java.sql.*;\r
32\r
33/**\r
34 * The main Bot Class.\r
35 * This class creates and manages the connection between the IRC Server and The Bot.\r
36 * @author Ozafy - ozafy@borknet.org - http://www.borknet.org\r
37 */\r
38public class Core\r
39{\r
40 /** Version reply sent to users */\r
c813e210 41 private String version = "The BorkNet Services Core (C) Laurens Panier (Ozafy) & BorkNet Dev-Com - http://www.borknet.org";\r
b1d4498c 42\r
43 /** Reads the IRC Server */\r
44 private BufferedReader IRCir;\r
45 /** Writes to the IRC Server */\r
46 private BufferedWriter IRCor;\r
47 /** Socket to connect to the IRC Server*/\r
48 private Socket IRCServerS;\r
49 /** Variable to keep the bot alive */\r
50 public boolean running;\r
51 /** Has our burst been accepted */\r
52 private boolean EA = false;\r
53 /** Have we ended our burst */\r
54 private boolean EB = false;\r
cb67c259
O
55 /** Internal Timer */\r
56 private CoreTimer timer;\r
57 /** Create mail daemon */\r
58 private Thread timerThread;\r
b1d4498c 59\r
60 /** Bot Description */\r
61 private String description = "";\r
62 /** Bot Nick */\r
63 private String nick = "";\r
64 /** Bot Ident */\r
65 private String ident = "";\r
66 /** Bot Host */\r
67 private String host = "";\r
68 /** Server to connect to */\r
69 private String server = "";\r
70 /** Port to connect on */\r
71 private int port = 0;\r
72 /** Password to connect */\r
73 private String pass = "";\r
74 /** Server numeric */\r
75 private String numeric = "";\r
76 /** Channel to report to */\r
77 private String reportchan = "";\r
78 /** SMTP server to send mails */\r
79 private String mailserver = "";\r
80 /** Port of the mail server */\r
81 private String mailport = "";\r
ac6b717f 82 /** SMTP server requires authentication? */\r
83 private Boolean mailauth = false;\r
84 /** SMTP server username */\r
85 private String mailuser = "";\r
86 /** SMTP server password */\r
87 private String mailpass = "";\r
b1d4498c 88 /** Name of the network the bot is connecting to */\r
89 private String network = "";\r
b1d4498c 90 /** Users needed to request Q */\r
91 private int rusers = 5;\r
92 /** Database server */\r
93 private String dbserv = "";\r
94 /** Database User */\r
95 private String dbuser = "";\r
96 /** Database Password */\r
97 private String dbpass = "";\r
98 /** Database Table */\r
99 private String dbtabl = "";\r
100\r
101 /** Keeps how many pings we've had, resets every 24 hours */\r
102 private int cleaner = 0;\r
103\r
104 /** Controls all data received from the IRC Server */\r
105 private CoreServer ser;\r
106 /** Controls all communication to the Database */\r
107 private CoreDBControl dbc;\r
108 private CoreModControl mod;\r
109 private ArrayList<String> modules = new ArrayList<String>();\r
110\r
111 /** DefCon level the network is in */\r
112 private int defcon = 5;\r
113 /** Logon information */\r
114 private String info = "0";\r
115 /** active netsplits */\r
116 private boolean split = false;\r
117 /** list of splitted servers */\r
118 private ArrayList<String> splits = new ArrayList<String>();\r
119 /** Core's numeric */\r
120 private String corenum = "AAA";\r
121\r
122 private boolean debug = false;\r
123\r
124 /** logging stuff */\r
578f8ab6 125 private Logger logger = Logger.getLogger("");\r
126 private FileHandler fh;\r
127 private SimpleDateFormat format = new SimpleDateFormat("EEE dd/MM/yyyy HH:mm:ss");\r
128 /**\r
129 * Constructs an IRCClient.\r
130 * @param dataSrc Holds all the configuration file settings.\r
131 * @param debug If we're running in debug.\r
132 */\r
b1d4498c 133 public Core(boolean debug)\r
134 {\r
135 this.debug = debug;\r
136 if(debug)\r
137 {\r
138 try\r
139 {\r
140 fh = new FileHandler("debug.%g", 1000000, 10, true);\r
141 fh.setFormatter(new ShortFormatter());\r
142 logger.addHandler(fh);\r
143 Handler handlers[] = logger.getHandlers();\r
144 for (int i = 0; i < handlers.length; i++)\r
145 {\r
146 if(handlers[i] instanceof ConsoleHandler)\r
147 {\r
148 logger.removeHandler(handlers[i]);\r
149 }\r
150 }\r
151 logger.setLevel(Level.ALL);\r
152 }\r
153 catch(Exception e)\r
154 {\r
155 System.out.println("Error creating logfile!");\r
156 System.exit(1);\r
157 }\r
158 }\r
159 load_conf();\r
160 create_coremodules();\r
161 //connect to the irc server\r
162 connect(server, port);\r
163 logon();\r
164\r
165 //keep running till we're told otherwise\r
166 running = true;\r
167 while(running)\r
168 {\r
169 service();\r
170 }\r
171\r
172 //disconnect\r
173 logoff();\r
174 disconnect();\r
175 }\r
176\r
177 public void printDebug(String s)\r
178 {\r
179 if(debug)\r
180 {\r
cb67c259 181 java.util.Date now = new java.util.Date();\r
32963f96 182 //filter out Q passwords\r
183 //[Mon 29/06/2009 17:13:34][>in <] >> ABCAE P Q@CServe.borknet.org :AUTH test test\r
184 try\r
185 {\r
186 String result[] = s.split("\\s");\r
187 if(result[4].equals("P") && result[6].equals(":AUTH"))\r
188 {\r
189 s=result[0]+" "+result[1]+" "+result[2]+" "+result[3]+" "+result[4]+" "+result[5]+" "+result[6]+" "+result[7]+" *****";\r
190 }\r
191 }\r
192 catch(Exception e)\r
193 {\r
194 //moo\r
195 }\r
196 finally\r
197 {\r
198 logger.info("["+format.format(now)+"]"+s);\r
199 }\r
b1d4498c 200 }\r
201 }\r
202\r
203 public void debug(Exception e)\r
204 {\r
205 if(debug)\r
206 {\r
207 StackTraceElement[] te = e.getStackTrace();\r
208 logger.info(e.toString());\r
209 for(StackTraceElement el : te)\r
210 {\r
211 logger.info("\tat "+el.getClassName()+"."+el.getMethodName()+"("+el.getFileName()+":"+el.getLineNumber()+")");\r
212 }\r
213 }\r
214 }\r
215\r
216 /**\r
217 * Load the config file\r
218 */\r
219 private void load_conf()\r
220 {\r
221 ConfLoader loader = new ConfLoader(this);\r
222 try\r
223 {\r
224 loader.load();\r
225 }\r
226 catch(Exception e)\r
227 {\r
228 debug(e);\r
bd09b4c0 229 System.exit(1);\r
b1d4498c 230 }\r
231 Properties dataSrc = loader.getVars();\r
232 try\r
233 {\r
234 //set all the config file vars\r
235 description = dataSrc.getProperty("description");\r
236 nick = dataSrc.getProperty("nick");\r
237 ident = dataSrc.getProperty("ident");\r
238 host = dataSrc.getProperty("host");\r
239 server = dataSrc.getProperty("server");\r
240 port = Integer.parseInt(dataSrc.getProperty("port"));\r
241 pass = dataSrc.getProperty("pass");\r
242 numeric = dataSrc.getProperty("numeric");\r
243 reportchan = dataSrc.getProperty("reportchan");\r
244 mailserver = dataSrc.getProperty("mailserver");\r
245 mailport = dataSrc.getProperty("mailport");\r
ac6b717f 246 mailauth = Boolean.parseBoolean(dataSrc.getProperty("mailauth"));\r
247 mailuser = dataSrc.getProperty("mailuser");\r
248 mailpass = dataSrc.getProperty("mailpass");\r
b1d4498c 249 network = dataSrc.getProperty("network");\r
b1d4498c 250 dbserv = dataSrc.getProperty("dbserv");\r
251 dbuser = dataSrc.getProperty("dbuser");\r
252 dbpass = dataSrc.getProperty("dbpass");\r
253 dbtabl = dataSrc.getProperty("dbtabl");\r
254 String mods[] = dataSrc.getProperty("modules").split(",");\r
255 for(int n=0; n<mods.length; n++)\r
256 {\r
257 modules.add(mods[n]);\r
258 }\r
259 }\r
260 catch(Exception e)\r
261 {\r
262 printDebug("Error loading configfile.");\r
263 debug(e);\r
bd09b4c0 264 System.exit(1);\r
b1d4498c 265 }\r
266 }\r
267\r
268 /**\r
269 * Create the modules\r
270 */\r
271 private void create_coremodules()\r
272 {\r
273 //create the db control class\r
274 dbc = new CoreDBControl(dbserv, dbuser, dbpass, dbtabl, this);\r
275 //create the server communication class\r
276 ser = new CoreServer(this, dbc);\r
cb67c259
O
277 timer = new CoreTimer(this);\r
278 Thread timerThread = new Thread(timer);\r
279 timerThread.setDaemon(true);\r
280 timerThread.start();\r
b1d4498c 281 }\r
282\r
283 /**\r
284 * Connects the bot to the given IRC Server\r
285 * @param serverHostname IP/host to connect to.\r
286 * @param serverPort Port to connect on.\r
287 */\r
288 private void connect(String serverHostname, int serverPort)\r
289 {\r
b1d4498c 290 InputStream IRCis = null;\r
291 OutputStream IRCos = null;\r
292 //check for input output streams\r
293 try\r
294 {\r
cb67c259 295 IRCServerS = new Socket(serverHostname, serverPort);\r
b1d4498c 296 IRCis = IRCServerS.getInputStream();\r
297 IRCos = IRCServerS.getOutputStream();\r
cb67c259
O
298 //make the buffers\r
299 IRCir = new BufferedReader(new InputStreamReader(IRCis,"ISO-8859-1"));\r
300 IRCor = new BufferedWriter(new OutputStreamWriter(IRCos,"ISO-8859-1"));\r
b1d4498c 301 }\r
302 catch(Exception e)\r
303 {\r
304 printDebug("error opening streams to IRC server");\r
305 debug(e);\r
bd09b4c0 306 System.exit(1);\r
b1d4498c 307 }\r
b1d4498c 308 return;\r
309 }\r
310\r
311 /**\r
312 * Kill the connection to the server.\r
313 */\r
314 private void disconnect()\r
315 {\r
316 try\r
317 {\r
318 IRCir.close();\r
319 IRCor.close();\r
320 }\r
321 catch(IOException e)\r
322 {\r
323 printDebug("Error disconnecting from IRC server");\r
324 debug(e);\r
325 }\r
326 }\r
327\r
328 /**\r
329 * Log off clean.\r
330 */\r
331 private void logoff()\r
332 {\r
333 BufferedReader br = IRCir;\r
334 BufferedWriter bw = IRCor;\r
335 try\r
336 {\r
337 if(!ircsend("quit :Shutting down."));\r
338 bw.write("quit :Shutting down.");\r
339 bw.newLine();\r
340 bw.flush();\r
341 }\r
342 catch(Exception e)\r
343 {\r
344 printDebug("logoff error: " + e);\r
bd09b4c0 345 System.exit(1);\r
b1d4498c 346 }\r
347 }\r
348\r
349 /**\r
350 * Start our connection burst\r
351 */\r
352 private void logon()\r
353 {\r
354 BufferedReader br = IRCir;\r
355 BufferedWriter bw = IRCor;\r
356 try\r
357 {\r
358 // send user info\r
359 printDebug("[>---<] >> *** Connecting to IRC server...");\r
360 printDebug("[>---<] >> *** Sending password...");\r
361 printDebug("[>out<] >> PASS " + pass);\r
362 bw.write("PASS " + pass);\r
363 bw.newLine();\r
cb67c259 364 printDebug("[>---<] >> *** Identify the Service...");\r
7e4fed7d 365 String time = get_time();\r
b1d4498c 366 //itroduce myself properly\r
7e4fed7d 367 printDebug("[>out<] >> SERVER " + host + " 1 " + time + " " + time + " J10 " + numeric + "]]] +s :" + description);\r
368 bw.write("SERVER " + host + " 1 " + time + " " + time + " J10 " + numeric + "]]] +s :" + description);\r
b1d4498c 369 bw.newLine();\r
cb67c259 370 dbc.addServer(numeric,host,"0",true);\r
b1d4498c 371 printDebug("[>---<] >> *** Sending EB");\r
372 printDebug("[>out<] >> " + numeric + " EB");\r
373 bw.write(numeric + " EB");\r
374 bw.newLine();\r
375 bw.flush();\r
376 }\r
377 catch(Exception e)\r
378 {\r
379 printDebug("logon error: " + e);\r
bd09b4c0 380 System.exit(1);\r
b1d4498c 381 }\r
382 return;\r
383 }\r
384\r
385 /**\r
386 * Send raw data to the IRC Server\r
387 */\r
388 public boolean ircsend(String message)\r
389 {\r
390 printDebug("[>out<] >> " + message);\r
391 try\r
392 {\r
393 IRCor.write(message);\r
394 IRCor.newLine();\r
395 IRCor.flush();\r
396 }\r
397 catch(IOException e)\r
398 {\r
399 return false;\r
400 }\r
401 return true;\r
402 }\r
403\r
404 /**\r
405 * Parse raw server data.\r
406 */\r
407 private void service()\r
408 {\r
409 try\r
410 {\r
411 if(IRCir.ready())\r
412 {\r
413 String msg = IRCir.readLine();\r
414 printDebug("[>in <] >> " + msg);\r
415 String prefix = null;\r
416 String command = null;\r
417 String params = null;\r
418 if(msg.substring(0,1).equals(":"))\r
419 {\r
420 prefix = msg.substring(1, msg.indexOf(' '));\r
421 msg = msg.substring(msg.indexOf(' ') + 1);\r
422 }\r
423 command = msg.substring(0, msg.indexOf(' '));\r
424 params = msg.substring(msg.indexOf(' ') + 1);\r
425 //was it a ping?\r
426 if(!pingpong(params))\r
427 {\r
428 //parse all server commands (that i needed)\r
429 //bursts\r
430 if(params.startsWith("EA "))\r
431 {\r
432 if(!EA)\r
433 {\r
434 printDebug("[>---<] >> *** Completed net.burst...");\r
435 ser.EA();\r
436 EA = true;\r
437 }\r
438 ser.sync(command);\r
439 }\r
440 if(params.startsWith("EB "))\r
441 {\r
442 if(!EB)\r
443 {\r
444 srv_EB();\r
445 EB = true;\r
446 }\r
447 }\r
448 //the mothership\r
449 if(command.equals("SERVER"))\r
450 {\r
bf5f32d5 451 //SERVER bob.be.borknet.org 1 1000000000 1129325005 J10 ABAP] +h :BorkNet IRC Server\r
b1d4498c 452 //compare to:\r
453 //AB S lightweight.borknet.org 2 0 1123847781 P10 [lAAD +s :The lean, mean opping machine.\r
454 ser.mserver(msg);\r
455 }\r
456 //privmsg\r
457 if(params.startsWith("P "))\r
458 {\r
459 //AWAAA P #feds :bla\r
460 String message = params.substring(params.indexOf(":") +1);\r
461 String me = params.substring(2, params.indexOf(":")-1);\r
462 ser.privmsg(me, command, message);\r
463 }\r
464 //some notice\r
465 if(params.startsWith("O "))\r
466 {\r
467 String message = params.substring(params.indexOf(":") +1);\r
468 String me = params.substring(2 , params.indexOf(":")-1);\r
469 ser.notice(me, command, message);\r
470 }\r
471 //nickchange\r
472 if(params.startsWith("N "))\r
473 {\r
bf5f32d5 474 //AB N Ozafy 1 1119649303 ozafy bob.be.borknet.org +oiwkgrxXnIh Ozafy Darth@Vader B]AAAB ABAXs :Laurens Panier\r
b1d4498c 475 ser.nickchange(command, params);\r
476 }\r
477 //quit\r
478 if(params.startsWith("Q "))\r
479 {\r
480 //Q :Quit: [SearchIRC] Indexed 16 channels in 3 secs @ Aug 12th, 2005, 6:46 pm\r
481 ser.quit(msg);\r
482 }\r
483 //disconnect\r
484 if(params.startsWith("D "))\r
485 {\r
486 //ACAAF D ABBRC :hub.uk.borknet.org!hub.uk.borknet.org!xirtwons (Now I've done a kill :p)\r
487 ser.quit(msg);\r
488 }\r
489 //some server died\r
490 if(params.startsWith("SQ "))\r
491 {\r
492 //AB SQ eclipse.il.us.borknet.org 1123885086 :Read error: Broken pipe\r
493 ser.squit(msg);\r
494 }\r
495 //some server connected\r
496 if(params.startsWith("S "))\r
497 {\r
498 //AB S lightweight.borknet.org 2 0 1123847781 P10 [lAAD +s :The lean, mean opping machine.\r
499 ser.server(msg);\r
500 }\r
501 //someone joined a channel\r
502 if(params.startsWith("J "))\r
503 {\r
504 //[>in <] >> ABAXs J #BorkNet 949217470\r
505 //[>in <] >> ABARL J 0\r
506 if(!params.equals("J 0"))\r
507 {\r
508 String chan = params.substring(params.indexOf("#"),params.indexOf(" ",params.indexOf("#")));\r
644fc012 509 String timestamp = params.substring(params.indexOf(" ",params.indexOf("#"))+1);\r
510 ser.join(command, chan, timestamp);\r
b1d4498c 511 }\r
512 else\r
513 {\r
514 ser.partAll(command);\r
515 }\r
516 }\r
517 //someone left a channel\r
518 if(params.startsWith("L "))\r
519 {\r
520 //ABBRG L #404forums\r
521 //[>in <] >> ABCVC L #advice :Leaving\r
522 //[>in <] >> ADABd L #lol,#zomg\r
523 //[>in <] >> ADABd L #lol,#zomg :Leaving\r
524 String chan = params.substring(params.indexOf("#"));\r
525 if(chan.contains(" "))\r
526 {\r
527 chan = chan.substring(0,chan.indexOf(" "));\r
528 }\r
529 ser.part(chan, command);\r
530 }\r
531 //someone got kicked\r
532 if(params.startsWith("K "))\r
533 {\r
534 //[>in <] >> ABAXs K #BorkNet ABBrj :bleh OC12B?O63C12B?O\r
535 String temp = params.substring(params.indexOf("#"));\r
536 String chan = temp.substring(0,temp.indexOf(" "));\r
537 String user = temp.substring(temp.indexOf(" ")+1, temp.indexOf(":")-1);\r
538 ser.kick(chan, user);\r
539 }\r
540 //someone created a channel\r
541 if(params.startsWith("C "))\r
542 {\r
543 //ABAAA C #Feds 1119880843\r
544 //[>in <] >> ABAXs C #bla,#bli,#blo 1125181542\r
545 String chan = params.substring(params.indexOf("#"),params.lastIndexOf(" "));\r
644fc012 546 String timestamp = params.substring(params.indexOf(" ")+1);\r
547 ser.create(chan, command, timestamp);\r
b1d4498c 548 }\r
549 //Topic change\r
550 if(params.startsWith("T "))\r
551 {\r
552 //GB T #Tutorial.Staff 1117290817 1123885058 :Tutorial Staff channel. Currently loaded tutorial: None.\r
553 String temp = params.substring(params.indexOf("#"));\r
554 String chan = temp.substring(0,temp.indexOf(" "));\r
555 String topic = params.substring(params.indexOf(":")+1);\r
556 ser.topic(command, chan, topic);\r
557 }\r
558 //chan burst\r
559 if(params.startsWith("B "))\r
560 {\r
561 //[>in <] >> AB B #BorkNet 949217470 +tncCNu ABBh8,ABBhz,ABBhn:v,ACAAT:o,ACAAV,ABAXs :%InsanitySane!*@sexplay.dk *!juliusjule@sexplay.dk naimex!*@sexplay.dk\r
562 //[>in <] >> AB B #BorkNet 949217470 ABBh8,ABBhz,ABBhn:v,ACAAT:o,ACAAV,ABAXs :%InsanitySane!*@sexplay.dk *!juliusjule@sexplay.dk naimex!*@sexplay.dk\r
cb67c259
O
563 //wtf at these:\r
564 //[>in <] >> AD B #Tutorial 0 +mtinDCN ADAAA\r
565 //[>in <] >> AD B #avpoe 0 ADATI\r
566 //[>in <] >> AD B #help 1 ADAAA:o\r
b1d4498c 567 /* a problem arises if a server splits, services (Q) get restarted during the split,\r
cb67c259 568 and they join a (now) empty channel (because of the split). the TS on our link will be\r
b1d4498c 569 younger then the ts on the rejoining server, so we lose our modes.\r
570 Possible solutions:\r
571 a) if this happens, the B line will have a mode string, so we can find the channels that way,\r
572 we parse the users/modes, and rejoin the channel.\r
573 b) we save the timestamps of known channels, and if we get one that doesn't equal ours, we\r
574 parse it like p10 discribes.\r
575 c) we trust services not to get restarted during splits ;p\r
576\r
577 a would be the simple dirty solution, b would require more work, and slow us down a bit more\r
578 but be correct\r
579\r
580\r
581 We're going for a.\r
b1d4498c 582\r
cb67c259
O
583 another problem surfaced where the timestamp being burst was a 0 or a 1. I have no idea why, however\r
584 this causes deops aswell. another fix was put inplace.\r
585 */\r
b1d4498c 586 String chan = params.substring(params.indexOf("#"),params.indexOf(" ",params.indexOf("#")));\r
587 String users = "";\r
b1d4498c 588 String result[] = params.split("\\s");\r
4fc25459 589 if(result.length > 3)\r
b1d4498c 590 {\r
4fc25459
O
591 //no bans\r
592 if(params.indexOf(" :") == -1)\r
593 {\r
594 users = params.substring(params.lastIndexOf(" ")+1);\r
595 }\r
596 //bans\r
597 else\r
598 {\r
599 users = params.substring(params.substring(0,params.indexOf(" :")).lastIndexOf(" ")+1,params.indexOf(" :"));\r
600 }\r
cb67c259 601 if(EA && (result[3].startsWith("+") || result[2].length() < 2))\r
4fc25459
O
602 {\r
603 reop(chan);\r
604 }\r
644fc012 605 ser.bline(chan, users, result[2]);\r
b1d4498c 606 }\r
b1d4498c 607 }\r
608 //a mode change\r
609 if(params.startsWith("M "))\r
610 {\r
611 //[>in <] >> ABAXs M #BorkNet -ov+ov ABBlK ABBli ABBly ABBlb\r
224417a9 612 //[>in <] >> ABASv M Ozafy +h moo@moop\r
b1d4498c 613 ser.mode(command, params);\r
614 }\r
615 //someone cleared modes.\r
616 if(params.startsWith("CM "))\r
617 {\r
618 //AQ CM #BorkNet ovpsmikblrcCNDu\r
619 ser.cmode(command, params);\r
620 }\r
621 //server mode change\r
622 if(params.startsWith("OM "))\r
623 {\r
624 //AW OM #coder-com +ov AWAAA AWAAA\r
625 ser.omode(command, params);\r
626 }\r
627 //someone auths.\r
628 if(params.startsWith("AC "))\r
629 {\r
630 //AQ AC ABBRG Froberg\r
631 ser.auth(command, params);\r
632 }\r
633 //someone auths.\r
634 if(params.startsWith("GL "))\r
635 {\r
636 //A] GL AW +#icededicated* 304538871 :Network Admin owns this channel.\r
637 ser.gline(command, params);\r
638 }\r
639 //A]AAB R u :AW ??\r
640 }\r
641 /*\r
642 AC ACCOUNT\r
643 AD ADMIN\r
644 LL ASLL\r
645 A AWAY\r
646 B BURST\r
647 CM CLEARMODE\r
648 CLOSE CLOSE\r
649 CN CNOTICE\r
650 CO CONNECT\r
651 CP CPRIVMSG\r
652 C CREATE\r
653 DE DESTRUCT\r
654 DS DESYNCH\r
655 DIE DIE\r
656 DNS DNS\r
657 EB END_OF_BURST\r
658 EA EOB_ACK\r
659 Y ERROR\r
660 GET GET\r
661 GL GLINE\r
662 HASH HASH\r
663 HELP HELP\r
664 F INFO\r
665 I INVITE\r
666 ISON ISON\r
667 J JOIN\r
668 JU JUPE\r
669 K KICK\r
670 D KILL\r
671 LI LINKS\r
672 LIST LIST\r
673 LU LUSERS\r
674 MAP MAP\r
675 M MODE\r
676 MO MOTD\r
677 E NAMES\r
678 N NICK\r
679 O NOTICE\r
680 OPER OPER\r
681 OM OPMODE\r
682 L PART\r
683 PA PASS\r
684 G PING\r
685 Z PONG\r
686 POST POST\r
687 P PRIVMSG\r
688 PRIVS PRIVS\r
689 PROTO PROTO\r
690 Q QUIT\r
691 REHASH REHASH\r
692 RESET RESET\r
693 RESTART RESTART\r
694 RI RPING\r
695 RO RPONG\r
696 S SERVER\r
697 SET SET\r
698 SE SETTIME\r
699 U SILENCE\r
700 SQ SQUIT\r
701 R STATS\r
702 TI TIME\r
703 T TOPIC\r
704 TR TRACE\r
705 UP UPING\r
706 USER USER\r
707 USERHOST USERHOST\r
708 USERIP USERIP\r
709 V VERSION\r
710 WC WALLCHOPS\r
711 WA WALLOPS\r
712 WU WALLUSERS\r
713 WV WALLVOICES\r
714 H WHO\r
715 W WHOIS\r
716 X WHOWAS\r
717 SN SVSNICK\r
718 SJ SVSJOIN\r
719 */\r
720 if(EA)\r
721 {\r
722 mod.parse(msg);\r
723 }\r
724 }\r
725 //nothing to do, nap\r
726 else\r
727 {\r
728 try\r
729 {\r
730 Thread.sleep(100);\r
731 }\r
732 catch(InterruptedException e)\r
733 {\r
734 }\r
735 }\r
736 }\r
737 //dun dun dun\r
738 catch(IOException e)\r
739 {\r
740 debug(e);\r
bd09b4c0 741 System.exit(1);\r
b1d4498c 742 }\r
743 }\r
744\r
745 /**\r
746 * Ping! Pong!\r
747 * @param msg ping message\r
748 */\r
749 private boolean pingpong(String msg) throws IOException\r
750 {\r
751 //AB G !1123885135.436177 releases.borknet.org 1123885135.436177\r
752 if(msg.startsWith("G !"))\r
753 {\r
9f393861 754 String pongmsg = numeric + " Z :" + host;\r
b1d4498c 755 IRCor.write(pongmsg);\r
756 IRCor.newLine();\r
757 IRCor.flush();\r
758 printDebug("[>out<] >> " + pongmsg);\r
b1d4498c 759 return true;\r
760 }\r
761 return false;\r
762 }\r
763\r
764 /**\r
765 * rehash & reconnect to our server.\r
766 */\r
767 public void rehash()\r
768 {\r
769 mod.stop();\r
cb67c259 770 timer.stop();\r
b1d4498c 771 logoff();\r
772 disconnect();\r
773 EA = false;\r
774 EB = false;\r
775 modules.clear();\r
776 load_conf();\r
777 create_coremodules();\r
778 connect(server,port);\r
779 logon();\r
780 }\r
bd09b4c0 781 \r
782 public void die(String quit)\r
783 {\r
784 get_modCore().stop();\r
785 cmd_quit(corenum, quit);\r
786 running = false;\r
787 }\r
b1d4498c 788\r
789 public void reop(String chan)\r
790 {\r
791 mod.reop(chan);\r
792 }\r
793\r
794 /**\r
795 * Get the bot's nick\r
796 * @return bot's nick\r
797 */\r
798 public String get_nick()\r
799 {\r
800 return nick;\r
801 }\r
802\r
803 /**\r
804 * Get the bot's host\r
805 * @return bot's host\r
806 */\r
807 public String get_host()\r
808 {\r
809 return host;\r
810 }\r
811\r
812 /**\r
813 * Get the bot's ident\r
814 * @return bot's ident\r
815 */\r
816 public String get_ident()\r
817 {\r
818 return ident;\r
819 }\r
820\r
821 /**\r
822 * Get the bot's numeric\r
823 * @return bot's numeric\r
824 */\r
825 public String get_numeric()\r
826 {\r
827 return numeric;\r
828 }\r
829\r
830 /**\r
831 * Get the bot's numeric\r
832 * @return bot's numeric\r
833 */\r
834 public String get_corenum()\r
835 {\r
836 return corenum;\r
837 }\r
838\r
839 /**\r
840 * Get the version reply\r
841 * @return the version reply\r
842 */\r
843 public String get_version()\r
844 {\r
845 return version;\r
846 }\r
847\r
848 /**\r
849 * Get the reportchannel\r
850 * @return reportchannel\r
851 */\r
852 public String get_reportchan()\r
853 {\r
854 return reportchan;\r
855 }\r
856\r
857 /**\r
858 * Get the network name\r
859 * @return network name\r
860 */\r
861 public String get_net()\r
862 {\r
863 return network;\r
864 }\r
865\r
b1d4498c 866 /**\r
867 * Get the usercount needed to request the bot\r
868 * @return usercount needed to request the bot\r
869 */\r
870 public int get_rusers()\r
871 {\r
872 return rusers;\r
873 }\r
874\r
875 /**\r
876 * Get the current netsplit status\r
877 * @return if the net's split or not\r
878 */\r
879 public boolean get_split()\r
880 {\r
881 return split;\r
882 }\r
883\r
884 /**\r
885 * Get the current netsplit servers\r
886 * @return list of servers\r
887 */\r
888 public ArrayList<String> get_splitList()\r
889 {\r
890 return splits;\r
891 }\r
892\r
893 /**\r
894 * Set the current netsplit status\r
895 * @param s if the net's split or not\r
896 */\r
897 public void set_split(boolean s)\r
898 {\r
899 split = s;\r
900 }\r
901\r
902 /**\r
903 * Add a splitted server\r
904 * @param host splitted server's host\r
905 */\r
906 public void add_split(String host)\r
907 {\r
908 splits.add(host);\r
909 set_split(true);\r
910 }\r
911\r
912 /**\r
913 * Delete a splitted server\r
914 * @param host joined server's host\r
915 */\r
916 public void del_split(String host)\r
917 {\r
918 if(splits.indexOf(host) != -1)\r
919 {\r
920 splits.remove(splits.indexOf(host));\r
921 }\r
922 if(splits.size()<1)\r
923 {\r
924 set_split(false);\r
925 }\r
926 }\r
927\r
928 /**\r
929 * Get the current defcon level\r
930 * @return current defcon level\r
931 */\r
932 public CoreDBControl get_dbc()\r
933 {\r
934 return dbc;\r
935 }\r
936\r
937 public CoreModControl get_modCore()\r
938 {\r
939 return mod;\r
940 }\r
941\r
942 public Connection getDBCon()\r
943 {\r
944 return dbc.getCon();\r
945 }\r
946\r
947 /**\r
948 * Get the current defcon level\r
949 * @return current defcon level\r
950 */\r
951 public int get_defcon()\r
952 {\r
953 return defcon;\r
954 }\r
955\r
956 /**\r
957 * Set the defcon level\r
958 * @param d new defcon level\r
959 */\r
960 public void set_defcon(int d)\r
961 {\r
962 //is it a legal defcon number\r
963 if(d>0 && d<6)\r
964 {\r
965 defcon = d;\r
966 String usertable[] = dbc.getNumericTable();\r
967 //WHAAAA MOOSES\r
968 String level = "THE MOOSES ARE COMMING!!!!!!! MAN THE BATTLE STATIONS!!!!!";\r
969 //set level accordingly\r
970 switch(d)\r
971 {\r
972 case 5:\r
973 level = "5: Normal.";\r
974 for(int n=0; n<usertable.length; n++)\r
975 {\r
976 cmd_notice(corenum, usertable[n], "Defcon " + level);\r
977 cmd_notice(corenum, usertable[n], "We were forced to activate the DefCon System due to an attack of malicious persons. The attack has been diverted and legal action will be taken. Services are now back to normal, we apologize for any inconvenience caused.");\r
978 }\r
979 break;\r
980 case 4:\r
981 level = "4: Increased Security: No new registrations.";\r
982 for(int n=0; n<usertable.length; n++)\r
983 {\r
984 cmd_notice(corenum, usertable[n], "Defcon " + level);\r
985 }\r
986 break;\r
987 case 3:\r
988 level = "3: Alert: No new registrations, no new connections.";\r
989 for(int n=0; n<usertable.length; n++)\r
990 {\r
991 cmd_notice(corenum, usertable[n], "Defcon " + level);\r
992 }\r
993 break;\r
994 case 2:\r
995 level = "2: High Alert: No new registrations, no new connections, no access level changes.";\r
996 for(int n=0; n<usertable.length; n++)\r
997 {\r
998 cmd_notice(corenum, usertable[n], "Defcon " + level);\r
999 }\r
1000 break;\r
1001 case 1:\r
1002 level = "1: Maximum Alert: No new connections, no access level changes, " + nick + " will ignore all regular users.";\r
1003 for(int n=0; n<usertable.length; n++)\r
1004 {\r
1005 cmd_notice(corenum, usertable[n], "Defcon " + level);\r
1006 }\r
1007 break;\r
1008 }\r
1009 return;\r
1010 }\r
1011 else\r
1012 {\r
1013 defcon = 5;\r
1014 }\r
1015 }\r
1016\r
1017 /**\r
1018 * Get the current logon info line\r
1019 * @return the current logon info line\r
1020 */\r
1021 public String get_info()\r
1022 {\r
1023 return info;\r
1024 }\r
1025\r
1026 /**\r
1027 * Set a new logon info line\r
1028 * @param info the new logon info line\r
1029 */\r
1030 public void set_info(String info)\r
1031 {\r
1032 this.info = info;\r
1033 }\r
1034\r
cb67c259
O
1035 /**\r
1036 * Get the EA\r
1037 * @return the current logon info line\r
1038 */\r
1039 public boolean get_EA()\r
1040 {\r
1041 return EA;\r
1042 }\r
1043\r
1044 /**\r
1045 * Get the EA\r
1046 * @return the current logon info line\r
1047 */\r
1048 public boolean get_debug()\r
1049 {\r
1050 return debug;\r
1051 }\r
1052\r
b1d4498c 1053 /**\r
1054 * Report directly to the reportchan\r
1055 * @param s what to report\r
1056 */\r
1057 public void report(String s)\r
1058 {\r
1059 cmd_privmsg(corenum, reportchan, s);\r
1060 }\r
1061\r
1062 /**\r
1063 * Send an Email\r
1064 * @param subj the subject of the mail\r
1065 * @param umail the user's e-mail\r
1066 * @param mesg content of the mail\r
1067 */\r
1068 public void send_mail(String subj, String umail, String mesg, String nick, String host)\r
1069 {\r
ac6b717f 1070 //create the mail sending class and deamon it.\r
1071 CoreMail mail = new CoreMail();\r
1072 mail.setMail(this, mailserver, mailport, mailauth, mailuser, mailpass, nick, host, umail, subj, mesg);\r
1073 Thread mailThread = new Thread(mail);\r
1074 mailThread.setDaemon(true);\r
1075 mailThread.start();\r
b1d4498c 1076 }\r
1077\r
e1852f91 1078 /**\r
1079 * Make the bot send <raw>\r
1080 * @param raw string to send\r
1081 */\r
1082 public void cmd_raw(String raw)\r
1083 {\r
1084 ircsend(raw);\r
1085 } \r
1086 \r
b1d4498c 1087 /**\r
1088 * Make the bot join a channel\r
1089 * @param channel channel to join\r
1090 */\r
1091 public void cmd_join(String num, String channel)\r
1092 {\r
644fc012 1093 if(dbc.chanExists(channel))\r
1094 {\r
1095 ircsend(numeric + num + " J " + channel);\r
1096 cmd_mode(numeric + num , channel , "+o");\r
1097 dbc.addUserChan(channel, numeric + num, "o","0");\r
1098 }\r
1099 else\r
1100 {\r
1101 ircsend(numeric + num + " C " + channel + " " + get_time());\r
1102 dbc.addUserChan(channel, numeric + num, "o", get_time());\r
1103 }\r
b1d4498c 1104 }\r
1105\r
1106 /**\r
1107 * Make the bot join a channel\r
1108 * @param channel channel to join\r
1109 */\r
1110 public void cmd_join(String numeric, String num, String channel)\r
1111 {\r
644fc012 1112 if(dbc.chanExists(channel))\r
1113 {\r
1114 ircsend(numeric + num + " J " + channel);\r
1115 cmd_mode(numeric + num , channel , "+o");\r
1116 dbc.addUserChan(channel, numeric + num, "o","0");\r
1117 }\r
1118 else\r
1119 {\r
1120 ircsend(numeric + num + " C " + channel + " " + get_time());\r
1121 dbc.addUserChan(channel, numeric + num, "o", get_time());\r
1122 }\r
b1d4498c 1123 }\r
1124\r
1125 /**\r
1126 * Make the bot join a channel\r
1127 * @param channel channel to join\r
1128 */\r
1129 public void cmd_join(String numeric, String num, String channel, boolean noop)\r
1130 {\r
644fc012 1131 if(dbc.chanExists(channel))\r
1132 {\r
1133 ircsend(numeric + num + " J " + channel);\r
1134 dbc.addUserChan(channel, numeric + num, "0", "0");\r
1135 }\r
1136 else\r
1137 {\r
1138 ircsend(numeric + num + " C " + channel + " " + get_time());\r
1139 dbc.addUserChan(channel, numeric + num, "0",get_time());\r
1140 }\r
b1d4498c 1141 }\r
1142\r
1143 /**\r
1144 * Make the server change a user's mode\r
1145 * @param user user's numeric\r
1146 * @param channel channel to change modes on\r
1147 * @param mode mode to change\r
1148 */\r
1149 public void cmd_mode(String user , String channel , String mode)\r
1150 {\r
1151 ircsend(numeric + " OM " + channel + " " + mode + " " + user);\r
1152 dbc.setUserChanMode(user, channel, mode);\r
1153 }\r
1154\r
1155 /**\r
1156 * Make the server change a user's mode\r
1157 * @param user user's numeric\r
1158 * @param channel channel to change modes on\r
1159 * @param mode mode to change\r
1160 */\r
1161 public void cmd_mode(String numeric, String user , String channel , String mode)\r
1162 {\r
1163 ircsend(numeric + " OM " + channel + " " + mode + " " + user);\r
1164 dbc.setUserChanMode(user, channel, mode);\r
1165 }\r
1166\r
1167 /**\r
1168 * Make the bot change a user's mode\r
1169 * @param user user's numeric\r
1170 * @param channel channel to change modes on\r
1171 * @param mode mode to change\r
1172 */\r
1173 public void cmd_mode_me(String num, String user, String channel, String mode)\r
1174 {\r
1175 ircsend(numeric + num + " M " + channel + " " + mode + " " + user);\r
1176 dbc.setUserChanMode(user, channel, mode);\r
1177 }\r
1178\r
1179 /**\r
1180 * Make the bot change a user's mode\r
1181 * @param user user's numeric\r
1182 * @param channel channel to change modes on\r
1183 * @param mode mode to change\r
1184 */\r
1185 public void cmd_mode_me(String numeric, String num, String user, String channel, String mode)\r
1186 {\r
1187 ircsend(numeric + num + " M " + channel + " " + mode + " " + user);\r
1188 dbc.setUserChanMode(user, channel, mode);\r
1189 }\r
1190\r
1191 /**\r
1192 * Make the bot part a channel\r
1193 * @param channel channel to part\r
1194 * @param reason say why we're leaving\r
1195 */\r
1196 public void cmd_part(String num, String channel, String reason)\r
1197 {\r
1198 ircsend(numeric + num + " L " + channel + " :" + reason);\r
1199 dbc.delUserChan(channel, numeric + num);\r
1200 }\r
1201\r
1202 /**\r
1203 * Make the bot part a channel\r
1204 * @param channel channel to part\r
1205 * @param reason say why we're leaving\r
1206 */\r
1207 public void cmd_part(String numeric, String num, String channel, String reason)\r
1208 {\r
1209 ircsend(numeric + num + " L " + channel + " :" + reason);\r
1210 dbc.delUserChan(channel, numeric + num);\r
1211 }\r
1212\r
1213 /**\r
1214 * Make the server send a privmsg\r
1215 * @param user user's numeric (or channel) where to privmsg to\r
1216 * @param msg what to say\r
1217 */\r
1218 public void cmd_sprivmsg(String user, String msg)\r
1219 {\r
1220 ircsend(numeric + " P " + user + " :" + msg);\r
1221 }\r
1222\r
1223 /**\r
1224 * Make the server send a privmsg\r
1225 * @param user user's numeric (or channel) where to privmsg to\r
1226 * @param msg what to say\r
1227 */\r
1228 public void cmd_sprivmsg(String numeric, String user, String msg)\r
1229 {\r
1230 ircsend(numeric + " P " + user + " :" + msg);\r
1231 }\r
1232\r
1233 /**\r
1234 * Make the bot send a privmsg\r
1235 * @param user user (or channel) where to privmsg to\r
1236 * @param msg what to say\r
1237 */\r
1238 public void cmd_privmsg(String num, String user, String msg)\r
1239 {\r
1240 ircsend(numeric + num + " P " + user + " :" + msg);\r
1241 }\r
1242\r
1243 /**\r
1244 * Make the bot send a privmsg\r
1245 * @param user user (or channel) where to privmsg to\r
1246 * @param msg what to say\r
1247 */\r
1248 public void cmd_privmsg(String numeric, String num, String user, String msg)\r
1249 {\r
1250 ircsend(numeric + num + " P " + user + " :" + msg);\r
1251 }\r
1252\r
1253 /**\r
1254 * Make the bot invite a user to a channel\r
1255 * @param user nick of user to invite\r
1256 * @param chan channel where we're inviting him to (we need op there)\r
1257 */\r
1258 public void cmd_invite(String num, String user, String chan)\r
1259 {\r
1260 ircsend(numeric + num + " I " + user + " :" + chan);\r
1261 }\r
1262\r
1263 /**\r
1264 * Make the bot invite a user to a channel\r
1265 * @param user nick of user to invite\r
1266 * @param chan channel where we're inviting him to (we need op there)\r
1267 */\r
1268 public void cmd_invite(String numeric, String num, String user, String chan)\r
1269 {\r
1270 ircsend(numeric + num + " I " + user + " :" + chan);\r
1271 }\r
1272\r
1273 /**\r
1274 * send a notice as bot\r
1275 * @param user user's numeric to notice\r
1276 * @param msg what to say\r
1277 */\r
1278 public void cmd_notice(String num, String user, String msg)\r
1279 {\r
1280 ircsend(numeric + num + " O " + user + " :" + msg);\r
1281 }\r
1282\r
1283 /**\r
1284 * send a notice as bot\r
1285 * @param user user's numeric to notice\r
1286 * @param msg what to say\r
1287 */\r
1288 public void cmd_notice(String numeric, String num, String user, String msg)\r
1289 {\r
1290 ircsend(numeric + num + " O " + user + " :" + msg);\r
1291 }\r
1292\r
1293 /**\r
1294 * set a G-Line\r
1295 * @param host host to ban\r
1296 * @param duration duration of the ban, in seconds\r
1297 * @param reason why we're banning him/her/it\r
1298 */\r
1299 public void cmd_gline(String host, String duration, String reason)\r
1300 {\r
1301 ircsend(numeric + " GL * +" + host + " " + duration + " :" + reason);\r
1302 }\r
1303\r
1304 /**\r
1305 * set a G-Line\r
1306 * @param host host to ban\r
1307 * @param duration duration of the ban, in seconds\r
1308 * @param reason why we're banning him/her/it\r
1309 */\r
1310 public void cmd_gline(String numeric, String host, String duration, String reason)\r
1311 {\r
1312 ircsend(numeric + " GL * +" + host + " " + duration + " :" + reason);\r
1313 }\r
1314\r
1315 /**\r
1316 * remove a G-Line\r
1317 * @param host host to unban\r
1318 */\r
1319 public void cmd_ungline(String host)\r
1320 {\r
1321 ircsend(numeric + " GL * -" + host);\r
1322 }\r
1323\r
1324 /**\r
1325 * remove a G-Line\r
1326 * @param host host to unban\r
1327 */\r
1328 public void cmd_ungline(String numeric, String host)\r
1329 {\r
1330 ircsend(numeric + " GL * -" + host);\r
1331 }\r
1332\r
1333 /**\r
1334 * set a Jupe\r
1335 * @param host host to ban\r
1336 * @param duration duration of the ban, in seconds\r
1337 * @param reason why we're banning him/her/it\r
1338 */\r
1339 public void cmd_jupe(String host, String numer)\r
1340 {\r
1341 //AB S lightweight.borknet.org 2 0 1123847781 P10 [lAAD +s :The lean, mean opping machine.\r
1342 ircsend(numeric + " S " + host + " 2 0 " + get_time() + " P10 "+numer+"AAD +s :Juped.");\r
cb67c259 1343 dbc.addServer(numer,host,numeric,true);\r
b1d4498c 1344 }\r
1345\r
1346 /**\r
1347 * set a Jupe\r
1348 * @param host host to ban\r
1349 * @param duration duration of the ban, in seconds\r
1350 * @param reason why we're banning him/her/it\r
1351 */\r
1352 public void cmd_jupe(String numeric, String host, String numer)\r
1353 {\r
1354 //AB S lightweight.borknet.org 2 0 1123847781 P10 [lAAD +s :The lean, mean opping machine.\r
1355 ircsend(numeric + " S " + host + " 3 0 " + get_time() + " P10 "+numer+"AAD +s :Juped.");\r
cb67c259 1356 dbc.addServer(numer,host,numeric,true);\r
b1d4498c 1357 }\r
1358\r
1359 /**\r
1360 * remove a Jupe\r
1361 * @param host host to unban\r
1362 */\r
bd09b4c0 1363 public void cmd_unjupe(String host)\r
b1d4498c 1364 {\r
1365 //AB SQ eclipse.il.us.borknet.org 1123885086 :Read error: Broken pipe\r
bd09b4c0 1366 ircsend(numeric + " SQ " + host + " 0 :EOF from client");\r
b1d4498c 1367 dbc.delServer(host);\r
1368 }\r
1369\r
1370 /**\r
1371 * remove a Jupe\r
1372 * @param host host to unban\r
1373 */\r
bd09b4c0 1374 public void cmd_unjupe(String numeric, String host)\r
b1d4498c 1375 {\r
1376 //AB SQ eclipse.il.us.borknet.org 1123885086 :Read error: Broken pipe\r
bd09b4c0 1377 ircsend(numeric + " SQ " + host + " 0 :EOF from client");\r
b1d4498c 1378 dbc.delServer(host);\r
1379 }\r
1380\r
1381 /**\r
1382 * Kill a user\r
1383 * @param user user's numeric\r
1384 * @param why reason why we're killing him/her/it\r
1385 */\r
cb67c259 1386 public void cmd_dis(String user, String why)\r
b1d4498c 1387 {\r
cb67c259 1388 ircsend(numeric + " D " + user + " : (" + why + ")");\r
b1d4498c 1389 dbc.delUser(user);\r
1390 }\r
1391\r
1392 /**\r
1393 * Kill a user\r
1394 * @param user user's numeric\r
1395 * @param why reason why we're killing him/her/it\r
1396 */\r
cb67c259 1397 public void cmd_dis(String numeric, String user, String why)\r
b1d4498c 1398 {\r
cb67c259 1399 ircsend(numeric + " D " + user + " : (" + why + ")");\r
b1d4498c 1400 dbc.delUser(user);\r
1401 }\r
1402\r
1403 /**\r
1404 * Make the bot quit IRC\r
1405 * @param quit message to give when quitting\r
1406 */\r
1407 public void cmd_quit(String num,String quit)\r
1408 {\r
1409 ircsend(numeric + num + " Q :Quit: " + quit);\r
1410 dbc.delUser(numeric + num);\r
1411 }\r
1412\r
1413 /**\r
1414 * Make the bot quit IRC\r
1415 * @param quit message to give when quitting\r
1416 */\r
1417 public void cmd_quit(String numeric, String num,String quit)\r
1418 {\r
1419 ircsend(numeric + num + " Q :Quit: " + quit);\r
1420 dbc.delUser(numeric + num);\r
1421 }\r
1422\r
1423 /**\r
1424 * set the topic as bot\r
1425 * @param chan channel to change topic on\r
1426 * @param topic new topic\r
1427 */\r
1428 public void cmd_topic(String num,String chan, String topic)\r
1429 {\r
1430 //ircsend(numeric + "AAA T " + chan + " " + 0 + " " + get_time() + " :" + topic);\r
1431 ircsend(numeric + num + " T " + chan + " :" + topic);\r
1432 }\r
1433\r
1434 /**\r
1435 * set the topic as bot\r
1436 * @param chan channel to change topic on\r
1437 * @param topic new topic\r
1438 */\r
1439 public void cmd_topic(String numeric, String num,String chan, String topic)\r
1440 {\r
1441 //ircsend(numeric + "AAA T " + chan + " " + 0 + " " + get_time() + " :" + topic);\r
1442 ircsend(numeric + num + " T " + chan + " :" + topic);\r
1443 }\r
1444\r
1445 /**\r
1446 * kick as bot\r
1447 * @param chan channel to kick from\r
1448 * @param user user's numeric to kick\r
1449 * @param msg reason why we're kicking\r
1450 */\r
1451 public void cmd_kick_me(String num,String chan, String user, String msg)\r
1452 {\r
1453 ircsend(numeric + num + " K " + chan + " " + user + " :" + msg);\r
1454 dbc.delUserChan(chan, user);\r
1455 }\r
1456\r
1457 /**\r
1458 * kick as bot\r
1459 * @param chan channel to kick from\r
1460 * @param user user's numeric to kick\r
1461 * @param msg reason why we're kicking\r
1462 */\r
1463 public void cmd_kick_me(String numeric,String num,String chan, String user, String msg)\r
1464 {\r
1465 ircsend(numeric + num + " K " + chan + " " + user + " :" + msg);\r
1466 dbc.delUserChan(chan, user);\r
1467 }\r
1468\r
1469 /**\r
1470 * kick as server\r
1471 * @param chan channel to kick from\r
1472 * @param user user's numeric to kick\r
1473 * @param msg reason why we're kicking\r
1474 */\r
1475 public void cmd_kick(String chan, String user, String msg)\r
1476 {\r
1477 ircsend(numeric + " K " + chan + " " + user + " :" + msg);\r
1478 dbc.delUserChan(chan, user);\r
1479 }\r
1480\r
1481 /**\r
1482 * kick as server\r
1483 * @param chan channel to kick from\r
1484 * @param user user's numeric to kick\r
1485 * @param msg reason why we're kicking\r
1486 */\r
1487 public void cmd_kick(String numeric, String chan, String user, String msg)\r
1488 {\r
1489 ircsend(numeric + " K " + chan + " " + user + " :" + msg);\r
1490 dbc.delUserChan(chan, user);\r
1491 }\r
1492\r
1493 /**\r
1494 * change the channel limit\r
1495 * @param chan channel to set a new limit\r
1496 * @param lim new limit\r
1497 */\r
1498 public void cmd_limit(String num, String chan, int lim)\r
1499 {\r
1500 ircsend(numeric + num + " M " + chan + " +l " + lim);\r
1501 }\r
1502\r
1503 /**\r
1504 * change the channel limit\r
1505 * @param chan channel to set a new limit\r
1506 * @param lim new limit\r
1507 */\r
1508 public void cmd_limit(String numeric, String num, String chan, int lim)\r
1509 {\r
1510 ircsend(numeric + num + " M " + chan + " +l " + lim);\r
1511 }\r
1512\r
1513 /**\r
1514 * change the channel key\r
1515 * @param chan channel to set a new key\r
1516 * @param key new key\r
1517 */\r
1518 public void cmd_key(String num, String chan, String key)\r
1519 {\r
1520 ircsend(numeric + num + " M " + chan + " +k " + key);\r
1521 }\r
1522\r
1523 /**\r
1524 * change the channel key\r
1525 * @param chan channel to set a new key\r
1526 * @param key new key\r
1527 */\r
1528 public void cmd_key(String numeric, String num, String chan, String key)\r
1529 {\r
1530 ircsend(numeric + num + " M " + chan + " +k " + key);\r
1531 }\r
1532\r
1533 /**\r
1534 * create a fake user\r
1535 * @param nick fake nickname\r
1536 * @param ident fake ident\r
1537 * @param host fake host\r
1538 * @param desc fake description\r
1539 */\r
1540 public void cmd_create_service(String num, String nick, String ident, String host, String modes, String desc)\r
1541 {\r
1542 String time = get_time();\r
1543 ircsend(numeric + " N " + nick + " 1 " + time + " " + ident + " " + host + " "+modes+" " + nick + " B]AAAB " + numeric+num+" :" + desc);\r
cb67c259 1544 dbc.addUser(numeric+num,nick,ident+"@"+host,modes,nick,true,numeric,"0.0.0.0","0");\r
b1d4498c 1545 }\r
1546\r
1547 /**\r
1548 * create a fake user\r
1549 * @param nick fake nickname\r
1550 * @param ident fake ident\r
1551 * @param host fake host\r
1552 * @param desc fake description\r
1553 */\r
1554 public void cmd_create_service(String numeric, String num, String nick, String ident, String host, String modes, String desc)\r
1555 {\r
1556 String time = get_time();\r
1557 ircsend(numeric + " N " + nick + " 1 " + time + " " + ident + " " + host + " "+modes+" " + nick + " B]AAAB " + numeric+num+" :" + desc);\r
cb67c259
O
1558 dbc.addUser(numeric+num,nick,ident+"@"+host,modes,nick,true,numeric,"0.0.0.0","0");\r
1559 }\r
1560\r
1561 /**\r
1562 * create a fake user\r
1563 * @param nick fake nickname\r
1564 * @param ident fake ident\r
1565 * @param host fake host\r
1566 * @param desc fake description\r
1567 */\r
1568 public void cmd_create_service(String numeric, String num, String nick, String ident, String host, String ip, String modes, String desc)\r
1569 {\r
1570 String time = get_time();\r
32310e5f 1571 ircsend(numeric + " N " + nick + " 1 " + time + " " + ident + " " + host + " "+modes+" " + nick + " "+base64Encode(ipToLong(ip))+" " + numeric+num+" :" + desc);\r
cb67c259 1572 dbc.addUser(numeric+num,nick,ident+"@"+host,modes,nick,true,numeric,"0.0.0.0","0");\r
b1d4498c 1573 }\r
1574\r
1575 /**\r
1576 * kill a fake user\r
1577 * @param nume fake numeric to kill\r
1578 */\r
1579 public void cmd_kill_service(String nume, String msg)\r
1580 {\r
1581 ircsend(nume + " Q :"+msg);\r
1582 dbc.delUser(nume);\r
1583 }\r
1584\r
1585 /**\r
1586 * create a fake user\r
1587[>in <] >> AB SQ spamscan.borknet.org 1135697097 :EOF from client\r
1588[>in <] >> AB S spamscan.borknet.org 2 0 1135956212 J10 ]S]]] +s :BorkNet Spamscan\r
1589[>in <] >> ]S EB\r
1590[>in <] >> ]S N S 2 1135956212 TheSBot spamscan.borknet.org +owkgrX S B]AAAB ]SAAA :BorkNet Spamscan\r
1591[>in <] >> ]SAAA J #coder-com 949217470\r
1592[>out<] >> ]QAAA M #coder-com +v ]SAAA\r
1593[>in <] >> ]S OM #coder-com +ov ]SAAA ]SAAA\r
1594[>in <] >> ]S EA\r
1595 */\r
1596 public void cmd_create_serer(String host, String num, String desc)\r
1597 {\r
1598 String time = get_time();\r
1599 ircsend(numeric + " S " + host + " 2 0 " + time + " J10 " + num + "]]] +s :"+desc);\r
cb67c259 1600 dbc.addServer(num,host,numeric,true);\r
b1d4498c 1601 }\r
1602\r
1603 /**\r
1604 * kill a fake user\r
1605 * @param nume fake numeric to kill\r
1606 */\r
1607 public void cmd_kill_server(String host, String msg)\r
1608 {\r
1609 String time = get_time();\r
1610 ircsend(numeric + " SQ "+host+ " 0 :"+msg);\r
1611 dbc.delServer(host);\r
1612 }\r
1613\r
cb67c259
O
1614 public void cmd_sethost(String num, String ident, String host, String modes)\r
1615 {\r
1616 ircsend(numeric + " SH " + num + " " + ident + " " + host);\r
1617 if (!modes.contains("h"))\r
1618 {\r
1619 dbc.setUserField(num, 3, modes + "h");\r
1620 }\r
1621 dbc.setUserField(num, 8, ident + "@" + host);\r
1622 }\r
1623\r
b1d4498c 1624 /**\r
1625 * get the system time\r
1626 *\r
1627 * @return the system time\r
1628 */\r
1629 public String get_time()\r
1630 {\r
cb67c259
O
1631 Calendar cal = Calendar.getInstance();\r
1632 long l = (cal.getTimeInMillis() / 1000);\r
1633 return l+"";\r
b1d4498c 1634 }\r
1635\r
1636 /**\r
1637 * gets executed every ping (90 seconds)\r
1638 */\r
cb67c259 1639 public void timerTick()\r
b1d4498c 1640 {\r
cb67c259 1641 if(cleaner == 960)\r
b1d4498c 1642 {\r
578f8ab6 1643 if(debug)\r
1644 {\r
1645 dbc.save();\r
1646 }\r
8a3ce9f6 1647 dbc.clean();\r
b1d4498c 1648 mod.clean();\r
1649 cleaner = 0;\r
cb67c259 1650 System.gc();\r
b1d4498c 1651 return;\r
1652 }\r
8a3ce9f6 1653 else\r
1654 {\r
1655 cleaner++;\r
1656 }\r
cb67c259 1657 ser.timerTick();\r
b1d4498c 1658 }\r
1659\r
1660 /**\r
1661 * Base64 decoding\r
1662 */\r
32310e5f 1663 public long base64Decode(String numer)\r
b1d4498c 1664 {\r
1665 char num[] = numer.toCharArray();\r
32310e5f 1666 long base64n = 0;\r
b1d4498c 1667 int pwr = num.length-1;\r
1668 for(char c : num)\r
1669 {\r
1670 int d = 0;\r
1671 switch (c) {\r
1672 case 'A': d = 0; break; case 'B': d = 1; break;\r
1673 case 'C': d = 2; break; case 'D': d = 3; break;\r
1674 case 'E': d = 4; break; case 'F': d = 5; break;\r
1675 case 'G': d = 6; break; case 'H': d = 7; break;\r
1676 case 'I': d = 8; break; case 'J': d = 9; break;\r
1677 case 'K': d = 10; break; case 'L': d = 11; break;\r
1678 case 'M': d = 12; break; case 'N': d = 13; break;\r
1679 case 'O': d = 14; break; case 'P': d = 15; break;\r
1680 case 'Q': d = 16; break; case 'R': d = 17; break;\r
1681 case 'S': d = 18; break; case 'T': d = 19; break;\r
1682 case 'U': d = 20; break; case 'V': d = 21; break;\r
1683 case 'W': d = 22; break; case 'X': d = 23; break;\r
1684 case 'Y': d = 24; break; case 'Z': d = 25; break;\r
1685 case 'a': d = 26; break; case 'b': d = 27; break;\r
1686 case 'c': d = 28; break; case 'd': d = 29; break;\r
1687 case 'e': d = 30; break; case 'f': d = 31; break;\r
1688 case 'g': d = 32; break; case 'h': d = 33; break;\r
1689 case 'i': d = 34; break; case 'j': d = 35; break;\r
1690 case 'k': d = 36; break; case 'l': d = 37; break;\r
1691 case 'm': d = 38; break; case 'n': d = 39; break;\r
1692 case 'o': d = 40; break; case 'p': d = 41; break;\r
1693 case 'q': d = 42; break; case 'r': d = 43; break;\r
1694 case 's': d = 44; break; case 't': d = 45; break;\r
1695 case 'u': d = 46; break; case 'v': d = 47; break;\r
1696 case 'w': d = 48; break; case 'x': d = 49; break;\r
1697 case 'y': d = 50; break; case 'z': d = 51; break;\r
1698 case '0': d = 52; break; case '1': d = 53; break;\r
1699 case '2': d = 54; break; case '3': d = 55; break;\r
1700 case '4': d = 56; break; case '5': d = 57; break;\r
1701 case '6': d = 58; break; case '7': d = 59; break;\r
1702 case '8': d = 60; break; case '9': d = 61; break;\r
1703 case '[': d = 62; break; case ']': d = 63; break;\r
1704 default: break;\r
1705 }\r
1706 if(pwr != 0)\r
1707 {\r
1708 base64n += (d*Math.pow(64,pwr));\r
1709 }\r
1710 else\r
1711 {\r
1712 base64n += d;\r
1713 }\r
1714 pwr--;\r
1715 }\r
32310e5f 1716 return base64n;\r
b1d4498c 1717 }\r
1718\r
32310e5f 1719 public String base64Encode(long numer)\r
cb67c259
O
1720 {\r
1721 String base64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789[]";\r
1722 char base[] = base64.toCharArray();\r
1723 String encoded = "";\r
1724 while(numer>0)\r
1725 {\r
32310e5f 1726 long i = numer%64;\r
1727 int index = (int) i;\r
cb67c259
O
1728 encoded = base[index] + encoded;\r
1729 numer = (int) Math.ceil(numer/64);\r
1730 }\r
1731 return encoded;\r
cb67c259
O
1732 }\r
1733\r
32310e5f 1734 public long ipToLong(String addr)\r
cb67c259
O
1735 {\r
1736 String[] addrArray = addr.split("\\.");\r
32310e5f 1737 long num = 0;\r
cb67c259
O
1738 for (int i=0;i<addrArray.length;i++)\r
1739 {\r
1740 int power = 3-i;\r
32310e5f 1741 num += ((Long.parseLong(addrArray[i])%256 * Math.pow(256,power)));\r
cb67c259
O
1742 }\r
1743 return num;\r
1744 }\r
1745\r
32310e5f 1746 public String longToIp(long i)\r
cb67c259
O
1747 {\r
1748 return ((i >> 24 ) & 0xFF) + "." + ((i >> 16 ) & 0xFF) + "." + ((i >> 8 ) & 0xFF) + "." + (i & 0xFF);\r
1749 }\r
1750\r
32310e5f 1751/**\r
1752 * process the End of Burst\r
1753 */\r
b1d4498c 1754 private void srv_EB()\r
1755 {\r
1756 //get the time\r
1757 String time = get_time();\r
1758 //create myself\r
1759 ircsend(numeric + " N " + nick + " 1 " + time + " " + ident + " " + host + " +oXwkgdr " + nick + " B]AAAB " + numeric+corenum+" :" + description);\r
cb67c259 1760 dbc.addUser(numeric+corenum, nick,ident+"@"+host,"+oXwkgdr",nick,true,numeric,"127.0.0.1","0");\r
b1d4498c 1761 dbc.setAuthField(nick,5, get_time());\r
1762 //join my debugchannel\r
1763 cmd_join(corenum,reportchan);\r
1764 //i'm done\r
1765 ircsend(numeric + " EA");\r
1766 mod = new CoreModControl(this, modules);\r
1767 }\r
1768}