X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;ds=sidebyside;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Firc%2FConnection.java;h=0cbbae83826cc672295397a9d28c79915705e751;hb=64c32d0191b803facf4e867cb94d5eb6812ef1cb;hp=bf6065f515dd22d9aa3eaba92261255c6cf9bbbc;hpb=201341daa514e5c54e832d2372c65fd65bcb6ebb;p=xudocci.git diff --git a/src/main/java/net/pterodactylus/irc/Connection.java b/src/main/java/net/pterodactylus/irc/Connection.java index bf6065f..0cbbae8 100644 --- a/src/main/java/net/pterodactylus/irc/Connection.java +++ b/src/main/java/net/pterodactylus/irc/Connection.java @@ -44,6 +44,7 @@ import net.pterodactylus.irc.event.ChannelMessageReceived; import net.pterodactylus.irc.event.ChannelNicknames; import net.pterodactylus.irc.event.ChannelNotJoined; import net.pterodactylus.irc.event.ChannelNotJoined.Reason; +import net.pterodactylus.irc.event.ChannelNoticeReceived; import net.pterodactylus.irc.event.ChannelTopic; import net.pterodactylus.irc.event.ClientQuit; import net.pterodactylus.irc.event.ConnectionClosed; @@ -56,6 +57,7 @@ import net.pterodactylus.irc.event.NicknameChanged; import net.pterodactylus.irc.event.NicknameInUseReceived; import net.pterodactylus.irc.event.NoNicknameGivenReceived; import net.pterodactylus.irc.event.PrivateMessageReceived; +import net.pterodactylus.irc.event.PrivateNoticeReceived; import net.pterodactylus.irc.event.UnknownReplyReceived; import net.pterodactylus.irc.util.RandomNickname; @@ -142,6 +144,22 @@ public class Connection extends AbstractExecutionThreadService implements Servic // /** + * Returns the hostname of the remote end of the connection. + * @return The remote’s hostname + */ + public String hostname() { + return hostname; + } + + /** + * Returns the port number of the remote end of the connection. + * @return The remote’s port number + */ + public int port() { + return port; + } + + /** * Returns whether this connection has already been established. * * @return {@code true} as long as this connection is established, {@code @@ -276,6 +294,16 @@ public class Connection extends AbstractExecutionThreadService implements Servic connectionHandler.sendCommand("PRIVMSG", recipient, String.format("\u0001DCC RESUME %s %d %d\u0001", filename, port, position)); } + /** + * Closes this connection. + * + * @throws IOException + * if an I/O error occurs + */ + public void close() throws IOException { + connectionHandler.close(); + } + // // ABSTRACTEXECUTIONTHREADSERVICE METHODS // @@ -339,6 +367,16 @@ public class Connection extends AbstractExecutionThreadService implements Servic eventBus.post(new ChannelMessageReceived(this, recipient, reply.source().get(), message)); } + } else if (command.equalsIgnoreCase("NOTICE")) { + String recipient = parameters.get(0); + String message = parameters.get(1); + if (message.startsWith("\u0001") && message.endsWith("\u0001")) { + /* CTCP! */ + handleCtcp(reply.source().get(), message); + } else if (!channelTypes.contains(recipient.charAt(0))) { + eventBus.post(new PrivateNoticeReceived(this, reply)); + } else { + eventBus.post(new ChannelNoticeReceived(this, reply.source().get(), recipient, message)); } /* 43x replies are for nick change errors. */