From c73481bb889de893d7be0b641074ca268d9959b3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Tue, 6 Feb 2024 12:56:34 +0100 Subject: [PATCH] =?utf8?q?=F0=9F=9A=A7=20Parse=20token=20from=20DCC=20SEND?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit We will need this once Reverse DCC is implemented. --- .../pterodactylus/irc/connection/CtcpHandler.java | 14 ++++++++---- .../pterodactylus/irc/event/DccSendReceived.java | 25 +++++++--------------- .../irc/connection/CtcpHandlerTest.java | 12 +++++++++++ 3 files changed, 30 insertions(+), 21 deletions(-) diff --git a/src/main/java/net/pterodactylus/irc/connection/CtcpHandler.java b/src/main/java/net/pterodactylus/irc/connection/CtcpHandler.java index 8dc6933..fb59ea7 100644 --- a/src/main/java/net/pterodactylus/irc/connection/CtcpHandler.java +++ b/src/main/java/net/pterodactylus/irc/connection/CtcpHandler.java @@ -81,7 +81,8 @@ public class CtcpHandler implements Handler { dccSendInformation.get().filename, dccSendInformation.get().internetAddress, dccSendInformation.get().port, - dccSendInformation.get().size)); + dccSendInformation.get().size, + dccSendInformation.get().token)); } else { logger.warn(format("Received malformed DCC SEND: “%s”", message)); } @@ -97,7 +98,11 @@ public class CtcpHandler implements Handler { if (!internetAddress.isPresent() || !port.isPresent()) { return absent(); } - return of(new DccSendInformation(messageWords[2], internetAddress.get(), port.get(), fileSize)); + String token = null; + if (messageWords.length > 6) { + token = messageWords[6]; + } + return of(new DccSendInformation(messageWords[2], internetAddress.get(), port.get(), fileSize, token)); } private static class DccSendInformation { @@ -106,13 +111,14 @@ public class CtcpHandler implements Handler { private final InetAddress internetAddress; private final int port; private final long size; + private final String token; - private DccSendInformation(String filename, - InetAddress internetAddress, int port, long size) { + private DccSendInformation(String filename, InetAddress internetAddress, int port, long size, String token) { this.filename = filename; this.internetAddress = internetAddress; this.port = port; this.size = size; + this.token = token; } } diff --git a/src/main/java/net/pterodactylus/irc/event/DccSendReceived.java b/src/main/java/net/pterodactylus/irc/event/DccSendReceived.java index 95494a4..b3f8bd6 100644 --- a/src/main/java/net/pterodactylus/irc/event/DccSendReceived.java +++ b/src/main/java/net/pterodactylus/irc/event/DccSendReceived.java @@ -44,29 +44,16 @@ public class DccSendReceived extends AbstractConnectionEvent { /** The filesize. */ private final long filesize; - /** - * Creates a new DCC SEND received event. - * - * @param connection - * The connetion the event occured on - * @param source - * The source offering the file - * @param filename - * The name of the file being offered - * @param inetAddress - * The IP address of the source - * @param port - * The port number of the source - * @param filesize - * The size of the file being offered ({@code -1} for unknown size) - */ - public DccSendReceived(Connection connection, Source source, String filename, InetAddress inetAddress, int port, long filesize) { + private final String token; + + public DccSendReceived(Connection connection, Source source, String filename, InetAddress inetAddress, int port, long filesize, String token) { super(connection); this.source = source; this.filename = filename; this.inetAddress = inetAddress; this.port = port; this.filesize = filesize; + this.token = token; } // @@ -120,4 +107,8 @@ public class DccSendReceived extends AbstractConnectionEvent { return port; } + public String token() { + return token; + } + } diff --git a/src/test/java/net/pterodactylus/irc/connection/CtcpHandlerTest.java b/src/test/java/net/pterodactylus/irc/connection/CtcpHandlerTest.java index e1463c9..c8d6306 100644 --- a/src/test/java/net/pterodactylus/irc/connection/CtcpHandlerTest.java +++ b/src/test/java/net/pterodactylus/irc/connection/CtcpHandlerTest.java @@ -3,6 +3,8 @@ package net.pterodactylus.irc.connection; import static net.pterodactylus.irc.Source.parseSource; import static net.pterodactylus.irc.connection.Replies.createReply; import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.is; import static org.mockito.ArgumentCaptor.forClass; import static org.mockito.Matchers.anyObject; @@ -131,6 +133,16 @@ public class CtcpHandlerTest { } @Test + public void dccCommandWithTokenIsRecognizedCorrectly() { + handler.handleReply(createReply(parseSource("User!user@host"), "PRIVMSG", "\u0001DCC SEND filename 1234 0 12345 T123\u0001")); + ArgumentCaptor dccSendReceivedCaptor = forClass(DccSendReceived.class); + verify(eventBus).post(dccSendReceivedCaptor.capture()); + assertThat(dccSendReceivedCaptor.getAllValues(), hasSize(1)); + DccSendReceived dccSendReceived = dccSendReceivedCaptor.getValue(); + assertThat(dccSendReceived.token(), equalTo("T123")); + } + + @Test public void dccAcceptCommandIsRecognized() { handler.handleReply(createReply(parseSource("User!user@host"), "NOTICE", -- 2.7.4