KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > drftpd > event > irc > Invite


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.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 /**
35  * @author mog
36  * @version $Id: Invite.java,v 1.9 2004/03/26 00:16:32 mog Exp $
37  */

38 public class Invite
39     extends GenericCommandAutoService
40     implements IRCPluginInterface {
41     private static final Logger logger = Logger.getLogger(Invite.class);
42
43     public String JavaDoc 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 JavaDoc msg = msgc.getMessage();
59         if (msg.startsWith("!invite ")
60             && msgc.isPrivateToUs(this.getConnection().getClientState())) {
61             String JavaDoc 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                 //_conn.sendCommand(
79
// new InviteCommand(msgc.getSource(), _channelName));
80
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