com.vwp.net.irc
Class IRC

java.lang.Object
  extended by java.lang.Thread
      extended by com.vwp.net.irc.IRC
All Implemented Interfaces:
Runnable

public class IRC
extends Thread

This is the base class which has to be used for an IRC connection. All other classes of this package are called from this one and don't have to be used in an other way. One exception is Ident, it can be used separately for establishing an ident server.


Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
 
Field Summary
static int DATA_IDENTERROR_STRING
          Data code: an error information form the ident server
static int DATA_KICKUSER_STRING
          Data code: this identifier is used in pipeMiscData() to pipe a name of a user which was kicked to the main program
static int DATA_NEWUSER_STRING
          Data code: this identifier is used in pipeMiscData() to pipe a new username to the main program
static int DATA_REMUSER_STRING
          Data code: this identifier is used in pipeMiscData() to pipe a name of a user which leaves to the main program
static int DATA_TOPIC_STRING
          Data code: this identifier is used in pipeMiscData() to pipe the actual topic
static int DATA_USERLIST_VECTOR
          Data code: this identifier is used in pipeMiscData() to pipe the UserList Vector to the main program
static int ERR_BANNED
          Error code: own user was banned from the channel
static int ERR_CHANNEL_LEFT
          Error code: own user has left the channel (e.g. he was kicked)
static int ERR_COULD_NOT_CONNECT
          Error code: connection to IRC server failed
static int ERR_COULD_NOT_LOGIN
          Error code: could not log into using this username and channel
static int ERR_INVITE_ONLY
          Error code: the specified channel is invite only
static int ERR_KICKED
          Error code: own user was kicked from the channel
static int ERR_LINK_CLOSED
          Error code: link closed from IRC network
static int ERR_NOSUCHUSER
          Error code: the specified user doesn't exists
static int ERR_REQUIRES_KEYWORD
          Error code: a keyword is required to enter the specified channel
static int SUCC_CHANNEL_ENTERED
          Return code: the IRC was entered successfully
static int SUCC_CHANNEL_JOINED
          Return code: the channel was joined successfully
static int SUCC_CHANNEL_LEFT
          Return code: actual channel left
static int SUCC_LOGGED_IN
          Return code: logged in successfully
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
IRC(String Server, short Port, String Channel, String Username, String Realname, MessagePipe TextOut, boolean retryOtherNicks, String DisconnectInfo)
          The default constructor for an IRC object.
 
Method Summary
 void disconnect()
          This method leaves the actual IRC channel, disconnects from the server and closes all connections immediately.
 String getChannelName()
          This method returns the name of the IRC channel this object already uses.
 String getServerName()
          This method returns the name of the IRC server this object already uses.
 void leaveChannel(String reason)
          This method sends a channel-left message to the actual IRC channel and leaves it, it should be called before disconnectiong
 void run()
           
 void sendChatText(String Text)
          This method has to be used to send chat texts to the actual channel.
 void sendWhisperText(String Text, String TargetUser)
          This method has to be used to send private chat texts to a specific user.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ERR_COULD_NOT_CONNECT

public static final int ERR_COULD_NOT_CONNECT
Error code: connection to IRC server failed

See Also:
Constant Field Values

ERR_COULD_NOT_LOGIN

public static final int ERR_COULD_NOT_LOGIN
Error code: could not log into using this username and channel

See Also:
Constant Field Values

ERR_LINK_CLOSED

public static final int ERR_LINK_CLOSED
Error code: link closed from IRC network

See Also:
Constant Field Values

ERR_CHANNEL_LEFT

public static final int ERR_CHANNEL_LEFT
Error code: own user has left the channel (e.g. he was kicked)

See Also:
Constant Field Values

ERR_BANNED

public static final int ERR_BANNED
Error code: own user was banned from the channel

See Also:
Constant Field Values

ERR_KICKED

public static final int ERR_KICKED
Error code: own user was kicked from the channel

See Also:
Constant Field Values

ERR_NOSUCHUSER

public static final int ERR_NOSUCHUSER
Error code: the specified user doesn't exists

See Also:
Constant Field Values

ERR_REQUIRES_KEYWORD

public static final int ERR_REQUIRES_KEYWORD
Error code: a keyword is required to enter the specified channel

See Also:
Constant Field Values

ERR_INVITE_ONLY

public static final int ERR_INVITE_ONLY
Error code: the specified channel is invite only

See Also:
Constant Field Values

SUCC_LOGGED_IN

public static final int SUCC_LOGGED_IN
Return code: logged in successfully

See Also:
Constant Field Values

SUCC_CHANNEL_LEFT

public static final int SUCC_CHANNEL_LEFT
Return code: actual channel left

See Also:
Constant Field Values

SUCC_CHANNEL_ENTERED

public static final int SUCC_CHANNEL_ENTERED
Return code: the IRC was entered successfully

See Also:
Constant Field Values

SUCC_CHANNEL_JOINED

public static final int SUCC_CHANNEL_JOINED
Return code: the channel was joined successfully

See Also:
Constant Field Values

DATA_USERLIST_VECTOR

public static final int DATA_USERLIST_VECTOR
Data code: this identifier is used in pipeMiscData() to pipe the UserList Vector to the main program

See Also:
Constant Field Values

DATA_NEWUSER_STRING

public static final int DATA_NEWUSER_STRING
Data code: this identifier is used in pipeMiscData() to pipe a new username to the main program

See Also:
Constant Field Values

DATA_REMUSER_STRING

public static final int DATA_REMUSER_STRING
Data code: this identifier is used in pipeMiscData() to pipe a name of a user which leaves to the main program

See Also:
Constant Field Values

DATA_KICKUSER_STRING

public static final int DATA_KICKUSER_STRING
Data code: this identifier is used in pipeMiscData() to pipe a name of a user which was kicked to the main program

See Also:
Constant Field Values

DATA_TOPIC_STRING

public static final int DATA_TOPIC_STRING
Data code: this identifier is used in pipeMiscData() to pipe the actual topic

See Also:
Constant Field Values

DATA_IDENTERROR_STRING

public static final int DATA_IDENTERROR_STRING
Data code: an error information form the ident server

See Also:
Constant Field Values
Constructor Detail

IRC

public IRC(String Server,
           short Port,
           String Channel,
           String Username,
           String Realname,
           MessagePipe TextOut,
           boolean retryOtherNicks,
           String DisconnectInfo)
The default constructor for an IRC object. This is the entry point for an IRC connection. Calling this function a Thread is started which connects to the server and tries to log in. That means the construction of an IRC object doesn't requires as much time as it needs for the whole connection and log-in-process. The information if this process could be performed successfully is submitted using the MessagePipe and an appropriate error or success code. The started thread finishes after the login process was completed. So during an IRC session only the protocol thread of IO is running.

Parameters:
Server - the name of the IRC server which has to be used
Port - the port number for the IRC connection
Channel - the name of the IRC channel, this name requires a leading "#" as known from the IRC channel names
Username - the user- or nickname to log into the IRC network with
Realname - the realname of the user which can be read using a "whois" request
TextOut - a MessagePipe which is used for the communication with the calling instance; this MessagePipe transfers all chat texts, error codes, information messages and so on
retryOtherNicks - if this parameter is set to true and the given Username already exists in IRC, it is tried to log in using other nicknames. These other names are constructed by appending the numbers from 1..9 to the given Username. If all these other nicknames aren't available too, the log in process fails
DisconnectInfo - a string which is displayed whenever the user leaves a channel. This string is used every time the connection has to be disconnected automatically. For an external triggered disconnect a separate reason can be specified.
Method Detail

getServerName

public String getServerName()
This method returns the name of the IRC server this object already uses.

Returns:
the IRC server name

getChannelName

public String getChannelName()
This method returns the name of the IRC channel this object already uses.

Returns:
the IRC channel name

run

public void run()
Specified by:
run in interface Runnable
Overrides:
run in class Thread

sendChatText

public void sendChatText(String Text)
This method has to be used to send chat texts to the actual channel. These texts are readable for everybody.

Parameters:
Text - the text which has to be sent to the channel

sendWhisperText

public void sendWhisperText(String Text,
                            String TargetUser)
This method has to be used to send private chat texts to a specific user. These texts are visible for this user only.

Parameters:
Text - the text which has to be sent to the user
TargetUser - the name of the user which has to receive the text

leaveChannel

public void leaveChannel(String reason)
This method sends a channel-left message to the actual IRC channel and leaves it, it should be called before disconnectiong

Parameters:
reason - this text is displayed when the user leaves the IRC channel

disconnect

public void disconnect()
This method leaves the actual IRC channel, disconnects from the server and closes all connections immediately.