Warm "hello" for the matscan. Removing garbage when shutting down a listener thread

This commit is contained in:
Dereku 2026-10-23 08:59:59 +07:00
parent 871ffbdc2c
commit fefd3eee9a
2 changed files with 12 additions and 5 deletions

View file

@ -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>

View file

@ -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,8 +121,10 @@ 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) {
this.logger.warning("An exception occurred while communicating with " + address); if (this.working.get()) {
this.logger.log(Level.WARNING, "Exception in " + this.getName(), ex); this.logger.warning("An exception occurred while communicating with " + address);
this.logger.log(Level.WARNING, "Exception in " + this.getName(), ex);
}
} }
} }
} }