Server functionality restored
This commit is contained in:
parent
30d90f22f2
commit
a4bf914c41
@ -32,7 +32,7 @@ public class ServerThread implements Runnable {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
byte[] PID = input.readNBytes(1);
|
byte[] PID = readPID();
|
||||||
if (PID.length == 0) {
|
if (PID.length == 0) {
|
||||||
socket.close();
|
socket.close();
|
||||||
return;
|
return;
|
||||||
@ -40,20 +40,18 @@ public class ServerThread implements Runnable {
|
|||||||
switch (PID[0]) {
|
switch (PID[0]) {
|
||||||
case COMMUNICATION -> {
|
case COMMUNICATION -> {
|
||||||
String msg = new String(input.readNBytes(4096), StandardCharsets.UTF_8).trim();
|
String msg = new String(input.readNBytes(4096), StandardCharsets.UTF_8).trim();
|
||||||
if (!msg.isEmpty()) {
|
Date date = new Date();
|
||||||
Date date = new Date();
|
String address = socket.getInetAddress().getHostAddress();
|
||||||
String address = socket.getInetAddress().getHostAddress();
|
|
||||||
|
|
||||||
String s = Sanitizer.sanitizeString(msg, true);
|
String s = Sanitizer.sanitizeString(msg, true);
|
||||||
String newContent = server.cache.content() + Sanitizer.formatMessage(date.getTime(), address, s);
|
String newContent = server.cache.content() + Sanitizer.formatMessage(date.getTime(), address, s);
|
||||||
server.cache = new Logs(newContent.getBytes().length, newContent);
|
server.cache = new Logs(newContent.getBytes().length, newContent);
|
||||||
|
|
||||||
new Thread(new LogDBThread(date, address, msg)).start();
|
new Thread(new LogDBThread(date, address, msg)).start();
|
||||||
}
|
} case LOGS_SIZE -> {
|
||||||
} /* case LOGS -> {
|
|
||||||
respond(server.cache.content());
|
|
||||||
} */ case LOGS_SIZE -> {
|
|
||||||
respond(String.valueOf(server.cache.sizeInBytes()));
|
respond(String.valueOf(server.cache.sizeInBytes()));
|
||||||
|
readPID();
|
||||||
|
sendLogs();
|
||||||
} default -> {
|
} default -> {
|
||||||
System.out.println("PID not implemented: " + PID[0]);
|
System.out.println("PID not implemented: " + PID[0]);
|
||||||
}
|
}
|
||||||
@ -64,6 +62,14 @@ public class ServerThread implements Runnable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private byte[] readPID() throws IOException {
|
||||||
|
return input.readNBytes(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendLogs() throws IOException {
|
||||||
|
respond(server.cache.content());
|
||||||
|
}
|
||||||
|
|
||||||
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();
|
||||||
|
Loading…
Reference in New Issue
Block a user