enum and string, limit?
#1

Does anybody know if 'enums' has got a limit on how large strings that can be stored?

Here's what I did,
pawn Код:
enum playerdata
{
    pPassword[129],
.....
// the rest
}
new pData[MAX_PLAYERS][playerdata];
As you might understand it's a Whirlpool hash string.
I made a debug print, and when i try to store this hash in that string, the string remains empty.

Код:
[17:28:34] Load password:           <- this is pData[playerid][pPassword]
[17:28:36] Input: tsakfasf
[17:28:36] Encr. input: 152AFCC2920528978F9140C1968DDE6708D6F82AFC344FDDF171DD5B3188CC4F2758094B1B2415D8F9720B93351620B63BFD9B4CC97DAE2B6A8E211F132F1A30
[17:28:36] Length: 128 (of encrypted input)
Wrong password ofcourse, but the problem remains and !strcmp returns 1, which lets the player in.....

When i instead of using that string create another one, like

pawn Код:
new password[129];
It works like a charm and the string gets stored and i can compare the stored hash with the encrypted password input hash...
Reply
#2

SA-MP limites
Reply
#3

I don't get the issue, if you're using whirlpool the string should be 129 long though it can be more(though it'll never exceed 128, the extra one is needed for the null terminator).
Reply
#4

The problem is not the storage, you can make an array however big you like, but mind that memory capacity will be a problem, so don't overdo it!

The problem is how you store the text that a player inputs to a variable. You should first check that that text is not NULL, i.e. empty (we use "isnull" for that, from the zcmd include). This is what might cause your "strcmp" check to fail.

Also, use the right technique to copy a string and don't use the old ones like "format", "strmid", or whatever other BS (we use strcpy for that).
Reply
#5

The issue is that it remains empty If i use it exactly the same way as every other string I store. :P
I know why It's sized 129, that's why it is.

This works:
pawn Код:
new pass[129],str[128],userpass[129];
    encrypt(pass,sizeof(pass),password);
        // retrieve stored password
    if(!strcmp(pass,userpass) && !isnull(password)) // I tried to change to strlen as part of debug
    {
This doesn't....

pawn Код:
new pass[129],str[128];
    encrypt(pass,sizeof(pass),password);
        // retrieve stored password
    if(!strcmp(pass,pData[playerid][pPassword]) && !isnull(password))
    {
Because string "pData[playerid][pPassword]" is empty, and string "userpass" isn't, when I retrieve the password exactly the same way.
Reply
#6

Then make sure "pData[playerid][pPassword]" is never empty! If it is, that might indicate the user isn't registered, if that's the case, make him register an account, save the password, load it when needed, and voilа - "pData[playerid][pPassword]" is not empty!
Also, you must put the "isnull" check before your "strcmp" check, preferably there where the user first inputs his password (for me that's under OnDialogResponse).
Reply
#7

I guess your problem also has to do with not working sizeof for 2d arrays. For example:
pawn Код:
sizeof(pData[playerid][pPassword]) == 1
//so
strcpy(pData[playerid][pPassword], "Hello world!"); // { '\0' }
//But
strcpy(pData[playerid][pPassword], "Hello world!", 6); // { 'H', 'e', 'l', 'l', 'o', '\0' }
This will cause problems with all functions relying on sizeof. Long time ago I used define to avoid that:
pawn Код:
#define MAX_PASS_LENGTH (129)

enum playerdata
{
    pPassword[MAX_PASS_LENGTH],
.....
// the rest
}
strcpy(pData[playerid][pPassword], "Hello world!", MAX_PASS_LENGTH);
Or you can use Zeex's compiler which fixes that.
Reply
#8

Quote:
Originally Posted by Virtual1ty
Посмотреть сообщение
Then make sure "pData[playerid][pPassword]" is never empty! If it is, that might indicate the user isn't registered, if that's the case, make him register an account, save the password, load it when needed, and voilа - "pData[playerid][pPassword]" is not empty!
Also, you must put the "isnull" check before your "strcmp" check, preferably there where the user first inputs his password (for me that's under OnDialogResponse).
That's what I'm trying to do, and It doesn't work as described above.
I'm perfectly smart enough to create a user system, and !isnull works fine like I've written it, since It does check
if the password match AND isn't empty, if one of the conditions fail it will fail.

But if the string is empty it will just let the player spawn WHEN i use 'pData[playerid][pPassword]', but it doesn't do that when i create a string right in OnDialogResponse and retrieve the password right there instead.

Now, It's not very important for me to store the password with the playerdata using enum, I just thought it might be a little easier that way, but It doesn't really matter... I just wonder why it does this :P

Also, the reason I'm asking why it doesn't work with the Whirlpool hash is because it works fine with the rest of my arrays;

Example:
pawn Код:
enum playerdata
{
    pFile[42],
    pBanreason[64],
    pBandate[48],
Reply
#9

Without any code we can't tell, and I'm pretty sure it's your programming logic and nothing else.
I did it the same way as I described above and no problems since!

But hey, if it works okay, then don't bother updating it. Just ignore the underlying problem.
Reply
#10

Quote:
Originally Posted by Virtual1ty
Посмотреть сообщение
Without any code we can't tell, and I'm pretty sure it's your programming logic and nothing else.
I did it the same way as I described above and no problems since!

But hey, if it works okay, then don't bother updating it. Just ignore the underlying problem.
I've written 10's of thousands of lines of working code between 2010-2012 and I just started again, back then I never had this problem. It seems like, an array smaller than a Whirlpool string works fine, thus my question about eventual limits...
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)