[Tutorial] MySQL [R41-2] Registration System
#13

Quote:
Originally Posted by Variable™
Посмотреть сообщение
I won't talk too much, I have debugged what you have said above just to show that your statements are wrong. Well, I have made a message prints to the log once the server shuts down with the "/rcon exit" method.

My OnPlayerDisconnect Code:
Код:
public OnPlayerDisconnect(playerid, reason)
{
	Corrupt_Check[playerid]++;

	new DB_Query[256];
	//Running a query to save the player's data using the stored stuff.
	mysql_format(Database, DB_Query, sizeof(DB_Query), "UPDATE `PLAYERS` SET `SCORE` = %d, `CASH` = %d, `KILLS` = %d, `DEATHS` = %d WHERE `ID` = %d LIMIT 1",
	pInfo[playerid][Score], pInfo[playerid][Cash], pInfo[playerid][Kills], pInfo[playerid][Deaths], pInfo[playerid][ID]);

	mysql_tquery(Database, DB_Query);

	if(cache_is_valid(pInfo[playerid][Player_Cache])) //Checking if the player's cache ID is valid.
	{
		cache_delete(pInfo[playerid][Player_Cache]); // Deleting the cache.
		pInfo[playerid][Player_Cache] = MYSQL_INVALID_CACHE; // Setting the stored player Cache as invalid.
	}

	pInfo[playerid][LoggedIn] = 0;
	print("OnPlayerDisconnect has been called."); // Sending message once OnPlayerDisconnect is called.
	return 1;
}
The result of the code:
Код:
[13:40:00] [connection] 10.42.0.74:61008 requests connection cookie.
[13:40:01] [connection] incoming connection: 10.42.0.74:61008 id: 0
[13:40:01] [join] Variable has joined the server (0:10.42.0.74)
[13:40:12] RCON (In-Game): Player #0 (Variable) has logged in.
[13:40:14] RCON (In-Game): Player [Variable] sent command: exit
[13:40:14] --- Server Shutting Down.
[13:40:14] OnPlayerDisconnect has been called.
[13:40:15] [part] Variable has left the server (0:0)
You saw the message being sent twice in the log? Nope.
Hopefully you'll next time make sure of what you state before you do and thanks.

You can also try that by yourself.

=======================================

Would like to make sure the OnPlayerDisconnect doesn't get called twice? Here's another evidence!

When I removed the part from OnGameModeExit, the message didn't show anymore.

Код:
public OnGameModeExit()
{
/*    for(new i = 0, j = GetPlayerPoolSize(); i <= j; i++) // Getting the highest player ID in the game.
    {
		if(IsPlayerConnected(i)) // Checking if the players stored in "i" are connected.
		{
			OnPlayerDisconnect(i, 1); // We do that so players wouldn't lose their data upon server's close.
		}
	}*/

	mysql_close(Database); // Closing the database.
	return 1;
}
Same stuff at OnPlayerDisconnect, as in this code:
Код:
public OnPlayerDisconnect(playerid, reason)
{
	Corrupt_Check[playerid]++;

	new DB_Query[256];
	//Running a query to save the player's data using the stored stuff.
	mysql_format(Database, DB_Query, sizeof(DB_Query), "UPDATE `PLAYERS` SET `SCORE` = %d, `CASH` = %d, `KILLS` = %d, `DEATHS` = %d WHERE `ID` = %d LIMIT 1",
	pInfo[playerid][Score], pInfo[playerid][Cash], pInfo[playerid][Kills], pInfo[playerid][Deaths], pInfo[playerid][ID]);

	mysql_tquery(Database, DB_Query);

	if(cache_is_valid(pInfo[playerid][Player_Cache])) //Checking if the player's cache ID is valid.
	{
		cache_delete(pInfo[playerid][Player_Cache]); // Deleting the cache.
		pInfo[playerid][Player_Cache] = MYSQL_INVALID_CACHE; // Setting the stored player Cache as invalid.
	}

	pInfo[playerid][LoggedIn] = 0;
	print("OnPlayerDisconnect has been called."); // Sending message once OnPlayerDisconnect is called.
	return 1;
}
The result from the log:
Код:
[13:57:34] [connection] 10.42.0.74:61529 requests connection cookie.
[13:57:35] [connection] incoming connection: 10.42.0.74:61529 id: 0
[13:57:35] [join] Variable has joined the server (0:10.42.0.74)
[13:57:49] RCON (In-Game): Player #0 (Variable) has logged in.
[13:57:52] RCON (In-Game): Player [Variable] sent command: exit
[13:57:52] --- Server Shutting Down.
[13:57:52] [part] Variable has left the server (0:0)
Seen the log message? Nothing has been called as the message didn't print to the log, that means its not even called. So, if I don't use my way, no one's stats will be saved once server closes.

For "/rcon gmx" method
  • If you kick at OnGameModeExit it'll call OnPlayerDisconnect, if you don't do anything at OnGameModeExit, once you close the server, no one's stats will be saved and will just save if you RESTART server only.
Which means, my solution is the finest for now.
That might only be the case for "/rcon exit", cause it is generally called when gamemode exits. Even at "changemode" or "gmx", OnPlayerDisconnect is called properly. I would rather hook "/rcon exit" with saving player data than doing it always when gamemode exits.
But anyways gamemode exit happens only once or twice in a long time period unless your mode requires gamemode switching for new rounds/games, where this could be concern for developers.
Reply


Messages In This Thread
MySQL [R41-2] Registration System - by Variable™ - 29.01.2017, 01:16
Re: MySQL [R41-2] Registration System - by Gammix - 29.01.2017, 03:51
Re: MySQL [R41-2] Registration System - by Variable™ - 29.01.2017, 10:31
Re: MySQL [R41-2] Registration System - by GoldenLion - 29.01.2017, 10:33
Re: MySQL [R41-2] Registration System - by Variable™ - 29.01.2017, 10:51
Re: MySQL [R41-2] Registration System - by GhostHacker9 - 29.01.2017, 11:42
Re: MySQL [R41-2] Registration System - by Variable™ - 29.01.2017, 12:26
Re: MySQL [R41-2] Registration System - by oMa37 - 29.01.2017, 12:30
Re: MySQL [R41-2] Registration System - by princejeet1510 - 29.01.2017, 12:40
Re: MySQL [R41-2] Registration System - by Variable™ - 29.01.2017, 12:45
Re: MySQL [R41-2] Registration System - by DerickClark - 29.01.2017, 14:39
Re: MySQL [R41-2] Registration System - by X337 - 29.01.2017, 14:49
Re: MySQL [R41-2] Registration System - by Gammix - 29.01.2017, 15:07
Re: MySQL [R41-2] Registration System - by PowerPC603 - 29.01.2017, 20:20
Re: MySQL [R41-2] Registration System - by princejeet1510 - 09.02.2017, 14:09
Re: MySQL [R41-2] Registration System - by Variable™ - 09.02.2017, 17:12
Re: MySQL [R41-2] Registration System - by TheLeech - 25.02.2017, 18:26
Re: MySQL [R41-2] Registration System - by Sabur - 27.02.2017, 05:48
Re: MySQL [R41-2] Registration System - by Variable™ - 27.02.2017, 23:02
Re: MySQL [R41-2] Registration System - by Eoussama - 10.03.2017, 11:46
Re: MySQL [R41-2] Registration System - by Variable™ - 10.03.2017, 16:57
Re: MySQL [R41-2] Registration System - by SteSte - 13.07.2017, 01:26
Re: MySQL [R41-2] Registration System - by valerastar - 26.07.2017, 18:18
Re: MySQL [R41-2] Registration System - by Uberanwar - 02.12.2017, 15:48
Re: MySQL [R41-2] Registration System - by AjaxM - 02.12.2017, 15:53
Re: MySQL [R41-2] Registration System - by Uberanwar - 02.12.2017, 16:06
Re: MySQL [R41-2] Registration System - by AjaxM - 02.12.2017, 17:00
Re: MySQL [R41-2] Registration System - by maddinat0r - 02.12.2017, 19:41
Re: MySQL [R41-2] Registration System - by SintaksTR - 02.01.2018, 14:23
Re: MySQL [R41-2] Registration System - by MrCesar - 09.01.2018, 19:58
Re: MySQL [R41-2] Registration System - by Flamehaze7 - 29.01.2018, 20:42
Re: MySQL [R41-2] Registration System - by OptimusBloodHunter - 29.01.2018, 20:59
Re: MySQL [R41-2] Registration System - by RxErT - 13.02.2018, 18:43
Re: MySQL [R41-2] Registration System - by JnniorDoug - 18.02.2018, 21:16
Re: MySQL [R41-2] Registration System - by insus100 - 21.02.2018, 19:14

Forum Jump:


Users browsing this thread: 3 Guest(s)