28.06.2009, 17:19
(
Последний раз редактировалось BlueG; 17.07.2010 в 14:50.
)
Quote:
Originally Posted by G-sTyLeZzZ
Код:
Update as of 06/28/09: - It's important that you recompile your script with the newest include file before using the plugin - Fixed various reported bugs such as mysql_debug - Improved almost all functions to decrease CPU usage - Added a alternative second parameter to 'mysql_query()' in combination with a new callback named 'OnQueryFinish()' to check whether a query is finished or not (suggested,tested and used by krisk) - Added 'mysql_insert_id()' (suggested by Gehaktbal) |
Here's an example of usage:
OBS: This explanation, and really the whole threaded feature, is for advanced users and users who understands pawn well, this is not a dummy guide, more a technical note with code snippets to show what I mean.
I have a global variable named "G_THREAD_LOGON_ID" to store the ID of the player awaiting result from OnQueryFinish, this is set here: (And ofcourse reset on player disconnect/connect.)
I also have a constant (define) named "D_THREAD_USERLOGON", that's just to make the code easier to understand, instead of just having the number "1" there or whatever you choose to identify which query you're using in the thread.
(Note: This script have been running on LS:RP for awhile and I've never yet seen the "Thread is busy by %i", it's just a precaution.)
(The snippet below is obviously a part of the /login command.)
pawn Код:
if(G_THREAD_LOGON_ID == -1)
{
G_THREAD_LOGON_ID = playerid;
mysql_query(query, D_THREAD_USERLOGON);
return 1;
}
else
{
new szRes[64];
format(szRes, sizeof(szRes), "Thread is busy by %i", G_THREAD_LOGON_ID);
return SendClientMessage(playerid, COLOR_YELLOW, szRes);
}
pawn Код:
public OnQueryFinish(query[], resultid, extraid, connectionHandle)
{
printf("Query with result id %d has finished! (Connection ID %d | Query: %s)",resultid,connectionHandle,query);
switch(resultid)
{
case D_THREAD_USERLOGON:
{
USERSYS_Receive_Thread(query);
}
default:
{
}
}
return 1;
}
And to understand the logic, in USERSYS_Receive_Thread(query), imagine that's just after you've done the mysql_query() call, so just go ahead and mysql_store_result() and validate it further for your own needs, based on your system.
OBS: This explanation, and really the whole threaded feature, is for advanced users and users who understands pawn well, this is not a dummy guide, more a technical note with code snippets to show what I mean.