• 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!

Feature Antirollback

PAPACU

Intermediate OT User
Joined
Oct 10, 2019
Messages
52
Reaction score
118
Instructions for anti rollback

1
- install gdb
sudo apt-get install gdb

2- compile the src with the flag for gdb
cmake -D CMAKE_BUILD_TYPE=RelWithDebInfo ..

3- put the antirollback_config file in the ot folder (next to start.sh)

4- Edit start.sh to your OT folder




antirollback_config

Lua:
set $_exitcode = 999
run
set $ec = $_exitcode
if $ec > 0
    call g_game.saveGameState()
    thread apply all bt full  
end
quit $ec



start.sh

Lua:
#!/bin/bash

# script to run the automatic server again in case of crash
echo "Starting the program"

cd /home/papacu/papaglobalzuda
mkdir -p logs

# config mysql
usersql=""
servername=""
sqlpassword=""

date=`date "+%d-%m-%y-%H-%M-%S"`
filename="${servername}-${date}"
databasefile="${filename}.sql"

#necessary configurations for Anti-rollback
ulimit -c unlimited
set -o pipefail

while true        
do
     #the antirollback_config file must be in the tfs folder
    gdb --batch -return-child-result --command=antirollback_config --args ./tfs 2>&1 | awk '{ print strftime("%F %T - "), $0; fflush(); }' | tee "logs/$(date +"%F %H-%M-%S.log")"
    mysqldump -u$usersql -p$sqlpassword --add-drop-table --add-locks --allow-keywords --extended-insert --quick --compress $servername > /home/papacu/papaglobalzuda/database/$databasefile
    gzip /home/papacu/papaglobalzuda/database/$databasefile-f
   
    if [ $? -eq 0 ]; then
        echo "Exit code 0, waiting 3 minutes..."
        sleep 180    #3 minutos
    else
        echo "Crash !! Restarting the server in 5 seconds (The log file is saved in the logs folder)"
        echo "If you want to shut down the server, press CTRL + C ..."
        sleep 5
    fi
done;

Extra edition!

in game.cpp
C++:
// Change function Game::saveGameState to the lines below

void Game::saveGameState(bool crash /= false/)
{
    if (gameState == GAME_STATE_NORMAL) {
        setGameState(GAME_STATE_MAINTAIN);
    }

    std::cout << "Saving server..." << std::endl;
    
    for (const auto& it : players) {
        if (crash) {
            it.second->loginPosition = it.second->getTown()->getTemplePosition();
        } else {
            it.second->loginPosition = it.second->getPosition();
        }

        IOLoginData::savePlayer(it.second);
    }

    Map::save();

    if (gameState == GAME_STATE_MAINTAIN) {
        setGameState(GAME_STATE_NORMAL);
    }
}




in game.h
//Search for saveGameState and change to the one below
void saveGameState(bool crash = false);




edit file antirollback_config

set $_exitcode = 999
run

if $_exitcode == 999
    thread apply all bt full
    call saveServer()
    quit
end

if $_exitcode != 999
    quit
end




in otserv.cpp

// Add at the end of the file after the last "}" add the following lines

#ifndef _WIN32
_attribute_ ((used)) void saveServer() {
    if(g_game.getPlayersOnline() > 0)
        g_game.saveGameState(true);
}
#endif

with these changes will send all players to the temple if the error occurs
 
Last edited by a moderator:
I didn't understand how this help with antirollback? You are creating mysql dumps in a infinite loop. If your database is huge, this gonna exhaust your CPU. Plus, if the server doens't save frequently, restoring db does not make a diff?
 
I didn't understand how this help with antirollback? You are creating mysql dumps in a infinite loop. If your database is huge, this gonna exhaust your CPU. Plus, if the server doens't save frequently, restoring db does not make a diff?
What? You know that every player is saved on logout right?
 
I am taking into consideration the server crashing or the machine freezing during a DDoS attack -- typical cases that causes rollbacks -- ; which then none is saved.
Do not worry
this has been in use for years. on servers that suffer major attacks.
 
new extra option
does not interfere in the operation for those who are using the current version. It is just an extra option that if the error occurs the player will be sent to the temple so he will not have a chance to return with full respawn
 
what exactly is this supposed to mean? Can't we just remove those lines?

Bash:
set $_exitcode = 999
run
set $ec = $_exitcode
if $ec > 0

Another thing to consider, under crashes, how do you trust the data that you will be saving? I mean, if there's a segmentation fault you have no way of trusting the integrity of the data in your memory...
 
Part of this code, probably all, but can't prove it, has been made by me. I didn't allow anyone to share it, so it's sad to see someone's using it without paying the author. Part of otserv.cpp has been 100% made by me in this case.

As a proof, screenshot when when i shared part of this code with other user, 2 years ago:
1592837478294.png
 
Last edited:
Ofcourse it was created by kondrah. Has there been anything released on this forum this past year that wasn't made by this god? I do not think so
 
Part of this code, probably all, but can't prove it, has been made by me. I didn't allow anyone to share it, so it's sad to see someone's using it without paying the author.

As a proof, screenshot when when i shared part of this code with other user, 2 years ago:
View attachment 46775
Everything that this guy is posting here, isn't made by him. He is doing that to piss people that made the codes. Read his topics. It's an fake user, but we know who is him. xD

He doesn't even know how to install things that he post. lmao
 
I think that it should be clarified. It looks like kind of solution for test server rather than official one. It is running under gdb so it is loosing performance. Or did I miss something and it's perfectly fine to run it on prod?

@Night Wolf
I think the idea is to set $_exitcode to 999 and if gdb catch some exception (program did not close correctly) then the $_exitcode still contains the value of 999 and you can perform some action, to save the server in this case. On proper program exit, $_exitcode should be changed to program's exit code.
 
This anti rollback feature was made by Mark Samman.

Here is my version:
Code:
catch signal SIGBUS SIGFPE SIGILL SIGINT SIGSEGV SIGSYS SIGSYS SIGXCPU SIGXFSZ
commands
set $MyVar = 1
call g_game.saveGameState()
end
set $MyVar = 0
run

if $MyVar == 0
quit
end
When there is a crash(SIGSEGV and other few signals) it will call g_game.saveGameState() and it will stop at that so you can manually issue bt full or any other gdb command.
 
Part of this code, probably all, but can't prove it, has been made by me. I didn't allow anyone to share it, so it's sad to see someone's using it without paying the author. Part of otserv.cpp has been 100% made by me in this case.
this edition was purchased from a famous program in the ot server br groups. so he was / is reselling.
just the extra part.

what exactly is this supposed to mean? Can't we just remove those lines?

Bash:
set $_exitcode = 999
run
set $ec = $_exitcode
if $ec > 0

Another thing to consider, under crashes, how do you trust the data that you will be saving? I mean, if there's a segmentation fault you have no way of trusting the integrity of the data in your memory...

this code can be optimized as I said it has been used on a large server for a long time and has never had any problems.
nor increased cpu / ram usage
servers that receive large numbers of attacks ddos and some that suffer with errors for buying bad services.
 
Part of this code, probably all, but can't prove it, has been made by me. I didn't allow anyone to share it, so it's sad to see someone's using it without paying the author.

As a proof, screenshot when when i shared part of this code with other user, 2 years ago:
View attachment 46775

Why don't you spend some 5k earned to buy dignity?
 
Part of this code, probably all, but can't prove it, has been made by me. I didn't allow anyone to share it, so it's sad to see someone's using it without paying the author. Part of otserv.cpp has been 100% made by me in this case.

As a proof, screenshot when when i shared part of this code with other user, 2 years ago:
View attachment 46775
To be honest this part has little to NONE impact. The catch is to ask GDB to call saveGame code:

if $ec > 0
call g_game.saveGameState()
thread apply all bt full
end

And I can confirm 100% that this was definetely not made by Kondrah as I have this same piece of code for the past 4 years..
I only choose to not use it since I believe saving crashed status aren't really the way to go, you may be as well fucking your database completely...
Post automatically merged:

@Night Wolf
I think the idea is to set $_exitcode to 999 and if gdb catch some exception (program did not close correctly) then the $_exitcode still contains the value of 999 and you can perform some action, to save the server in this case. On proper program exit, $_exitcode should be changed to program's exit code.
This make little sense to me, when do gdb set exitcode variable? this seems just a regular var he created, and why use another variable "ec"? @Yamaken version seems much more cleaner and allow you to choose which signals to perform this. SIGSEV definetely should be outside this list though.
 
Last edited:
To be honest this part has little to NONE impact. The catch is to ask GDB to call saveGame code:

if $ec > 0
call g_game.saveGameState()
thread apply all bt full
end

And I can confirm 100% that this was definetely not made by Kondrah as I have this same piece of code for the past 4 years..
I only choose to not use it since I believe saving crashed status aren't really the way to go, you may be as well fucking your database completely...
Post automatically merged:


This make little sense to me, when do gdb set exitcode variable? this seems just a regular var he created, and why use another variable "ec"? @Yamaken version seems much more cleaner and allow you to choose which signals to perform this. SIGSEV definetely should be outside this list though.

This is special variable which value is set by gdb internally:
$_exitcode
When the program being debugged terminates normally, GDB automatically sets this variable to the exit code of the program, and resets $_exitsignal to void.
src: Debugging with GDB: Convenience Vars (https://sourceware.org/gdb/current/onlinedocs/gdb/Convenience-Vars.html)

I agree that ec variable is not needed and introduce unnecessary noise. And I also prefer @Yamaken version ;)
 
Instructions for anti rollback

1
- install gdb
sudo apt-get install gdb

2- compile the src with the flag for gdb
cmake -D CMAKE_BUILD_TYPE=RelWithDebInfo ..

3- put the antirollback_config file in the ot folder (next to start.sh)

4- Edit start.sh to your OT folder




antirollback_config

Lua:
set $_exitcode = 999
run
set $ec = $_exitcode
if $ec > 0
    call g_game.saveGameState()
    thread apply all bt full
end
quit $ec



start.sh

Lua:
#!/bin/bash

# script to run the automatic server again in case of crash
echo "Starting the program"

cd /home/papacu/papaglobalzuda
mkdir -p logs

# config mysql
usersql=""
servername=""
sqlpassword=""

date=`date "+%d-%m-%y-%H-%M-%S"`
filename="${servername}-${date}"
databasefile="${filename}.sql"

#necessary configurations for Anti-rollback
ulimit -c unlimited
set -o pipefail

while true      
do
     #the antirollback_config file must be in the tfs folder
    gdb --batch -return-child-result --command=antirollback_config --args ./tfs 2>&1 | awk '{ print strftime("%F %T - "), $0; fflush(); }' | tee "logs/$(date +"%F %H-%M-%S.log")"
    mysqldump -u$usersql -p$sqlpassword --add-drop-table --add-locks --allow-keywords --extended-insert --quick --compress $servername > /home/papacu/papaglobalzuda/database/$databasefile
    gzip /home/papacu/papaglobalzuda/database/$databasefile-f
 
    if [ $? -eq 0 ]; then
        echo "Exit code 0, waiting 3 minutes..."
        sleep 180    #3 minutos
    else
        echo "Crash !! Restarting the server in 5 seconds (The log file is saved in the logs folder)"
        echo "If you want to shut down the server, press CTRL + C ..."
        sleep 5
    fi
done;

Extra edition!

in game.cpp
C++:
// Change function Game::saveGameState to the lines below

void Game::saveGameState(bool crash /= false/)
{
    if (gameState == GAME_STATE_NORMAL) {
        setGameState(GAME_STATE_MAINTAIN);
    }

    std::cout << "Saving server..." << std::endl;
  
    for (const auto& it : players) {
        if (crash) {
            it.second->loginPosition = it.second->getTown()->getTemplePosition();
        } else {
            it.second->loginPosition = it.second->getPosition();
        }

        IOLoginData::savePlayer(it.second);
    }

    Map::save();

    if (gameState == GAME_STATE_MAINTAIN) {
        setGameState(GAME_STATE_NORMAL);
    }
}




in game.h
//Search for saveGameState and change to the one below
void saveGameState(bool crash = false);




edit file antirollback_config

set $_exitcode = 999
run

if $_exitcode == 999
    thread apply all bt full
    call saveServer()
    quit
end

if $_exitcode != 999
    quit
end




in otserv.cpp

// Add at the end of the file after the last "}" add the following lines

#ifndef _WIN32
_attribute_ ((used)) void saveServer() {
    if(g_game.getPlayersOnline() > 0)
        g_game.saveGameState(true);
}
#endif

with these changes will send all players to the temple if the error occurs



Error in sourced command file:
No symbol "g_game" in current context. How to resolve this? TFS 0.3.6
 
Back
Top