org.relayirc.chatengine
Class Server

java.lang.Object
  extended by org.relayirc.chatengine.Server
All Implemented Interfaces:
java.io.Serializable, IChatObject

public class Server
extends java.lang.Object
implements IChatObject, java.io.Serializable

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

After you have constructed a Server, add a ServerListener to be notified of server connection and disconnection, channel joins and parts and status messages from the Server. Connect to the 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.

Version:
$Revision: 1.1.2.8 $

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:
Serialized Form

Constructor Summary
Server(java.lang.String name, int port, java.lang.String network, java.lang.String title)
          Construct a server by specifying server name, port, network and port.
 
Method Summary
 void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
          Add a property change listener: not fully implemented.
 void addServerListener(ServerListener listener)
          Add a server listener.
 void connect(java.lang.String nick, java.lang.String altNick, java.lang.String userName, java.lang.String fullName)
          Connect to IRC server that was specified in the constructor.
 void connect(User user)
          Connect to IRC server that was specified in the constructor.
 void disconnect(java.lang.String message)
          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 ServerListeners, used internally.
 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.
 Channel getChannel(java.lang.String name)
          Returns view for specified channel, or null if there is none.
 Channel getChannel(java.lang.String name, boolean force)
          Returns channel object specified by name, creates one if necessary.
 java.lang.String getDescription()
          Get object's description.
 java.lang.String getName()
          Host name of server.
 java.lang.String getNetwork()
           
 java.lang.String getNick()
          Get nick name currently in use
 int getPort()
          Get default port: first port in port array.
 int[] getPorts()
          Get port array.
 java.lang.String getTitle()
           
 boolean isConnected()
          Check connection status and returns true if connected.
 boolean isConnecting()
          Check connection status and returns true if server is in the process of connecting.
 boolean isFavorite()
           
 void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
          Remove a property change listener: not fully implemented.
 void removeServerListener(ServerListener listener)
          Remove a server 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 server'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 sendNick(java.lang.String nick)
          Send new nick name request.
 void sendPart(Channel chan, java.lang.String message)
          Send channel PART with the message, notify listeners and remove channel.
 void sendPart(java.lang.String chanName, java.lang.String message)
          Send channel PART with the message, notify listeners and remove channel.
 void sendPrivateMessage(java.lang.String target, java.lang.String message)
          Send private message.
 void sendPrivateMessage(java.lang.String target, java.lang.String message, boolean isNotice)
          Send private message.
 void sendQuit(java.lang.String str)
          Send quit message to server.
 void sendVersion(java.lang.String user)
          Send version information to server
 void sendWhoIs(java.lang.String nick)
          Send WHIOS for user specified by nick name.
 void sendWhoIs(User user)
          Send WHIOS for user specified by User object, object will be updated when WHOIS information is received.
 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 setDescription(java.lang.String desc)
          Set object's description.
 void setFavorite(boolean fave)
           
 void setName(java.lang.String name)
           
 void setNetwork(java.lang.String network)
           
 void setPort(int port)
          Set default port: first port in port array.
 void setPorts(int[] ports)
          Set port array.
 void setTitle(java.lang.String title)
           
 void startChannelSearch(ChannelSearch search)
          Start a channel search using the specified channel search object.
 java.lang.String toString()
          String representation for display purposes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Server

public Server(java.lang.String name,
              int port,
              java.lang.String network,
              java.lang.String title)
Construct a server by specifying server name, port, network and port.

Parameters:
name - IRC chat server hostname (e.g. irc.mindspring.com).
port - Default IRC server port (e.g. 6667).
network - Name of server's network (e.g. EFNet)
title - Title or display name of server.
Method Detail

toString

public java.lang.String toString()
String representation for display purposes.

Overrides:
toString in class java.lang.Object

getAppName

public java.lang.String getAppName()
Get app name to be reported to version queries.


setAppName

public void setAppName(java.lang.String name)
Set app name to be reported to version queries.


getAppVersion

public java.lang.String getAppVersion()
Get app version to be reported to version queries.


setAppVersion

public void setAppVersion(java.lang.String version)
Set app verion to be reported to version queries.


isConnected

public boolean isConnected()
Check connection status and returns true if connected.


isConnecting

public boolean isConnecting()
Check connection status and returns true if server is in the process of connecting.


getDescription

public java.lang.String getDescription()
Description copied from interface: IChatObject
Get object's description.

Specified by:
getDescription in interface IChatObject

setDescription

public void setDescription(java.lang.String desc)
Description copied from interface: IChatObject
Set object's description.

Specified by:
setDescription in interface IChatObject

isFavorite

public boolean isFavorite()

setFavorite

public void setFavorite(boolean fave)

getTitle

public java.lang.String getTitle()

setTitle

public void setTitle(java.lang.String title)

getName

public java.lang.String getName()
Host name of server. For example: irc.sprynet.com.


setName

public void setName(java.lang.String name)

getNetwork

public java.lang.String getNetwork()

setNetwork

public void setNetwork(java.lang.String network)

getNick

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


getPort

public int getPort()
Get default port: first port in port array.


setPort

public void setPort(int port)
Set default port: first port in port array.


getPorts

public int[] getPorts()
Get port array.


setPorts

public void setPorts(int[] ports)
Set port array.


addPropertyChangeListener

public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
Add a property change listener: not fully implemented.


removePropertyChangeListener

public void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
Remove a property change listener: not fully implemented.


addServerListener

public void addServerListener(ServerListener listener)
Add a server listener.


removeServerListener

public void removeServerListener(ServerListener listener)
Remove a server listener.


connect

public void connect(java.lang.String nick,
                    java.lang.String altNick,
                    java.lang.String userName,
                    java.lang.String fullName)
Connect to IRC server that was specified in the constructor.


connect

public void connect(User user)
Connect to IRC server that was specified in the constructor.


disconnect

public void disconnect(java.lang.String message)
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.

Parameters:
message - The QUIT message.

startChannelSearch

public void startChannelSearch(ChannelSearch search)
Start a channel search using the specified channel search object.


sendCommand

public void sendCommand(java.lang.String str)
Send command string directly to server


sendPrivateMessage

public void sendPrivateMessage(java.lang.String target,
                               java.lang.String message)
Send private message.

Parameters:
target - Channel name or nick name that is target of message.
message - The message to be sent.

sendPrivateMessage

public void sendPrivateMessage(java.lang.String target,
                               java.lang.String message,
                               boolean isNotice)
Send private message.

Parameters:
target - Channel name or nick name that is target of message.
message - The message to be sent.
isNotice - If it is NOTICE message then true, otherwise false.

sendJoin

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


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.


sendNick

public void sendNick(java.lang.String nick)
Send new nick name request.


sendPart

public void sendPart(Channel chan,
                     java.lang.String message)
Send channel PART with the message, notify listeners and remove channel.

Parameters:
message - It will send as PART message.

sendPart

public void sendPart(java.lang.String chanName,
                     java.lang.String message)
Send channel PART with the message, notify listeners and remove channel.

Parameters:
message - It will send as PART message.

sendVersion

public void sendVersion(java.lang.String user)
Send version information to server


sendQuit

public void sendQuit(java.lang.String str)
Send quit message to server.


sendWhoIs

public void sendWhoIs(java.lang.String nick)
Send WHIOS for user specified by nick name.


sendWhoIs

public void sendWhoIs(User user)
Send WHIOS for user specified by User object, object will be updated when WHOIS information is received.


fireStatusEvent

public void fireStatusEvent(java.lang.String msg)
Send status message to all ServerListeners, used internally.


getChannel

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


getChannel

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

Parameters:
name - Name of channel.
force - Force creation of channel if it does not exist.