Class AutoDccSetup

  extended by f00f.net.irc.martyr.GenericCommandAutoService
      extended by f00f.net.irc.martyr.dcc.AutoDccSetup
All Implemented Interfaces:

public abstract class AutoDccSetup
extends GenericCommandAutoService

AutoDccSetup enables an application to "listen" for when another client is offering a DCC connection to us. AutoDccSetup checks incoming CTCPs to see if they are DCC connection requests, and if so, sets up the connection. You can use the AutoDccSetup by subclassing it with your own AutoDccSetup and overriding the appropriate methods.

In order to use this class you must provide an implementation for authorizeConnect. Additionally, you will want to override getDccChatHandler and/or getDccSendHandler, so that a customized version of the stock DccChatHandler and DccSendHandler is provided. This gives you easy access to the chat stream and file stream, respectively.

Note that all the methods in this class are executed in the event handler thread. The dcc session should occur in a seperate thread, which is why getDccChatHandler and getDccSendHandler return seperate classes. The handler classes are threads which are spawned by AutoDccSetup and should self-terminate.

DccTestBot provides a simple example of how DCC works.

See Also:
getDccChatHandler(java.net.Socket), getDccSendHandler(java.net.Socket, java.lang.String, int)

Field Summary
Fields inherited from class f00f.net.irc.martyr.GenericCommandAutoService
connection, enabled
Constructor Summary
AutoDccSetup(IRCConnection connection)
Method Summary
protected abstract  boolean authorizeConnect(DccType type, java.lang.String argument, java.net.InetAddress netaddr, int port, int filesize)
          This is called after parsing the request to find out if the connection should be performed.
protected  DccChatHandler getDccChatHandler(java.net.Socket socket)
          Returns a DCC chat handler.
protected  DccSendHandler getDccSendHandler(java.net.Socket socket, java.lang.String filename, int filesize)
          Returns a DCC file "send" (receive to us) handler.
protected  void handleCtcp(CtcpMessage ctcpMsg)
protected  void handleDccConnection(java.net.Socket socket, DccType type, java.lang.String filename, int filesize)
          Handles a chat or send connection.
protected  java.net.Socket makeSocket(java.net.InetAddress dest, int port)
          Generates a connected socket, connected to the machine that made the request for a DCC.
 java.lang.String toString()
 void updateCommand(InCommand updated)
          Checks to see if the message is a CTCP message, and if so, calls handleCtcp.
Methods inherited from class f00f.net.irc.martyr.GenericCommandAutoService
disable, enable, getConnection, isEnabled, update
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

Constructor Detail


public AutoDccSetup(IRCConnection connection)
Method Detail


public void updateCommand(InCommand updated)
Checks to see if the message is a CTCP message, and if so, calls handleCtcp. Exceptions thrown by handleCtcp are ignored. If you wish to handle exceptions, you should override this method. Simply check if updated is an instance of CtcpMessage, and then call handleCtcp.

Specified by:
updateCommand in class GenericCommandAutoService


protected void handleCtcp(CtcpMessage ctcpMsg)
                   throws DccException,
ctcpMsg - Message to be handled
InvalidDccException - if the DCC of not of a known type
UnauthorizedDccException - if the DCC is not authorized
java.io.IOException - if the connection failed.


protected DccChatHandler getDccChatHandler(java.net.Socket socket)
Returns a DCC chat handler. A chat session consists of each side sending a line of text over the socket, whenever desired.

socket - Socket where the dcc chat will be handled
DccChatHandler instance tied to a socket


protected DccSendHandler getDccSendHandler(java.net.Socket socket,
                                           java.lang.String filename,
                                           int filesize)
Returns a DCC file "send" (receive to us) handler. A DCC file transfer session is fairly slow, but effective, peer to peer scheme. A DccSendHandler subclass does not need to worry about the details of the protocol, a subclass merely needs to provide a stream that the file can be written out to.

socket - Socket where dcc send will be handled
filename - Filename to send
filesize - Size of file to send
DccSendHandler instance tied to socket


protected void handleDccConnection(java.net.Socket socket,
                                   DccType type,
                                   java.lang.String filename,
                                   int filesize)
Handles a chat or send connection. It calls either getDccSendHandler or getDccChatHandler and calls start() on the result.

socket - Socket where dcc connection will be handled
type - Type of dcc event
filename - Name of file involved in dcc event
filesize - Size of file involved in dcc event


protected java.net.Socket makeSocket(java.net.InetAddress dest,
                                     int port)
                              throws java.io.IOException
Generates a connected socket, connected to the machine that made the request for a DCC.

dest - Address we will connect to
port - Port we will connect to
Socket connected to address and port
java.io.IOException - if unable to create socket


protected abstract boolean authorizeConnect(DccType type,
                                            java.lang.String argument,
                                            java.net.InetAddress netaddr,
                                            int port,
                                            int filesize)
This is called after parsing the request to find out if the connection should be performed. Note that execution of this occurrs in the event thread, so if an option is presented to the user, a subclass should override update(...) so that processing occurs in its own thread and does not block the event handler.

type - Either DccType.SEND or DccType.CHAT
argument - "CHAT" if a chat, a filename if a file.
netaddr - The address, although only the raw IP will be useful.
port - The port to connect on
filesize - The filesize, if one was provided.
True or false if connection is authorized


public java.lang.String toString()
toString in class java.lang.Object

Copyright © 2000-2007 Ben Damm, Daniel Henninger, et al.