AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [MySql] what to do (https://forums.alliedmods.net/showthread.php?t=336292)

wilian159 02-09-2022 18:09

[MySql] what to do
 
what to do when the player enters before the bank establishes connection?

I have a ban system and I have a query right in 'client_connect'
but sometimes the game enters faster than the bank is connected

and get the error
Invalid info tuple handle: 0

Any solution?

CrazY. 02-09-2022 20:00

Re: [MySql] what to do
 
You should implement some kind of queue and process it once the database is available.
To get you started

Code:

#include <amxmodx>
#include <sqlx>

const TASK_PROCCESS_QUEUE = 100

new Handle:g_dbTuple
new Stack:g_queue

public plugin_init()
{
        g_queue = CreateStack()
}

public client_authorized(index, const authid[])
{
        // Database isn't available yet       
        if (g_dbTuple == Empty_Handle)
        {
                // Push this player to the queue
                PushStackCell(g_queue, get_user_userid(index))

                // Start processing the queue
                if (!task_exists(TASK_PROCCESS_QUEUE)) {
                        set_task(1.0, "ProccessQueue", TASK_PROCCESS_QUEUE, .flags="b")
                }
        }
}

public ProccessQueue(task)
{
        // Database isn't available yet
        if (g_dbTuple == Empty_Handle) {
                return
        }

        // Queue is empty
        if (IsStackEmpty(g_queue)) {
                // You can probably stop processing the queue here
                //remove_task(task)
                return
        }

        new userid
        PopStackCell(g_queue, userid)

        new player = find_player_ex(FindPlayer_MatchUserId|FindPlayer_IncludeConnecting, userid)

        // Player has disconnected
        if (player == 0) {
                return
        }

        // Do something here
}

By the way, I assume you're dealing with the player's steamid, if that is the case you should replace client_connect with client_authorized. client_connect is called too soon, the player will likely not have a valid steam id at this point.

wilian159 02-09-2022 20:13

Re: [MySql] what to do
 
Quote:

Originally Posted by CrazY. (Post 2770995)
You should implement some kind of queue and process it once the database is available.
To get you started

Code:

#include <amxmodx>
#include <sqlx>

const TASK_PROCCESS_QUEUE = 100

new Handle:g_dbTuple
new Stack:g_queue

public plugin_init()
{
        g_queue = CreateStack()
}

public client_authorized(index, const authid[])
{
        // Database isn't available yet       
        if (g_dbTuple == Empty_Handle)
        {
                // Push this player to the queue
                PushStackCell(g_queue, get_user_userid(index))

                // Start processing the queue
                if (!task_exists(TASK_PROCCESS_QUEUE)) {
                        set_task(1.0, "ProccessQueue", TASK_PROCCESS_QUEUE, .flags="b")
                }
        }
}

public ProccessQueue(task)
{
        // Database isn't available yet
        if (g_dbTuple == Empty_Handle) {
                return
        }

        // Queue is empty
        if (IsStackEmpty(g_queue)) {
                // You can probably stop processing the queue here
                //remove_task(task)
                return
        }

        new userid
        PopStackCell(g_queue, userid)

        new player = find_player_ex(FindPlayer_MatchUserId|FindPlayer_IncludeConnecting, userid)

        // Player has disconnected
        if (player == 0) {
                return
        }

        // Do something here
}

By the way, I assume you're dealing with the player's steamid, if that is the case you should replace client_connect with client_authorized. client_connect is called too soon, the player will likely not have a valid steam id at this point.

interesting, after it finishes the task is removed

Natsheh 02-09-2022 21:16

Re: [MySql] what to do
 
Always post the code, or at least what you've tried.


All times are GMT -4. The time now is 11:44.

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