}
void registerConnection(String nick, String username, String hostname, String realName, String password) {
log.debug("registering connection");
Message nickMessage = new Message(MessageType.NICK, nick);
Message userMessage = new Message(MessageType.USER, username, hostname, hostname, realName);
if (password != null) {
/* Send a PASS message first */
connection.send(new Message(MessageType.PASS, password));
}
Message response;
try {
response = connection.request(
null,
MessageFilters.any(
MessageFilters.message(MessageType.RPL_ENDOFMOTD),
MessageFilters.message(MessageType.RPL_LUSERME),
MessageFilters.message(MessageType.RPL_LUSERCHANNELS),
MessageFilters.message(MessageType.RPL_LUSERCLIENT),
MessageFilters.message(MessageType.RPL_LUSEROP),
MessageFilters.message(MessageType.RPL_LUSERUNKNOWN),
MessageFilters.message(MessageType.ERR_NICKNAMEINUSE)),
nickMessage, userMessage).get(0);
} catch (InterruptedException e) {
throw new ConnectionException("Interrupted while awaiting connection registration response");
}
switch (response.getType()) {
case ERR_NICKNAMEINUSE:
throw new NickNameInUseException();
default:
log.debug("connection registered");
break;