Description: Limiting Connections Per IP.
How it Works: Each time someone tries to connect to the server, the list simply adds that IP to the array. Once the list see's that same IP appearing a number of times, it simply rejects it.
Difficulty: 2/10
Assumed Knowledge: Importing, declaring, some knowledge about lists.
Tested Server: Pali 508, but will work for every base.
Files/Classes Modified: SocketListener.java, Player.java
Alright, i saw Miescooldude release a way of using Lists to block connections on 317's, and i'm pretty sure not everyone saw it or if it's still around, so i'll just post the way to do it w/ 508s
Before i begin - i would like to explain what a list is just so we know what we're doing.
A list is an array of an object in java, if you know what an array is then this will make sense etc... kind of consuing because a list is an object itself. You might want to read miescooldude's tutorial to understand more about lists.
Anyway, lets get down to it.
Step 1)
We need to import list's right? So lets put this in our imports in the SocketLister class.
Code:
import java.util.*;
You don't really need to import the whole folder since we are only using Lists so just import Lists + Arraylists:
Code:
import java.util.ArrayList;
import java.util.List;
Now, we need to declare our list, so lets call our list... connectionsList
Code:
public static List connectionsList = new ArrayList();
Step 2)
Now, with our list declared and having our lists imported, let's skip on over to the part where the list adds the persons IP upon connecting.
Now, in the method where a persons connection is accepted (Its in socketListener go find out where.)
You would add:
Code:
connectionsList.add(getAddress(socket));
Step 3)
Now, if you would want to make it so its just one IP per connection, you would just put this in the method on the top:
Code:
if(!connectionsList.contains(getAddress(socket)))
But if you were wanting to make it more connections, you'd declare this:
Code:
public int totalConnections(String connection) {
int count = 0;
for(Object o : connectionsList.toArray()) {
if(o.toString().equals(connection)) {
count++;
}
}
return count;
}
And replace
Code:
if(!connectionsList.contains(getAddress(socket)))
with
Code:
if(totalConnections(getAddress(socket)) < #LimitHere)
Instead of
#LimitHere you'd put the max connections you want
So if you want it 3 connections per 1 IP it'd be
Code:
if(totalConnections(getAddress(socket)) < 4)
and this would be 2
Code:
if(totalConnections(getAddress(socket)) < 3)
And so on.
Step 4)
That's right, the final step is to get the list to remove the persons connection when they log out otherwise their IP will stay in the list lal.
So in the player class, in the destruct method, simply add this line:
Code:
Server.socketListener.connectionsList.remove(Server.socketListener.getAddress(this.socket.socket));
And compile, and you are done!
Post all errors you get here.
Correct me on anything if i did anything wrong.
I hope you enjoyed my crappy work )";
Credits:
100% Meiscooldude
Dont forget to import your Server class if you get any errors.
Code:
import palidino76.rs2.Server;