Ban uses IP (not the entire address).
This commit is contained in:
parent
bf2c69bb32
commit
51f3d88a8e
@ -178,7 +178,8 @@ public class Server implements Runnable {
|
|||||||
public void ban(int id, String reason) {
|
public void ban(int id, String reason) {
|
||||||
int pos = findClient(id);
|
int pos = findClient(id);
|
||||||
if(pos < 0) return;
|
if(pos < 0) return;
|
||||||
String clientIP = clients.get(pos).getSocket().getRemoteSocketAddress().toString();
|
String clientAddress = clients.get(pos).getSocket().getRemoteSocketAddress().toString();
|
||||||
|
String clientIP = clientAddress.substring(1, clientAddress.indexOf(':'));
|
||||||
try {
|
try {
|
||||||
PrintWriter banwriter = new PrintWriter(new BufferedWriter(new FileWriter("banned.txt", true)));
|
PrintWriter banwriter = new PrintWriter(new BufferedWriter(new FileWriter("banned.txt", true)));
|
||||||
banwriter.println(clientIP);
|
banwriter.println(clientIP);
|
||||||
@ -212,8 +213,10 @@ public class Server implements Runnable {
|
|||||||
// Add a new client
|
// Add a new client
|
||||||
public void addThread(Socket socket) {
|
public void addThread(Socket socket) {
|
||||||
// If IP is banned to not admit!
|
// If IP is banned to not admit!
|
||||||
|
String clientAddress = socket.getRemoteSocketAddress().toString();
|
||||||
|
String clientIP = clientAddress.substring(1, clientAddress.indexOf(':'));
|
||||||
for(int i = 0; i < banned.size(); i++) {
|
for(int i = 0; i < banned.size(); i++) {
|
||||||
if(socket.getRemoteSocketAddress().toString().equals(banned.get(i))) return;
|
if(clientIP.equals(banned.get(i))) return;
|
||||||
}
|
}
|
||||||
// Otherwise add them
|
// Otherwise add them
|
||||||
clients.add(new ServerThread(this, socket));
|
clients.add(new ServerThread(this, socket));
|
||||||
|
Loading…
Reference in New Issue
Block a user