SA-MP Forums Archive
Mysql have big bytes - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Mysql have big bytes (/showthread.php?tid=565286)



Mysql have big bytes - arlindi - 26.02.2015

Hello when i add the code to CheckBan Mysql i get this Problem

PHP код:
Pawn compiler 3.2.3664              Copyright (c1997-2006ITB CompuPhase
Header size
:           9988 bytes
Code size
:           490368 bytes
Data size
:          3181236 bytes
Stack
/heap size:      16384 bytesestimated maxusage=4414 cells (17656 bytes)
Total requirements3697976 bytes 
This is the code

PHP код:
stock CheckBan(playerid)
{
       new 
Query[500],playerIP[16],timeBanned[256],largestringtwo[256],adminName[24],bannedName[24],reasonBanned[128];
    
GetPlayerIp(playeridplayerIPsizeof(playerIP));
    
format(Querysizeof(Query), "SELECT * FROM `banlog` WHERE ( `Name` = '%s' OR `pIPBanned` = '%s' ) AND `pAccountLock` = '1' LIMIT 1",PlayerName(playerid),playerIP);
    
mysql_query(Query);
    
mysql_store_result();
    if(
mysql_num_rows() != 0)
    {
        while(
mysql_fetch_row(Query))
        {
                
mysql_fetch_field_row(reasonBanned"pBannedReason");
                
mysql_fetch_field_row(adminName"pBannedBy");
                
mysql_fetch_field_row(timeBanned"pTime");
                
mysql_fetch_field_row(playerIP"pIPBanned");
                
mysql_fetch_field_row(bannedName"Name");
        }
        
format(largestringtwosizeof(largestringtwo), "You are currently banned from this server. \r\nUser: %s \r\nIP: %s  \r\nTime: %s \r\nAdmin: %s\r\nReason: %s"bannedNameplayerIPtimeBannedadminNamereasonBanned);
        
ShowPlayerDialog(playeridDIALOG_BANNEDDIALOG_STYLE_MSGBOX"You are banned from this server"largestringtwo"Leave""");
        
Kick(playerid);
        
printf("Username %s || IP %s is banned!",PlayerName(playerid),playerIP);
    }
    return 
1;

Fast help mee


Re: Mysql have big bytes - FOTIS6 - 26.02.2015

Try to add this on your script

#pragma dynamic 145000

That should work


Re: Mysql have big bytes - arlindi - 26.02.2015

Thank you broo ) You're best scripter
Add mee on skype Armando.Gjoni1


Re: Mysql have big bytes - Vince - 26.02.2015

That is not a solution, that's a workaround.

That select query is only 97 characters long, not accounting for the placeholder. Given that maximum length of a player's name is 24 characters and the maximum length of an ip address is 15 characters, the total maximum length for that query is 97 + 24 + 15 + 1 null terminator = 137 characters. Yet you declare a string 500 characters in size to hold that.

Then you declare another 256 character string to hold "timeBanned" which should realistically only contain something like 16 characters.

Then you declare yet another 256 character to format the message sent to the client, even though the maximum chat output is 144 characters.

In short: decrease your string sizes wherever you can and don't scatter them around carelessly.


Re: Mysql have big bytes - FOTIS6 - 26.02.2015

Vince is also right, I didn't check your script before xD
There is no need for a Query of 500 characters.
Any string you define should be defined as long as it really is or around that.
I mean if you need to hold that timeBanned there is no need for 256 variable length. Use around 16-32 as Vince said. This way you will end up saving Ram usage/cpu cache of the server. (I guess xD)


Re: Mysql have big bytes - arlindi - 26.02.2015

Fixed

But have problem if

I add Query more than 256 ?
What will happend? I have to add more now


Re: Mysql have big bytes - FOTIS6 - 26.02.2015

Nothing will happen, you just waste bytes to nothing there. There is no need. 150-200 for your query would be good.


Re: Mysql have big bytes - arlindi - 26.02.2015

Thank you
You added mee on skype ?