org.relayirc.chatengine
Class ChatEngine

java.lang.Object
  |
  +--org.relayirc.chatengine.ChatEngine

public class ChatEngine
extends java.lang.Object
implements IChatEngine

Manages a connection to an IRC server and handles incoming messages by creating channel objects, routing messages to channel objects and routing events to chat engine listeners.

After you have constructed a chat engine, add a ChatEngineListener to be notified of server connection and disconnection, channel joins and parts and status messages from the engine. Connect to the chat server using the connect() method and use the sendJoin() and sendPart() commands to join and leave chat channels. When a channel is joined, your listener will be informed and you may add a ChannelListener to the channel object so that you can repond to messages, bans, kicks, etc. from that channel.

See Also:
ChatEngineListener, Server, Channel, IdentServer, ChannelSearch, IChatApp, IRCConnection, IRCConnectionListener

Constructor Summary
ChatEngine(java.lang.String serverName, int serverPort, java.lang.String nick, java.lang.String altNick, java.lang.String userName, java.lang.String fullName)
          Construct a chat engine by specifying server name, server port and user logon parameters.
 
Method Summary
 void addChatEngineListener(ChatEngineListener listener)
          Add a chat engine listener.
 void connect()
          Connect to IRC server that was specified in the constructor.
 void disconnect()
          Disconnect from server by sending a QUIT to the server, closing the socket to the server and then waiting for the message loop thread to die.
 void fireStatusEvent(java.lang.String msg)
          Send status message to all ChatEngineListeners.
 java.lang.String getAppName()
          Get app name to be reported to version queries.
 java.lang.String getAppVersion()
          Get app version to be reported to version queries.
 java.lang.String getNick()
          Get nick name currently in use
 boolean isConnected()
          Check connection status and returns true if connected.
 boolean isConnecting()
          Check connection status and returns true if engine is in the process of connecting
 void processUserInput(java.lang.String txt, java.lang.String chan)
          Processes text entered by the user within a channel.
 void removeChatEngineListener(ChatEngineListener listener)
          Remove a chat engine listener.
 void sendCommand(java.lang.String str)
          Send command string directly to server
 void sendJoin(Channel chan)
          Join specified channel by sending JOIN command to IRC server, adding channel object to engine's channel collection and notifying listeners of channel join.
 void sendJoin(java.lang.String name)
          Join specified channel by sending a JOIN command to the IRC server creating a new channel object and notifying listeners of channel join.
 void sendMessage(java.lang.String str, java.lang.String chan)
          Deprecated. Use Channel.privMsg() instead.
 void sendPart(Channel chan)
          Send channel part, notify listeners and remove channel.
 void sendPart(java.lang.String chanName)
          Send channel part, notify listeners and remove channel.
 void sendQuit(java.lang.String str)
          Send quit message to server.
 void sendVersion(java.lang.String user)
          Send version information to server
 void setAppName(java.lang.String name)
          Set app name to be reported to version queries.
 void setAppVersion(java.lang.String version)
          Set app verion to be reported to version queries.
 void startChannelSearch(ChannelSearch search)
          Start a channel search using the specified channel search object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ChatEngine

public ChatEngine(java.lang.String serverName,
                  int serverPort,
                  java.lang.String nick,
                  java.lang.String altNick,
                  java.lang.String userName,
                  java.lang.String fullName)
Construct a chat engine by specifying server name, server port and user logon parameters.
Parameters:
serverName - IRC chat server hostname (e.g. irc.mindspring.com).
serverPort - IRC chat server port (e.g. 6667).
altNick - Alternate nickname
userName - User's UNIX login name
fullName - User's real name
Method Detail

addChatEngineListener

public void addChatEngineListener(ChatEngineListener listener)
Add a chat engine listener.
Specified by:
addChatEngineListener in interface IChatEngine

removeChatEngineListener

public void removeChatEngineListener(ChatEngineListener listener)
Remove a chat engine listener.
Specified by:
removeChatEngineListener in interface IChatEngine

getAppName

public java.lang.String getAppName()
Get app name to be reported to version queries.
Specified by:
getAppName in interface IChatEngine

setAppName

public void setAppName(java.lang.String name)
Set app name to be reported to version queries.
Specified by:
setAppName in interface IChatEngine

getAppVersion

public java.lang.String getAppVersion()
Get app version to be reported to version queries.
Specified by:
getAppVersion in interface IChatEngine

setAppVersion

public void setAppVersion(java.lang.String version)
Set app verion to be reported to version queries.
Specified by:
setAppVersion in interface IChatEngine

isConnected

public boolean isConnected()
Check connection status and returns true if connected.
Specified by:
isConnected in interface IChatEngine

isConnecting

public boolean isConnecting()
Check connection status and returns true if engine is in the process of connecting
Specified by:
isConnecting in interface IChatEngine

getNick

public java.lang.String getNick()
Get nick name currently in use
Specified by:
getNick in interface IChatEngine

connect

public void connect()
Connect to IRC server that was specified in the constructor.
Specified by:
connect in interface IChatEngine

disconnect

public void disconnect()
Disconnect from server by sending a QUIT to the server, closing the socket to the server and then waiting for the message loop thread to die.
Specified by:
disconnect in interface IChatEngine

fireStatusEvent

public void fireStatusEvent(java.lang.String msg)
Send status message to all ChatEngineListeners.
Specified by:
fireStatusEvent in interface IChatEngine

processUserInput

public void processUserInput(java.lang.String txt,
                             java.lang.String chan)
Processes text entered by the user within a channel. If the text starts with /me, then the rest of the text is sent to the server as an ACTION command. If the text starts with / then the / is stripped off and the text is sent to the server as a command. Otherwise, the text is sent as a message.
Specified by:
processUserInput in interface IChatEngine

sendCommand

public void sendCommand(java.lang.String str)
Send command string directly to server
Specified by:
sendCommand in interface IChatEngine

sendJoin

public void sendJoin(Channel chan)
Join specified channel by sending JOIN command to IRC server, adding channel object to engine's channel collection and notifying listeners of channel join.
Specified by:
sendJoin in interface IChatEngine

sendJoin

public void sendJoin(java.lang.String name)
Join specified channel by sending a JOIN command to the IRC server creating a new channel object and notifying listeners of channel join.
Specified by:
sendJoin in interface IChatEngine

sendMessage

public void sendMessage(java.lang.String str,
                        java.lang.String chan)
Deprecated. Use Channel.privMsg() instead.

Send a PRIVMSG message to server.
Specified by:
sendMessage in interface IChatEngine

sendPart

public void sendPart(Channel chan)
Send channel part, notify listeners and remove channel.
Specified by:
sendPart in interface IChatEngine

sendPart

public void sendPart(java.lang.String chanName)
Send channel part, notify listeners and remove channel.
Specified by:
sendPart in interface IChatEngine

sendVersion

public void sendVersion(java.lang.String user)
Send version information to server
Specified by:
sendVersion in interface IChatEngine

sendQuit

public void sendQuit(java.lang.String str)
Send quit message to server.
Specified by:
sendQuit in interface IChatEngine

startChannelSearch

public void startChannelSearch(ChannelSearch search)
Start a channel search using the specified channel search object.
Specified by:
startChannelSearch in interface IChatEngine