[MySQL] From StickenKid's plugin to BlueG's plugin
#2

Well converting from StrickenKid's will be different because r39 threaded and they aren't similar to the old one which I am referring to r6, I suggest you to read this https://sampwiki.blast.hk/wiki/MySQL/R33 and this https://sampforum.blast.hk/showthread.php?tid=337810 those link will help you a lot! so this is the code.

pawn Code:
new
    rCheck[MAX_PLAYERS]; // declare a per-player array/var.

//Under OnPlayerConnect
++ rCheck[playerid];

//Under OnPlayerDisconnect
++ rCheck[playerid];


//Sends a query which will be executed in another thread and calls the callback (if there is one) when the execution is finished.
mysql_tquery(connectionHandle, "SELECT * FROM `characters` WHERE `Activated` = 0 AND `Deletable` = 0 AND `DenialReason` = 'DenialReason' LIMIT 1", "OnCharactersLoad", "ii", playerid, rCheck[playerid]);

forward OnCharactersLoad(playerid, race_check);
public OnCharactersLoad(playerid, race_check)
{
    new
        rows = cache_num_rows();

    if(rCheck[playerid] != race_check) //if the race_check
        return Kick(playerid), printf("Invalid Race Check: rCheck[playerid]: %i - race_check:%i", rCheck[playerid], race_check);

    if(rows) //if rows is more than one, we proceed loading player's status.
    {
        cache_get_field_content(0, "CharacterName", destination, connectionHandle = 1, sizeof(destination));
        //and so on loading
    }
    return true;
}
Why does race_check needed?

Quote:
Originally Posted by maddinat0r
race condition check:
player A connects -> SELECT query is fired -> this query takes very long
while the query is still processing, player A with playerid 2 disconnects
player B joins now with playerid 2 -> our laggy SELECT query is finally finished, but for the wrong player

what do we do against it?
we create a connection count for each playerid and increase it everytime the playerid connects or disconnects
we also pass the current value of the connection count to our OnPlayerDataLoaded callback
then we check if current connection count is the same as connection count we passed to the callback
if yes, everything is okay, if not, we just kick the player
Reply


Messages In This Thread
[MySQL] From StickenKid's plugin to BlueG's plugin - by jessejanssen - 14.06.2014, 17:57
Re: [MySQL] From StickenKid's plugin to BlueG's plugin - by Patrick - 14.06.2014, 18:16
Re: [MySQL] From StickenKid's plugin to BlueG's plugin - by jessejanssen - 15.06.2014, 01:20

Forum Jump:


Users browsing this thread: 1 Guest(s)