Dialog Response
#1

removed
Reply
#2

Are you using sscanf in your script?
If you are, use this:
Код:
new weaponid;
if (sscanf(inputtext, "i", weaponid)) return // Inputtext is not a number
And then use weaponid instead of strval(inputtext).

Also, you shouldn't use functions that much in an if statement. Use switch instead:
Код:
switch (weaponid)
{
    case 0..5: // If weaponid = 0 or 1 or 2 to 5
    {

    }
}
If you aren't using sscanf, search for a function called "IsNumeric" to check if it's an actual number.
Reply
#3

Wouldn't doing new weaponid = strval(inputtext); just work fine? I've been doing this directly and have no issues. Though, sscanf could be a better choice.
Reply
#4

Quote:
Originally Posted by Sjn
Посмотреть сообщение
Wouldn't doing new weaponid = strval(inputtext); just work fine? I've been doing this directly and have no issues. Though, sscanf could be a better choice.
strval will return 0 if the text doesn't contain only numbers. Checking if the index 0 and 1 are equal to '0' and '\0' respectively is not something people would do and sscanf is really much easier to use.
Reply
#5

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
strval will return 0 if the text doesn't contain only numbers. Checking if the index 0 and 1 are equal to '0' and '\0' respectively is not something people would do and sscanf is really much easier to use.
Oh, never knew this. Something new I got to know today, might as well change mine also.
Reply
#6

strval is also unsecure if you use it on user-input without further checks.
If the input contains a very large number or is too long (no matter what it contains) it will or might crash the server, so at least check for the length first.

Or just use sscanf as already suggested.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)