public class DefaultIRCConnection extends Object implements IRCConnection
IRCConnection. Typically created via
IRCConnectionFactory.newConnection(org.schwering.irc.lib.IRCConfig)
or
IRCConnectionFactory.newConnection(IRCServerConfig, IRCRuntimeConfig)
. Creates a new connection to an IRC server. It's the main class of the
IRClib, the point everything starts.| Modifier and Type | Class and Description |
|---|---|
protected class |
DefaultIRCConnection.Consumer
|
INVALID_TIMEOUT| Constructor and Description |
|---|
DefaultIRCConnection(IRCServerConfig serverConfig,
IRCRuntimeConfig runtimeConfig)
|
| Modifier and Type | Method and Description |
|---|---|
void |
addIRCEventListener(IRCEventListener l)
Adds a new
IRCEventListener which listens for actions coming from
the IRC server. |
void |
addIRCEventListener(IRCEventListener l,
int i) |
void |
close()
Close the connection forcefully.
|
void |
connect()
Establish a connection to the server.
|
protected Runnable |
createConsumer() |
protected Thread |
createThread() |
void |
doAway()
Removes away message.
|
void |
doAway(String msg)
Sets away message.
|
void |
doInvite(String nick,
String chan)
Invites a user to a channel.
|
void |
doIson(String nick)
Checks if one or more nicks are used on the server.
|
void |
doJoin(String chan)
Joins a channel without a key.
|
void |
doJoin(String chan,
String key)
Joins a channel with a key.
|
void |
doKick(String chan,
String nick)
Kicks a user from a channel.
|
void |
doKick(String chan,
String nick,
String msg)
Kicks a user from a channel with a comment.
|
void |
doList()
Lists all channels with their topic and status.
|
void |
doList(String chan)
Lists channel(s) with their topic and status.
|
void |
doMode(String chan)
Requests a Reply 324 for the modes of a given channel.
|
void |
doMode(String target,
String mode)
Sends a mode to the server.
|
void |
doNames()
Lists all visible users.
|
void |
doNames(String chan)
Lists all visible users of (a) channel(s).
|
void |
doNick(String nick)
Changes the nickname.
|
void |
doNotice(String target,
String msg)
Notices a message to a person or a channel.
|
void |
doPart(String chan)
Parts from a given channel.
|
void |
doPart(String chan,
String msg)
Parts from a given channel with a given parg-msg.
|
void |
doPong(String ping)
Quits from the IRC server with a quit-msg.
|
void |
doPrivmsg(String target,
String msg)
Sends a message to a person or a channel.
|
void |
doQuit()
Quits from the IRC server.
|
void |
doQuit(String msg)
Quits from the IRC server with a quit-msg.
|
void |
doTopic(String chan)
Requests the topic of a chan.
|
void |
doTopic(String chan,
String topic)
Changes the topic of a chan.
|
void |
doUserhost(String nick)
Requires host-information about up to 5 users which must be listed and
divided by spaces.
|
void |
doWho(String criteric)
Requests information about users matching the given criteric, for example
a channel they are on.
|
void |
doWhois(String nick)
Requires information about an existing user.
|
void |
doWhowas(String nick)
Requires host-information about a user, who is not connected anymore.
|
InetAddress |
getLocalAddress()
Returns the local address of the connection socket.
|
String |
getNick()
Returns the nickname of this instance.
|
int |
getPort()
Returns the port to which the
IRCConnection connected, or
0 if the connection failed or wasn't tried yet. |
int |
getTimeout()
Returns the timeout of the socket.
|
boolean |
isConnected()
Tells whether there's a connection to the IRC network or not.
|
boolean |
isSSL() |
boolean |
removeIRCEventListener(IRCEventListener l)
Removes the first occurence of the given
IRCEventListener from
the listener-vector. |
void |
send(String line)
Sends a String to the server.
|
String |
toString() |
public DefaultIRCConnection(IRCServerConfig serverConfig, IRCRuntimeConfig runtimeConfig)
DefaultIRCConnection out of the given
IRCServerConfig and IRCRuntimeConfig. DO not forget to
call connect() after you have prepared the connection.serverConfig - the IRCServerConfigruntimeConfig - the IRCRuntimeConfigpublic void connect()
throws IOException,
KeyManagementException,
NoSuchAlgorithmException
IRCConnection
It tries all ports from IRCServerConfig.getPorts() until the connecting
succeeds. If all ports fail an IOException is thrown.
This method can be invokde once only.
connect in interface IRCConnectionIOException - If an I/O error occurs.SocketException - If the connect method was already invoked.KeyManagementException - rethrown from the SSL layerNoSuchAlgorithmException - rethrown from the SSL layerIRCConnection.connect()protected Thread createThread()
protected Runnable createConsumer()
DefaultIRCConnection.Consumer.public void send(String line)
IRCConnectiondo* methods (like
doJoin). A carriage return line feed (\r\n) is
appended automatically.send in interface IRCConnectionline - The line which should be send to the server without the
trailing carriage return line feed (\r\n).IRCConnection.send(java.lang.String)public void close()
IRCConnection
This method does not send QUIT IRC command. Consider
using IRCConnection.doQuit() or IRCConnection.doQuit(String) to send the proper
QUIT command to the server.
This method should be used only when there is a good reason for that,
e.g. that the IRC server does not react to QUIT command.
Possibly occuring IOExceptions are handled according to the
set exception handling.
close in interface IRCConnectionIRCConnection.close()public void addIRCEventListener(IRCEventListener l)
IRCConnectionIRCEventListener which listens for actions coming from
the IRC server.addIRCEventListener in interface IRCConnectionl - An instance of the IRCEventListener interface.IRCConnection.addIRCEventListener(org.schwering.irc.lib.IRCEventListener)public void addIRCEventListener(IRCEventListener l, int i)
public boolean removeIRCEventListener(IRCEventListener l)
IRCConnectionIRCEventListener from
the listener-vector.removeIRCEventListener in interface IRCConnectionl - An instance of the IRCEventListener interface.true if the listener was successfully removed;
false if it was not found.IRCConnection.removeIRCEventListener(org.schwering.irc.lib.IRCEventListener)public boolean isConnected()
IRCConnectionconnect wasn't called yet, it returns false.isConnected in interface IRCConnectiontrue if it's
connected.IRCConnection.isConnected()public String getNick()
IRCConnectiongetNick in interface IRCConnectionIRCConnection.getNick()public int getPort()
IRCConnectionIRCConnection connected, or
0 if the connection failed or wasn't tried yet.getPort in interface IRCConnectionIRCConnection, or
0 if the connection failed or wasn't tried yet.IRCConnection.getPort()public int getTimeout()
IRCConnection-1 is returned.
The possibly occuring IOException are handled according to
the set exception handling.getTimeout in interface IRCConnectionIRCConnection.getTimeout()public InetAddress getLocalAddress()
IRCConnectionnull is returned.getLocalAddress in interface IRCConnectionIRCConnection.getLocalAddress()public void doAway()
IRCConnectiondoAway in interface IRCConnectionIRCConnection.doAway()public void doAway(String msg)
IRCConnectiondoAway in interface IRCConnectionmsg - The away message.IRCConnection.doAway(java.lang.String)public void doInvite(String nick, String chan)
IRCConnectiondoInvite in interface IRCConnectionnick - The nickname of the user who should be invited.chan - The channel the user should be invited to.IRCConnection.doInvite(java.lang.String,
java.lang.String)public void doIson(String nick)
IRCConnectiondoIson in interface IRCConnectionnick - The nickname of the user we search for.IRCConnection.doIson(java.lang.String)public void doJoin(String chan)
IRCConnectiondoJoin in interface IRCConnectionchan - The channel which is to join.IRCConnection.doJoin(java.lang.String)public void doJoin(String chan, String key)
IRCConnectiondoJoin in interface IRCConnectionchan - The channel which is to join.key - The key of the channel.IRCConnection.doJoin(java.lang.String,
java.lang.String)public void doKick(String chan, String nick)
IRCConnectiondoKick in interface IRCConnectionchan - The channel somebody should be kicked from.nick - The nickname of the user who should be kicked.IRCConnection.doKick(java.lang.String,
java.lang.String)public void doKick(String chan, String nick, String msg)
IRCConnectiondoKick in interface IRCConnectionchan - The channel somebody should be kicked from.nick - The nickname of the user who should be kicked.msg - The optional kickmessage.IRCConnection.doKick(java.lang.String,
java.lang.String, java.lang.String)public void doList()
IRCConnectiondoList in interface IRCConnectionIRCConnection.doList()public void doList(String chan)
IRCConnectiondoList in interface IRCConnectionchan - The channel the LIST refers to.IRCConnection.doList(java.lang.String)public void doNames()
IRCConnectiondoNames in interface IRCConnectionIRCConnection.doNames()public void doNames(String chan)
IRCConnectiondoNames in interface IRCConnectionchan - The channel the NAMES command is refering to.IRCConnection.doNames(java.lang.String)public void doPrivmsg(String target, String msg)
IRCConnectiondoPrivmsg in interface IRCConnectiontarget - The nickname or channel the message should be sent to.msg - The message which should be transmitted.IRCConnection.doPrivmsg(java.lang.String,
java.lang.String)public void doMode(String chan)
IRCConnectiondoMode in interface IRCConnectionchan - The channel the MODE request is refering to.IRCConnection.doMode(java.lang.String)public void doMode(String target, String mode)
IRCConnectionString mode must contain the operators (+/-), the modes
(o/v/i/k/l/p/s/w) and the possibly values (nicks/banmask/limit/key).doMode in interface IRCConnectiontarget - The nickname or channel of the user whose modes will be
changed.mode - The new modes.IRCConnection.doMode(java.lang.String,
java.lang.String)public void doNick(String nick)
IRCConnectiondoNick in interface IRCConnectionnick - The new nickname.IRCConnection.doNick(java.lang.String)public void doNotice(String target, String msg)
IRCConnectiondoNotice in interface IRCConnectiontarget - The nickname or channel (group) the message should be sent to.msg - The message which should be transmitted.IRCConnection.doNotice(java.lang.String,
java.lang.String)public void doPart(String chan)
IRCConnectiondoPart in interface IRCConnectionchan - The channel you want to part from.IRCConnection.doPart(java.lang.String)public void doPart(String chan, String msg)
IRCConnectiondoPart in interface IRCConnectionchan - The channel you want to part from.msg - The optional partmessage.IRCConnection.doPart(java.lang.String,
java.lang.String)public void doPong(String ping)
IRCConnectiondoPong in interface IRCConnectionping - The ping which was received in onPing. It's a
String, because sometimes on some networks the
server-hostname (for example splatterworld.quakenet.org) is
given as parameter which would throw an Exception if we gave
the ping as long.IRCConnection.doPong(java.lang.String)public void doQuit()
IRCConnectiondisconnect-method which
does the work actually.doQuit in interface IRCConnectionIRCConnection.doQuit()public void doQuit(String msg)
IRCConnectiondisconnect-method which does the work actually.doQuit in interface IRCConnectionmsg - The optional quitmessage.IRCConnection.doQuit(java.lang.String)public void doTopic(String chan)
IRCConnectiondoTopic in interface IRCConnectionchan - The channel which topic should be requested.IRCConnection.doTopic(java.lang.String)public void doTopic(String chan, String topic)
IRCConnectiondoTopic in interface IRCConnectionchan - The channel which topic is changed.topic - The new topic.IRCConnection.doTopic(java.lang.String,
java.lang.String)public void doWho(String criteric)
IRCConnectiondoWho in interface IRCConnectioncriteric - The criterics of the WHO query.IRCConnection.doWho(java.lang.String)public void doWhois(String nick)
IRCConnectiondoWhois in interface IRCConnectionnick - The nickname of the user the query is refering to.IRCConnection.doWhois(java.lang.String)public void doWhowas(String nick)
IRCConnectiondoWhowas in interface IRCConnectionnick - The nickname of the user the query is refering to.IRCConnection.doWhowas(java.lang.String)public void doUserhost(String nick)
IRCConnectiondoUserhost in interface IRCConnectionnick - The nickname of the user the query is refering to.IRCConnection.doUserhost(java.lang.String)public boolean isSSL()
isSSL in interface IRCConnectiontrue if the connection is using SSLIRCConnection.isSSL()Copyright © 2006–2015. All rights reserved.