KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > drftpd > master > command > plugins > IRC


1 /*
2  * This file is part of DrFTPD, Distributed FTP Daemon.
3  *
4  * DrFTPD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * DrFTPD is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with DrFTPD; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18 package net.sf.drftpd.master.command.plugins;
19
20 import net.sf.drftpd.ObjectNotFoundException;
21 import net.sf.drftpd.master.BaseFtpConnection;
22 import net.sf.drftpd.master.FtpReply;
23 import net.sf.drftpd.master.FtpRequest;
24 import net.sf.drftpd.master.command.CommandManager;
25 import net.sf.drftpd.master.command.CommandManagerFactory;
26 import net.sf.drftpd.master.usermanager.NoSuchUserException;
27
28 import org.apache.log4j.Logger;
29 import org.drftpd.commands.CommandHandler;
30 import org.drftpd.commands.CommandHandlerFactory;
31 import org.drftpd.commands.UnhandledCommandException;
32 import org.drftpd.plugins.SiteBot;
33
34 /**
35  * @author mog
36  * @version $Id: IRC.java,v 1.4.2.1 2004/06/19 23:37:26 mog Exp $
37  */

38 public class IRC implements CommandHandlerFactory, CommandHandler {
39
40     private static final Logger logger = Logger.getLogger(IRC.class);
41
42     public IRC() {
43         super();
44     }
45
46     public FtpReply execute(BaseFtpConnection conn)
47         throws UnhandledCommandException {
48         try {
49             if (!conn.getUser().isAdmin()) {
50                 return FtpReply.RESPONSE_530_ACCESS_DENIED;
51             }
52         } catch (NoSuchUserException e1) {
53             throw new RuntimeException JavaDoc(e1);
54         }
55         SiteBot irc;
56         try {
57             irc =
58                 (SiteBot) conn.getConnectionManager().getFtpListener(
59                     SiteBot.class);
60         } catch (ObjectNotFoundException e) {
61             return new FtpReply(500, "IRCListener not loaded");
62         }
63
64         if (!conn.getRequest().hasArgument())
65             return FtpReply.RESPONSE_501_SYNTAX_ERROR;
66         FtpRequest req2 = new FtpRequest(conn.getRequest().getArgument());
67         if (req2.getCommand().equals("RECONNECT")) {
68             irc.reconnect();
69             return new FtpReply(
70                 200,
71                 "Told bot to disconnect, auto-reconnect should handle the rest");
72         } else if (req2.getCommand().equals("DISCONNECT")) {
73             irc.disconnect();
74             return new FtpReply(200, "Told bot to disconnect");
75         } else if (req2.getCommand().equals("CONNECT")) {
76             try {
77                 irc.connect();
78                 return new FtpReply(200, "Sitebot connected");
79             } catch (Exception JavaDoc e) {
80                 logger.warn("", e);
81                 return new FtpReply(500, e.getMessage());
82             }
83         } else if (req2.getCommand().equals("SAY")) {
84             irc.sayGlobal(req2.getArgument());
85             return new FtpReply(200, "Said: " + req2.getArgument());
86         }
87         return new FtpReply(501, conn.jprintf(IRC.class, "irc.usage"));
88     }
89
90     public CommandHandler initialize(
91         BaseFtpConnection conn,
92         CommandManager initializer) {
93         return this;
94     }
95
96     public String JavaDoc[] getFeatReplies() {
97         return null;
98     }
99
100     public void load(CommandManagerFactory initializer) {
101     }
102
103     public void unload() {
104     }
105
106 }
107
Popular Tags