f00f.net.irc.martyr
Class AutoRegister
java.lang.Object
|
+--f00f.net.irc.martyr.GenericCommandAutoService
|
+--f00f.net.irc.martyr.GenericAutoService
|
+--f00f.net.irc.martyr.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.
|
Constructor Summary |
AutoRegister(IRCConnection connection,
java.lang.String nick,
java.lang.String user,
java.lang.String name)
|
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
MAX_ATTEMPTS
public static final int MAX_ATTEMPTS
AutoRegister
public AutoRegister(IRCConnection connection,
java.lang.String nick,
java.lang.String user,
java.lang.String name)
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.
updateState
protected void updateState(State state)
- Overrides:
updateState in class GenericAutoService
updateCommand
protected void updateCommand(InCommand command)
- Overrides:
updateCommand in class GenericCommandAutoService
toString
public java.lang.String toString()
- Overrides:
toString in class java.lang.Object
Copyright © 2000,2001,2002,2003 f00f networks.