Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.relayirc.chatengine
Class ChatEngine  view ChatEngine download ChatEngine.java

java.lang.Object
  extended byorg.relayirc.chatengine.ChatEngine
All Implemented Interfaces:
IChatEngine

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.


Nested Class Summary
private  class ChatEngine._ChatEngineMux
           
(package private) static interface ChatEngine._EngineEventNotifier
           
 
Field Summary
private  java.lang.String _altNick
           
private  java.lang.String _appName
           
private  java.lang.String _appVersion
           
private  int _channelCount
           
private  java.util.Hashtable _channels
           
private  IRCConnection _connection
           
private  java.lang.String _fullName
           
private  IdentServer _identd
           
private  java.util.Vector _listeners
           
private  ChatEngine._ChatEngineMux _mux
           
private  java.lang.String _nick
           
private  ChannelSearch _search
           
private  Server _server
           
private  java.lang.String _userName
           
 
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.
private  void createChannel(java.lang.String name)
           
 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.
private  Channel getChannel(java.lang.String name)
          Returns view for specified channel, or null if there is none.
private  Channel getChannel(java.lang.String name, boolean manditory)
          Returns channel object specified by name, creates one if necessary.
 java.lang.String getNick()
          Get nick name currently in use
private  boolean isChannelActive(java.lang.String channel)
          Determine if channel view is active.
 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
private  void notifyListeners(ChatEngine._EngineEventNotifier notifier)
           
 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
 

Field Detail

_server

private Server _server

_channelCount

private int _channelCount

_nick

private java.lang.String _nick

_altNick

private java.lang.String _altNick

_userName

private java.lang.String _userName

_fullName

private java.lang.String _fullName

_connection

private IRCConnection _connection

_search

private ChannelSearch _search

_identd

private IdentServer _identd

_channels

private java.util.Hashtable _channels

_listeners

private java.util.Vector _listeners

_appName

private java.lang.String _appName

_appVersion

private java.lang.String _appVersion

_mux

private ChatEngine._ChatEngineMux _mux
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.

Method Detail

notifyListeners

private void notifyListeners(ChatEngine._EngineEventNotifier notifier)

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

createChannel

private void createChannel(java.lang.String name)

isChannelActive

private boolean isChannelActive(java.lang.String channel)
Determine if channel view is active.


getChannel

private Channel getChannel(java.lang.String name)
Returns view for specified channel, or null if there is none.


getChannel

private Channel getChannel(java.lang.String name,
                           boolean manditory)
Returns channel object specified by name, creates one if necessary.