AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   MySQL problem (https://forums.alliedmods.net/showthread.php?t=246085)

skz 08-11-2014 18:31

MySQL problem
 
Hi!

In my server, I have a Point System in Mysql, everything works fine but sometimes a new player join the server and gets the same points as the top player who have more points.

Can someone tell me if this is a problem in mysql or in my plugin?

wickedd 08-11-2014 18:33

Re: MySQL problem
 
How are you saving players points, by Name, IP, or SteamID?

skz 08-11-2014 18:43

Re: MySQL problem
 
SteamID

Nextra 08-11-2014 19:02

Re: MySQL problem
 
What point system? This is way too little information. It sounds like you forget to reset something on connect/disconnect but we can't help you like this.

skz 08-11-2014 19:47

Re: MySQL problem
 
It's a point system that I created...

PHP Code:

public client_putinserver(id)
{
    
Load_MySql(id)
    
points_in_name(id
    
set_task(5.0"PontosHud"id__"b")
}

public 
client_disconnect(id)
{
    
Save_MySql(id)



Nextra 08-11-2014 19:49

Re: MySQL problem
 
That is an awfully short plugin you have there. I'm impressed if that does anything at all.

skz 08-11-2014 20:47

Re: MySQL problem
 
Lol man, I just posted the connect and disconnect functions, as you wanted...

YamiKaitou 08-11-2014 20:57

Re: MySQL problem
 
Quote:

Originally Posted by skz (Post 2182566)
Lol man, I just posted the connect and disconnect functions, as you wanted...

No you didn't. You are missing the Load_MySql, points_in_name, PontosHud and Save_MySql functions

skz 08-11-2014 21:27

Re: MySQL problem
 
PHP Code:

public Load_MySql(id)
{
    new 
szSteamId[32], szTemp[512]
    
get_user_authid(idszSteamIdcharsmax(szSteamId))
    
    new 
Data[1]
    
Data[0] = id
    
    format
(szTemp,charsmax(szTemp),"SELECT * FROM `pontos` WHERE (`pontos`.`steamid` = '%s')"szSteamId)
    
SQL_ThreadQuery(g_SqlTuple,"register_client",szTemp,Data,1)
}
public 
Save_MySql(id)
{
    new 
szSteamId[32], szTemp[512]
    
get_user_authid(idszSteamIdcharsmax(szSteamId))
    
    
format(szTemp,charsmax(szTemp),"UPDATE `pontos` SET `exp` = '%i' WHERE `pontos`.`steamid` = '%s';"iJBPacks[id], szSteamId)
    
SQL_ThreadQuery(g_SqlTuple,"IgnoreHandle",szTemp)
}
stock points_in_name(id)

    new 
szName[32
    
get_user_name(idszNamecharsmax(szName)) 
    new 
iLen strlen(szName
     
    new 
iPos iLen 
    
if( szName[iPos] == ']' 
    { 
        for( new 
16i++) 
        { 
            if( 
szName[iPos i] == '[' 
            { 
                
iLen iPos 
                szName
[iLen] = '^0' 
                
break 
            } 
        } 
    } 
    
    
format(szName[iLen], charsmax(szName) - iLenszName[iLen-1] == ' ' "[%d]" " [%d]"iJBPacks[id]) 
    
set_user_info(id"name"szName

public 
PontosHud(id)
{
    
set_hudmessage(6464640.750.8206.02.5)
    
show_hudmessage(id,"Pontos: %i"iJBPacks[id])



Nextra 08-11-2014 22:31

Re: MySQL problem
 
While this is still missing code pieces (register_client) we have somewhere to start.
  • Use the client_authorized forward instead of client_putinserver. You are not guaranteed to have the SteamID available when client_putinserver fires
  • Related to the above you're not actually verifying you have a valid steamid on your hands.
  • You're using threaded queries but you're doing nothing to prevent data races. You need to ensure that you can't have two setup processes running for the same client id.


All times are GMT -4. The time now is 13:17.

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