HashString (self made) refuses to work ingame (Unknown command)
#1

Hello.
I have made a 'HashString' function which works in printf ( in main() ). It works there (it outputs an integer).
When I go ingame and register, it refuses to work. It returns a 'SERVER: Unknown command'. Here are some parts of the script (NOTE: The HashString function is not completely shown, to prevent safety failures for later )

HashString function with the functions it needs:
pawn Код:
stock HashString(input[])
{
    new tmpStr[129],
           tmpOutputA,
           tmpOutputB
    ;

    WP_Hash(tmpStr, 129, input); //Thanks to Alex Cole (******) for adding whirlpool to SAMP
    for(new i = 0; i < strlen(tmpStr); i++)
    {
        //CUT
        //CUT    
    }
    tmpOutputA  =   tmpOutputA  %   2237;
    tmpOutputB  =   tmpOutputB  %   2237;
    //CUT
    //CUT

    return ((tmpOutputA << 6) + (tmpOutputB << 6));
}

stock alphabetIndex(const input) //Made by Kwarde, BIG Edit by Ryder` :'). Thanks Ryder` :P
    return ('a' <= input <= 'z') ? (input - 96) : ('A' <= input <= 'Z') ? (input - 64) : 0;

stock isNumeric(input[])
{
    for(new i = 0; i < strlen(input); i++)
    {
        if(input[i] >= 0 && input[i] <= 9 || input[i] == '+' || input[i] == '-') continue;
        else return false;
    }
    return true;
}
So that HashString works in main(), example:
pawn Код:
main()
{
    printf("test = %d", HashString("test"));
    printf("Test = %d", HashString("Test"));
    printf("tEst = %d", HashString("tEst"));
    printf("TEST = %d", HashString("TEST"));
    return 1;
}
It outputs:
Код:
test = 80576
Test = 82560
tEst = 81408
TEST = 81920
And now the /register command + the functions it needs: (It looks a bit like shit with the sscanf, I tried sscanf to try to fix it, without success):
pawn Код:
CMD:register(playerid, params[])
{
    new password[75];
    if(PlayerInfo[playerid][pLogged] || PlayerInfo[playerid][pMustLogin]) return SendClientMessage(playerid, COLOR_ERROR, "ERROR: You cannot register. You are either logged in or this account is registered already.");
    if(sscanf(params, "s[75]", password)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /register [password]");
    if(strlen(password) < 3 || strlen(password) > 75) return SendClientMessage(playerid, COLOR_ERROR, "To prevent safety leaks, your password must be atleast 3 and maximal 75 characters.");
    ResetPlayer(playerid);
    PlayerInfo[playerid][pPassword] = HashString(password);
    UpdateUserFile(playerid);
    SendClientMessage(playerid, COLOR_GREEN, "Congratulations. You have been successfully registered with the password: null");
    PlayerInfo[playerid][pLogged] = true;
    SpawnPlayer(playerid);
    return 1;
}

CB:UpdateUserFile(playerid)
{
    //CUT: It just creates a file if it doesn't exist and save the variables
    return 1;
}

stock ResetPlayer(playerid)
{
    PlayerInfo[playerid][pLogged]       =   false;
    PlayerInfo[playerid][pMustLogin]    =   false;
   
    PlayerInfo[playerid][pPassword]     =   0;
    PlayerInfo[playerid][pTeam]         =   0;
    PlayerInfo[playerid][pRank]         =   0;
    PlayerInfo[playerid][pNewUserStep]  =   0;
    return 1;
}
Is there anyone that knows what to do? Because I'm getting tired of this, and it's annoying :P
Thanks in advance.

Sirencely,
Kevin
Reply
#2

I can not fix the problem but I can help you finding the place of it:

Just put a print("1"); / print("2"); / ... between every line of your function and then try to register. There where the print stops is the mistake. I suppose that you exceed any array size.

Jeffry
Reply
#3

If you are lazy enough, why don't try the crashdetect plugin?
Use print("balbalba"); between functions will also help you debug the script.

Also, you don't need a sscanf for pure strings. Directly use "params" and isnull instead.
Last but not least, I guess the type in
pawn Код:
stock alphabetIndex(const input)
is incorrect. Shouldn't that be something like
pawn Код:
char:input
?

Edit:
Didn't see the above post
Reply
#4

I am very sure it is the HashString: Without it it does work. And it doesn't crash (crashdetect plugin), it just returns a "SERVER: Unknown command", but then only when the password is filled with 3-75 characters and when I'm not yet logged in.
About Alphabet index: It works perfectly so I guess it's not. (( Just tested:
Код:
(177) : error 010: invalid function or declaration
(177) : error 010: invalid function or declaration
(178) : error 010: invalid function or declaration
))
No it's allright. However after dinner I'll check that crashdetect plugin, because I haven't got another solution yet.

Sirencely,
Kevin
Reply
#5

Quote:
Originally Posted by Kwarde
Посмотреть сообщение
it just returns a "SERVER: Unknown command"

No it's allright. However after dinner I'll check that crashdetect plugin, because I haven't got another solution yet.
That happens mostly when you exceed an array size. Try the print thing. I don't think that crashdetect will help.
Reply
#6

Well, thanks for saying that. Whirlpool was first always too long for DJSON so I used this thing (It worked before -.-). Because I thought of this (because of your question) I was just thinking that it was fixed. So ehm, I'll use normal whirlpool again. But, I still wonder why this is happening - It works in another gamemode I made
Reply
#7

I see. About 'Just change DJSON': Do you mean, change to something else then DJSON or edit DJSON?
By the way, I removed that stupid stringHash and now I am using the num_hash from dudb (editted. First it changes the input to Whirlpool. Just for extra safety.)

Sirencely,
Kevin
Reply
#8

Crashdetect plugin can check for runtime errors like "Array exceeds declared size".
If you want to know why it crashes, try to print out something in the hash function.

Also, months ago I was using DJSON with Whirlpool, and all my user data messed up (most of the data are lost). Now I'm using into simple ini/sav systems and it works fine.
I think you should change the file system (sorry DracoBlue).
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)