Raised This Month: $12 Target: $400
 3% 

client_disconnected() <-> plugin_end()


Post New Thread Reply   
 
Thread Tools Display Modes
meTaLiCroSS
Gaze Upon My Hat
Join Date: Feb 2009
Location: Viņa del Mar, Chile
Old 05-23-2019 , 15:10   Re: client_disconnected() <-> plugin_end()
Reply With Quote #21

Your mistake is you are saving all data when client disconnects, when it must be saved a few seconds later a data is changed. Then you can assume is not needed to re-save data on disconnect (and avoid this) and your data would be safe from a random crash, which wont call any data save function from your addon. In summary, refactor your save code, it must get a bit complex to make it work as expected.
__________________
Quote:
Originally Posted by joropito View Post
You're right Metalicross
meTaLiCroSS is offline
JocAnis
Veteran Member
Join Date: Jun 2010
Old 05-23-2019 , 18:56   Re: client_disconnected() <-> plugin_end()
Reply With Quote #22

well i changed method to hlev's suggestion, to send big query...so big query is sent every 5 seconds (loop) with updating kills+deaths for every connected player...client_disconnect is (still) updating only one column for last_join (before plugin_end)...result: no duplicated rows for now (400 players in new table)...i guess thats it

code for that big query if anyone would use, again, thanks to hlev for the suggestion:

Code:
public update_big_query()
{
	new  buffer[2048], len, players[ 32 ], pnum
	get_players( players, pnum, "chi" )

	len = formatex(buffer, 2047, "UPDATE TABLE_NAME \
		SET kills = ( case " )
		
	if( pnum <= 1 )
		return PLUGIN_HANDLED
		
	for( new i = 0; i <= pnum; i++ )
	{
		if( !is_user_connected( players[ i ] ) ) continue 
		
		if( g_iPlayerKills[ players[ i ] ] != 0 )
		{
			len += formatex( buffer[len], 2047-len, "when id=%d then '%d'", g_iPlayerID[ players[ i ] ], g_iPlayerKills[ players[ i ] ] )
		}
	}
		
	len += formatex( buffer[len], 2047-len, " end ), deaths = ( case " )
	for( new i = 0; i <= pnum; i++ )
	{
		if( !is_user_connected( players[ i ] ) ) continue 
		
		len += formatex( buffer[len], 2047-len, "when id=%d then '%d'", g_iPlayerID[ players[ i ] ], g_iPlayerDeaths[ players[ i ] ] )
	}
	
	len += formatex( buffer[len], 2047-len, " end ) WHERE id in ( " )
	
	for( new i = 0; i <= pnum; i++ )
	{
		if( !is_user_connected( players[ i ] ) ) continue 
		
		if( g_iPlayerKills[ players[ i ] ] != 0 )
			len += formatex( buffer[len], 2047-len, "%s%d", i > 1 ? ", ":"", g_iPlayerID[ players[ i ] ] )
	}
		
	len += formatex( buffer[len], 2047-len, " )" )
	
	if( !disconnect )
		SQL_ThreadQuery( g_SqlTuple, "IgnoreHandle", buffer ) 
		
	//client_print( 0, print_console, "%s", buffer )
	return PLUGIN_HANDLED
}
__________________
KZ Public Autocup - PrimeKZ

My blog: http://primekz.xyz (in progress...) - not active (dec 2022)

Last edited by JocAnis; 10-31-2019 at 14:17.
JocAnis is offline
JocAnis
Veteran Member
Join Date: Jun 2010
Old 10-25-2019 , 06:48   Re: client_disconnected() <-> plugin_end()
Reply With Quote #23

I saw some people were using the code from the post above, just to inform it had a big issue if your server went with big amount of players + bots ect...LIKE i had the problem in that period, which probably wasnt cuz of client_disconnect or plugin_end but by this 'error', so its updated now

- dont ask me how the hell this came to my mind to this fix after 5 months, but i know i missed back then a opportunity to get *fine cash* for this project cuz of this, stupid me

problem was obvious, indexes of players: g_iPlayerKills[ i ] -> g_iPlayerKills[ players[ i ] ], so it was the reason of loading/saving wrong players, even duplicating
__________________
KZ Public Autocup - PrimeKZ

My blog: http://primekz.xyz (in progress...) - not active (dec 2022)

Last edited by JocAnis; 10-25-2019 at 06:50.
JocAnis is offline
^SmileY
Veteran Member
Join Date: Jan 2010
Location: Brazil [<o>]
Old 10-31-2019 , 13:10   Re: client_disconnected() <-> plugin_end()
Reply With Quote #24

Do it like csstats module, at round end or round start.

Do not matter if server has crashed or server changed level.
I also have a stats plugin that i'm planning to do in this way
__________________
Projects:

- See my Git Hub: https://github.com/SmileYzn
PHP Code:
set_pcvar_num(pCvar, !get_pcvar_num(pCvar)); 
^SmileY is offline
Send a message via MSN to ^SmileY Send a message via Skype™ to ^SmileY
JocAnis
Veteran Member
Join Date: Jun 2010
Old 10-31-2019 , 14:17   Re: client_disconnected() <-> plugin_end()
Reply With Quote #25

Quote:
Originally Posted by ^SmileY View Post
Do it like csstats module, at round end or round start.
plan was to have like live version of statistics...what if player disconnect for whatever reason before round_end but he got 22 kills in that round ?
__________________
KZ Public Autocup - PrimeKZ

My blog: http://primekz.xyz (in progress...) - not active (dec 2022)

Last edited by JocAnis; 10-31-2019 at 14:18.
JocAnis is offline
^SmileY
Veteran Member
Join Date: Jan 2010
Location: Brazil [<o>]
Old 10-31-2019 , 14:50   Re: client_disconnected() <-> plugin_end()
Reply With Quote #26

if you can't handle big query anyway in server changelevel or client disconnects. it is a solution for it.
Do not matter if players do a rage quit from server. Is not admin or server fault bro.

Using sqlx will never cover such situations when you use a lot of data to save or load from database.

I presume if you can use sql to save data, you can also try a plugin like hl statsx ce or psychostats that use logs to handle data, so basically you will not need to hurry about client disconnects or change levels.

I'm still have some doubt how we can save player data with efficiency and accuracy.
__________________
Projects:

- See my Git Hub: https://github.com/SmileYzn
PHP Code:
set_pcvar_num(pCvar, !get_pcvar_num(pCvar)); 

Last edited by ^SmileY; 10-31-2019 at 14:52.
^SmileY is offline
Send a message via MSN to ^SmileY Send a message via Skype™ to ^SmileY
JocAnis
Veteran Member
Join Date: Jun 2010
Old 04-10-2020 , 20:17   Re: client_disconnected() <-> plugin_end()
Reply With Quote #27

this all was wrong. i mean, i had a problem the new player was getting mysql info from last disconnected player (when server is 32/32 so its always switching players)...my bad is that i thought map_end or smth like that was making a big mess...so fix is:

Code:
//Load_MySql( task )

new Data[ 2 ] 
Data[ 0 ] = id
Data[ 1 ] = get_user_userid( id )
formatex(szTemp,charsmax(szTemp),"SELECT * FROM players WHERE steamid = '%s';", szSteamId) 
	
SQL_ThreadQuery(g_SqlTuple,"register_client",szTemp,Data, sizeof( Data ) ) 

//and then later in register_client:

new id, uid
id = Data[ 0 ]
uid = Data[ 1 ]
	
if( !is_user_connected( id ) || uid != get_user_userid( id ) )
	return PLUGIN_HANDLED	

//and on other ThreadQueries, just to be sure
}
didnt test yet, but i see the logic here

big thanks to lazarev for pointing that out for me
__________________
KZ Public Autocup - PrimeKZ

My blog: http://primekz.xyz (in progress...) - not active (dec 2022)

Last edited by JocAnis; 04-11-2020 at 08:48.
JocAnis is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 03:21.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode