1 18 package net.sf.drftpd.event.irc; 19 20 import net.sf.drftpd.event.InviteEvent; 21 import net.sf.drftpd.master.ConnectionManager; 22 import net.sf.drftpd.master.usermanager.NoSuchUserException; 23 import net.sf.drftpd.master.usermanager.User; 24 import net.sf.drftpd.master.usermanager.UserFileException; 25 26 import org.apache.log4j.Level; 27 import org.apache.log4j.Logger; 28 import org.drftpd.plugins.*; 29 30 import f00f.net.irc.martyr.GenericCommandAutoService; 31 import f00f.net.irc.martyr.InCommand; 32 import f00f.net.irc.martyr.commands.MessageCommand; 33 34 38 public class Invite 39 extends GenericCommandAutoService 40 implements IRCPluginInterface { 41 private static final Logger logger = Logger.getLogger(Invite.class); 42 43 public String getCommands() { 44 return "!invite(msg)"; 45 } 46 47 private ConnectionManager _cm; 48 49 public Invite(SiteBot ircListener) { 50 super(ircListener.getIRCConnection()); 51 _cm = ircListener.getConnectionManager(); 52 } 53 54 protected void updateCommand(InCommand command) { 55 if (!(command instanceof MessageCommand)) 56 return; 57 MessageCommand msgc = (MessageCommand) command; 58 String msg = msgc.getMessage(); 59 if (msg.startsWith("!invite ") 60 && msgc.isPrivateToUs(this.getConnection().getClientState())) { 61 String args[] = msg.split(" "); 62 User user; 63 try { 64 user = _cm.getUserManager().getUserByName(args[1]); 65 } catch (NoSuchUserException e) { 66 logger.log(Level.WARN, args[1] + " " + e.getMessage(), e); 67 return; 68 } catch (UserFileException e) { 69 logger.log(Level.WARN, "", e); 70 return; 71 } 72 if (user.checkPassword(args[2])) { 73 logger.info( 74 "Invited \"" 75 + msgc.getSourceString() 76 + "\" as user " 77 + user.getUsername()); 78 getConnectionManager().dispatchFtpEvent( 81 new InviteEvent("INVITE", msgc.getSource().getNick())); 82 } else { 83 logger.log( 84 Level.WARN, 85 msgc.getSourceString() 86 + " attempted invite with bad password: " 87 + msgc); 88 } 89 } 90 } 91 92 private ConnectionManager getConnectionManager() { 93 return _cm; 94 } 95 } 96 | Popular Tags |