1 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 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 (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 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 [] getFeatReplies() { 97 return null; 98 } 99 100 public void load(CommandManagerFactory initializer) { 101 } 102 103 public void unload() { 104 } 105 106 } 107 | Popular Tags |