Execute custom functions during server shutdown
by Mark Jonker · in Torque 3D Professional · 01/26/2012 (3:19 am) · 7 replies
Hey all,
I am having some problems where to put my own functions which should be executed after using the command quit(); on the console/command line on the server.
I read a post http://www.garagegames.com/community/forums/viewthread/66081 that mentioned to place the functions in the OnExit() function. I assume its the one in main.cs but when I place my functions in there they are not being executed.
I also tried to put my function in "void StandardMainLoop::shutdown()" in the file source/app/mainLoop.cpp, which also has other exit functions like, Con::shutdown(), Net::shutdown() and more, but putting my function in there does not work. Maybe im executing it wrong but as far as I know I have to use Con::executef("functionname");, in my case thats Con::executef("ExitOffline"); And in my main.cs I made the function ExitOffline() and placed the stuff in there that I want to be executed during/after shutting down the server.
Can someone help me in the right direction, where or what do I need to change in order to make my function being executed?
I am using Torque 3D 1.1 Beta 3
Thanks in advance.
I am having some problems where to put my own functions which should be executed after using the command quit(); on the console/command line on the server.
I read a post http://www.garagegames.com/community/forums/viewthread/66081 that mentioned to place the functions in the OnExit() function. I assume its the one in main.cs but when I place my functions in there they are not being executed.
I also tried to put my function in "void StandardMainLoop::shutdown()" in the file source/app/mainLoop.cpp, which also has other exit functions like, Con::shutdown(), Net::shutdown() and more, but putting my function in there does not work. Maybe im executing it wrong but as far as I know I have to use Con::executef("functionname");, in my case thats Con::executef("ExitOffline"); And in my main.cs I made the function ExitOffline() and placed the stuff in there that I want to be executed during/after shutting down the server.
Can someone help me in the right direction, where or what do I need to change in order to make my function being executed?
I am using Torque 3D 1.1 Beta 3
Thanks in advance.
#2
onServerDestroyed()
shutdownCore()
onServerDestroyed()
destroyGame()
But none of those work for me.
Also completely different, when I use trace(1) in main.cs it gives me stuff like "Leaving onServerCreated() - return" and "Leaving [GameCore]endMission() - return" so I know when what happens, but when I use the command quit(); it does not give me any indication which functions its going through, is it possible to change that, so I might see what functions are callled and what not, or is that done on purpose because the core is shutting down?
01/26/2012 (7:11 am)
In theory it sounds logical but it does not work for me. I even tried to place it in the following functions (found those while going through scripts/server/game.csonServerDestroyed()
shutdownCore()
onServerDestroyed()
destroyGame()
But none of those work for me.
Also completely different, when I use trace(1) in main.cs it gives me stuff like "Leaving onServerCreated() - return" and "Leaving [GameCore]endMission() - return" so I know when what happens, but when I use the command quit(); it does not give me any indication which functions its going through, is it possible to change that, so I might see what functions are callled and what not, or is that done on purpose because the core is shutting down?
#3
01/26/2012 (7:19 am)
Perhaps you should find where quit() is located in source and go from there?
#4
Recompiling the source takes about 18 minutes for me, so I have to change the code, recompile, test and do that over and over. That gets really annyoing after a few tries. But still thanks for the idea.
01/26/2012 (8:23 am)
@Robert Fritzen: Yea I have been trying to do that but since I can't find the correct function and it takes ages to recompile the source I hoped it would be easier if someone already figured it out and could help me with it.Recompiling the source takes about 18 minutes for me, so I have to change the code, recompile, test and do that over and over. That gets really annyoing after a few tries. But still thanks for the idea.
#5
The function Con::executef("ExitOffline"); is executed now and seems to work.
01/26/2012 (8:44 am)
I put my code in source/console/simManager.cpp in the function "void ImmediateShutdown(S32 exitCode, S32 signalNum)". I also used "Con::printf" to print a line, but it does not print the line to bad but acceptable, I can probably use the function to print the lines needed.The function Con::executef("ExitOffline"); is executed now and seems to work.
#6
01/26/2012 (10:55 am)
Glad to hear it's working, I'll probably go digging through the source later to see where quit(); is defined just in case you need it.
#7
Weird, I know.
01/26/2012 (4:58 pm)
Well, don't forget that some of this might be defined in the core/scripts/server stuff and might be ignoring things you're doing in the scripts/server folder....Weird, I know.
Torque Owner Richard Ranft
Roostertail Games
Hope that gets you moving in the right direction!