3 # BorkNet Services Core
7 # Copyright (C) 2004 Ozafy - ozafy@borknet.org - http://www.borknet.org
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.
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.
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.
28 This one only parses private messages and relays them to commands.
30 However, it can parse any message on the network, and could infact
31 be adjusted to support diffrent protocols (in theory ;)
36 import java
.security
.*;
37 import borknet_services
.core
.*;
40 * The server communication class of the Q IRC Bot.
41 * @author Ozafy - ozafy@borknet.org - http://www.borknet.org
53 /** the server's numeric */
54 private String numeric
;
55 /** the bot's numeric */
56 private String corenum
;
57 /** the channel we report to */
58 private String reportchan
;
59 /** our version reply */
60 private String version
;
61 /** counts the number of received pings, used as a timer for channel limits */
62 private int limit
= 0;
68 * Constructs a Server communicator.
69 * @param B The main bot
70 * @param dbc The connection to the database
72 public Server(Core C
, V Bot
)
76 CC
= new Commands(C
,Bot
);
79 numeric
= C
.get_numeric();
80 corenum
= C
.get_corenum();
81 version
= C
.get_version();
82 reportchan
= C
.get_reportchan();
85 public void parse(ArrayList
<String
> params
)
87 String source
= params
.get(0);
88 String command
= params
.get(1);
89 if(command
.equals("P"))
93 else if(command
.equals("N"))
95 if(Bot
.get_qwebirc() || Bot
.get_automatic())
104 * @param me Server it's going to.
105 * @param username numeric of the user talking to me
106 * @param message the message we got from the user
108 public void privmsg(ArrayList
<String
> params
)
114 * Handles N lines, these can be a user nickchange, or new clients connecting
116 * @param usernumeric the user's numeric
117 * @param params raw irc data
119 public void nickchange(ArrayList
<String
> params
)
121 //AB N Ozafy 1 1119649303 ozafy bob.be.borknet.org +oiwkgrxXnIh Ozafy Darth@Vader B]AAAB ABAXs :Laurens Panier
122 String source
= params
.get(0);
123 if(source
.length() < 3)
127 String ident
= params
.get(5);
131 ip
= InetAddress
.getByName(params
.get(6)).getHostAddress();
133 catch(UnknownHostException e
)
137 String numeric
= params
.get(params
.size()-2);
138 if(Bot
.get_qwebirc() && params
.get(6).equals(Bot
.get_qhost()))
142 long realip
= Long
.parseLong(ident
.substring(1),16);
143 setHost(numeric
, Bot
.get_qident(), C
.longToHost(realip
));
145 catch(Exception longex
)
150 else if(Bot
.get_automatic())
152 String vhost
= encrypt(ip
) + "." + Bot
.get_vhost();
153 setHost(numeric
, ident
, vhost
);
156 catch(ArrayIndexOutOfBoundsException e
)
158 C
.printDebug("ArrayIndexOutOfBoundsException in srv_nickchange! (1)");
160 C
.report("ArrayIndexOutOfBoundsException in srv_nickchange! (1)");
165 public void setHost(String numeric
, String ident
, String vhost
)
167 C
.cmd_sethost(numeric
, ident
, vhost
);
170 public String
encrypt(String str
)
174 for(int i
= 0; i
< str
.length(); i
++)
176 hash
= (hash
<< 4) + str
.charAt(i
);
177 if((x
= hash
& 0xF0000000L
) != 0)