com.leafdigital.irc.api
Interface Server


public interface Server

Represents a low-level server connection.


Nested Class Summary
static interface Server.ConnectionProgress
          Interface used to report on progress of connection.
static class Server.StatusPrefix
          Mapping from mode letter to status prefix symbol
 
Field Summary
static int CHANMODE_ADDRESS
          Channel mode is an 'address' mode that has a param whether + or - and can be sent from client without + or - to get a list of people affected.
static int CHANMODE_ALWAYSPARAM
          Channel mode always takes a parameter, whether + or -.
static int CHANMODE_NOPARAM
          Channel mode never takes a parameter.
static int CHANMODE_SETPARAM
          Channel mode takes a parameter when + but not when - (type C)
static int CHANMODE_UNKNOWN
          Unrecognised channel mode
static int CHANMODE_USERSTATUS
          Channel mode that applies to user status (from PREFIX).
static java.lang.String IDENTIFYEVENT_CONNECT
          Identify event constant: on connect
static java.lang.String IDENTIFYEVENT_NICK
          Identify event constant: on nick change
static java.lang.String IDENTIFYEVENT_SERVICES
          Identify event constant: when services come online
static int UNTRACKED_REQUEST
          Used to report that a server request is not tracked
 
Method Summary
 void beginConnect(java.lang.String host, int port, Server.ConnectionProgress cp)
          Starts the process of connecting to the server.
 void disconnect()
          Disconnects from the server.
 void disconnectGracefully()
          Disconnects from the server after sending a quit message.
 int getApproxPrefixLength()
           
 int getChanModeParamCount()
           
 java.lang.String getChanModes()
           
 int getChanModeType(char mode)
           
 java.lang.String getChanTypes()
           
 java.lang.String getConnectedHost()
           
 java.lang.String getConnectedIpAddress()
           
 int getConnectedPort()
           
 java.lang.String getCurrentShortName()
           
 MessageDisplay getDefaultMessageDisplay()
           
 java.lang.String getDefaultNick()
           
 NetworkException getError()
           
 java.lang.String getIdentifyCommand()
          Deprecated. This is the old identify command, do not use
 java.lang.String getIdentifyPattern()
           
 java.lang.String getISupport(java.lang.String parameter)
          Access information from the RPL_ISUPPORT (005) numeric.
 java.net.InetAddress getLocalAddress()
           
 int getMaxModeParams()
           
 int getMaxTopicLength()
           
 java.lang.String getNickPassword(java.lang.String nick)
           
 java.lang.String getOurHost()
           
 java.lang.String getOurNick()
           
 java.lang.String getOurUser()
           
 PreferencesGroup getPreferences()
           
 Server.StatusPrefix[] getPrefix()
           
 java.lang.Object getProperty(java.lang.Class<?> c, java.lang.String key)
           
 java.lang.String getQuitMessage()
           
 java.lang.String getReportedHost()
           
 java.lang.String getReportedOrConnectedHost()
           
 java.lang.String getServerPassword()
           
 java.lang.String getStatusMsg()
           
 java.lang.String getVersion()
           
 boolean isAway()
           
 boolean isConnected()
           
 boolean isConnectionFinished()
           
 boolean isPrefixAtLeast(char prefix, char required)
           
 boolean isSecureConnection()
           
 void sendLine(byte[] line)
          Sends a line of data to the server.
 int sendServerRequest(byte[] line)
          Sends a line of data to the server.
 java.lang.Object setProperty(java.lang.Class<?> c, java.lang.String key, java.lang.Object value)
           
 boolean shouldIdentify(java.lang.String identifyEvent)
           
 boolean silence(java.lang.String mask)
          Attempt to silence the given mask.
 void suppressAutoJoin()
          Prevents autojoin for the server.
 boolean unsilence(java.lang.String mask)
          Attempt to unsilence the given mask.
 boolean wasQuitRequested()
           
 

Field Detail

UNTRACKED_REQUEST

static final int UNTRACKED_REQUEST
Used to report that a server request is not tracked

See Also:
Constant Field Values

IDENTIFYEVENT_CONNECT

static final java.lang.String IDENTIFYEVENT_CONNECT
Identify event constant: on connect

See Also:
Constant Field Values

IDENTIFYEVENT_NICK

static final java.lang.String IDENTIFYEVENT_NICK
Identify event constant: on nick change

See Also:
Constant Field Values

IDENTIFYEVENT_SERVICES

static final java.lang.String IDENTIFYEVENT_SERVICES
Identify event constant: when services come online

See Also:
Constant Field Values

CHANMODE_UNKNOWN

static final int CHANMODE_UNKNOWN
Unrecognised channel mode

See Also:
Constant Field Values

CHANMODE_ADDRESS

static final int CHANMODE_ADDRESS
Channel mode is an 'address' mode that has a param whether + or - and can be sent from client without + or - to get a list of people affected. (type A)

See Also:
Constant Field Values

CHANMODE_ALWAYSPARAM

static final int CHANMODE_ALWAYSPARAM
Channel mode always takes a parameter, whether + or -. (type B)

See Also:
Constant Field Values

CHANMODE_SETPARAM

static final int CHANMODE_SETPARAM
Channel mode takes a parameter when + but not when - (type C)

See Also:
Constant Field Values

CHANMODE_NOPARAM

static final int CHANMODE_NOPARAM
Channel mode never takes a parameter. (type D)

See Also:
Constant Field Values

CHANMODE_USERSTATUS

static final int CHANMODE_USERSTATUS
Channel mode that applies to user status (from PREFIX).

See Also:
Constant Field Values
Method Detail

beginConnect

void beginConnect(java.lang.String host,
                  int port,
                  Server.ConnectionProgress cp)
Starts the process of connecting to the server. Returns immediately. To monitor connection, you may synchronize on this ServerConnection object and wait repeatedly until either isConnected, or getError, returns something.

Parameters:
host - Host for connection
port - Port for connection
cp - Object that monitors progress of connection

isConnected

boolean isConnected()
Returns:
True if the socket is connected.

isConnectionFinished

boolean isConnectionFinished()
Returns:
True if the connection is finished i.e. if ServerConnectionFinishedMsg was/is being sent

isSecureConnection

boolean isSecureConnection()
Returns:
True if currently connected and the connection is secure (SSL)

getError

NetworkException getError()
Returns:
An exception that occurred, preventing connection (or null if none)

wasQuitRequested

boolean wasQuitRequested()
Returns:
True once a QUIT command has been sent to the server

getDefaultMessageDisplay

MessageDisplay getDefaultMessageDisplay()
                                        throws java.lang.IllegalStateException
Returns:
Default MessageDisplay for this server
Throws:
java.lang.IllegalStateException - If Connections.setDefaultMessageDisplay was not called

sendLine

void sendLine(byte[] line)
Sends a line of data to the server.

Parameters:
line - Line of data, not including CRLF
See Also:
sendServerRequest(byte[])

sendServerRequest

int sendServerRequest(byte[] line)
Sends a line of data to the server. If the line corresponds to a supported server request, e.g. WHO, then the server will return a unique identifier which can be used to identify the response to that particular request.

Parameters:
line - Line of data, not including CRLF
Returns:
Tracking ID or UNTRACKED_REQUEST
See Also:
ServerIRCMsg.getResponseID()

disconnectGracefully

void disconnectGracefully()
Disconnects from the server after sending a quit message.


disconnect

void disconnect()
Disconnects from the server.


getOurNick

java.lang.String getOurNick()
Returns:
Our current nickname, may be null if not connected

getOurUser

java.lang.String getOurUser()
Returns:
Our current username (as the server thinks), may be null if not yet known

getOurHost

java.lang.String getOurHost()
Returns:
Our current hostname (as the server thinks), may be null if not yet known

getApproxPrefixLength

int getApproxPrefixLength()
Returns:
Approximate length in bytes of the current prefix :nick!user@host, possibly allowing a slight overestimate in case servers mess with hostnames.

getReportedHost

java.lang.String getReportedHost()
Returns:
Reported hostname, may be null if not connected or not set

getConnectedHost

java.lang.String getConnectedHost()
Returns:
Connected hostname (the one specified in beginConnect), may be null if not connected

getConnectedPort

int getConnectedPort()
Returns:
Connected port, may be 0 if not connected

getConnectedIpAddress

java.lang.String getConnectedIpAddress()
Returns:
Connected remote IP address, may be null if not connected

getLocalAddress

java.net.InetAddress getLocalAddress()
Returns:
The internet address at this end of the connection

getCurrentShortName

java.lang.String getCurrentShortName()
Returns:
Short name. The short name varies depending on which servers are connected, and ranges from the network name, through the server name, up to the server name plus port.

getReportedOrConnectedHost

java.lang.String getReportedOrConnectedHost()
Returns:
Reported hostname if set, otherwise connected one if connected, otherwise null

getVersion

java.lang.String getVersion()
Returns:
Server version string, may be null if unknown

getPreferences

PreferencesGroup getPreferences()
Returns:
Preferences entries for this server (must be connected)
Throws:
BugException - If not connected (or something else goes horribly wrong)

getDefaultNick

java.lang.String getDefaultNick()
Returns:
Default nick from preferences

getQuitMessage

java.lang.String getQuitMessage()
Returns:
Quit message from preferences

getServerPassword

java.lang.String getServerPassword()
Returns:
Server password from preferences, null if none

getNickPassword

java.lang.String getNickPassword(java.lang.String nick)
Parameters:
nick - Nickname
Returns:
Password from preferences for nickname, or "" if none

shouldIdentify

boolean shouldIdentify(java.lang.String identifyEvent)
Parameters:
identifyEvent - An IDENTIFYEVENT_xx constant
Returns:
True if client should identify in that context

getIdentifyCommand

java.lang.String getIdentifyCommand()
Deprecated. This is the old identify command, do not use

Returns:
Identify command from preferences

getIdentifyPattern

java.lang.String getIdentifyPattern()
Returns:
Identify pattern from preferences, containing ${nick} and ${password}

getISupport

java.lang.String getISupport(java.lang.String parameter)
Access information from the RPL_ISUPPORT (005) numeric. This is only available once that numeric has been received! Also see the various access methods in this class, which handle problem cases such as if the value wasn't supplied.

Parameters:
parameter - ISUPPORT parameter name
Returns:
ISUPPORT parameter value, or null if none

getChanTypes

java.lang.String getChanTypes()
Returns:
String containing channel prefixes that are supported e.g. "#&" (from CHANTYPES)

getStatusMsg

java.lang.String getStatusMsg()
Returns:
String containing status prefixes that are supported in channel notices e.g. "@+" (from STATUSMSG)

getMaxModeParams

int getMaxModeParams()
Returns:
The max number of chan modes with a param inside one command (from MODES)

getMaxTopicLength

int getMaxTopicLength()
Returns:
Max length of a topic in bytes (from TOPICLEN)

getPrefix

Server.StatusPrefix[] getPrefix()
Returns:
Array of channel status prefixes that are shown in WHO, NAMES output (from PREFIX). First prefix is 'highest' level, etc.

isPrefixAtLeast

boolean isPrefixAtLeast(char prefix,
                        char required)
Parameters:
prefix - User's prefix
required - Required prefix
Returns:
True if user's prefix is better than or equal to the required one

getChanModes

java.lang.String getChanModes()
Returns:
String listing all available chan modes (from CHANMODES and PREFIX)

getChanModeType

int getChanModeType(char mode)
Parameters:
mode - Mode letter
Returns:
Type of given chan mode (from CHANMODES and PREFIX) as CHANMODE_xx

getChanModeParamCount

int getChanModeParamCount()
Returns:
Maximum number of modes that take a parameter per mode command

getProperty

java.lang.Object getProperty(java.lang.Class<?> c,
                             java.lang.String key)
Parameters:
c - Class that owns property
key - Property key
Returns:
Value of property or null if unset

setProperty

java.lang.Object setProperty(java.lang.Class<?> c,
                             java.lang.String key,
                             java.lang.Object value)
Parameters:
c - Class that owns property
key - Property key
value - New value for property
Returns:
Previous value of property or null if unset

silence

boolean silence(java.lang.String mask)
Attempt to silence the given mask.

Parameters:
mask - Mask to silence
Returns:
True if mask was silenced, false if server doesn't support silence (or we've run out of slots)

unsilence

boolean unsilence(java.lang.String mask)
Attempt to unsilence the given mask. It is OK to call this with masks that aren't actually silenced at the moment.

Parameters:
mask - Mask to silence
Returns:
True if mask was previously silenced and is no longer, false if it wasn't silenced anyhow

isAway

boolean isAway()
Returns:
True if currently marked away

suppressAutoJoin

void suppressAutoJoin()
Prevents autojoin for the server. Should be called before the ServerConnectionFinishedMsg is sent, e.g. while handling ServerConnectedMsg.



Copyright © 2011 Samuel Marshall. All rights reserved.