Raised This Month: $ Target: $400
 0% 

[SOLVED]client_disconnect & mysql


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
One
Veteran Member
Join Date: Oct 2008
Location: Hardstyle-eSports.de
Old 05-05-2011 , 21:06   [SOLVED]client_disconnect & mysql
Reply With Quote #1

hi,

i'm writing a plugin to put a mini live status to db.
now i have a problem to delete users stats in db when he left the server.

now i want to ask is there a way to delete users data without a loop to see who is not anymore on the server?

i tried :
on client connect
PHP Code:
public Load_SQL(id)
{
    new 
steam_id[33],Temp[512],name[33],loss,ping
    
/*team :
        0 = connecting
        1 = spectating
        2 = Catcher
        3 = Fleer
    */
    
    
get_user_ping(id,ping,loss)
    
get_user_authid(idsteam_idcharsmax(steam_id))
    
get_user_name(id,name,32)
    
    if (
equal(steam_id,"ID_PENDING"))
    {
        return 
PLUGIN_HANDLED
    
}
    
format(Temp,charsmax(Temp),"INSERT INTO `catch_live` ( `authid` , `name` , `Score` , `Deaths` , `Ping` , `speed` , `Maxspeed` , `fps` , `team` , `ag` , `map`)VALUES ('%s','%s','0','0','%d','0','0','%d','con','1','%s');",steam_id,name,ping,users_fps,map)
    
SQL_ThreadQuery(sqldb,"IgnoreHandle",Temp)
    return 
PLUGIN_HANDLED

on client_disconnect

PHP Code:
public client_disconnect(id)
{
    
/* Maybe i should delete the table or check if there are resaults for player on client_connect bacause of server crashes or such problems */
    
g_iIsSpectator[id] = 0
    
new steam_id[33],Temp[512]
    
    if (
equal(steam_id,"ID_PENDING"))
    {
        return 
PLUGIN_HANDLED
    
}
    
format(Temp,charsmax(Temp),"DELETE FROM `catch_live` WHERE `authid` = '%s'"steam_id);
    
SQL_ThreadQuery(sqldb,"IgnoreHandle",Temp)
    return 
PLUGIN_HANDLED

the problem here is that the client is not anymore on server and i have no steamid to delete his stats.
__________________
One is offline
Send a message via ICQ to One Send a message via AIM to One Send a message via MSN to One Send a message via Yahoo to One Send a message via Skype™ to One
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 05-05-2011 , 21:09   Re: client_disconnect & mysql
Reply With Quote #2

IIRC, you can still get their SteamID in client_disconnect() but remember, you actually have to get the SteamID to use it .

Edit: Your if() statement will always be false BTW.
__________________
fysiks is offline
One
Veteran Member
Join Date: Oct 2008
Location: Hardstyle-eSports.de
Old 05-05-2011 , 21:52   Re: client_disconnect & mysql
Reply With Quote #3

omg. damn i forgot to get the steamid :-)))

and i wonder why this will not delete my infos.as debug i tried to insert datas in db stand deleting and i got not steamid in table =))

my bad & ok ill delete the line
__________________
One is offline
Send a message via ICQ to One Send a message via AIM to One Send a message via MSN to One Send a message via Yahoo to One Send a message via Skype™ to One
One
Veteran Member
Join Date: Oct 2008
Location: Hardstyle-eSports.de
Old 05-05-2011 , 22:30   Re: [SOLVED]client_disconnect & mysql
Reply With Quote #4

sorry for double post.
i just wanted to ask if is it ok to update the table in register_think fw?

EDIT: ok i see it. im around 5 min disconnected from the server but the stats are still updating in db.

whats the best time to update the stats? 10 sec?
i think its better to do it with task
__________________

Last edited by One; 05-05-2011 at 22:34.
One is offline
Send a message via ICQ to One Send a message via AIM to One Send a message via MSN to One Send a message via Yahoo to One Send a message via Skype™ to One
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 05-06-2011 , 00:45   Re: [SOLVED]client_disconnect & mysql
Reply With Quote #5

It really depends on what you are doing. Definitely not recommended to use any type of think forward. Also, the very last point that you should update is on disconnect (not after). Just going by common sense here.
__________________
fysiks is offline
Hunter-Digital
Veteran Member
Join Date: Aug 2006
Location: In the Game [ro]
Old 05-06-2011 , 06:52   Re: [SOLVED]client_disconnect & mysql
Reply With Quote #6

Hmm, I think client_connect() triggers when player is accepted to server while in loading, but if the player cancells in loading the client_disconnect() doesn't trigger unless the player has entered the game.
So, if that's surely true , you should use client_putinserver() for adding to db.

You should test it tough, add server prints to console upon connect and disconnect, connect to the server and then cancel while loading.

And just a small note: about your team comment, are those numbers from their actual team (like [cs_]get_user_team) ? Because in-game, the spectators are team 3.


And about your updating stuff... where do you actually update the stats ? All I see is INSERT and DELETE... because if you're having trouble deleting that when player left, you can do it just fine in the update sequence, just check is_user_connected() (or better: a global variable) and check it before updating then delete player and skip to next one.

And if you don't have a updating sequence already, set_task() on 5-30 seconds will do just fine.
__________________

Last edited by Hunter-Digital; 05-06-2011 at 06:59.
Hunter-Digital is offline
One
Veteran Member
Join Date: Oct 2008
Location: Hardstyle-eSports.de
Old 05-06-2011 , 09:55   Re: [SOLVED]client_disconnect & mysql
Reply With Quote #7

Quote:
Originally Posted by fysiks View Post
It really depends on what you are doing. Definitely not recommended to use any type of think forward. Also, the very last point that you should update is on disconnect (not after). Just going by common sense here.
i wanted to update the db in speedometer think :-D
it worked perfectly but how i said, i was disconnected from the server but the stats was still @ updating.
everytime i refreshed the table, i saw new Speed values in tables.
i think it caused by traffic or so :-(
Quote:
Originally Posted by Hunter-Digital View Post
Hmm, I think client_connect() triggers when player is accepted to server while in loading, but if the player cancells in loading the client_disconnect() doesn't trigger unless the player has entered the game.
So, if that's surely true , you should use client_putinserver() for adding to db.

You should test it tough, add server prints to console upon connect and disconnect, connect to the server and then cancel while loading.

And just a small note: about your team comment, are those numbers from their actual team (like [cs_]get_user_team) ? Because in-game, the spectators are team 3.


And about your updating stuff... where do you actually update the stats ? All I see is INSERT and DELETE... because if you're having trouble deleting that when player left, you can do it just fine in the update sequence, just check is_user_connected() (or better: a global variable) and check it before updating then delete player and skip to next one.

And if you don't have a updating sequence already, set_task() on 5-30 seconds will do just fine.
Hmm... you'r right. i wanted to have it realisticer and add on the page as status :
Connecting
Connected
Spec
Fleer
Cather
thats point2. i have my own teams. a counter-terrorist can be in team 2 or 3. better said, this willbe changed every round.
first round are Ts the team 2 and next round are CTs as team 2 defined.
PHP Code:
    /*team :
        0 = connecting
        1 = spectating
        2 = Catcher
        3 = Fleer
    */ 
and how i said, i upadte the stats in my speed think. if its needed i can paste it here ( im now online with laptop )

anyways for first thanks for answers.
i think its better to add a cvar for the task to set the update task.
__________________
One is offline
Send a message via ICQ to One Send a message via AIM to One Send a message via MSN to One Send a message via Yahoo to One Send a message via Skype™ to One
Hunter-Digital
Veteran Member
Join Date: Aug 2006
Location: In the Game [ro]
Old 05-06-2011 , 10:43   Re: [SOLVED]client_disconnect & mysql
Reply With Quote #8

I've tested that connect/disconnect thing and it's true.
Still, server IS notified if player drops in loading so there's a way to detect that too if you really need "connecting" status... and I belive Orpheu is the one for this.

Also, updating stats in the think it's not really a good ideea because think (with all checks for skipping frames and stuff so that it's got a few seconds delay between updates) it's pretty inaccurate because not all players have the same FPS... and players with high fps may lag your server.
__________________

Last edited by Hunter-Digital; 05-06-2011 at 10:46.
Hunter-Digital is offline
One
Veteran Member
Join Date: Oct 2008
Location: Hardstyle-eSports.de
Old 05-06-2011 , 10:50   Re: [SOLVED]client_disconnect & mysql
Reply With Quote #9

ok, ill try to catch with orpheu.
i made a page to see it.
http://www.jva-multigaming.at/catchmod/ << if you check it now you will see im on server but in real im disconnected and this thing is still updating.
its realy a bad idea to update the tables in think :-D i wanted to have it in real time.


anyways it will now be updated in think ( i have to recode it and upload it on server but you can now test it if you like :-)) ) server deatails in my sign. server pw : test

EDIT :

here is my speed think
PHP Code:
public SpeedTask()
{
    static 
itarget
    
static Float:velocity[3]
    static 
Float:speed
    
for(i=1i<=E_MaxPlayersi++)
    {
        if(
is_user_alive(i))
        {
            
target pev(ipev_iuser1) == pev(ipev_iuser2) : i
            pev
(targetpev_velocityvelocity)
            
            
speed vector_length(velocity)
            
set_hudmessage(CV_Speedo_RCV_Speedo_GCV_Speedo_B0.410.7600.0FREQ0.010.0)
            if(
speed users_maxspeed_round[i])
            {
                
users_maxspeed_round[i] = speed            
            
}
            if(
speed users_maxspeed_map[i])
            {
                
users_maxspeed_map[i] = speed
            
}
            if(
speed best_speed)
            {
                
best_speed speed
                get_user_name
(i,top_speed_name,32)
            }
            new 
steam_id[33],Temp[512],loss,ping
            
/*team :
                0 = connecting
                1 = spectating
                2 = Catcher
                3 = Fleer
            */
    
            
get_user_ping(i,ping,loss)
            
get_user_authid(isteam_idcharsmax(steam_id))
    
            if(!
corrent_AG[i])
            {
                
format(Temp,charsmax(Temp),"UPDATE `catch_live` SET `speed`='%f' , `Maxspeed`='%f' , `fps`='%d' ,`Ping`='%d' , `ag`='0' WHERE `authid`='%s'",speed,users_maxspeed_round[i],users_fps,ping,steam_id)
                
ShowSyncHudMsg(i,SyncHud,"%L",LANG_PLAYER,"HUD_SPEED_NOAG",users_maxspeed_round[i],users_maxspeed_map[i],best_speed,top_speed_name)
            }
            else
            {
                
format(Temp,charsmax(Temp),"UPDATE `catch_live` SET `speed`='%f' , `Maxspeed`='%f' , `fps`='%d' ,`Ping`='%d' , `ag`='%d' WHERE `authid`='%s'",speed,users_maxspeed_round[i],users_fps,ping,corrent_AG[i],steam_id)
                
ShowSyncHudMsg(i,SyncHud,"%L",LANG_PLAYER,"HUD_SPEED_AGS",corrent_AG[i],users_maxspeed_round[i],users_maxspeed_map[i],best_speed,top_speed_name)
            }
            
//client_print(i,print_chat,"%s",Temp)
            
SQL_ThreadQuery(sqldb,"IgnoreHandle",Temp)
            if(
speed <= 1000)
            {
                
cs_set_user_armor(i,floatround(speed),CS_ARMOR_NONE)
                if(!
under_tausend[i])
                {
                    
message_begin(MSG_ONE,iconstatus,{0,0,0},i)
                    
write_byte(0
                    
write_string("item_longjump")
                    
write_byte(0)
                    
write_byte(255)
                    
write_byte(0)
                    
message_end()
                    
under_tausend[i] = 1
                    over_tausend
[i] = 0
                    over_twotausend
[i] = 0
                    dead_fixed_icon
[i] = 0
                    
if(!user_is_catcher[i])
                    {
                        
set_user_rendering(i,kRenderFxGlowShell,CV_FLEER_Color_R,CV_FLEER_Color_G,CV_FLEER_Color_B,kRenderNormal,CV_render_amount_U)
                    }
                    else
                    {
                        
set_user_rendering(i,kRenderFxGlowShell,CV_Catcher_Color_R,CV_Catcher_Color_G,CV_Catcher_Color_B,kRenderNormal,CV_render_amount_U)
                    }
                }
            }
            else if(
speed 1000 && speed 2000)
            {
                
cs_set_user_armor(i,floatround(speed) - 1000,CS_ARMOR_NONE)
                if(!
over_tausend[i])
                {
                    
message_begin(MSG_ONE,iconstatus,{0,0,0},i)
                    
write_byte(2)
                    
write_string("item_longjump")
                    
write_byte(0)
                    
write_byte(255
                    
write_byte(0)
                    
message_end()
                    
over_tausend[i] = 1
                    under_tausend
[i] = 0
                    over_twotausend
[i] = 0
                    dead_fixed_icon
[i] = 0
                    
if(user_is_catcher[i])
                    {
                        
set_user_rendering(i,kRenderFxGlowShell,CV_Catcher_Color_R,CV_Catcher_Color_G,CV_Catcher_Color_B,kRenderNormal,CV_render_amount_O)
                    }
                    else
                    {
                        
set_user_rendering(i,kRenderFxGlowShell,CV_FLEER_Color_R,CV_FLEER_Color_G,CV_FLEER_Color_B,kRenderNormal,CV_render_amount_O)
                    }
                }
                if(
speed 1200 && !AG_anzahl[i][1])
                {
                    
AG_anzahl[i][1] = 1
                    corrent_AG
[i] = 1
                    
                
}
                else if(
speed 1200 && !AG_anzahl[i][2])
                {
                    
AG_anzahl[i][2] = 1
                    corrent_AG
[i] = 2
                
}
                else if(
speed 1400 && !AG_anzahl[i][3])
                {
                    
AG_anzahl[i][3] = 1
                    corrent_AG
[i] = 3
                
}
                else if(
speed 1600 && !AG_anzahl[i][4])
                {
                    
AG_anzahl[i][4] = 1
                    corrent_AG
[i] = 4
                
}
                else if(
speed 1800 && !AG_anzahl[i][5])
                {
                    
AG_anzahl[i][5] = 1
                    corrent_AG
[i] = 5
                
}
            }
            else if(
speed 2000 && speed 3000)
            {
                
cs_set_user_armor(i,floatround(speed) - 2000,CS_ARMOR_NONE)
                if(!
over_twotausend[i])
                {
                    
message_begin(MSG_ONE,iconstatus,{0,0,0},i)
                    
write_byte(2)
                    
write_string("item_longjump")
                    
write_byte(255)
                    
write_byte(255)
                    
write_byte(0)
                    
message_end()
                    
over_tausend[i] = 0
                    under_tausend
[i] = 0
                    over_twotausend
[i] = 1
                    dead_fixed_icon
[i] = 0
                    
if(!user_is_catcher[i])
                    {
                        
set_user_rendering(i,kRenderFxGlowShell,CV_FLEER_Color_R,CV_FLEER_Color_G,CV_FLEER_Color_B,kRenderNormal,CV_render_amount_OO)
                    }
                    else
                    {
                        
set_user_rendering(i,kRenderFxGlowShell,CV_Catcher_Color_R,CV_Catcher_Color_G,CV_Catcher_Color_B,kRenderNormal,CV_render_amount_OO)
                    }
                }
                if(
speed 2100 && !AG_anzahl[i][6])
                {
                    
AG_anzahl[i][6] = 1
                    corrent_AG
[i] = 6
                
}
                else if(
speed 2400 && !AG_anzahl[i][7])
                {
                    
AG_anzahl[i][7] = 1
                    corrent_AG
[i] = 8
                
}
            }
        }
        else
        {
            if(
is_user_connected(i) && !dead_fixed_icon[i])
            {
                
message_begin(MSG_ONE,iconstatus,{0,0,0},i)
                
write_byte(2)
                
write_string("item_longjump")
                
write_byte(255)
                
write_byte(255)
                
write_byte(0)
                
message_end()
                
dead_fixed_icon[i] = 1
            
}
            
ShowSyncHudMsg(i,SyncHud,"%L",LANG_PLAYER,"HUD_SPEED_SPEC",speed,best_speed,top_speed_name)
        }
        
users_AG[i] = corrent_AG[i]
        
g_points[i] = users_AG[i]
        
g_speed[i] = floatround(users_maxspeed_round[i])
    }

__________________

Last edited by One; 05-06-2011 at 11:00.
One is offline
Send a message via ICQ to One Send a message via AIM to One Send a message via MSN to One Send a message via Yahoo to One Send a message via Skype™ to One
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 05-06-2011 , 18:57   Re: [SOLVED]client_disconnect & mysql
Reply With Quote #10

Quote:
Originally Posted by Hunter-Digital View Post
Also, updating stats in the think it's not really a good ideea because think (with all checks for skipping frames and stuff so that it's got a few seconds delay between updates) it's pretty inaccurate because not all players have the same FPS... and players with high fps may lag your server.
Thinks are based on the server only and not client rates. prethink and postthink forwards are based on server frames AFAIK.
__________________
fysiks is offline
Reply



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 04:22.


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