sscanf string length - 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: sscanf string length (
/showthread.php?tid=633700)
sscanf string length -
Bwandon - 06.05.2017
I have this command, when I remove the overflow it works perfectly although can go over string limit of 'MAX_PLAYER_NAME' - 24.
This crashes the server, so i'm just starting to add these overflow things in to all my commands although this particular command just keep showing the scp...
PHP код:
forward OnAccountUnsuspended(adminID);
public OnAccountUnsuspended(adminID) {
new rows;
cache_get_row_count(rows);
if(rows) {
} else return SendError(playerid, "Couldn't find the selected account.");
return 1;
}
COMMAND:unsuspend(playerid, params[]) {
if(!PlayerInfo[playerid][aAdmin] && !PlayerInfo[playerid][aHelper]) return SendError(playerid, CANT_USE_CMD);
new iPlayer[MAX_PLAYER_NAME];
if(sscanf(params, "s[" #MAX_PLAYER_NAME "]", iPlayer)) return SCP(playerid, "< Full_Name >");
if(!IsPlayerConnected(GetPlayerId(iPlayer))) {
new iQuery[159]; mysql_format(Pipeline, iQuery, sizeof(iQuery), "SELECT `ID`, `AccountID`, `CharName` FROM `pInfo` WHERE `CharName` = '%e' LIMIT 1", iPlayer);
mysql_tquery(Pipeline, iQuery, "OnAccountUnsuspended", "d", playerid);
} else return SendError(playerid, CANT_FIND_PLAYER);
return 1;
}
Also am I using an outdated sscanf?
my version:
https://pastebin.com/jew8sFh2
Re: sscanf string length -
Toroi - 06.05.2017
Why don't you just use 24 instead of this disaster
Код:
"s[" #MAX_PLAYER_NAME "]"
Re: sscanf string length -
Gammix - 06.05.2017
PHP код:
"s[" #MAX_PLAYER_NAME "]"
is fine as long as MAX_PLAYER_NAME don't have any brackets involved like:
PHP код:
#define MAX_PLAYER_NAME (24)
Re: sscanf string length -
Vince - 06.05.2017
You don't need to use sscanf if the only input is a string. Simply use strlen to check if the length is between 1 - 24. You can also check for forbidden characters, although I assume that one trusts his own hired admins.
Also don't call your variables "iQuery" and "iPlayer" when they in fact contain text. Unless the "i" actually stands for input or index. But I reckon most people (like me) will read the "i" as "integer" which is confusing as hell in situations like this.