KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > drftpd > plugins > OnConnect


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 org.drftpd.plugins;
19
20 import net.sf.drftpd.event.irc.IRCPluginInterface;
21 import f00f.net.irc.martyr.GenericAutoService;
22 import f00f.net.irc.martyr.IRCConnection;
23 import f00f.net.irc.martyr.InCommand;
24 import f00f.net.irc.martyr.State;
25 import f00f.net.irc.martyr.commands.JoinCommand;
26 import f00f.net.irc.martyr.commands.RawCommand;
27 import f00f.net.irc.martyr.commands.WelcomeCommand;
28 import f00f.net.irc.martyr.errors.ChannelBannedError;
29 import f00f.net.irc.martyr.errors.ChannelInviteOnlyError;
30 import f00f.net.irc.martyr.errors.ChannelLimitError;
31 import f00f.net.irc.martyr.errors.ChannelWrongKeyError;
32  
33 /**
34  * @author mog
35  * @version $Id: OnConnect.java,v 1.3 2004/04/25 18:15:19 mog Exp $
36  */

37 public class OnConnect extends GenericAutoService implements IRCPluginInterface {
38         private State _state;
39  
40         public OnConnect(SiteBot sitebot) {
41                 super(sitebot.getIRCConnection());
42                 IRCConnection connection = sitebot.getIRCConnection();
43  
44                 updateState( connection.getState() );
45                 _state = connection.getState();
46         }
47  
48         protected void updateState(State state) {}
49  
50         protected void updateCommand(InCommand command) {
51                 if(command.getState() != _state && command.getState() == State.REGISTERED && command instanceof WelcomeCommand) {
52                         onConnect((WelcomeCommand)command);
53                 }
54                 _state = command.getState();
55  
56                 if(command instanceof JoinCommand) {
57                         onJoin((JoinCommand)command);
58                 }
59                 else if(command instanceof ChannelInviteOnlyError) {
60                         needInvite((ChannelInviteOnlyError)command);
61                 }
62                 else if(command instanceof ChannelWrongKeyError) {
63                         needKey((ChannelWrongKeyError)command);
64                 }
65                 else if(command instanceof ChannelBannedError) {
66                         needUnban((ChannelBannedError)command);
67                 }
68                 else if(command instanceof ChannelLimitError) {
69                         needLimit((ChannelLimitError)command);
70                 }
71                 //TODO need-op?
72
}
73  
74         private void onJoin(JoinCommand command) {
75         }
76  
77         private void needLimit(ChannelLimitError error) {
78         }
79  
80         private void needUnban(ChannelBannedError error) {
81         }
82  
83         private void needKey(ChannelWrongKeyError error) {
84         }
85  
86         private void needInvite(ChannelInviteOnlyError error) {
87         }
88  
89         private void onConnect(WelcomeCommand command) {
90                 getConnection().sendCommand(new RawCommand("MODE "+command.getNick()+" :+i"));
91         }
92  
93         public String JavaDoc getCommands() {
94                 return null;
95         }
96 }
97
Popular Tags