+ private void processDccSend(Source client, String message,
+ String[] messageWords) {
+ Optional<DccSendInformation> dccSendInformation = parseDccSendInformation(messageWords);
+ if (dccSendInformation.isPresent()) {
+ eventBus.post(new DccSendReceived(connection, client,
+ dccSendInformation.get().filename,
+ dccSendInformation.get().internetAddress,
+ dccSendInformation.get().port,
+ dccSendInformation.get().size));
+ } else {
+ logger.warn(format("Received malformed DCC SEND: “%s”", message));
+ }
+ }
+
+ private Optional<DccSendInformation> parseDccSendInformation(String[] messageWords) {
+ if (messageWords.length <5) {
+ return absent();
+ }
+ Optional<InetAddress> internetAddress = parseInetAddress(messageWords[3]);
+ Optional<Integer> port = fromNullable(Ints.tryParse(messageWords[4]));
+ long fileSize = (messageWords.length > 5) ? fromNullable(Longs.tryParse(messageWords[5])).or(-1L) : -1;
+ if (!internetAddress.isPresent() || !port.isPresent()) {
+ return absent();
+ }
+ return of(new DccSendInformation(messageWords[2], internetAddress.get(), port.get(), fileSize));
+ }
+
+ private static class DccSendInformation {
+
+ private final String filename;
+ private final InetAddress internetAddress;
+ private final int port;
+ private final long size;
+
+ private DccSendInformation(String filename,
+ InetAddress internetAddress, int port, long size) {
+ this.filename = filename;
+ this.internetAddress = internetAddress;
+ this.port = port;
+ this.size = size;
+ }
+
+ }
+