• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

[1-12-2008] Player Protection against DDoS / Flood / Nuke attack

ragal

Member
Joined
Nov 29, 2007
Messages
735
Reaction score
19
Location
Germany - Berlin
-- This code is free to use and modify. Credits go to Proglin --

Problem: your server is constantly under DDoS / Flood / Nuke attack and players are dying.

One possible solution: when player dies try to reach a computer outside to see if your server connection is ok.

Comments: I have developed this solution because my server in constantly under DDoS attack. I used SVN revision from begining of December, but you can use this code as base to your personal necessity.


Modifications:

@ game.cpp

After:
PHP:
#include "talkaction.h"
#include "spells.h"
#include "configmanager.h"
Add:
PHP:
#include "tools.h"
After:
PHP:
Game::Game()
{
Add:
PHP:
    #ifdef __UCB_DDOS_PROTECTION__
    connectionTestFalseValidUntil = std::time(NULL) + 2*60; //Ignore verification in first 2 minutes
       connectionTestTrueValidUntil = connectionTestFalseValidUntil;
    connectionTestOk = true;
    #endif
At botton add:
PHP:
#ifdef __UCB_DDOS_PROTECTION__
bool Game::isOutSideWorldResponding(){
    uint32_t now = std::time(NULL);
    if( !connectionTestOk ){
        if( now > connectionTestFalseValidUntil ){
            //Redo test
            connectionTestOk = isWorldReachable();
            connectionTestFalseValidUntil = now + 60; //False result is valid for 60 seconds
        }
    } else {
        if( now > connectionTestTrueValidUntil ){
            //Redo test
            connectionTestOk = isWorldReachable();
            connectionTestTrueValidUntil = now + 10; //Ok result is valid for 10 secongs
        }
    }
    return connectionTestOk;
}
#endif
@ game.h

After:
PHP:
    void internalCreatureChangeVisible(Creature* creature, bool visible);
    void changeLight(const Creature* creature);

#ifdef __SKULLSYSTEM__
    void changeSkull(Player* player, Skulls_t newSkull);
#endif
Add:
PHP:
    #ifdef __UCB_DDOS_PROTECTION__
    bool isOutSideWorldResponding();
    #endif
After:
PHP:
    uint32_t inFightTicks;
    uint32_t exhaustionTicks;
    uint32_t fightExhaustionTicks;
Add:
PHP:
    #ifdef __UCB_DDOS_PROTECTION__
    bool connectionTestOk;
       uint32_t connectionTestTrueValidUntil;
       uint32_t connectionTestFalseValidUntil;
    #endif
@ tools.cpp

Add at bottom:
PHP:
#ifdef __UCB_DDOS_PROTECTION__
bool isWorldReachable(){
    int32_t ret;
    #if defined __WINDOWS__    
    ret = system("ping -n 1 -w 500 google.com > NUL");
    #else
    ret = system("ping -q -c 1 -w 1 google.com > /dev/null");    
    #endif
    return (ret == 0);
}
#endif
@ tools.h

Add at bottom:
PHP:
#ifdef __UCB_DDOS_PROTECTION__
bool isWorldReachable();
#endif
@ player.cpp
Change this line:
PHP:
if(skillLoss){
To:
PHP:
#ifdef __UCB_DDOS_PROTECTION__
if(skillLoss && g_game.isOutSideWorldResponding()){
#else
if(skillLoss){
#endif
Chage this other line:
PHP:
experience -= getLostExperience();
To:
PHP:
#ifdef __UCB_DDOS_PROTECTION__
if( g_game.isOutSideWorldResponding() ){
     experience -= getLostExperience();
}
#else
experience -= getLostExperience();
#endif

Now rebuild all and test :p (remeber to use flag: -D__UCB_DDOS_PROTECTION__

Note: you can change the part "google.com" for anyone that you think is better. For test if this is ok, change this part to a site that you know that is not responding and kill youself in server. If it works ok you will go to temple with full life.

Have new year

Later I could improve this code.

Have FUN

-- This code is free to use and modify. Credits go to Proglin --


Rep++ ME!

 
Last edited:
The only reason your server is under attack is because you allow the attacks to happen. I barley have any attacks anymore after I eliminated my enemies.
 
C:\Documents and Settings\Andre\Desktop\trunk\game.cpp In member function `bool Game::isOutSideWorldResponding()':
4504 C:\Documents and Settings\Andre\Desktop\trunk\game.cpp `gameLock' undeclared (first use this function)
(Each undeclared identifier is reported only once for each function it appears in.)
C:\Documents and Settings\Andre\Desktop\Raven World\Makefile.win [Build Error] [../trunk/game.o] Error 1
 
Proglin is my friend. The solution to this is ->
Delete this:
OTSYS_THREAD_LOCK_CLASS lockClass(gameLock, "Game::isOutSideWorldResponding()");
 
Help Error plz


C:\tags\0.2\game.cpp In member function `bool Game::isOutSideWorldResponding()':
C:\tags\0.2\game.cpp `gameLock' was not declared in this scope
C:\tags\0.2\dev-cpp\Makefile.win [Build Error] [obj//game.o] Error 1


Use TFS last rev
 
I get
game.cpp: In member function âbool Game::isOutSideWorldResponding()â:
game.cpp:5141: error: âisWorldReachableâ was not declared in this scope
game.cpp:5147: error: âisWorldReachableâ was not declared in this scope
make: *** [game.o] Error 1

with the latest rev of TFS tags 0.2
 
I've compiled this script witout any errors, but when the next day i started my OTS, i saw that something is wrong. Anyone didnt lose exp when he died.
I cant use this script, its not working corectly, sry.


#Edit
When i add only the script its working without any errors/bugs, but when i add the script and "D__UCB_DDOS_PROTECTION__" its working like i said (with bugs).
 
Last edited:
scorpio u need to change the webpage to a non existing web page i think its explained in the first post
 
"Up
Ok, i will try with this, but i think he didnt said that must be changed:
Note: you can change the part "google.com" for anyone that you think is better...
, i think he said that if someone want to change it :F
 
Back
Top