forked from pixtaded/crab
Minor fixes
This commit is contained in:
parent
e6c41073b0
commit
8f77d2a511
@ -34,7 +34,7 @@ public class Main {
|
|||||||
if (args.length > 1) {
|
if (args.length > 1) {
|
||||||
boolean isProxied = false;
|
boolean isProxied = false;
|
||||||
if (args.length > 2)
|
if (args.length > 2)
|
||||||
isProxied = args[2].equals("on") ? true : false;
|
isProxied = args[2].equals("on");
|
||||||
try {
|
try {
|
||||||
server = new CrabServer(Integer.parseInt(args[1]), isProxied);
|
server = new CrabServer(Integer.parseInt(args[1]), isProxied);
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
@ -42,15 +42,12 @@ public class Main {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
System.err.println("Now enough arguments.");
|
System.err.println("Not enough arguments.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
server.run();
|
server.run();
|
||||||
}
|
}
|
||||||
default -> {
|
default -> System.err.println("Unknown argument");
|
||||||
System.err.println("Unknown argument");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ import java.io.IOException;
|
|||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.ServerSocket;
|
import java.net.ServerSocket;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
|
import java.sql.SQLException;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
public class CrabServer implements Crab {
|
public class CrabServer implements Crab {
|
||||||
@ -92,8 +93,11 @@ public class CrabServer implements Crab {
|
|||||||
isStopped = true;
|
isStopped = true;
|
||||||
try {
|
try {
|
||||||
if (serverSocket != null) serverSocket.close();
|
if (serverSocket != null) serverSocket.close();
|
||||||
|
getDb().close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.err.println("An error occured while closing the socket: " + e.getMessage());
|
System.err.println("An error occured while closing the socket: " + e.getMessage());
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
} finally {
|
} finally {
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
}
|
}
|
||||||
|
@ -61,4 +61,8 @@ public class Database {
|
|||||||
String logsString = s.toString();
|
String logsString = s.toString();
|
||||||
return new Logs(logsString.isEmpty() ? 0 : logsString.getBytes().length, logsString);
|
return new Logs(logsString.isEmpty() ? 0 : logsString.getBytes().length, logsString);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void close() throws SQLException {
|
||||||
|
connection.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,7 @@ public class ServerThread implements Runnable {
|
|||||||
}
|
}
|
||||||
if (Arrays.equals(readUntilChar(' '),"ROXY".getBytes())) {
|
if (Arrays.equals(readUntilChar(' '),"ROXY".getBytes())) {
|
||||||
readUntilChar(' '); // proto
|
readUntilChar(' '); // proto
|
||||||
byte source[] = readUntilChar(' ');
|
byte[] source = readUntilChar(' ');
|
||||||
address = new String(source);
|
address = new String(source);
|
||||||
readUntilChar(' '); // destination IP
|
readUntilChar(' '); // destination IP
|
||||||
readUntilChar(' '); // source port
|
readUntilChar(' '); // source port
|
||||||
@ -99,14 +99,14 @@ public class ServerThread implements Runnable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private byte[] readUntilChar(char c) throws IOException {
|
private byte[] readUntilChar(char c) throws IOException {
|
||||||
byte b[] = new byte[256];
|
byte[] b = new byte[256];
|
||||||
int i;
|
int i;
|
||||||
for (i = 0;; i++) {
|
for (i = 0;; i++) {
|
||||||
b[i] = (byte)input.read();
|
b[i] = (byte)input.read();
|
||||||
if (b[i] == c)
|
if (b[i] == c)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
byte r[] = new byte[i];
|
byte[] r = new byte[i];
|
||||||
System.arraycopy(b, 0, r, 0, i);
|
System.arraycopy(b, 0, r, 0, i);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user