Raised This Month: $ Target: $400
 0% 

[MySql] what to do


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

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
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 11:44.


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