f00f.net.irc.martyr.services
Class AutoRegister

java.lang.Object
  extended by f00f.net.irc.martyr.GenericCommandAutoService
      extended by f00f.net.irc.martyr.GenericAutoService
          extended by f00f.net.irc.martyr.services.AutoRegister
All Implemented Interfaces:
java.util.Observer

public class AutoRegister
extends GenericAutoService

AutoRegister performs the task of registering the user with the server once connected, including finding an appropriate nickname to use if the desired one is taken.

AutoRegister's default behaviour is to send the provided nickname. If it receives an ERR_NICKNAMEINUSE while unregistered, AutoRegister will try again, with an _ appended to the nick. If this fails five times, AutoRegister will ask the IRCConnection to disconnect(). Note that if it fails to connect it remains enabled, so that if IRCConnection.connect() is called, it will re-try the same 5 NICKs.

This default behaviour can be overridden by subclassing AutoRegister and overriding the getNickIterator( String baseNick ) method. It returns an instance of the java.util.Iterator interface which supplies nicknames (each object retreived from the Iterator is presumed to be a String). AutoRegister will iterate through the nickname list until there are no more items, at which point it will stop. For simple tasks such as providing a custom way to form new nicknames, overriding getNickIterator is sufficient.

AutoRegister will add itself as a state observer and as a command observer. It needs to receive the error.NickInUseError command so that it can re-try the registration, and it needs to detect when we transition into the UNREGISTERED state.

AutoRegister should be created before the IRCConnection.connect() is called. AutoRegister can be disabled by calling the 'disable()' method at any time. This simply removes AutoRegister as an observer for the state and commands.


Field Summary
static int MAX_ATTEMPTS
           
 
Fields inherited from class f00f.net.irc.martyr.GenericCommandAutoService
connection, enabled
 
Constructor Summary
AutoRegister(IRCConnection connection, java.lang.String nick, java.lang.String user, java.lang.String name)
           
AutoRegister(IRCConnection connection, java.lang.String nick, java.lang.String user, java.lang.String name, java.lang.String pass)
           
 
Method Summary
protected  java.util.Iterator getNickIterator(java.lang.String baseNick)
          This method supplies an Iterator that generates nicknames.
 java.lang.String toString()
           
protected  void updateCommand(InCommand command)
           
protected  void updateState(State state)
           
 
Methods inherited from class f00f.net.irc.martyr.GenericAutoService
disable, enable, update
 
Methods inherited from class f00f.net.irc.martyr.GenericCommandAutoService
getConnection, isEnabled
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

MAX_ATTEMPTS

public static final int MAX_ATTEMPTS
See Also:
Constant Field Values
Constructor Detail

AutoRegister

public AutoRegister(IRCConnection connection,
                    java.lang.String nick,
                    java.lang.String user,
                    java.lang.String name)

AutoRegister

public AutoRegister(IRCConnection connection,
                    java.lang.String nick,
                    java.lang.String user,
                    java.lang.String name,
                    java.lang.String pass)
Method Detail

getNickIterator

protected java.util.Iterator getNickIterator(java.lang.String baseNick)

This method supplies an Iterator that generates nicknames. Each successive failed attempt to login to the server with a nickname will be met with a new try using the next nickname in the iterator. When there are no more nicknames in the Iterator, AutoRegister gives up. Defining the Iterator as an anonymous class works well.

The iterator should iterate over String objects.

Parameters:
baseNick - The nickname passed into the constructor.
Returns:
Iterator over other attempts of nicks to try

updateState

protected void updateState(State state)
Specified by:
updateState in class GenericAutoService

updateCommand

protected void updateCommand(InCommand command)
Specified by:
updateCommand in class GenericCommandAutoService

toString

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


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