01: /*
02: * This file is part of DrFTPD, Distributed FTP Daemon.
03: *
04: * DrFTPD is free software; you can redistribute it and/or modify
05: * it under the terms of the GNU General Public License as published by
06: * the Free Software Foundation; either version 2 of the License, or
07: * (at your option) any later version.
08: *
09: * 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 org.drftpd.sitebot;
19:
20: import java.util.ArrayList;
21: import java.util.StringTokenizer;
22:
23: import net.sf.drftpd.event.InviteEvent;
24:
25: import org.apache.log4j.Level;
26: import org.apache.log4j.Logger;
27: import org.drftpd.GlobalContext;
28: import org.drftpd.commands.UserManagement;
29: import org.drftpd.plugins.SiteBot;
30: import org.drftpd.usermanager.NoSuchUserException;
31: import org.drftpd.usermanager.User;
32: import org.drftpd.usermanager.UserFileException;
33: import org.tanesha.replacer.ReplacerEnvironment;
34:
35: import f00f.net.irc.martyr.commands.MessageCommand;
36:
37: /**
38: * @author mog
39: * @version $Id: Invite.java 1513 2006-10-13 22:41:08Z tdsoul $
40: */
41: public class Invite extends IRCCommand {
42: private static final Logger logger = Logger.getLogger(Invite.class);
43:
44: public Invite(GlobalContext gctx) {
45: super (gctx);
46: }
47:
48: public ArrayList<String> doInvite(String args, MessageCommand msgc) {
49: ArrayList<String> out = new ArrayList<String>();
50: ReplacerEnvironment env = new ReplacerEnvironment(
51: SiteBot.GLOBAL_ENV);
52:
53: StringTokenizer st = new StringTokenizer(args);
54: if (st.countTokens() < 2)
55: return out;
56:
57: String username = st.nextToken();
58: String password = st.nextToken();
59:
60: User user;
61: try {
62: user = getGlobalContext().getUserManager().getUserByName(
63: username);
64: } catch (NoSuchUserException e) {
65: logger.log(Level.WARN, username + " " + e.getMessage(), e);
66: return out;
67: } catch (UserFileException e) {
68: logger.log(Level.WARN, "", e);
69: return out;
70: }
71: boolean success = user.checkPassword(password);
72: getGlobalContext().dispatchFtpEvent(
73: new InviteEvent(success ? "INVITE" : "BINVITE", msgc
74: .getSource().getNick(), user));
75:
76: String ident = msgc.getSource().getNick() + "!"
77: + msgc.getSource().getUser() + "@"
78: + msgc.getSource().getHost();
79:
80: if (success) {
81: logger.info("Invited \"" + ident + "\" as user "
82: + user.getName());
83: user.getKeyedMap()
84: .setObject(UserManagement.IRCIDENT, ident);
85: try {
86: user.commit();
87: } catch (UserFileException e1) {
88: logger.warn("Error saving userfile", e1);
89: }
90: } else {
91: logger.log(Level.WARN, msgc.getSourceString()
92: + " attempted invite with bad password: " + msgc);
93: }
94:
95: return out;
96: }
97:
98: }
|