org.relayirc.core
Class IRCConnection

java.lang.Object
  |
  +--org.relayirc.core.IRCConnection
All Implemented Interfaces:
IRCConstants, java.lang.Runnable

public class IRCConnection
extends java.lang.Object
implements java.lang.Runnable, IRCConstants

A socket connection to a RFC-1459 compatible IRC server. Parses incoming IRC messages, replies, commands and errors and notifies all listeners of such. Also provides a writeln() method for sending commands to the IRC server.

FIX: Currently, only one listener is allowed.

Author:
David M. Johnson

The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.mozilla.org/MPL/

Original Code: Relay IRC Chat Server
Initial Developer: David M. Johnson
Contributor(s): No contributors to this file
Copyright (C) 1997-2000 by David M. Johnson
All Rights Reserved.
See Also:
IRCConnectionListener, IRCConnectionAdapter, IdentServer

Field Summary
static int CONNECTED
           
static int CONNECTING
           
static int DISCONNECTED
           
static int DISCONNECTING
           
 
Fields inherited from interface org.relayirc.core.IRCConstants
ERR_ALREADYREGISTRED, ERR_BADCHANNELKEY, ERR_BANNEDFROMCHAN, ERR_CANNOTSENDTOCHAN, ERR_CANTKILLSERVER, ERR_CHANNELISFULL, ERR_CHANOPRIVSNEEDED, ERR_ERRONEUSNICKNAME, ERR_FILEERROR, ERR_INVITEONLYCHAN, ERR_KEYSET, ERR_NEEDMOREPARAMS, ERR_NICKCOLLISION, ERR_NICKNAMEINUSE, ERR_NOADMININFO, ERR_NOLOGIN, ERR_NOMOTD, ERR_NONICKNAMEGIVEN, ERR_NOOPERHOST, ERR_NOORIGIN, ERR_NOPERMFORHOST, ERR_NOPRIVILEGES, ERR_NORECIPIENT, ERR_NOSUCHCHANNEL, ERR_NOSUCHNICK, ERR_NOSUCHSERVER, ERR_NOTEXTTOSEND, ERR_NOTONCHANNEL, ERR_NOTOPLEVEL, ERR_NOTREGISTERED, ERR_PASSWDMISMATCH, ERR_SUMMONDISABLED, ERR_TOOMANYCHANNELS, ERR_TOOMANYTARGETS, ERR_UMODEUNKNOWNFLAG, ERR_UNKNOWNCOMMAND, ERR_UNKNOWNMODE, ERR_USERNOTINCHANNEL, ERR_USERONCHANNEL, ERR_USERSDISABLED, ERR_USERSDONTMATCH, ERR_WASNOSUCHNICK, ERR_WILDTOPLEVEL, ERR_YOUREBANNEDCREEP, RPL_ADMINEMAIL, RPL_ADMINLOC1, RPL_ADMINLOC2, RPL_ADMINME, RPL_AWAY, RPL_BANLIST, RPL_CHANNELMODEIS, RPL_CLOSEEND, RPL_CLOSING, RPL_ENDOFBANLIST, RPL_ENDOFINFO, RPL_ENDOFLINKS, RPL_ENDOFMOTD, RPL_ENDOFNAMES, RPL_ENDOFSERVICES, RPL_ENDOFSTATS, RPL_ENDOFUSERS, RPL_ENDOFWHO, RPL_ENDOFWHOIS, RPL_ENDOFWHOWAS, RPL_INFO, RPL_INFOSTART, RPL_INVITING, RPL_ISON, RPL_KILLDONE, RPL_LINKS, RPL_LIST, RPL_LISTEND, RPL_LISTSTART, RPL_LUSERCHANNELS, RPL_LUSERCLIENT, RPL_LUSERME, RPL_LUSEROP, RPL_LUSERUNKNOWN, RPL_MOTD, RPL_MOTDSTART, RPL_MYPORTIS, RPL_NAMREPLY, RPL_NONE, RPL_NOTOPIC, RPL_NOUSERS, RPL_NOWAWAY, RPL_REHASHING, RPL_SERVICE, RPL_SERVICEINFO, RPL_SERVLIST, RPL_SERVLISTEND, RPL_STATSCLINE, RPL_STATSCOMMANDS, RPL_STATSHLINE, RPL_STATSILINE, RPL_STATSKLINE, RPL_STATSLINKINFO, RPL_STATSLLINE, RPL_STATSNLINE, RPL_STATSOLINE, RPL_STATSQLINE, RPL_STATSUPTIME, RPL_STATSYLINE, RPL_SUMMONING, RPL_TIME, RPL_TOPIC, RPL_TRACECLASS, RPL_TRACECONNECTING, RPL_TRACEHANDSHAKE, RPL_TRACELINK, RPL_TRACELOG, RPL_TRACENEWTYPE, RPL_TRACEOPERATOR, RPL_TRACESERVER, RPL_TRACEUNKNOWN, RPL_TRACEUSER, RPL_UMODEIS, RPL_UNAWAY, RPL_USERHOST, RPL_USERS, RPL_USERSSTART, RPL_VERSION, RPL_WHOISCHANNELS, RPL_WHOISCHANOP, RPL_WHOISIDLE, RPL_WHOISOPERATOR, RPL_WHOISSERVER, RPL_WHOISUSER, RPL_WHOREPLY, RPL_WHOWASUSER, RPL_YOUREOPER
 
Constructor Summary
IRCConnection(java.lang.String server, int port, java.lang.String nick, java.lang.String altNick, java.lang.String userName, java.lang.String fullName)
          Constructs, but does not open, an IRC connection by specifying server hostname and port of a IRC server as well as user registration information.
 
Method Summary
 void close()
          Close socket connection to IRC server and close down message loop thread.
 java.lang.String getNick()
          Get nick name currently in use.
 int getState()
          Get engine's state (see ChatEngine.DISCONNECTED, ChatEngine.CONNECTED, etc.
 void open()
          Opens socket connection to IRC server.
 void open(IRCConnection previousConnection)
          Opens socket connection to IRC server.
 void run()
          The main message loop.
 void sendNick(java.lang.String nick)
          Send change-nickname request to IRC server and save value as the nick name currently in use.
 void setIRCConnectionListener(IRCConnectionListener listener)
          For now, only one listener is supported.
 void setState(int state)
          Set engine's state (see ChatEngine.DISCONNECTED, ChatEngine.CONNECTED, etc.
 void writeln(java.lang.String message)
          Write directly to the IRC chat server, refer to RFC-1459 for valid commands.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CONNECTED

public static final int CONNECTED

CONNECTING

public static final int CONNECTING

DISCONNECTED

public static final int DISCONNECTED

DISCONNECTING

public static final int DISCONNECTING
Constructor Detail

IRCConnection

public IRCConnection(java.lang.String server,
                     int port,
                     java.lang.String nick,
                     java.lang.String altNick,
                     java.lang.String userName,
                     java.lang.String fullName)
Constructs, but does not open, an IRC connection by specifying server hostname and port of a IRC server as well as user registration information.
Parameters:
server - DNS-resolvable hostname of server.
port - Server port number to connect to.
nick - User's IRC nick name (e.g. Mortz).
userName - User's login/user name (e.g. mps).
fullName - User's full name (e.g. Mortimer P. Snerd)
Method Detail

getState

public int getState()
Get engine's state (see ChatEngine.DISCONNECTED, ChatEngine.CONNECTED, etc.

setState

public void setState(int state)
Set engine's state (see ChatEngine.DISCONNECTED, ChatEngine.CONNECTED, etc.

open

public void open()
Opens socket connection to IRC server. Starts message loop thread and starts firing events to listeners.

open

public void open(IRCConnection previousConnection)
Opens socket connection to IRC server. Starts message loop thread and starts firing events to listeners. Syncs with previousConnection as suggested in bug #211402.

close

public void close()
Close socket connection to IRC server and close down message loop thread.

setIRCConnectionListener

public void setIRCConnectionListener(IRCConnectionListener listener)
For now, only one listener is supported.

getNick

public java.lang.String getNick()
Get nick name currently in use.

sendNick

public void sendNick(java.lang.String nick)
Send change-nickname request to IRC server and save value as the nick name currently in use.

writeln

public void writeln(java.lang.String message)
Write directly to the IRC chat server, refer to RFC-1459 for valid commands.

run

public void run()
The main message loop. Opens a socket connection to the IRC server, sends logon information and enters message loop. The message loop parses each incoming message into a command string or opcode and arguments and calls the appropriate method on the mux.
Specified by:
run in interface java.lang.Runnable