Fix server throwing an ArrayOutOfBoundsException when someone tries to leave
This commit is contained in:
parent
a7ad8770c9
commit
c2e8927c42
@ -30,10 +30,13 @@ public class ServerThread implements Runnable {
|
||||
public void run() {
|
||||
try {
|
||||
byte[] PID = input.readNBytes(1);
|
||||
if (PID.length == 0) {
|
||||
socket.close();
|
||||
return;
|
||||
}
|
||||
switch (PID[0]) {
|
||||
case MESSAGE -> {
|
||||
server.getDb().logMessage(new Date(), socket.getInetAddress().getHostAddress(), new String(input.readNBytes(4096), StandardCharsets.UTF_8).trim());
|
||||
socket.close();
|
||||
} case LOGS -> {
|
||||
respond(server.getDb().getLogs());
|
||||
} case LOGS_SIZE -> {
|
||||
@ -42,6 +45,7 @@ public class ServerThread implements Runnable {
|
||||
System.out.println("PID not implemented: " + PID[0]);
|
||||
}
|
||||
}
|
||||
socket.close();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
@ -50,7 +54,6 @@ public class ServerThread implements Runnable {
|
||||
private void respond(byte[] data) throws IOException {
|
||||
socket.getOutputStream().write(data);
|
||||
socket.getOutputStream().flush();
|
||||
socket.close();
|
||||
}
|
||||
|
||||
private void respond(String utf8) throws IOException {
|
||||
|
Loading…
Reference in New Issue
Block a user