com.zerjio.JIRC
Class IRCClient

java.lang.Object
  extended bycom.zerjio.JIRC.IRCClient
All Implemented Interfaces:
java.lang.Runnable

public class IRCClient
extends java.lang.Object
implements java.lang.Runnable

This class allows a higher level of interaction within the IRC client and the IRC server. This class is the cornerstone of the package. Every application which wants to communicate with the IRC server should use this class. It allows sending the basic IRC commands, and even a RAW command (a command that it is not directly implemented). It also is responsible of reading all incoming IRC messages from the server and to deliver it to the appropiate message listeners.


Constructor Summary
IRCClient()
          Creates a new IRC client without specifying a server nor port to connect
IRCClient(java.lang.String server, int port)
          Creates a new IRC client with a determined server name and port.
 
Method Summary
 void addJOINListener(JOINListener listener)
          Adds a JOINListener.
 void addMsgListener(MsgListener listener)
          Adds a MsgListener.
 void addNICKListener(NICKListener listener)
          Adds a NICKListener.
 void addPARTListener(PARTListener listener)
          Adds a PARTListener.
 void addPINGListener(PINGListener listener)
          Adds a PINGListener.
 void addPRIVMSGListener(PRIVMSGListener listener)
          Adds a PRIVMSGListener.
 void addQUITListener(QUITListener listener)
          Adds a QUITListener.
 void addReplyMsgListener(ReplyMsgListener listener)
          Adds a ReplyMsgListener.
 void addTOPICListener(TOPICListener listener)
          Adds a TOPICListener.
 boolean connect()
          Makes a connection to the IRC server.
 void disconnect()
          Breaks the connection with the IRC server.
 int getPort()
          Returns the server port where the client will connect.
 java.lang.String getServer()
          Returns the server name
 boolean isClosed()
          Returns if the connection is closed.
 void removeAllJOINListeners()
          Removes all JOINListeners that have been previously added.
 void removeAllMsgListeners()
          Removes all MsgListeners that have been previously added.
 void removeAllNICKListeners()
          Removes all NICKListeners that have been previously added.
 void removeAllPARTListeners()
          Removes all PARTListeners that have been previously added.
 void removeAllPINGListeners()
          Removes all PINGListeners that have been previously added.
 void removeAllPRIVMSGListeners()
          Removes all PRIVMSGListeners that have been previously added.
 void removeAllQUITListeners()
          Removes all QUITListeners that have been previously added.
 void removeAllReplyMsgListeners()
          Removes all ReplyMsgListeners that have been previously added.
 void removeAllTOPICListeners()
          Removes all TOPICListeners that have been previously added.
 void removeJOINListener(JOINListener listener)
          Removes a JOINListener that has been previously added.
 void removeMsgListener(MsgListener listener)
          Removes a MsgListener that has been previously added.
 void removeNICKListener(NICKListener listener)
          Removes a NICKListener that has been previously added.
 void removePARTListener(PARTListener listener)
          Removes a PARTListener that has been previously added.
 void removePINGListener(PINGListener listener)
          Removes a PINGListener that has been previously added.
 void removePRIVMSGListener(PRIVMSGListener listener)
          Removes a PRIVMSGListener that has been previously added.
 void removeQUITListener(QUITListener listener)
          Removes a QUITListener that has been previously added.
 void removeReplyMsgListener(ReplyMsgListener listener)
          Removes a ReplyMsgListener that has been previously added.
 void removeTOPICListener(TOPICListener listener)
          Removes a TOPICListener that has been previously added.
 void run()
          Gets all information send by the IRC server continuously.
 void sendJOINMessage(java.lang.String channels)
          Sends a JOIN message to the IRC server.
 void sendJOINMessage(java.lang.String channels, java.lang.String keys)
          Sends a JOIN message to the IRC server.
 void sendMessage(IRCMessage msg)
          Sends an IRCMessage to the IRC server.
 void sendNICKMessage(java.lang.String nick)
          Sends a NICK message to the IRC server.
 void sendPARTMessage(java.lang.String channels)
          Sends a PART message to the IRC server.
 void sendPASSMessage()
          Sends a PASS message to the IRC server with a random connection password.
 void sendPASSMessage(java.lang.String passwd)
          Sends a PASS message to the IRC server.
 void sendPINGMessage(java.lang.String server1)
          Sends a PING message to the IRC server.
 void sendPINGMessage(java.lang.String server1, java.lang.String server2)
          Sends a PING message to the IRC server.
 void sendPONGMessage(java.lang.String daemon)
          Sends a PONG message to the IRC server.
 void sendPONGMessage(java.lang.String daemon, java.lang.String daemon2)
          Sends a PONG message to the IRC server.
 void sendPRIVMSGMessage(java.lang.String receivers, java.lang.String message)
          Sends a PRIVMSG message to the IRC server.
 void sendQUITMessage()
          Sends a QUIT message to the IRC server.
 void sendQUITMessage(java.lang.String quitMsg)
          Sends a QUIT message with an optional text to the IRC server.
 void sendRawMessage(java.lang.String msg)
          Sends a raw message to the IRC server.
 void sendTOPICMessage(java.lang.String channelName)
          Sends a TOPIC message to the IRC server to retrieve the topic of a channel.
 void sendTOPICMessage(java.lang.String channelName, java.lang.String topic)
          Sends a TOPIC message to the IRC server to set the topic of a channel.
 void sendUSERMessage(java.lang.String userName, java.lang.String hostName, java.lang.String serverName, java.lang.String realName)
          Sends a USER message to the IRC server.
 void setPort(int port)
          Sets the server port where will connect the client.
 void setServer(java.lang.String server)
          Sets the server name
 void setServerAndPort(java.lang.String server, int port)
          Sets the server name and port where will connect the client.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IRCClient

public IRCClient()
Creates a new IRC client without specifying a server nor port to connect


IRCClient

public IRCClient(java.lang.String server,
                 int port)
Creates a new IRC client with a determined server name and port.

Parameters:
server - The server name (or IP adress)
port - The server port where the client will connect.
Method Detail

getServer

public java.lang.String getServer()
Returns the server name

Returns:
The server name

getPort

public int getPort()
Returns the server port where the client will connect.

Returns:
The server port where the client will connect.

setServer

public void setServer(java.lang.String server)
Sets the server name

Parameters:
server - The server name

setPort

public void setPort(int port)
Sets the server port where will connect the client.

Parameters:
port - The server port

setServerAndPort

public void setServerAndPort(java.lang.String server,
                             int port)
Sets the server name and port where will connect the client.

Parameters:
server - The server name
port - The server port

connect

public boolean connect()
Makes a connection to the IRC server. It also starts listening to messages from the server. If there was a previous connection it will be closed first.

Returns:
true if the connection is successful. false if the conection has failed.

isClosed

public boolean isClosed()
Returns if the connection is closed.

Returns:
true if the connection is closed. false if the connection is active.

disconnect

public void disconnect()
Breaks the connection with the IRC server. It also stops reading messages from it.


addPINGListener

public void addPINGListener(PINGListener listener)
Adds a PINGListener. It will be placed in the last position between active PINGListeners. When a PINGMessage is received it will be delivered to all PINGListeners (see processRawMessage(...) for more details).

Parameters:
listener - The PINGListener to be added.

removePINGListener

public void removePINGListener(PINGListener listener)
Removes a PINGListener that has been previously added.

Parameters:
listener - The PINGListener that should be removed.
See Also:
addPINGListener

removeAllPINGListeners

public void removeAllPINGListeners()
Removes all PINGListeners that have been previously added.

See Also:
addPINGListener

addPRIVMSGListener

public void addPRIVMSGListener(PRIVMSGListener listener)
Adds a PRIVMSGListener. It will be placed in the last position between active PRIVMSGListeners. When a PRIVMSGMessage is received it will be delivered to all PRIVMSGListeners (see processRawMessage(...) for more details).

Parameters:
listener - The PRIVMSGListener to be added.

removePRIVMSGListener

public void removePRIVMSGListener(PRIVMSGListener listener)
Removes a PRIVMSGListener that has been previously added.

Parameters:
listener - The PRIVMSGListener that should be removed.
See Also:
addPRIVMSGListener

removeAllPRIVMSGListeners

public void removeAllPRIVMSGListeners()
Removes all PRIVMSGListeners that have been previously added.

See Also:
addPRIVMSGListener

addTOPICListener

public void addTOPICListener(TOPICListener listener)
Adds a TOPICListener. It will be placed in the last position between active TOPICListeners. When a TOPICMessage is received it will be delivered to all TOPICListeners (see processRawMessage(...) for more details).

Parameters:
listener - The TOPICListener to be added.

removeTOPICListener

public void removeTOPICListener(TOPICListener listener)
Removes a TOPICListener that has been previously added.

Parameters:
listener - The TOPICListener that should be removed.
See Also:
addTOPICListener

removeAllTOPICListeners

public void removeAllTOPICListeners()
Removes all TOPICListeners that have been previously added.

See Also:
addTOPICListener

addPARTListener

public void addPARTListener(PARTListener listener)
Adds a PARTListener. It will be placed in the last position between active PARTListeners. When a PARTMessage is received it will be delivered to all PARTListeners (see processRawMessage(...) for more details).

Parameters:
listener - The PARTListener to be added.

removePARTListener

public void removePARTListener(PARTListener listener)
Removes a PARTListener that has been previously added.

Parameters:
listener - The PARTListener that should be removed.
See Also:
addPARTListener

removeAllPARTListeners

public void removeAllPARTListeners()
Removes all PARTListeners that have been previously added.

See Also:
addPARTListener

addJOINListener

public void addJOINListener(JOINListener listener)
Adds a JOINListener. It will be placed in the last position between active JOINListeners. When a JOINMessage is received it will be delivered to all JOINListeners (see processRawMessage(...) for more details).

Parameters:
listener - The JOINListener to be added.

removeJOINListener

public void removeJOINListener(JOINListener listener)
Removes a JOINListener that has been previously added.

Parameters:
listener - The JOINListener that should be removed.
See Also:
addJOINListener

removeAllJOINListeners

public void removeAllJOINListeners()
Removes all JOINListeners that have been previously added.

See Also:
addJOINListener

addQUITListener

public void addQUITListener(QUITListener listener)
Adds a QUITListener. It will be placed in the last position between active QUITListeners. When a QUITMessage is received it will be delivered to all QUITListeners (see processRawMessage(...) for more details).

Parameters:
listener - The QUITListener to be added.

removeQUITListener

public void removeQUITListener(QUITListener listener)
Removes a QUITListener that has been previously added.

Parameters:
listener - The QUITListener that should be removed.
See Also:
addQUITListener

removeAllQUITListeners

public void removeAllQUITListeners()
Removes all QUITListeners that have been previously added.

See Also:
addQUITListener

addReplyMsgListener

public void addReplyMsgListener(ReplyMsgListener listener)
Adds a ReplyMsgListener. It will be placed in the last position between active ReplyMsgListeners. When a ReplyMessage is received it will be delivered to all ReplyMsgListeners (see processRawMessage(...) for more details).

Parameters:
listener - The ReplyMsgListener to be added.

removeReplyMsgListener

public void removeReplyMsgListener(ReplyMsgListener listener)
Removes a ReplyMsgListener that has been previously added.

Parameters:
listener - The ReplyMsgListener that should be removed.
See Also:
addReplyMsgListener

removeAllReplyMsgListeners

public void removeAllReplyMsgListeners()
Removes all ReplyMsgListeners that have been previously added.

See Also:
addReplyMsgListener

addNICKListener

public void addNICKListener(NICKListener listener)
Adds a NICKListener. It will be placed in the last position between active NICKListeners. When a NICKMessage is received it will be delivered to all NICKListeners (see processRawMessage(...) for more details).

Parameters:
listener - The NICKListener to be added.

removeNICKListener

public void removeNICKListener(NICKListener listener)
Removes a NICKListener that has been previously added.

Parameters:
listener - The NICKListener that should be removed.
See Also:
addNICKListener

removeAllNICKListeners

public void removeAllNICKListeners()
Removes all NICKListeners that have been previously added.

See Also:
addNICKListener

addMsgListener

public void addMsgListener(MsgListener listener)
Adds a MsgListener. It will be placed in the last position between active MsgListeners. When a IRCMessage is received it will be delivered to all MsgListeners (see processRawMessage(...) for more details).

Parameters:
listener - The MsgListener to be added.

removeMsgListener

public void removeMsgListener(MsgListener listener)
Removes a MsgListener that has been previously added.

Parameters:
listener - The MsgListener that should be removed.
See Also:
addMsgListener

removeAllMsgListeners

public void removeAllMsgListeners()
Removes all MsgListeners that have been previously added.

See Also:
addMsgListener

run

public void run()
Gets all information send by the IRC server continuously. It reads from the connection every READING_INTERVAL.

Specified by:
run in interface java.lang.Runnable

sendPASSMessage

public void sendPASSMessage(java.lang.String passwd)
Sends a PASS message to the IRC server. The password will be the connection password. If no explicit password is provided it will generate a random one.

Parameters:
passwd - The connection password. If null or "" it will generate a random password.

sendPASSMessage

public void sendPASSMessage()
Sends a PASS message to the IRC server with a random connection password.


sendNICKMessage

public void sendNICKMessage(java.lang.String nick)
Sends a NICK message to the IRC server.

Parameters:
nick - The nick.

sendUSERMessage

public void sendUSERMessage(java.lang.String userName,
                            java.lang.String hostName,
                            java.lang.String serverName,
                            java.lang.String realName)
Sends a USER message to the IRC server.

Parameters:
userName - The user name.
hostName - The host name.
serverName - The server name.
realName - The real name.

sendQUITMessage

public void sendQUITMessage(java.lang.String quitMsg)
Sends a QUIT message with an optional text to the IRC server.

Parameters:
quitMsg - The quit message (the optional text).

sendQUITMessage

public void sendQUITMessage()
Sends a QUIT message to the IRC server.


sendPINGMessage

public void sendPINGMessage(java.lang.String server1)
Sends a PING message to the IRC server.

Parameters:
server1 - The server that must be pinged.

sendPINGMessage

public void sendPINGMessage(java.lang.String server1,
                            java.lang.String server2)
Sends a PING message to the IRC server.

Parameters:
server1 - The server that must be pinged.
server2 - The PING will be forwarded to this server.

sendPONGMessage

public void sendPONGMessage(java.lang.String daemon)
Sends a PONG message to the IRC server.

Parameters:
daemon - Name of the daemon that has responded.

sendPONGMessage

public void sendPONGMessage(java.lang.String daemon,
                            java.lang.String daemon2)
Sends a PONG message to the IRC server.

Parameters:
daemon - Name of the daemon that has responded.
daemon2 - The PONG message will be forwarded to daemon2.

sendJOINMessage

public void sendJOINMessage(java.lang.String channels)
Sends a JOIN message to the IRC server. With it the user can try to join a channel (or more). If more than one channels should be joined they should be comma separated, and there must not be spaces between their names.

Parameters:
channels - The channels that must be joined

sendJOINMessage

public void sendJOINMessage(java.lang.String channels,
                            java.lang.String keys)
Sends a JOIN message to the IRC server. With it the user can try to join a channel (or more). If more than one channels should be joined they should be comma separated, and there must not be spaces between their names. If there are more than one key they also must be comma separated and without spaces.

Parameters:
channels - The channels that must be joined
keys - The keys to enter the channels (they are optional).

sendPARTMessage

public void sendPARTMessage(java.lang.String channels)
Sends a PART message to the IRC server. If the user wants to leave more than one channel the names of them should be comma separated and without spaces.

Parameters:
channels - The channels that must be parted.

sendTOPICMessage

public void sendTOPICMessage(java.lang.String channelName)
Sends a TOPIC message to the IRC server to retrieve the topic of a channel.

Parameters:
channelName - The name of the channel that the topic should be retrieved.

sendTOPICMessage

public void sendTOPICMessage(java.lang.String channelName,
                             java.lang.String topic)
Sends a TOPIC message to the IRC server to set the topic of a channel.

Parameters:
channelName - The name of the channel that the topic will be set.
topic - The desired topic for the channel.

sendPRIVMSGMessage

public void sendPRIVMSGMessage(java.lang.String receivers,
                               java.lang.String message)
Sends a PRIVMSG message to the IRC server. The receiver can be channels and / or nicks. To specify more than one receiver they must be comma separated with no spaces between them.

Parameters:
receivers - The receivers of the PRIVMSG.
message - The text of the message.

sendMessage

public void sendMessage(IRCMessage msg)
Sends an IRCMessage to the IRC server.

Parameters:
msg - The message to be sended.

sendRawMessage

public void sendRawMessage(java.lang.String msg)
Sends a raw message to the IRC server. It should not include the final CRLF, although there will be no problem if the message includes them (a void message will be sended).