From ed80af620fa03ff1749bc1a4385e22f709a4693a Mon Sep 17 00:00:00 2001
From: Matteo Morena <8678043+xmamo@users.noreply.github.com>
Date: Fri, 21 Oct 2016 20:39:06 +0200
Subject: [PATCH] Fix #16
---
pom.xml | 2 +-
.../mamo/vanillaVotifier/VotifierServer.java | 9 +++++++--
.../VotifierServerListener.java | 5 +++++
.../event/ReadTimedOutExceptionEvent.java | 20 +++++++++++++++++++
.../mamo/vanillaVotifier/lang/lang.properties | 5 +++--
.../vanillaVotifier/lang/lang_it.properties | 3 ++-
6 files changed, 38 insertions(+), 6 deletions(-)
create mode 100644 src/main/java/mamo/vanillaVotifier/event/ReadTimedOutExceptionEvent.java
diff --git a/pom.xml b/pom.xml
index bcbfdaa..ec9ef91 100644
--- a/pom.xml
+++ b/pom.xml
@@ -20,7 +20,7 @@
4.0.0
mamo
VanillaVotifier
- 4.0.1
+ 4.0.2
org.jetbrains
diff --git a/src/main/java/mamo/vanillaVotifier/VotifierServer.java b/src/main/java/mamo/vanillaVotifier/VotifierServer.java
index 1521014..4df6d4a 100644
--- a/src/main/java/mamo/vanillaVotifier/VotifierServer.java
+++ b/src/main/java/mamo/vanillaVotifier/VotifierServer.java
@@ -25,11 +25,11 @@
import org.jetbrains.annotations.Nullable;
import javax.crypto.BadPaddingException;
-import java.io.BufferedInputStream;
-import java.io.IOException;
+import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketOptions;
+import java.net.SocketTimeoutException;
import java.security.interfaces.RSAPublicKey;
import java.util.AbstractMap.SimpleEntry;
import java.util.HashMap;
@@ -73,6 +73,9 @@ public void run() {
try {
notifyListeners(new ConnectionEstablishedEvent(socket));
socket.setSoTimeout(SocketOptions.SO_TIMEOUT); // SocketException: handled by try/catch.
+ BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
+ writer.write("VOTIFIER 2.9\n");
+ writer.flush();
BufferedInputStream in = new BufferedInputStream(socket.getInputStream()); // IOException: handled by try/catch.
byte[] request = new byte[((RSAPublicKey) votifier.getConfig().getKeyPair().getPublic()).getModulus().bitLength() / Byte.SIZE];
in.read(request); // IOException: handled by try/catch.
@@ -128,6 +131,8 @@ public void run() {
} catch (Exception e) { // IOException: catching just in case. Continue even if stream doesn't close.
notifyListeners(new ConnectionInputStreamCloseExceptionEvent(socket, e));
}
+ } catch (SocketTimeoutException e) {
+ notifyListeners(new ReadTimedOutExceptionEvent(socket, e));
} catch (BadPaddingException e) {
notifyListeners(new DecryptInputExceptionEvent(socket, e));
} catch (Exception e) {
diff --git a/src/main/java/mamo/vanillaVotifier/VotifierServerListener.java b/src/main/java/mamo/vanillaVotifier/VotifierServerListener.java
index 5d08d0e..29c5933 100644
--- a/src/main/java/mamo/vanillaVotifier/VotifierServerListener.java
+++ b/src/main/java/mamo/vanillaVotifier/VotifierServerListener.java
@@ -118,6 +118,11 @@ public void onEvent(@NotNull Event event) {
new SimpleEntry("exception", connectionCloseException.getException()));
} else if (event instanceof DecryptInputExceptionEvent) {
votifier.getLogger().printlnTranslation("s46");
+ } else if (event instanceof ReadTimedOutExceptionEvent) {
+ ReadTimedOutExceptionEvent readTimedOutExceptionEvent = (ReadTimedOutExceptionEvent) event;
+ votifier.getLogger().printlnTranslation("s64",
+ new SimpleEntry("ip", readTimedOutExceptionEvent.getSocket().getInetAddress().getHostAddress()),
+ new SimpleEntry("port", readTimedOutExceptionEvent.getSocket().getPort()));
} else if (event instanceof CommunicationExceptionEvent) {
votifier.getLogger().printlnTranslation("s29", new SimpleEntry("exception", ((CommunicationExceptionEvent) event).getException()));
} else if (event instanceof ConnectionEstablishExceptionEvent) {
diff --git a/src/main/java/mamo/vanillaVotifier/event/ReadTimedOutExceptionEvent.java b/src/main/java/mamo/vanillaVotifier/event/ReadTimedOutExceptionEvent.java
new file mode 100644
index 0000000..4f55c27
--- /dev/null
+++ b/src/main/java/mamo/vanillaVotifier/event/ReadTimedOutExceptionEvent.java
@@ -0,0 +1,20 @@
+package mamo.vanillaVotifier.event;
+
+import org.jetbrains.annotations.NotNull;
+
+import java.net.Socket;
+
+public class ReadTimedOutExceptionEvent extends AbstractExceptionEvent implements SocketEvent {
+ protected @NotNull Socket socket;
+
+ public ReadTimedOutExceptionEvent(@NotNull Socket socket, @NotNull Exception exception) {
+ super(exception);
+ this.socket = socket;
+ }
+
+ @Override
+ @NotNull
+ public Socket getSocket() {
+ return socket;
+ }
+}
\ No newline at end of file
diff --git a/src/main/resources/mamo/vanillaVotifier/lang/lang.properties b/src/main/resources/mamo/vanillaVotifier/lang/lang.properties
index 8c6a5de..c602cb3 100644
--- a/src/main/resources/mamo/vanillaVotifier/lang/lang.properties
+++ b/src/main/resources/mamo/vanillaVotifier/lang/lang.properties
@@ -54,7 +54,7 @@ s39=Can't send RCon command: connection refused! Perhaps the Minecraft RCon serv
s40-location=info.txt
s41=Wrong arguments! Correct usage: info
s45=Can't load config: JSON is malformed! ${exception}
-s46=Error while while decrypting client input! Perhaps the client has the wrong public key?
+s46=Error while decrypting client input! Perhaps the client has the wrong public key?
s47=Invalid public key file!
s48=Invalid public key file!
s49=Public key file not found!
@@ -69,4 +69,5 @@ s59=Sending shell command: ${command}
s60=Shell command sent.
s61=Can't send shell command: invalid command!
s62=Unexpected exception while sending shell command: ${exception}
-s63=Wrong arguments! Correct usage: showkey <(public|private)>
\ No newline at end of file
+s63=Wrong arguments! Correct usage: showkey <(public|private)>
+s64=${ip}:${port}: connection lost!
\ No newline at end of file
diff --git a/src/main/resources/mamo/vanillaVotifier/lang/lang_it.properties b/src/main/resources/mamo/vanillaVotifier/lang/lang_it.properties
index b046249..f66fe76 100644
--- a/src/main/resources/mamo/vanillaVotifier/lang/lang_it.properties
+++ b/src/main/resources/mamo/vanillaVotifier/lang/lang_it.properties
@@ -69,4 +69,5 @@ s59=Invio comando a shell: ${command}
s60=Comando shell inviato.
s61=Impossibile inviare il comando shell: comando non valido!
s62=Errore imprevisto nell'invio del comando shell: ${exception}
-s63=Argomenti invalidi! Uso corretto: showkey <(public|private)>
\ No newline at end of file
+s63=Argomenti invalidi! Uso corretto: showkey <(public|private)>
+s64=${ip}:${port}: connessione scaduta!
\ No newline at end of file