SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Plugin Development

Reply
 
Thread Tools Display Modes
Old 24/06/2009, 06:42 AM   #101
CyberGuerilla
Little Clucker
 
Join Date: Jan 2009
Posts: 31
Reputation: 0
Default Re: [REL] Alternative MySQL Plugin v1.0.2.2 (+example PAWN/PHP script)

Quote:
Originally Posted by Sneaky.
Thank you very much Sneaky
CyberGuerilla is offline   Reply With Quote
Old 24/06/2009, 01:23 PM   #102
Chaprnks
Gangsta
 
Chaprnks's Avatar
 
Join Date: Sep 2007
Location: Soviet America
Posts: 571
Reputation: 69
Default Re: [REL] Alternative MySQL Plugin v1.0.2.2 (+example PAWN/PHP script)

Quote:
Originally Posted by krisk
And the inbuilt debug makes it so much easier to run betas/tests.
Could you get the debug to show your "mysql_fetch_row" correctly? Most of mine ended up saying something like this.
pawn Code:
[08:19:39] mysql_fetch_row(



// and so on
__________________
Chaprnks is offline   Reply With Quote
Old 25/06/2009, 12:40 PM   #103
CyberGuerilla
Little Clucker
 
Join Date: Jan 2009
Posts: 31
Reputation: 0
Default Re: [REL] Alternative MySQL Plugin v1.0.2.2 (+example PAWN/PHP script)

[Removed]
CyberGuerilla is offline   Reply With Quote
Old 25/06/2009, 08:51 PM   #104
BlueG
Beta Tester
 
BlueG's Avatar
 
Join Date: Sep 2007
Location: Los Angeles, CA
Posts: 58
Reputation: 305
Default Re: [REL] Alternative MySQL Plugin v1.0.2.2 (+example PAWN/PHP script)

Quote:
Originally Posted by ǝɹoɯ‾ʎ
Quote:
Originally Posted by krisk
And the inbuilt debug makes it so much easier to run betas/tests.
Could you get the debug to show your "mysql_fetch_row" correctly? Most of mine ended up saying something like this.
pawn Code:
[08:19:39] mysql_fetch_row(



// and so on
Well, I'm currently working on a new final version which works faster and decreases your CPU usage at the same time. It's currently running on LS-RP and appearantly works fine.

I still need to run some tests till it's completely ready. Also some people reported that the debug function sometimes crashes the server and gives you some weird characters like you posted, but this bug is now finally fixed. Almost all functions are completely re-written and should avoid server-crash's. I should also mention that there aren't any (cell) limits for mysql_fetch_row/_format in the coming version. I've included a new callback and a new function, which were suggested by krisk and Gehaktbal.

I hope I'm able to release the new plugin as soon as possible.
BlueG is offline   Reply With Quote
Old 26/06/2009, 02:08 AM   #105
Damian
Beta Tester
 
Join Date: Jan 2006
Posts: 112
Reputation: 169
Default Re: [REL] Alternative MySQL Plugin v1.0.2.2 (+example PAWN/PHP script)

Quote:
I've also noticed an overall performance increase/less CPU usage, and things works as supposed to here, no need to do lame walk-arounds to free memory and stuff like that, generally easy to understand, even Damian wanted to try out on SQL when we switched
Yep that's right, so easy even I get it.
Damian is offline   Reply With Quote
Old 26/06/2009, 10:48 AM   #106
CyberGuerilla
Little Clucker
 
Join Date: Jan 2009
Posts: 31
Reputation: 0
Default Re: [REL] Alternative MySQL Plugin v1.0.2.2 (+example PAWN/PHP script)

All GF Edits: For switch your GM's old Mysql plugin to this plugin, watch.

I working about this, for 4 days. I solved this problem.

Step 1: Find samp_mysql_ in your script. Change this to mysql_
Step 2: Change a_sampmysql to a_mysql
Step 3: Add G_Stylezz plugin to your plugins folder.
Step 4: Edit your server.cfg (add: plugins mysql)
Step 5: Find OnPlayerLogin in your script.
Step 6: Find MySQLCheckConnection change to MYSQLBaglantiKontrol

Change function to:

Code:
public OnPlayerLogin(playerid,password[])
{
	MYSQLBaglantiKontrol();
	new tmp2[256];
  new string2[64];
	new Isim[MAX_PLAYER_NAME];
  GetPlayerName(playerid, Isim, sizeof(Isim));
  new query[MAX_STRING];
  new query2[MAX_STRING];
  
	format(query,sizeof(query),"SELECT * FROM `oyuncular` WHERE Name = '%s' AND Password = '%s'",Isim,password);
	mysql_query(query);
	mysql_store_result();
	if(mysql_num_rows() == 1)
	{
   mysql_free_result();
   MYSQLOyuncuGiris(playerid, PlayerInfo[playerid][pSQLID]);
	}
	else
	{
    mysql_free_result();
		SendClientMessage(playerid, COLOR_WHITE, "SUNUCU: Sifrenizi yanlis girdiniz.");
		gPlayerLogTries[playerid] += 1;
		if(gPlayerLogTries[playerid] == 4) { Ban(playerid); }
		return 1;
	}
		PlayerInfo[playerid][pAdjustable] = 0;
		NormalParaSil(playerid);
		ConsumingMoney[playerid] = 1;
		NormalParaVer(playerid,PlayerInfo[playerid][pCash]);
		CurrentMoney[playerid] = PlayerInfo[playerid][pCash];
		if(PlayerInfo[playerid][pReg] == 0)
		{
  	new tckimlik = 10000000000 + random(24000000000);
	  format(query2, sizeof(query2), "SELECT * FROM oyuncular WHERE LOWER(TC) = LOWER('%s')", tckimlik);
	  mysql_query(query2);
  	mysql_store_result();
	  if(mysql_num_rows() == 0)
	  {
  	PlayerInfo[playerid][pTC] = tckimlik;
  	PlayerInfo[playerid][pReg] = 1;
  	}
  	mysql_free_result();
		}
		if(PlayerInfo[playerid][pHesapKilit] == 1)
		{
			Ban(playerid);
		}
   	if (PlayerInfo[playerid][pHikayeKabul] == 0)
  	{
	  	SendClientMessage(playerid, COLOR_LIGHTRED, "..:BILGI: Hikayeniz henuz kontrol edilmemis.");
	  	SendClientMessage(playerid, COLOR_LIGHTRED, "..:BILGI: Hikayeniz kontrol edilince size E-Posta ile bildirilecektir.");
	  	Kick(playerid);
  	}
		if(PlayerInfo[playerid][pKO] == 1)
		{
 		  format(string2, sizeof(string2), "..:BILGI: Hayatinizi kaybettiniz. Yeni bir hesap aliniz.");
			SendClientMessage(playerid, COLOR_WHITE, string2);
		  Kick(playerid);
		}
		if(PlayerInfo[playerid][pVaaz] > 0)
		{
      SendClientMessage(playerid, COLOR_WHITE,"..:BILGI: Vaaziniz sonra erdi.");
		  VaazBitir(playerid);
		  PlayerInfo[playerid][pVaaz] = 0;
		}
		if (PlayerInfo[playerid][pDonateRank] > 0)
		{
			SendClientMessage(playerid, COLOR_WHITE,"..:BILGI: Siz ust seviye bir kullanicisiniz.");
		}
 		new isim[MAX_PLAYER_NAME], soyisim[MAX_PLAYER_NAME];
 	  RPName(PlayerName(playerid),isim,soyisim)
		format(string2, sizeof(string2), "..:BILGI: Sayin %s, hosgeldiniz.",soyisim);
		SendClientMessage(playerid, COLOR_WHITE,string2);
		printf("%s giris yapti.",Isim);
 		new nxtlevel = PlayerInfo[playerid][pLevel]+1;
		new expamount = nxtlevel*levelexp;
		PlayerInfo[playerid][pSeviyeTavan] = expamount;
		SetSpawnInfo(playerid, 0, PlayerInfo[playerid][pModel], PlayerInfo[playerid][pPos_x], PlayerInfo[playerid][pPos_y], PlayerInfo[playerid][pPos_z], 1.0, -1, -1, -1, -1, -1, -1);
		gPlayerLogged[playerid] = 1;
		SpawnPlayer(playerid);
		format(tmp2, sizeof(tmp2), "~w~Hosgeldiniz ~n~~y~  %s", Isim);
		DateProp(playerid);
		GameTextForPlayer(playerid, tmp2, 5000, 1);
		SendClientMessage(playerid, COLOR_YELLOW, motd);
 		for(new i = 0; i < MAX_PLAYERS; i++)
		{
	  	if(IsPlayerConnected(i))
	  	{
	    	if(PlayerInfo[i][pMaskeKullanim] == 1)
	    	{
	      	ShowPlayerNameTagForPlayer(playerid, i, 0);
	    	}
	  	}
		}
		PlayerInfo[playerid][pMuted] = 0;
		OnPlayerUpdate(playerid);
	return 1;
}
NOT: Adapt this new function to your script

Add:

http://cyberguerilla.pastebin.com/f7f0a01da

NOT: Adapt this new function to your script too!

Sorry for my English
CyberGuerilla is offline   Reply With Quote
Old 26/06/2009, 04:31 PM   #107
CyberGuerilla
Little Clucker
 
Join Date: Jan 2009
Posts: 31
Reputation: 0
Default Re: [REL] Alternative MySQL Plugin v1.0.2.2 (+example PAWN/PHP script)

Sorry for double posting, but It's not enough

We must change OnPlayerUpdate function for fix memory allocation problem.

Change old function to:

http://cyberguerilla.pastebin.com/f62f2f968

NOT: Adapt this new function to your script too!
CyberGuerilla is offline   Reply With Quote
Old 28/06/2009, 05:19 PM   #108
krisk
Big Clucker
 
krisk's Avatar
 
Join Date: Jun 2007
Posts: 53
Reputation: 15
Default Re: [REL] MySQL Plugin (06/28/09)

Quote:
Originally Posted by G-sTyLeZzZ
Code:
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)
The alternative second parameter, making the queries return it's whatever result in OnQueryFinish() makes this a threaded mysql plugin. Then, if your DB is lagging, a big query, lots of shit being returned etc. you don't have to freeze the main thread so everybody lags, you simply just execute the query in a separate thread and call pawn with the result when it's done, this decreased any lag issue on LS:RP a lot, considering we have lots of shit running on SQL and relying on SQL, when I moved over lots to use another thread than the main thread instead, the lag was gone.

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 Code:
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);
}

This is the OnQueryFinish() callback, that's the thing receiving the data/result from the plugin thread when it's been processed by SQL.
pawn Code:
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;
}

After this I can within the function USERSYS_Receive_Thread(query) process the logon as usual, as I'd have done with any script, just that the "playerid" is in the G_THREAD_LOGON_ID variable, easy as that!

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.

Last edited by BlueG; 17/07/2010 at 02:50 PM.
krisk is offline   Reply With Quote
Old 29/06/2009, 04:02 AM   #109
ledzep
Huge Clucker
 
Join Date: Nov 2007
Posts: 287
Reputation: 2
Default Re: [REL] MySQL Plugin (06/28/09)

Epic update.

I'm sure most scripters will be switching to this plugin now.
Well, the smarter ones :P

Edit:

Does it matter what OnQueryFinish(...) returns?
ledzep is offline   Reply With Quote
Old 29/06/2009, 04:54 AM   #110
Misiek
Big Clucker
 
Join Date: May 2006
Posts: 111
Reputation: 16
Default Re: [REL] MySQL Plugin (06/28/09)

Okay, I've got a serious problem in here.
I'm successfully running this plugin on my PC for few months now and it works (and always did) great.
However, when i try to install it on the main server - Windows Server `08 - it simply doesn't want to load and i have to use the other one.

I was trying to fix the problem, but I'm giving up.
I have two versions of libmysql.dll. One is exactly 2 174 976 bytes big (from this topic), and the second one - 2 617 344 bytes.
  • For sampmysql.dll, I use the second, bigger one, because your version causes sampmysql.dll to crash when a query is executed.
  • For mysq.dll, I tried both of them, and after noticing, that nothing works - even simply deleting libmysql.dll. Still nothing. All I get is:
Code:
[06:24:06] Server Plugins
[06:24:06] --------------
[06:24:06] Loading plugin: mysql
[06:24:06]  Failed.
[06:24:06] Loaded 0 plugins.
I really need your plugin, I'm just in front of making a huge usage of MySQL and I'd need to reduce resource usage done by MySQL, also by using the callback functionality.

I'll be glad and thankful if anyone helps me, thanks.
__________________
Ex-SA-MP beta tester 😉
net4game.com
Misiek is offline   Reply With Quote
Reply

Thread Tools
Display Modes

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
****** Project: Glass int3s0 Everything and Nothing 99 26/02/2013 04:22 PM
MySQL Plugin R5 plugin problem dud Scripting Help 12 05/12/2011 06:28 PM
Strikens Mysql vs BlueG's Mysql plugin PrawkC Scripting Help 4 30/09/2011 10:30 AM
[help][plugin] Can't load mysql plugin mariomako Help Archive 8 16/07/2011 02:37 PM
mysql plugin. loading plugin failed ikkentim Help Archive 2 10/02/2011 02:32 PM


All times are GMT. The time now is 09:26 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.