]> jfr.im git - irc/borknet/trunk.git/blame - core/modules/s/Commands.java
Q: Removed the '!' at the end of the line directly giving the userpassword
[irc/borknet/trunk.git] / core / modules / s / Commands.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# MERCHANTABotILITY 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, Botoston, MA 02111-1307, USA.\r
22#\r
b1d4498c 23*/\r
24import java.util.*;\r
25import java.net.*;\r
26import java.io.*;\r
27import borknet_services.core.*;\r
28\r
29\r
30/**\r
31 * The server communication class of the Q IRC Botot.\r
32 * @author Ozafy - ozafy@borknet.org - http://www.borknet.org\r
33 */\r
34public class Commands\r
35{\r
36 private ArrayList<Object> cmds = new ArrayList<Object>();\r
37 private ArrayList<String> cmdn = new ArrayList<String>();\r
38 private Core C;\r
39 private S Bot;\r
40 private DBControl dbc;\r
41 private String numeric = "";\r
42 private String botnum = "";\r
43 private String network = "";\r
44 private String rules = "";\r
59411fcf 45 private Spamwords spamwords;\r
46 public Commands(Core C, S Bot)\r
b1d4498c 47 {\r
48 this.C = C;\r
49 this.Bot = Bot;\r
50 dbc = Bot.getDBC();\r
51 numeric = Bot.get_num();\r
52 botnum = Bot.get_corenum();\r
53 cmds = Bot.getCmds();\r
54 cmdn = Bot.getCmdn();\r
55 rules = Bot.getRules();\r
56 network = C.get_net();\r
59411fcf 57 spamwords = new Spamwords(C);\r
b1d4498c 58 }\r
59\r
60 public void privmsg(String target, String username, String message)\r
61 {\r
62 if(target.startsWith("#"))\r
63 {\r
cb67c259 64 if(dbc.SchanExists(target) && dbc.getAuthLev(username) < 2 && !dbc.isService(username))\r
b1d4498c 65 {\r
66 String f = dbc.getChanFlags(target);\r
67 if(f.equals("n"))\r
68 {\r
69 spamscan(username, message);\r
70 }\r
71 else if(f.equals("i"))\r
72 {\r
cb67c259 73 C.cmd_dis(username, "You are violating "+network+" rules. Please read "+rules+". ID: "+dbc.getID());\r
b1d4498c 74 }\r
75 }\r
76 }\r
77 if(!target.equals(numeric) && !target.equals(numeric+botnum) && !target.equalsIgnoreCase(Bot.get_nick()+"@"+Bot.get_host())) return;\r
78 String command = "";\r
79 try\r
80 {\r
81 String[] result = message.split("\\s");\r
82 command = result[0].toLowerCase();\r
83 }\r
84 catch(ArrayIndexOutOfBoundsException e)\r
85 {\r
86 command = message.toLowerCase();\r
87 }\r
88 if(command.equals("help"))\r
89 {\r
90 String cmd = "";\r
91 try\r
92 {\r
93 String[] result = message.split("\\s");\r
94 cmd = result[1].toLowerCase();\r
95 }\r
96 catch(ArrayIndexOutOfBoundsException e)\r
97 {\r
bf5f32d5 98 showCommands(username);\r
b1d4498c 99 return;\r
100 }\r
101 int compo = cmdn.indexOf(cmd);\r
102 if(compo > -1)\r
103 {\r
104 Command ccommand = (Command) cmds.get(compo);\r
105 CoreDBControl dbc = C.get_dbc();\r
cb67c259 106 int lev = dbc.getAuthLev(username);\r
b1d4498c 107 ccommand.parse_help(C,Bot,numeric,botnum,username,lev);\r
108 }\r
109 else\r
110 {\r
111 C.cmd_notice(numeric, botnum,username,"This command is either unknown, or you need to be opered up to use it.");\r
112 }\r
113 return;\r
114 }\r
115 if(command.equals("showcommands"))\r
116 {\r
bf5f32d5 117 showCommands(username);\r
b1d4498c 118 return;\r
119 }\r
120 int compo = cmdn.indexOf(command);\r
121 if(command.startsWith("\1"))\r
122 {\r
123 compo = cmdn.indexOf(command.replace("\1",""));\r
124 }\r
125 if(compo > -1)\r
126 {\r
127 Command ccommand = (Command) cmds.get(compo);\r
128 ccommand.parse_command(C,Bot,numeric,botnum,username,message);\r
129 }\r
130 else\r
131 {\r
132 C.cmd_notice(numeric, botnum,username,"This command is either unknown, or you need to be opered up to use it.");\r
133 C.cmd_notice(numeric, botnum,username,"/msg "+Bot.get_nick()+" showcommands");\r
134 }\r
135 }\r
bf5f32d5 136 private void showCommands(String username)\r
137 {\r
138 C.cmd_notice(numeric, botnum,username,"The following commands are available to you:");\r
139 CoreDBControl dbc = C.get_dbc();\r
140 String user[] = dbc.getUserRow(username);\r
141 int lev = 0;\r
142 if(!user[4].equals("0"))\r
143 {\r
144 String auth[] = dbc.getAuthRow(user[4]);\r
145 lev = Integer.parseInt(auth[3]);\r
146 }\r
147 for(int n=0; n<cmds.size(); n++)\r
148 {\r
149 Command ccommand = (Command) cmds.get(n);\r
150 ccommand.showcommand(C,Bot,numeric,botnum,username,lev);\r
151 }\r
152 C.cmd_notice(numeric, botnum,username,"End of list.");\r
153 }\r
b1d4498c 154 private void spamscan(String username, String msg)\r
155 {\r
27d60a0f 156 dbc.addPoints(username, Bot.getSpamtext());\r
b1d4498c 157 if(msg.contains("#"))\r
158 {\r
159 if(msg.indexOf("#",msg.indexOf("#")) > -1)\r
160 {\r
161 String chans[] = msg.split("\\s");\r
162 for (String chan : chans)\r
163 {\r
164 if(chan.startsWith("#") && dbc.chanExists(chan))\r
165 {\r
27d60a0f 166 dbc.addPoints(username, Bot.getSpamchan());\r
b1d4498c 167 }\r
168 }\r
169 }\r
170 else\r
171 {\r
172 String chan = msg.substring(msg.indexOf("#"));\r
173 if(chan.contains(" "))\r
174 {\r
175 chan = chan.substring(chan.indexOf("#"),chan.indexOf(" ",chan.indexOf("#")));\r
176 }\r
177 if(dbc.chanExists(chan))\r
178 {\r
27d60a0f 179 dbc.addPoints(username, Bot.getSpamchan());\r
b1d4498c 180 }\r
181 }\r
182 }\r
183 if(msg.contains("http://") || msg.contains("www."))\r
184 {\r
27d60a0f 185 dbc.addPoints(username, Bot.getSpamweb());\r
b1d4498c 186 }\r
187 if(dbc.repeat(username,msg))\r
188 {\r
27d60a0f 189 dbc.addPoints(username, Bot.getSpamrepeat());\r
b1d4498c 190 }\r
59411fcf 191 dbc.addPoints(username, spamwords.getPoints(msg));\r
b1d4498c 192 dbc.setMsg(username,msg);\r
27d60a0f 193 if(dbc.getPoints(username) >= Bot.getSpamwarning())\r
b1d4498c 194 {\r
195 C.cmd_notice(numeric, botnum,username, "You are violating "+network+" rules. Please read "+rules+" and cease your abuse.");\r
196 }\r
27d60a0f 197 if(dbc.getPoints(username) >= Bot.getSpamkill())\r
b1d4498c 198 {\r
cb67c259 199 C.cmd_dis(username, "You are violating "+network+" rules. Please read "+rules+". ID: "+dbc.getID());\r
b1d4498c 200 }\r
201 }\r
202}