Skip to content

Commit

Permalink
Ignore stop socket connections that don't attempt a password
Browse files Browse the repository at this point in the history
  • Loading branch information
bdw429s committed Oct 11, 2023
1 parent 33efa25 commit f335fb2
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/main/java/runwar/StopMonitor.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
package runwar;

import runwar.options.ServerOptions;
import runwar.Server;
import static runwar.logging.RunwarLogger.LOG;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketException;

import static runwar.logging.RunwarLogger.LOG;

import runwar.options.ServerOptions;

public class StopMonitor extends Thread {

Expand Down Expand Up @@ -42,15 +38,18 @@ public void run() {
listening = true;
LOG.info("Starting 'stop' listener thread - Host: 127.0.0.1 - Socket: " + serverOptions.stopPort());
while (listening) {
if (Server.getServerState() == Server.ServerState.STOPPED || Server.getServerState() == Server.ServerState.STOPPING) {
if (Server.getServerState() == Server.ServerState.STOPPED
|| Server.getServerState() == Server.ServerState.STOPPING) {
listening = false;
}
final Socket clientSocket = serverSocket.accept();
int r, i = 0;
BufferedReader reader = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
try {
boolean receivedInput = false;
while (listening && (r = reader.read()) != -1) {
char ch = (char) r;
receivedInput = true;
if (stoppassword.length > i && ch == stoppassword[i]) {
i++;
} else {
Expand All @@ -61,7 +60,11 @@ public void run() {
listening = false;
} else {
if (listening) {
LOG.warn("Incorrect password used when trying to stop server.");
// Ignore connections that simplky disconnect without sending any data. This is
// probablky just a check to see if the serverr is online
if (receivedInput) {
LOG.warn("Incorrect password used when trying to stop server.");
}
} else {
LOG.debug("Stopped listening for stop password.");
}
Expand Down

0 comments on commit f335fb2

Please sign in to comment.