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

C++ How to insert in C++ code something to restart server

dervin13

Active Member
Joined
Apr 26, 2008
Messages
458
Solutions
1
Reaction score
28
Hello, I would like to know if it's possible to add a restart code when this errors occurs, because the automatic restart doesnt work as the tfs doesnt close and it didn't appear any error to close... thanks

void allocationHandler()
{
puts("Allocation failed, server out of memory!\nDecrease size of your map or compile in a 64-bit mode.");
char buffer[1024];
delete fgets(buffer, 1024, stdin);
exit(-1);
}
 
had that problem just use this on your exe while it is not running make sure yo make copy of you original exe its becuase you compiled as 32bits i use this thing for my demonia.org because I cant seem to make the sources to compile to 64 without errors as of yet haha :)
this patch will allow it to allocate more than 2 GB memory I wasted about 20minutes to find that exe so hope you actually gonna look at it bro. haha save you time
 

Attachments

Hello, I would like to know if it's possible to add a restart code when this errors occurs, because the automatic restart doesnt work as the tfs doesnt close and it didn't appear any error to close... thanks

void allocationHandler()
{
puts("Allocation failed, server out of memory!\nDecrease size of your map or compile in a 64-bit mode.");
char buffer[1024];
delete fgets(buffer, 1024, stdin);
exit(-1);
}
It's a bad idea for a program to restart itself in the event that it is about to crash. You should use an external script to relaunch the application.
If you are receiving the message Allocation failed, server out of memory Decrease size of your map or compile in a 64-bit mode then you need to reevaluate the things running on the server.
 
I already use a script, the problem is with this kind of error, the server stops and dont appear a error to close and without this is impossible to restart the server... So i'm looking for something that make it possible to restart the server without my presence
 
Just create a BAT file with a loop and a timeout.
That's what all the minecraft server owners do anyhow.

Code:
@echo off
:StartServer

CLS
echo Starting Server...
TFS_Server.exe
echo Server has crashed or shut down. Restarting in 10 seconds.
echo Press any key to restart immediately...
TIMEOUT /T 10

GOTO StartServer

That way if the server crashes, it will wait 10 seconds (or until you press a key) and then automatically run the server again.
And if you're the one that shut it down, and want to keep it down, you'll have 10 seconds to close the bat window.

It's of course possible to make it more advanced, like have it listen for return values, but for now this should be good enough.
 
not working

@Echo off
:StartServer

CLS
echo Starting Server...
theforgottenserver-x64.exe
echo Server has crashed or shut down. Restarting in 10 seconds.
echo Press any key to restart immediately...
TIMEOUT /T 10

GOTO StartServe
windows 10
 
Why you guys complain so much with this. Simply use server save and use Restart On Crash.

Regards!
 
No, just testing. Anyway, why?
If I understood correctly, your server is crashing right? If you server crashes, players can abuse it in different ways, the most common is duplicating items. If players figure out a way to crash your server and it will be rebooting everytime it crashes, they are gonna be able to dups items non-stop.

Your goal should be lower the chance to crash the engine as close to 0%.
 
If I understood correctly, your server is crashing right? If you server crashes, players can abuse it in different ways, the most common is duplicating items. If players figure out a way to crash your server and it will be rebooting everytime it crashes, they are gonna be able to dups items non-stop.

Your goal should be lower the chance to crash the engine as close to 0%.
Good point here ^^ Be sure you don't have any error on your server otherwise what @Terotrificy says will happen and it's really a nightmare. Anyways, if you have 0 errors and you need something to start the server after global server save RestartOnCrash will work perfectly.
 
Back
Top