Warm "hello" for the matscan. Removing garbage when shutting down a listener thread
This commit is contained in:
parent
871ffbdc2c
commit
fefd3eee9a
2 changed files with 12 additions and 5 deletions
2
pom.xml
2
pom.xml
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
<groupId>net.rubeta</groupId>
|
||||
<artifactId>LegacyPing</artifactId>
|
||||
<version>2.1</version>
|
||||
<version>2.2</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>LegacyPing</name>
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ public class ServerThread extends Thread {
|
|||
private static final String DISCONNECT_REASON = "[\"\",{\"text\":\"This is b1.7.3 server. Visit \"}," +
|
||||
"{\"text\":\"https://rubeta.net\",\"underlined\":true},{\"text\":\" for more information.\"}]";
|
||||
private static final String SLOWSTACK_ID = "slowstack.tv";
|
||||
private static final String MATSCAN_ID = "matscan";
|
||||
private final AtomicBoolean working = new AtomicBoolean(false);
|
||||
private final Server minecraftServer;
|
||||
private final String version;
|
||||
|
|
@ -86,12 +87,16 @@ public class ServerThread extends Thread {
|
|||
final int port = inputStream.readShort();
|
||||
final int status = this.readVarInt(inputStream);
|
||||
this.logger.info("Ping from " + socket.getRemoteSocketAddress() + " to " + hostname + ":" + port);
|
||||
boolean slowstack = hostname.equalsIgnoreCase(SLOWSTACK_ID);
|
||||
if (status != 2) {
|
||||
if (slowstack) {
|
||||
if (hostname.equalsIgnoreCase(SLOWSTACK_ID)) {
|
||||
this.responseForModernPing(outputStream, MODERN_RESPONSE.replace(
|
||||
"%motd%", "%motd% \nHello, slowstack.tv!"
|
||||
));
|
||||
} else if (hostname.equalsIgnoreCase(MATSCAN_ID)) {
|
||||
this.responseForModernPing(outputStream, MODERN_RESPONSE
|
||||
.replace("%motd%", "%motd% \nHello, matscan!")
|
||||
.replace("%version%", "⚠ Error")
|
||||
);
|
||||
} else {
|
||||
this.responseForModernPing(outputStream, MODERN_RESPONSE);
|
||||
}
|
||||
|
|
@ -116,8 +121,10 @@ public class ServerThread extends Thread {
|
|||
outputStream.writeLong(inputStream.readLong()); // timestamp
|
||||
} catch (SocketTimeoutException | EOFException ignore) {
|
||||
} catch (Exception ex) {
|
||||
this.logger.warning("An exception occurred while communicating with " + address);
|
||||
this.logger.log(Level.WARNING, "Exception in " + this.getName(), ex);
|
||||
if (this.working.get()) {
|
||||
this.logger.warning("An exception occurred while communicating with " + address);
|
||||
this.logger.log(Level.WARNING, "Exception in " + this.getName(), ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue