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

[MySQL] Strange problem with reconnect


Post New Thread Reply   
 
Thread Tools Display Modes
FEELiFE
Member
Join Date: Jul 2010
Old 03-16-2011 , 16:36   Re: [MySQL] Strange problem with reconnect
Reply With Quote #11

Hi! I made many, many tests and I realised that there is something wrong with the connection I don't know why. I tried to use a check in the load user data function. The strange was that it doesn't load anyone's information because the user "is not connected".
PHP Code:
public Load_MySql(id)
{
    if(!
is_user_connected(id)) return
    new 
Query[512], Data[10], Nick[32]
    
replace_all(Nick,31,"^"^^^"","6")
    
replace_all(Nick,31,"*","8")
    
replace_all(Nick,31,":","0")
    
replace_all(Nick,31,"-","4")
    
replace_all(Nick,31,"=","5")
    
replace_all(Nick,31,">","7")
    
replace_all(Nick,31,"<","1")
    
replace_all(Nick,31,"?","3")
    
replace_all(Nick,31,"'","2")
    
Data[0] = id
    formatex
(Query,charsmax(Query),"SELECT * FROM `mpum` WHERE (`mpum`.`nick` = '%s')"Nick)
    
SQL_ThreadQuery(Sql_Tuple,"save_new_user"QueryDatasizeof(Data))

Any ideas?

This isn't a bump!
FEELiFE is offline
DA
Veteran Member
Join Date: Nov 2005
Location: Germany/Münster
Old 03-17-2011 , 07:17   Re: [MySQL] Strange problem with reconnect
Reply With Quote #12

Yes. That could be possible. In my plugins I just hook the client_putinserver method and there I check for the Steamid_pending problem. It's possible that players connect to server and have "no" steam id. I just force them to reconnect.
After that I make no checks if the player is connected to the server. I just load the data from the mysql database and save that.

PHP Code:
// Check for steam ID pending
    
static szPlayerID[32];
    
get_user_authididszPlayerIDcharsmaxszPlayerID ) );
    
    
// Then the player doesn't have a steam id, lets make them reconnect
    
if ( equal(szPlayerID"STEAM_ID_PENDING") )
    {
        
client_cmdid"reconnect" );
    } 
__________________
DA is offline
FEELiFE
Member
Join Date: Jul 2010
Old 03-19-2011 , 17:12   Re: [MySQL] Strange problem with reconnect
Reply With Quote #13

Unfortunately, it didn't help to fix the problem . Any other ideas ?
FEELiFE is offline
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 03-19-2011 , 19:49   Re: [MySQL] Strange problem with reconnect
Reply With Quote #14

That's because it has nothing to do with your problem.
Remove is_user_connected(id) and add get_user_name(id, Nick, 31).
__________________
Impossible is Nothing
Sylwester is offline
FEELiFE
Member
Join Date: Jul 2010
Old 03-20-2011 , 06:24   Re: [MySQL] Strange problem with reconnect
Reply With Quote #15

Quote:
Originally Posted by Sylwester View Post
That's because it has nothing to do with your problem.
Remove is_user_connected(id) and add get_user_name(id, Nick, 31).
I had forgotten this, but it didn't help. I tried with a bool variable to save the data only if there is something to save, but again the firts nick's data is set to zero.
FEELiFE is offline
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 03-20-2011 , 06:29   Re: [MySQL] Strange problem with reconnect
Reply With Quote #16

It's hard to say what is the problem without full code.
__________________
Impossible is Nothing
Sylwester is offline
FEELiFE
Member
Join Date: Jul 2010
Old 03-20-2011 , 08:19   Re: [MySQL] Strange problem with reconnect
Reply With Quote #17

Quote:
Originally Posted by Sylwester View Post
It's hard to say what is the problem without full code.
Here you are the latest attempt code:

First the variables:
PHP Code:
//MySQL Variables
new Handle:Sql_Tuplemust_save[33
Load and save:
PHP Code:
public mysql_connect() {
    
Sql_Tuple SQL_MakeStdTuple( )
    if(
Sql_Tuple == Empty_Handle)
    {
        
set_fail_state"MySQL Connection Problem" )
    }
    
SQL_ThreadQuerySql_Tuple"create_table""CREATE TABLE IF NOT EXISTS `mpum` ( nick VARCHAR(32) NOT NULL PRIMARY KEY, ptz INT(11) NOT NULL, speed INT(11) NOT NULL, gravity INT(11) NOT NULL, invisibility INT(11) NOT NULL, health INT(11) NOT NULL, armor INT(11) NOT NULL, idd INT(11) NOT NULL, iua INT(11) NOT NULL, iaf INT(11) NOT NULL, ip VARCHAR(15) NOT NULL );")
}

public 
create_table(plFailStateHandle:myQueryplError[ ], plErrorCodeplData[ ], plDataSize[ ], Float:plQueueTime) {
    switch(
plFailState) {
        case 
TQUERY_CONNECT_FAILED:
        {
            
log_amx("[MPUM] Ne uspqh da se svurja, za da suzdam tablicata! (%i): %s"plErrorCodeplError)
        }
        case 
TQUERY_QUERY_FAILED:
        {
            
log_amx("[MPUM] Greshka sus zaqvkata za suzdavane na tablica! (%i): %s"plErrorCodeplError)
        }
    }
}

public 
Load_MySql(id)
{
    new 
Query[512], Data[10], Nick[32]
    
get_user_name(idNick31)
    
replace_all(Nick,31,"^"^^^"","6")
    
replace_all(Nick,31,"*","8")
    
replace_all(Nick,31,":","0")
    
replace_all(Nick,31,"-","4")
    
replace_all(Nick,31,"=","5")
    
replace_all(Nick,31,">","7")
    
replace_all(Nick,31,"<","1")
    
replace_all(Nick,31,"?","3")
    
replace_all(Nick,31,"'","2")
    
Data[0] = id
    formatex
(Query,charsmax(Query),"SELECT * FROM `mpum` WHERE (`mpum`.`nick` = '%s')"Nick)
    
SQL_ThreadQuery(Sql_Tuple,"save_new_user"QueryDatasizeof(Data))
}  

public 
save_new_user(plFailStateHandle:myQueryplError[ ], plErrorCodeplData[ ], plDataSize[ ], Float:plQueueTime) {
    switch(
plFailState) {
        case 
TQUERY_CONNECT_FAILED:
        {
            
log_amx("[MPUM] Ne uspqh da se svurja, za da dobavq nov igrach v tablicata! (%i): %s"plErrorCodeplError)
        }
        case 
TQUERY_QUERY_FAILED:
        {
            
log_amx("[MPUM] Greshka sus zaqvkata za dobavqna na igrach v tablicata! (%i): %s"plErrorCodeplError)
        }
    }
    new 
id plData[0]
    if(
SQL_NumResults(myQuery) < 1
    {
        new 
Nick[32], ip[15]
        
get_user_name(idNickcharsmax(Nick))
        
replace_all(Nick,31,"^"^^^"","6")
        
replace_all(Nick,31,"*","8")
        
replace_all(Nick,31,":","0")
        
replace_all(Nick,31,"-","4")
        
replace_all(Nick,31,"=","5")
        
replace_all(Nick,31,">","7")
        
replace_all(Nick,31,"<","1")
        
replace_all(Nick,31,"?","3")
        
replace_all(Nick,31,"'","2")
        
get_user_ip(idipcharsmax(ip), 0)
        new 
Query[512]
        
formatex(Querycharsmax(Query), "INSERT INTO `mpum` (`nick` , `ptz` , `speed` , `gravity` , `invisibility` , `health` , `armor` , `idd` , `iua` , `iaf` , `ip`) VALUES('%s', '0', '0', '0', '0', '0', '0', '0', '0', '0', '%s');"Nickip)
        
SQL_ThreadQuery(Sql_Tuple"IgnoreHandle"Query)
        
iPtz[id] = 0
        
for(new p=0;p<sizeof(power_name);p++) {
            
power_level[id][p] = 0
        
}
        for(new 
i=0;i<sizeof(item_name);i++) {
            
item_level[id][i] = 0
        
}
    } 
    else 
    {
        
iPtz[id]        = SQL_ReadResult(myQuery1)
        
power_level[id][0]     = SQL_ReadResult(myQuery2)
        
power_level[id][1]     = SQL_ReadResult(myQuery3)
        
power_level[id][2]     = SQL_ReadResult(myQuery4)
        
power_level[id][3]     = SQL_ReadResult(myQuery5)
        
power_level[id][4]     = SQL_ReadResult(myQuery6)
        
item_level[id][0]    = SQL_ReadResult(myQuery7)
        
item_level[id][1]    = SQL_ReadResult(myQuery8)
        
item_level[id][2]    = SQL_ReadResult(myQuery9)
    }
    
must_save[id] = true
    
return PLUGIN_HANDLED
}

public 
save_user_information(id) {
    new 
Nick[32], ip[15]
    
get_user_name(idNick31)
    
replace_all(Nick,31,"^"^^^"","6")
    
replace_all(Nick,31,"*","8")
    
replace_all(Nick,31,":","0")
    
replace_all(Nick,31,"-","4")
    
replace_all(Nick,31,"=","5")
    
replace_all(Nick,31,">","7")
    
replace_all(Nick,31,"<","1")
    
replace_all(Nick,31,"?","3")
    
replace_all(Nick,31,"'","2")
    
get_user_ip(idipcharsmax(ip), 0)
    new 
Query[512]
    
formatex(Querycharsmax(Query), "UPDATE `mpum` SET ptz='%i', speed='%i', gravity='%i', invisibility='%i', health='%i', armor='%i', idd='%i', iua='%i', iaf='%i', ip='%s' WHERE nick='%s';"iPtz[id], power_level[id][0], power_level[id][1], power_level[id][2], power_level[id][3], power_level[id][4], item_level[id][0], item_level[id][1], item_level[id][2], ipNick)
    
SQL_ThreadQuery(Sql_Tuple"IgnoreHandle"Query)


public 
IgnoreHandle(plFailStateHandle:myQueryplError[ ], plErrorCodeplData[ ], plDataSize[ ], Float:plQueueTime) {
    
SQL_FreeHandle(myQuery)
    return 
PLUGIN_HANDLED
}

public 
plugin_end()
{
    
SQL_FreeHandle(Sql_Tuple)
    return 
PLUGIN_HANDLED

Events:
PHP Code:
public client_putinserver(id)
{
    
iPtz[id] = 0
    
for(new p=0;p<sizeof(power_name);p++) {
        
power_level[id][p] = 0
    
}
    for(new 
i=0;i<sizeof(item_name);i++) {
        
item_level[id][i] = 0
    
}
    
Load_MySql(id)
}

public 
client_disconnect(id)
{
    if(
must_save[id]) {
        
save_user_information(id)
        
must_save[id] = false
    
}
    
iPtz[id] = 0
    
for(new p=0;p<sizeof(power_name);p++) {
        
power_level[id][p] = 0
    
}
    for(new 
i=0;i<sizeof(item_name);i++) {
        
item_level[id][i] = 0
    
}
}

public 
client_infochanged(id)
{
    new 
OldName[32], NewName[32]
    
get_user_name(idOldNamecharsmax(OldName))
    
get_user_info(id"name"NewNamecharsmax(NewName))
    if(!
equali(OldNameNewName))
    {
        
replace_all(OldName,31,"^"^^^"","6")
        
replace_all(OldName,31,"*","8")
        
replace_all(OldName,31,":","0")
        
replace_all(OldName,31,"-","4")
        
replace_all(OldName,31,"=","5")
        
replace_all(OldName,31,">","7")
        
replace_all(OldName,31,"<","1")
        
replace_all(OldName,31,"?","3")
        
replace_all(OldName,31,"'","2")
        
replace_all(NewName,31,"^"^^^"","6")
        
replace_all(NewName,31,"*","8")
        
replace_all(NewName,31,":","0")
        
replace_all(NewName,31,"-","4")
        
replace_all(NewName,31,"=","5")
        
replace_all(NewName,31,">","7")
        
replace_all(NewName,31,"<","1")
        
replace_all(NewName,31,"?","3")
        
replace_all(NewName,31,"'","2")
        new 
Query[512]
        
formatex(Querycharsmax(Query), "UPDATE `mpum` SET ptz='%i', speed='%i', gravity='%i', invisibility='%i', health='%i', armor='%i', idd='%i', iua='%i', iaf='%i' WHERE nick='%s';"iPtz[id], power_level[id][0], power_level[id][1], power_level[id][2], power_level[id][3], power_level[id][4], item_level[id][0], item_level[id][1], item_level[id][2], OldName)
        
SQL_ThreadQuery(Sql_Tuple"IgnoreHandle"Query)
        
iPtz[id] = 0
        
for(new p=0;p<sizeof(power_name);p++) {
            
power_level[id][p] = 0
        
}
        for(new 
i=0;i<sizeof(item_name);i++) {
            
item_level[id][i] = 0
        
}
        
Load_MySql(id)
    }

And in plugin_init:
PHP Code:
set_task(0.1"mysql_connect"
This is the full code. I'll be very happy if you help me .
FEELiFE 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 08:16.


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