Vice City: Multiplayer

VC:MP Discussion => Bugs and Crashes => Support => Closed Bug Reports => Topic started by: BigcaT_ on Mar 02, 2015, 01:17 PM

Title: [BUG] Server does not wait for all events to finish before exiting
Post by: BigcaT_ on Mar 02, 2015, 01:17 PM
Look, here is the code of OnScriptUnload:
function onScriptUnload()
{
for( local i=0; i <= GetMaxPlayers()-1; i++ )
{
local plr = FindPlayer(i);
if(plr) onPlayerPart(plr, 255);
}
DisconnectSQL( MainDatabase );
DisconnectSQL( PropsDB );
DisconnectSQL( acmds );
DisconnectSQL( IPdb );
DisconnectSQL( VehDB );
}

code of OnPlayerPart:

function onPlayerPart( player,  reason )
{
    SaveStats(player);
}
// OnPlayerPart is working..

code of SaveStats

function SaveStats( player )
{
local id = player.ID;
if ( status[ id ].IsReg == true )
{
QuerySQL( MainDatabase, "UPDATE Account SET Kills='" + player.Score + "', Deaths='" + status[ id ].Deaths + "', Cash='" + player.Cash + "' WHERE Name='" + player.Name.tolower() + "'" );
}
}

 When I close the server by myself, player stats can't save. why?
Title: Re: [BUG] Server does not wait for all events to finish before exiting
Post by: ali_vcmp on Mar 02, 2015, 04:16 PM
Try This

function SaveStats( player )
{
try{
 local id = player.ID;
 if ( status[ id ].IsReg == true )
 {
       QuerySQL( db, "UPDATE Account SET Kills='" + status[ id ].Kills + "', Deaths='" + status[ player.ID ].Deaths + "', Cash='" + status[ id ].Cash + "', Bank='" + status[ id ].Bank + "', Joins='" + status[id].Joins + "' WHERE Name='" + player.Name + "'" );
   print( "" + player.Name + " Stats Saved [" + player.ID + "]" );
 status[ id ] = null;
 }
}
   catch(e) print( "Save Stats Error: " + e );
}
Title: Re: [BUG] Server does not wait for all events to finish before exiting
Post by: Thijn on Mar 02, 2015, 07:10 PM
You should first question yourself if you need that many databases. You can create multiple tables inside one file, you know?

Have you tried adding debug text to know if your callback is actually called?
Title: Re: [BUG] Server does not wait for all events to finish before exiting
Post by: BigcaT_ on Mar 03, 2015, 05:17 AM
Quote from: Thijn on Mar 02, 2015, 07:10 PMYou should first question yourself if you need that many databases. You can create multiple tables inside one file, you know?

Have you tried adding debug text to know if your callback is actually called?

Quote from: ali_vcmp on Mar 02, 2015, 04:16 PMTry This

function SaveStats( player )
{
try{
 local id = player.ID;
 if ( status[ id ].IsReg == true )
 {
       QuerySQL( db, "UPDATE Account SET Kills='" + status[ id ].Kills + "', Deaths='" + status[ player.ID ].Deaths + "', Cash='" + status[ id ].Cash + "', Bank='" + status[ id ].Bank + "', Joins='" + status[id].Joins + "' WHERE Name='" + player.Name + "'" );
   print( "" + player.Name + " Stats Saved [" + player.ID + "]" );
 status[ id ] = null;
 }
}
   catch(e) print( "Save Stats Error: " + e );
}
This still not working...

I  think the reason is that when I close my server, function onScriptUnload not call.
I put a message onscriptunload:


function onScriptUnload()
{
for( local i=0; i <= GetMaxPlayers()-1; i++ )
{
local plr = FindPlayer(i);
if(plr) onPlayerPart(plr, 255);
}
DisconnectSQL( MainDatabase );
DisconnectSQL( PropsDB );
DisconnectSQL( acmds );
DisconnectSQL( IPdb );
DisconnectSQL( VehDB );
print("Script Unloaded..");
}
but I can't see any message on the console when I close the server..
Title: Re: [BUG] Server does not wait for all events to finish before exiting
Post by: Thijn on Mar 03, 2015, 06:42 AM
I figured that was happening, well done finding out.

@Stormeus The server needs proper exit codes and needs to gracefully wait till all events are done processing :x
Title: Re: [BUG] Server does not wait for all events to finish before exiting
Post by: . on Mar 03, 2015, 08:03 AM
Quote from: BigcaT_ on Mar 03, 2015, 07:29 AMI tried to use onServerStop() , but still not working when I close the server.

Yeah, there's a problem. Unfortunately, there's some issues when the server shuts down. And depending on the loaded modules you might not receive an event through that function. We've discussed (http://forum.vc-mp.org/?topic=247.0) this and stormeus promised to look into this for the next release.
Title: Re: [BUG] Server does not wait for all events to finish before exiting
Post by: BigcaT_ on Mar 03, 2015, 11:25 AM
Quote from: S.L.C on Mar 03, 2015, 08:03 AM
Quote from: BigcaT_ on Mar 03, 2015, 07:29 AMI tried to use onServerStop() , but still not working when I close the server.

Yeah, there's a problem. Unfortunately, there some issues when the server shuts down. And depending on the loaded modules you might not receive an event through that function. We've discussed (http://forum.vc-mp.org/?topic=247.0) this and stormeus promised to look into this for the next release.
ok. Thanks for telling.
Title: Re: [BUG] Server does not wait for all events to finish before exiting
Post by: Stormeus on Mar 03, 2015, 07:04 PM
Quote from: Thijn on Mar 03, 2015, 06:42 AM@Stormeus The server needs proper exit codes and needs to gracefully wait till all events are done processing :x

I'm refiling this as a bug because the server is actually supposed to wait for events to finish.
Title: Re: [BUG] Server does not wait for all events to finish before exiting
Post by: BigcaT_ on Apr 19, 2015, 03:52 AM
Quote from: stormeus on Mar 03, 2015, 07:04 PM
Quote from: Thijn on Mar 03, 2015, 06:42 AM@Stormeus The server needs proper exit codes and needs to gracefully wait till all events are done processing :x

I'm refiling this as a bug because the server is actually supposed to wait for events to finish.

Stormeus how can I use this now?
Title: Re: [BUG] Server does not wait for all events to finish before exiting
Post by: Stormeus on Apr 19, 2015, 05:53 AM
Quote from: BigcaT_ on Apr 19, 2015, 03:52 AM
Quote from: stormeus on Mar 03, 2015, 07:04 PM
Quote from: Thijn on Mar 03, 2015, 06:42 AM@Stormeus The server needs proper exit codes and needs to gracefully wait till all events are done processing :x

I'm refiling this as a bug because the server is actually supposed to wait for events to finish.

Stormeus how can I use this now?

Is this still an issue? The last server update should've given plugins a chance to shut down gracefully on both Linux and Windows.
Title: Re: [BUG] Server does not wait for all events to finish before exiting
Post by: BigcaT_ on May 23, 2015, 01:56 PM
Quote from: stormeus on Apr 19, 2015, 05:53 AM
Quote from: BigcaT_ on Apr 19, 2015, 03:52 AM
Quote from: stormeus on Mar 03, 2015, 07:04 PM
Quote from: Thijn on Mar 03, 2015, 06:42 AM@Stormeus The server needs proper exit codes and needs to gracefully wait till all events are done processing :x

I'm refiling this as a bug because the server is actually supposed to wait for events to finish.

Stormeus how can I use this now?

Is this still an issue? The last server update should've given plugins a chance to shut down gracefully on both Linux and Windows.


stormeus a hacker always DDOS my server, and server can not call ShutDownServer(), it causes the player in server 's stats could not save, I hope to fix onScriptUnload, please!
Title: Re: [BUG] Server does not wait for all events to finish before exiting
Post by: Stormeus on May 23, 2015, 04:47 PM
The server won't save anything if it crashes.
Title: Re: [BUG] Server does not wait for all events to finish before exiting
Post by: ysc3839 on May 23, 2015, 06:52 PM
Quote from: BigcaT_ on May 23, 2015, 01:56 PM
Quote from: stormeus on Apr 19, 2015, 05:53 AM
Quote from: BigcaT_ on Apr 19, 2015, 03:52 AM
Quote from: stormeus on Mar 03, 2015, 07:04 PM
Quote from: Thijn on Mar 03, 2015, 06:42 AM@Stormeus The server needs proper exit codes and needs to gracefully wait till all events are done processing :x

I'm refiling this as a bug because the server is actually supposed to wait for events to finish.

Stormeus how can I use this now?

Is this still an issue? The last server update should've given plugins a chance to shut down gracefully on both Linux and Windows.


stormeus a hacker always DDOS my server, and server can not call ShutDownServer(), it causes the player in server 's stats could not save, I hope to fix onScriptUnload, please!
It isn't a bug. You should save players' stats when players take some action(such as when a player kill other player, increases its "kill stats" and then save it immediately). This may solve most problem.
Title: Re: [BUG] Server does not wait for all events to finish before exiting
Post by: ℛḝξ☂ on May 24, 2015, 01:44 AM
Locked.
Title: Re: [BUG] Server does not wait for all events to finish before exiting
Post by: Stormeus on May 24, 2015, 03:44 AM
Quote from: Sentral on May 24, 2015, 01:44 AMLocked.

Who are you?

Unlocked.
Title: Re: [BUG] Server does not wait for all events to finish before exiting
Post by: ℛḝξ☂ on May 24, 2015, 04:29 AM
I am Bigcat,
I deleted the last account.
and created a new account.

And there's one more thing,  did the client update yesterday ?
Title: Re: [BUG] Server does not wait for all events to finish before exiting
Post by: Stormeus on May 24, 2015, 04:47 AM
Quote from: Sentral on May 24, 2015, 04:29 AMAnd there's one more thing,  did the client update yesterday ?

Nope.
Title: Re: [BUG] Server does not wait for all events to finish before exiting
Post by: ℛḝξ☂ on May 24, 2015, 04:57 AM
OK.