Tá aí um code feito pelo programador Brasileiro Proglin(membro de outro fórum)
Feito para servidores SQL..
Foi testado na svn de dezembro(12/07)
Bom, vamos ao codigo :
Em game.cpp, depois de :
#include "talkaction.h" #include "spells.h" #include "configmanager.h"
Adicione :
#include "tools.h"
Depois de :
Game::Game() {
Adicione :
#ifdef __UCB_DDOS_PROTECTION__ connectionTestFalseValidUntil = std::time(NULL) + 2*60; //Ignore verification in first 2 minutes connectionTestTrueValidUntil = connectionTestFalseValidUntil; connectionTestOk = true; #endif
Adicione no final :
#ifdef __UCB_DDOS_PROTECTION__ bool Game::isOutSideWorldResponding(){ OTSYS_THREAD_LOCK_CLASS lockClass(gameLock, "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
Agora em game.h, depois de :
void internalCreatureChangeVisible(Creature* creature, bool visible); void changeLight(const Creature* creature); #ifdef __SKULLSYSTEM__ void changeSkull(Player* player, Skulls_t newSkull); #endif
Adicione :
#ifdef __UCB_DDOS_PROTECTION__ bool isOutSideWorldResponding(); #endif
Depois de :
uint32_t inFightTicks; uint32_t exhaustionTicks; uint32_t fightExhaustionTicks;
Adicione :
#ifdef __UCB_DDOS_PROTECTION__ bool connectionTestOk; uint32_t connectionTestTrueValidUntil; uint32_t connectionTestFalseValidUntil; #endif
Agora em tools.cpp, adicione no final :
#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
Agora em tools.h, adicione no final :
#ifdef __UCB_DDOS_PROTECTION__ bool isWorldReachable(); #endif
Agora em players.cpp, substitua :
if(skillLoss){
Por :
#ifdef __UCB_DDOS_PROTECTION__ if(skillLoss && g_game.isOutSideWorldResponding()){ #else if(skillLoss){ #endif
Substitua :
experience -= getLostExperience();
Por :
#ifdef __UCB_DDOS_PROTECTION__ if( g_game.isOutSideWorldResponding() ){ experience -= getLostExperience(); } #else experience -= getLostExperience(); #endif
Agora vá em Projeto > Opções do Projeto > Parâmetros > Compilador C++ e adicione no final :
-D__UCB_DDOS_PROTECTION__
Agora Recompile tudo (Ctrl + F11)!
Créditos constam no inicio do tópico..