Skip to content

Commit

Permalink
Fix #16
Browse files Browse the repository at this point in the history
  • Loading branch information
xmamo committed Oct 21, 2016
1 parent b87dad7 commit ed80af6
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>mamo</groupId>
<artifactId>VanillaVotifier</artifactId>
<version>4.0.1</version>
<version>4.0.2</version>
<dependencies>
<dependency>
<groupId>org.jetbrains</groupId>
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/mamo/vanillaVotifier/VotifierServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ public void onEvent(@NotNull Event event) {
new SimpleEntry<String, Object>("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<String, Object>("ip", readTimedOutExceptionEvent.getSocket().getInetAddress().getHostAddress()),
new SimpleEntry<String, Object>("port", readTimedOutExceptionEvent.getSocket().getPort()));
} else if (event instanceof CommunicationExceptionEvent) {
votifier.getLogger().printlnTranslation("s29", new SimpleEntry<String, Object>("exception", ((CommunicationExceptionEvent) event).getException()));
} else if (event instanceof ConnectionEstablishExceptionEvent) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
5 changes: 3 additions & 2 deletions src/main/resources/mamo/vanillaVotifier/lang/lang.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand All @@ -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)>
s63=Wrong arguments! Correct usage: showkey <(public|private)>
s64=${ip}:${port}: connection lost!
Original file line number Diff line number Diff line change
Expand Up @@ -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)>
s63=Argomenti invalidi! Uso corretto: showkey <(public|private)>
s64=${ip}:${port}: connessione scaduta!

0 comments on commit ed80af6

Please sign in to comment.