1 /*****************************************************/
2 /* This java file is a part of the */
4 /* - Plouf's Java IRC Client - */
6 /* Copyright (C) 2002 - 2004 Philippe Detournay */
8 /* All contacts : theplouf@yahoo.com */
10 /* PJIRC is free software; you can redistribute */
11 /* it and/or modify it under the terms of the GNU */
12 /* General Public License as published by the */
13 /* Free Software Foundation; version 2 or later of */
16 /* PJIRC is distributed in the hope that it will */
17 /* be useful, but WITHOUT ANY WARRANTY; without */
18 /* even the implied warranty of MERCHANTABILITY or */
19 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU */
20 /* General Public License for more details. */
22 /* You should have received a copy of the GNU */
23 /* General Public License along with PJIRC; if */
24 /* not, write to the Free Software Foundation, */
25 /* Inc., 59 Temple Place, Suite 330, Boston, */
26 /* MA 02111-1307 USA */
28 /*****************************************************/
32 import java.util.Enumeration;
37 public class IRCInterpretor extends BasicInterpretor {
39 * Create a new IRCInterpretor.
42 * global configuration.
44 public IRCInterpretor(IRCConfiguration config) {
49 protected void handleCommand(Source source, String cmd, String[] parts, String[] cumul) {
52 IRCServer server = (IRCServer) source.getServer();
53 if (cmd.equals("amsg")) {
55 Enumeration e = server.getChannels();
56 while (e.hasMoreElements()) {
57 ((Channel) e.nextElement()).sendString(cumul[1]);
59 } else if (cmd.equals("ame")) {
61 Enumeration e = server.getChannels();
62 while (e.hasMoreElements()) {
63 ((Channel) e.nextElement()).sendString("/me " + cumul[1]);
65 } else if (cmd.equals("list")) {
66 if (parts.length <= 1)
67 server.execute("LIST");
69 server.execute("LIST " + parts[1]);
70 } else if (cmd.equals("topic")) {
72 server.execute("TOPIC " + parts[1] + " :" + cumul[2]);
73 } else if (cmd.equals("away")) {
74 if (parts.length <= 1)
75 server.execute("AWAY");
77 server.execute("AWAY :" + cumul[1]);
78 } else if (cmd.equals("quit")) {
80 server.execute("QUIT :" + cumul[1]);
82 server.execute("QUIT");
83 } else if (cmd.equals("part")) {
85 if (parts.length == 2) {
86 server.execute("PART " + parts[1]);
88 server.execute("PART " + parts[1] + " :" + cumul[2]);
90 } else if (cmd.equals("kick")) {
92 if (parts.length == 3) {
93 server.execute("KICK " + parts[1] + " " + parts[2]);
95 server.execute("KICK " + parts[1] + " " + parts[2] + " :" + cumul[3]);
97 } else if (cmd.equals("notice")) {
99 server.execute("NOTICE " + parts[1] + " :" + cumul[2]);
100 source.report("-> -" + parts[1] + "- " + cumul[2]);
101 } else if (cmd.equals("onotice")) {
103 sendString(source, "/notice @" + parts[1] + " " + cumul[2]);
104 } else if (cmd.equals("join")) {
106 String chan = parts[1];
107 if (!chan.startsWith("#") && !chan.startsWith("!") && !chan.startsWith("&") && !chan.startsWith("+"))
109 if (parts.length <= 2)
110 server.execute("JOIN " + chan);
112 server.execute("JOIN " + chan + " " + parts[2]);
113 } else if (cmd.equals("j")) {
114 sendString(source, "/join " + cumul[1]);
115 } else if (cmd.equals("query")) {
117 server.getQuery(parts[1], true);
118 } else if (cmd.equals("ignore")) {
120 if (!server.ignore(parts[1])) {
121 server.addIgnore(parts[1]);
122 source.report(getText(IRCTextProvider.INTERPRETOR_IGNORE_ON, parts[1]));
124 } else if (cmd.equals("unignore")) {
126 if (server.ignore(parts[1])) {
127 server.removeIgnore(parts[1]);
128 source.report(getText(IRCTextProvider.INTERPRETOR_IGNORE_OFF, parts[1]));
130 } else if (cmd.equals("server")) {
134 if (parts.length > 2)
135 port = (new Integer(parts[2])).intValue();
136 if (parts.length > 3)
138 String host = parts[1];
139 if (server.isConnected())
141 server.setServers(new String[] { host }, new int[] { port }, new String[] { pass });
143 } else if (cmd.equals("connect")) {
145 } else if (cmd.equals("disconnect")) {
148 super.handleCommand(source, cmd, parts, cumul);
150 } catch (NotEnoughParametersException ex) {
151 source.report(getText(IRCTextProvider.INTERPRETOR_INSUFFICIENT_PARAMETERS, ex.getMessage()));