master #1

Merged
bedohswe merged 27 commits from pixtaded/crab:master into master 2025-02-11 18:05:01 +00:00
Showing only changes of commit c2e8927c42 - Show all commits

View File

@ -30,10 +30,13 @@ public class ServerThread implements Runnable {
public void run() { public void run() {
try { try {
byte[] PID = input.readNBytes(1); byte[] PID = input.readNBytes(1);
if (PID.length == 0) {
socket.close();
return;
}
switch (PID[0]) { switch (PID[0]) {
case MESSAGE -> { case MESSAGE -> {
server.getDb().logMessage(new Date(), socket.getInetAddress().getHostAddress(), new String(input.readNBytes(4096), StandardCharsets.UTF_8).trim()); server.getDb().logMessage(new Date(), socket.getInetAddress().getHostAddress(), new String(input.readNBytes(4096), StandardCharsets.UTF_8).trim());
socket.close();
} case LOGS -> { } case LOGS -> {
respond(server.getDb().getLogs()); respond(server.getDb().getLogs());
} case LOGS_SIZE -> { } case LOGS_SIZE -> {
@ -42,6 +45,7 @@ public class ServerThread implements Runnable {
System.out.println("PID not implemented: " + PID[0]); System.out.println("PID not implemented: " + PID[0]);
} }
} }
socket.close();
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
@ -50,7 +54,6 @@ public class ServerThread implements Runnable {
private void respond(byte[] data) throws IOException { private void respond(byte[] data) throws IOException {
socket.getOutputStream().write(data); socket.getOutputStream().write(data);
socket.getOutputStream().flush(); socket.getOutputStream().flush();
socket.close();
} }
private void respond(String utf8) throws IOException { private void respond(String utf8) throws IOException {