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

[MySql] what to do


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
wilian159
Member
Join Date: Dec 2013
Old 02-09-2022 , 18:09   [MySql] what to do
Reply With Quote #1

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?
__________________
wilian159 is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 02-09-2022 , 20:00   Re: [MySql] what to do
Reply With Quote #2

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.
__________________









Last edited by CrazY.; 02-09-2022 at 20:04.
CrazY. is offline
wilian159
Member
Join Date: Dec 2013
Old 02-09-2022 , 20:13   Re: [MySql] what to do
Reply With Quote #3

Quote:
Originally Posted by CrazY. View Post
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
__________________
wilian159 is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 02-09-2022 , 21:16   Re: [MySql] what to do
Reply With Quote #4

Always post the code, or at least what you've tried.
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !

Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
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 01:49.


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