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>
|
<groupId>net.rubeta</groupId>
|
||||||
<artifactId>LegacyPing</artifactId>
|
<artifactId>LegacyPing</artifactId>
|
||||||
<version>2.1</version>
|
<version>2.2</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>LegacyPing</name>
|
<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 \"}," +
|
private static final String DISCONNECT_REASON = "[\"\",{\"text\":\"This is b1.7.3 server. Visit \"}," +
|
||||||
"{\"text\":\"https://rubeta.net\",\"underlined\":true},{\"text\":\" for more information.\"}]";
|
"{\"text\":\"https://rubeta.net\",\"underlined\":true},{\"text\":\" for more information.\"}]";
|
||||||
private static final String SLOWSTACK_ID = "slowstack.tv";
|
private static final String SLOWSTACK_ID = "slowstack.tv";
|
||||||
|
private static final String MATSCAN_ID = "matscan";
|
||||||
private final AtomicBoolean working = new AtomicBoolean(false);
|
private final AtomicBoolean working = new AtomicBoolean(false);
|
||||||
private final Server minecraftServer;
|
private final Server minecraftServer;
|
||||||
private final String version;
|
private final String version;
|
||||||
|
|
@ -86,12 +87,16 @@ public class ServerThread extends Thread {
|
||||||
final int port = inputStream.readShort();
|
final int port = inputStream.readShort();
|
||||||
final int status = this.readVarInt(inputStream);
|
final int status = this.readVarInt(inputStream);
|
||||||
this.logger.info("Ping from " + socket.getRemoteSocketAddress() + " to " + hostname + ":" + port);
|
this.logger.info("Ping from " + socket.getRemoteSocketAddress() + " to " + hostname + ":" + port);
|
||||||
boolean slowstack = hostname.equalsIgnoreCase(SLOWSTACK_ID);
|
|
||||||
if (status != 2) {
|
if (status != 2) {
|
||||||
if (slowstack) {
|
if (hostname.equalsIgnoreCase(SLOWSTACK_ID)) {
|
||||||
this.responseForModernPing(outputStream, MODERN_RESPONSE.replace(
|
this.responseForModernPing(outputStream, MODERN_RESPONSE.replace(
|
||||||
"%motd%", "%motd% \nHello, slowstack.tv!"
|
"%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 {
|
} else {
|
||||||
this.responseForModernPing(outputStream, MODERN_RESPONSE);
|
this.responseForModernPing(outputStream, MODERN_RESPONSE);
|
||||||
}
|
}
|
||||||
|
|
@ -116,12 +121,14 @@ public class ServerThread extends Thread {
|
||||||
outputStream.writeLong(inputStream.readLong()); // timestamp
|
outputStream.writeLong(inputStream.readLong()); // timestamp
|
||||||
} catch (SocketTimeoutException | EOFException ignore) {
|
} catch (SocketTimeoutException | EOFException ignore) {
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
|
if (this.working.get()) {
|
||||||
this.logger.warning("An exception occurred while communicating with " + address);
|
this.logger.warning("An exception occurred while communicating with " + address);
|
||||||
this.logger.log(Level.WARNING, "Exception in " + this.getName(), ex);
|
this.logger.log(Level.WARNING, "Exception in " + this.getName(), ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void shutdown() {
|
public void shutdown() {
|
||||||
this.working.set(false);
|
this.working.set(false);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue