Jump to content
A Duck Tale

Simple anti-spam for PI(317)

Recommended Posts

EDIT: Ok so I had decided not to sleep and just get it done. there were few errors(due to typos) that made me take it off but I've managed to find and fix them. Enjoy :)

Just made a simple anti-spam for my Project Insanity server and thought I should share. Currently, it blocks out auto typers as well as people spamming the server.

The first thing you'll need to do is to locate your Chat.java

Under the line "public class Chat implements PacketType" put:
[CODE]
// Anti-Spam Check By: A Duck Tale
int spamsAllowed = 8; // amount of spams allowed
int timeAllowed = 5 * 1000; // time to wait in milliseconds.

// Initialize variables
int spamCount = 0;
long timeWaited = 0;
long startTime = 0;
long endTime = 0;
byte[] message = null;
byte[] storeMessage = null;[/CODE]
then under the line "c.inStream.readBytes_reverseA(c.getChatText(), c.getChatTextSize(), 0);" place:
[CODE]
message = c.getChatText();

if (storeMessage == null){
storeMessage = message;
}
else if (storeMessage != null){
if (storeMessage == message){
spamCount++;
if(startTime == 0){
startTime = System.currentTimeMillis();
}
if (spamCount >= spamsAllowed){
endTime = System.currentTimeMillis();
timeWaited = endTime - startTime;
if (timeWaited < timeAllowed){
System.out.println("Kicking....");
startTime = 0;
spamCount = 0;
timeWaited = 0;
endTime = 0;
storeMessage = null;
message = null;
c.logout();
}
else if(timeWaited >= timeAllowed){
startTime = 0;
spamCount = 0;
timeWaited = 0;
endTime = 0;
storeMessage = null;
message = null;
}
}
}
else if (storeMessage != message){
spamCount = 0;
startTime = 0;
storeMessage = message;
}
}[/CODE]
now there are only two things you'll need to change to suit your needs. The first one is the variable 'spamsAllowed', which will be the number of messages the user can type in a given time before kicking them. The second one is 'timeAllowed', which is said 'given time' and determines how long the player must wait until their spam count resets. Let me know if you are having troubles with the code below :) Edited by A Duck Tale

Share this post


Link to post
Share on other sites
nice, but wont use

Share this post


Link to post
Share on other sites
Could be done alot better, thanks though!

Share this post


Link to post
Share on other sites
Very nice, I like it. I might use it as it's very efficient. :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×