Jump to content

Recommended Posts

Posted

Note: This does not invoke you to use any god damn firewall, or for you to do a lot of work. This is probably one of the ONLY ways you can fully stop SYI and any other DDoS'r until they learn how to send Packet 14.

 

If this gets locked, it gets locked. I don't know how long it'll take you to do it, and it's kind of hard to avoid c|p. At least you get one good thing out of it: No more SYI pissing us off.

 

 

Seriously guys, the shitty tutorials about firewalls and incorrectly blocking this and your lame-brain questions have got to stop.

Not sure if this was ever made before, but this is my version. I changed everything around to make it look a lot more readable, and removed unnecessary junk (useless comments, etc, etc).

 

This will: Correctly protect your server against DDoS attacks and deal with them right. We will NOT use any Firewalls, and instead use what you people should have been using.

 

Before you start, you should know: Well, you're going to have to work. You will have to add all of the handlers you use to the class provided here. Only ones added are the obvious ones: clientHandler and playerHandler.

 

Base: Any wL base. You probably use it, right?

 

This has been tested: Yes.. But not extensively. KEEP BACKUPS.

 

Alright, well there isnt a lot of stuff to do, so let's start.

 

Open the client class.

Now, search for:

 

if(inStream.readUnsignedByte() != 14) {

 

This will be found in your run method.

 

Comment or delete the block of code. It looks similar to:

 

if(inStream.readUnsignedByte() != 14) {
			shutdownError("Expected login Id 14 from client.");
			disconnected = true;
			return;
		}

 

This block will check if packet 14 exists, but of course when we're checking for the packet in the socket process it makes it mysteriously disappear. Big Grin

 

 

Now we have the fun part, we get to redo your server class! Make a backup of your server class, just incase. Smiley

Replace your WHOLE class with the following: (Yes, I did say REPLACE.)

 

/*
* server.java
* 
* Version 1.0a
*
* Date: Tuesday June 19th, 2008.
* 
* Author: M@n80$
*
*  Correctly blocking SYI, and useless **** taken out.
*/

import java.sql.*;
import java.io.*;
import java.net.Socket;
import java.util.StringTokenizer;
import java.util.Calendar;
import java.util.GregorianCalendar;

public class server implements Runnable {

public server() { }

public static void main(java.lang.String args[]) {
	clientHandler = new server();
	(new Thread(clientHandler)).start();
	playerHandler = new PlayerHandler();
	int waitFails = 0;
	long lastTicks = System.currentTimeMillis();
	long totalTimeSpentProcessing = 0;
	int cycle = 0;
	while(!shutdownServer) {
		if(updateServer)
			calcTime();
		playerHandler.process();
		System.gc();
		long timeSpent = System.currentTimeMillis() - lastTicks;
		totalTimeSpentProcessing += timeSpent;
		if(timeSpent >= cycleTime) {
			timeSpent = cycleTime;
			if(++waitFails > 100) {
				misc.println("[KERNEL]: machine is too slow to run this server!");
			}
		}
		try {
			Thread.sleep(cycleTime-timeSpent);
		} catch(java.lang.Exception _ex) { }
		lastTicks = System.currentTimeMillis();
		cycle++;
		if(cycle % 100 == 0) {
			float time = ((float)totalTimeSpentProcessing)/cycle;
		}
		if (cycle % 3600 == 0) {
			System.gc();
		}
		if (ShutDown == true) {
			if (ShutDownCounter >= 100) {
				shutdownServer = true;
			}
			ShutDownCounter++;
		}
	}
	playerHandler.destruct();
	clientHandler.killServer();
	clientHandler = null;
}

public void run() {
	try {
		shutdownClientHandler = false;
		clientListener = new java.net.ServerSocket(serverListenerPort, 1, null);
		misc.println("Running server on port: "+serverListenerPort);
		misc.println("     Server class revamped by Hidendra.");
		while(true) {
			Socket s = clientListener.accept();
			s.setTcpNoDelay(true);
			String connectingHost = s.getInetAddress().getHostName();
			int type = 0;
			type = s.getInputStream().read();
			if(clientListener != null) {
				int Found = -1;
				for (int i = 0; i < MaxConnections; i++) {
					if (Connections[i] == connectingHost) {
						Found = ConnectionCount[i];
						break;
					}
				}
				if (Found < 3) {
					if(type == 14) {
						misc.println("ClientHandler: Accepted from "+connectingHost+":"+s.getPort());
						playerHandler.newPlayerClient(s, connectingHost);
					} else {
						// if you want to do anything for INVALID clients, add it here.
						//  don't just ipban them box-side (ie: iptables).. 
						//  because possible connections include, but not limited to:
						//    - DDoS'ers / SYI
						//    - Server Status checkers (Mopar's, ETC!)
						PrintWriter out = new PrintWriter(s.getOutputStream());
						out.println("HTTP/1.0 200 OK");
						out.println("Content-Type: text/html");
						out.println("Server: Bot");
						out.println("");
						out.println("You are connecting to this private server VIA a web browser. <br/> <br/>   Please connect using a <b>VALID</b> client, like MoparScape. <br/>Thank you!");
						out.flush();
						s.close();
					}
				}
			}
		}
	} catch(java.io.IOException ioe) {
		if(!shutdownClientHandler) {
			misc.println("[FATAL]: Port: "+serverListenerPort+" already in use?");
		} else {
			misc.println("ClientHandler was shut down.");
		}
	}
}

public static void calcTime() {
	long curTime = System.currentTimeMillis();
	updateSeconds = 180 - ((int)(curTime - startTime) / 1000);
	if(updateSeconds == 0) {
		shutdownServer = true;
	}
}

public void killServer() {
	try {
		shutdownClientHandler = true;
		if(clientListener != null) clientListener.close();
		clientListener = null;
	} catch(java.lang.Exception __ex) {
		__ex.printStackTrace();
	}
}

public static int EnergyRegian = 60;
public static int MaxConnections = 999000;
public static String[] Connections = new String[MaxConnections];
public static int[] ConnectionCount = new int[MaxConnections];
public static boolean ShutDown = false;
public static int ShutDownCounter = 0;
public static final int cycleTime = 500;
public static boolean updateServer = false;
public static int updateSeconds = 180;
public static long startTime;
public static Connection connection = null;
public static server clientHandler = null;
public static java.net.ServerSocket clientListener = null;
public static boolean shutdownServer = false;
public static boolean shutdownClientHandler;
public static int serverListenerPort = 43594;
public static PlayerHandler playerHandler = null;


}

 

Now, it should work.. You shouldn't be invadedz by nulls and weird connecting from..'s

I added a sorta-cool twist to the server class, when your server is running, in a web browser type http://localhostort in your address bar, where port is the port of the server, IE 43594.. I implemented a quick webserver to send that information, you can easily change or remove it by looking at the code. Smiley

 

Not really much of a webserver, just a 5 second thing xD.

 

 

Also, you will have to add your handlers yourself, including the public static <class> <othername> yourself, and the new <class>();

No, I am not doing it for you. If you want DDoS protection, then you're going to have to work for it.

 

If you have any questions, please post them here and I will of course try to answer them as best I can..

Cheers!

 

 

AND I DO REALIZE YOU CAN JUST USE FIREWALL VOIDS I JUST FIND THIS EASIER!

Posted

Nice !

 

One question : where's the DDoS protection ?

 

jajajaja LOOOOOOOOOOL can't stop laughing xD :P

BTW if someone wants to dosS you then nothing can save you from the anger of a powerful hacker ;o

 

 

Posted

jajajaja LOOOOOOOOOOL can't stop laughing xD :P

BTW if someone wants to dosS you then nothing can save you from the anger of a powerful hacker ;o

 

 

 

You can always unplug the PC and run around with your arms in the air, may not save you, but it'll be really fun to watch, you may even become an Internet meme.

Posted

jajajaja LOOOOOOOOOOL can't stop laughing xD :P

BTW if someone wants to dosS you then nothing can save you from the anger of a powerful hacker ;o

 

 

Oh God.
Posted

You can always unplug the PC and run around with your arms in the air, may not save you, but it'll be really fun to watch, you may even become an Internet meme.

I laughed hard to this one. I will be behind with a camera to take photo and post on facebook if that happens.

 

CLICK ME

 

Trolollololololol. H4Xl33t.

 

Locked.

Guest
This topic is now closed to further replies.


  • Posts

    • faster than i thought but congratulation that's looking pretty pure work here 
    • L2 PEARL — OPEN BETA REWARDS   Join the L2 Pearl Open Beta and receive exclusive rewards for your participation. ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ OPEN BETA REWARDS   Players who participate in the Open Beta will receive: • One exclusive Open Beta Hat • 3 days of Premium Account ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ REWARD LIMIT   Rewards are limited to one reward per HWID. Each eligible hardware ID can receive the Open Beta reward only once. Multiple accounts connected to the same HWID will not receive additional rewards. ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ The Open Beta begins on 2 October 2026.   Take part in the testing phase, help us improve the server and get ready for the official launch of the first season. Please note that all Open Beta progress will be wiped before the Grand Opening. The exclusive hat and the 3 days of Premium Account will be granted according to the Open Beta reward conditions. Grand Opening 9 October 2026   Join the Open Beta and secure your exclusive rewards. https://www.l2pearl.com https://discord.com/invite/l2pearl
    • 🛡️ Sguard — A New Version Is Coming in 2026 Hello everyone — clients, server owners, and fellow developers! We have been working on a new version of Sguard, with release planned for the end of 2026. AI-assisted development has helped us work faster, reduce repetitive tasks, and spend more time on implementation and testing. Our team remains responsible for the engineering and the results. The goal is straightforward: better quality, dependable operation, and more affordable pricing. We believe the L2 protection market needs renewed attention — ongoing development, responsive support, and closer cooperation with server administrators. That is the direction we are taking with Sguard. Early Testing Applications Are Open We are looking for server administrators willing to test the new version, report issues, and share practical feedback. 🎁 The first testers will receive free licenses. If you would like to participate, contact us with: Your server’s chronicles and protocol. A brief description of your setup. Whether you can provide a test environment. This is a preliminary announcement. We will share specific features, compatibility details, and testing dates as they are ready. Thank you for your continued support. We look forward to building the next version of Sguard with your feedback. ✉️ APPLY FOR TESTING — @L2scripts Send us a message with “Sguard Test” and tell us about your server.
    • 🚀 End-of-month restock! Upgrade your personal Gmail to 5TB + Gemini Pro instantly with 100% private automated delivery! 🎃 Fresh October Batch Active! Upgrade your personal Gmail to 5TB + Gemini Pro Advanced (12-18M) instantly. 100% private, automated delivery 24/7!
  • Topics

×
×
  • Create New...

Important Information

This community uses essential cookies to function properly. Non-essential cookies and third-party services are used only with your consent. Read our Privacy Policy and We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue..