1 /*****************************************************/
\r
2 /* This java file is a part of the */
\r
4 /* - Plouf's Java IRC Client - */
\r
6 /* Copyright (C) 2002 - 2005 Philippe Detournay */
\r
8 /* All contacts : theplouf@yahoo.com */
\r
10 /* PJIRC is free software; you can redistribute */
\r
11 /* it and/or modify it under the terms of the GNU */
\r
12 /* General Public License as published by the */
\r
13 /* Free Software Foundation; version 2 or later of */
\r
16 /* PJIRC is distributed in the hope that it will */
\r
17 /* be useful, but WITHOUT ANY WARRANTY; without */
\r
18 /* even the implied warranty of MERCHANTABILITY or */
\r
19 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU */
\r
20 /* General Public License for more details. */
\r
22 /* You should have received a copy of the GNU */
\r
23 /* General Public License along with PJIRC; if */
\r
24 /* not, write to the Free Software Foundation, */
\r
25 /* Inc., 59 Temple Place, Suite 330, Boston, */
\r
26 /* MA 02111-1307 USA */
\r
28 /*****************************************************/
\r
32 import irc.dcc.prv.DCCChatServer;
\r
33 import irc.dcc.prv.DCCFileHandler;
\r
35 import java.io.File;
\r
36 import java.util.Date;
\r
39 * The CTCP interpretor.
\r
41 public class CTCPInterpretor extends BasicInterpretor {
\r
45 // protected CTCPFilter _filter;
\r
46 protected ServerManager _mgr;
\r
49 * Create a new CTCPInterpretor.
\r
52 * global configuration.
\r
54 * next interpretor to use if command is unknown.
\r
58 public CTCPInterpretor(IRCConfiguration config, Interpretor next/*
\r
61 */, ServerManager mgr) {
\r
62 super(config, next);
\r
67 private void send(Server s, String destination, String msg) {
\r
68 s.say(destination, "\1" + msg + "\1");
\r
72 protected void handleCommand(Source source, String cmd, String[] parts, String[] cumul) {
\r
74 if (cmd.equals("ctcp")) {
\r
75 test(cmd, parts, 1);
\r
76 if (parts[1].toLowerCase(java.util.Locale.ENGLISH).equals("ping")) {
\r
77 test(cmd, parts, 2);
\r
78 send(source.getServer(), parts[2], "PING " + (new Date()).getTime());
\r
79 // _filter.ping(source.getServer(),parts[2]);
\r
80 } else if (parts[1].toLowerCase(java.util.Locale.ENGLISH).equals("action")) {
\r
81 test(cmd, parts, 2);
\r
82 if (source.talkable()) {
\r
83 send(source.getServer(), source.getName(), "ACTION " + cumul[2]);
\r
84 // _filter.action(source.getServer(),source.getName(),cumul[2]);
\r
85 source.action(source.getServer().getNick(), cumul[2]);
\r
87 source.report(getText(IRCTextProvider.INTERPRETOR_NOT_ON_CHANNEL));
\r
89 } else if (parts[1].toLowerCase(java.util.Locale.ENGLISH).equals("dcc")) {
\r
90 test(cmd, parts, 2);
\r
91 if (parts[2].toLowerCase(java.util.Locale.ENGLISH).equals("chat") && _ircConfiguration.getB("allowdccchat")) {
\r
92 test(cmd, parts, 3);
\r
93 // _filter.chat(source.getServer(),parts[3]);
\r
94 Server s = source.getServer();
\r
95 String nick = parts[3];
\r
97 DCCChatServer cserver = new DCCChatServer(_ircConfiguration, s.getNick(), nick);
\r
98 String arg = cserver.openPassive();
\r
99 if (arg.length() == 0) {
\r
100 cserver.sendStatusMessage(getText(IRCTextProvider.DCC_UNABLE_PASSIVE_MODE));
\r
102 send(s, nick, "DCC CHAT chat " + arg);
\r
104 _mgr.newServer(cserver, false);
\r
105 } catch (Throwable ex) {
\r
106 _ircConfiguration.internalError("dcc chat error", ex, "plouf@pjirc.com");
\r
109 } else if (parts[2].toLowerCase(java.util.Locale.ENGLISH).equals("send")
\r
110 && _ircConfiguration.getB("allowdccfile")) {
\r
111 String file = null;
\r
112 test(cmd, parts, 3);
\r
114 if (parts.length > 4)
\r
117 Server s = source.getServer();
\r
118 String nick = parts[3];
\r
122 f = new File(file);
\r
124 f = _ircConfiguration.getSecurityProvider().getLoadFile("Send file");
\r
126 DCCFileHandler handler = new DCCFileHandler(_ircConfiguration, nick, f);
\r
128 String filename = f.getName();
\r
129 if (filename.indexOf(" ") != -1)
\r
130 filename = guil + filename + guil;
\r
131 String arg = filename + " " + handler.send();
\r
132 send(s, nick, "DCC SEND " + arg);
\r
133 _mgr.newServer(handler, false);
\r
135 } catch (Throwable ex) {
\r
136 _ircConfiguration.internalError("dcc send error", ex, "plouf@pjirc.com");
\r
139 source.report(getText(IRCTextProvider.INTERPRETOR_UNKNOWN_DCC, parts[2]));
\r
141 } else if (parts[1].toLowerCase(java.util.Locale.ENGLISH).equals("raw")) {
\r
142 test(cmd, parts, 3);
\r
143 send(source.getServer(), parts[2], cumul[3]);
\r
144 // _filter.genericSend(source.getServer(),parts[2],cumul[3]);
\r
145 } else if (parts[1].toLowerCase(java.util.Locale.ENGLISH).equals("sound")) {
\r
146 test(cmd, parts, 2);
\r
147 send(source.getServer(), source.getName(), "SOUND " + parts[2]);
\r
149 test(cmd, parts, 2);
\r
150 send(source.getServer(), parts[2], parts[1]);
\r
151 // _filter.genericSend(source.getServer(),parts[2],parts[1]);
\r
154 super.handleCommand(source, cmd, parts, cumul);
\r
156 } catch (NotEnoughParametersException ex) {
\r
157 source.report(getText(IRCTextProvider.INTERPRETOR_INSUFFICIENT_PARAMETERS, ex.getMessage()));
\r