Little help
#1

Hello, im making an autologin based on last ip. This is how i scripted it:

pawn Код:
function OnPlayerDataLoaded(playerid, race_check)
{
    if (race_check != g_MysqlRaceCheck[playerid]) return Kick(playerid);

    new string[115];
     
    if (!strcmp(Player[playerid][LastIP], ReturnPlayerIp(playerid), true))
    {
    cache_set_active(Player[playerid][Cache_ID]);
    AssignPlayerData(playerid);
    cache_delete(Player[playerid][Cache_ID]);
    Player[playerid][Cache_ID] = MYSQL_INVALID_CACHE;
    KillTimer(Player[playerid][LoginTimer]);
    Player[playerid][LoginTimer] = 0;
    Player[playerid][IsLoggedIn] = true;
    }
    else
    {
    if(cache_num_rows() > 0)
    {
    cache_get_value(0, "password", Player[playerid][Password], 65);
    cache_get_value(0, "salt", Player[playerid][Salt], 17);
    Player[playerid][Cache_ID] = cache_save();
    format(string, sizeof string, "This account (%s) is registered. Please login by entering your password in the field below:", Player[playerid][Name]);
    ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Login", string, "Login", "Abort");
    Player[playerid][LoginTimer] = SetTimerEx("OnLoginTimeout", SECONDS_TO_LOGIN * 1000, false, "d", playerid);
    }
    }
    else
    {
    format(string, sizeof string, "Welcome %s, you can register by entering your password in the field below:", Player[playerid][Name]);
    ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "Registration", string, "Register", "Abort");
    }
    return 1;
}
But i'm getting this error:

Quote:

error 029: invalid expression, assumed zero

The error is referred to the last "else".

What's wrong? :/
Reply
#2

You can't have double else statement.
This example is wrong and will result an error like yours.
PHP код:
if(expression)
{
}
else
{
}
else
{

If you have multiple expressions, use else if.
PHP код:
if(expression)
{
}
else if(
expression2)
{
}
else
{

If you have multiple result with the same type (integer only), use switch - case ; this is for condition which check a result.

PHP код:
switch(number)
{
    case 
0: ...
    case 
1: ...

Nested statements can be made:
PHP код:
if(expression)
{
    if(
expression2)
    {
        if(
expression3)
        {
        }
        else
        {
        }
    }
    else if(
expression87)
    {
    }
    else
    {
    
    }
}
else
{

Reply
#3

Ok i fixed in this way but...

pawn Код:
function OnPlayerDataLoaded(playerid, race_check)
{
    if (race_check != g_MysqlRaceCheck[playerid]) return Kick(playerid);

    new string[115];
     
    if (!strcmp(Player[playerid][LastIP], ReturnPlayerIp(playerid), true))
    {
    cache_set_active(Player[playerid][Cache_ID]);
    AssignPlayerData(playerid);
    cache_delete(Player[playerid][Cache_ID]);
    Player[playerid][Cache_ID] = MYSQL_INVALID_CACHE;
    KillTimer(Player[playerid][LoginTimer]);
    Player[playerid][LoginTimer] = 0;
    Player[playerid][IsLoggedIn] = true;
    }
    else if(cache_num_rows() > 0)
    {
    cache_get_value(0, "password", Player[playerid][Password], 65);
    cache_get_value(0, "salt", Player[playerid][Salt], 17);
    Player[playerid][Cache_ID] = cache_save();
    format(string, sizeof string, "This account (%s) is registered. Please login by entering your password in the field below:", Player[playerid][Name]);
    ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Login", string, "Login", "Abort");
    Player[playerid][LoginTimer] = SetTimerEx("OnLoginTimeout", SECONDS_TO_LOGIN * 1000, false, "d", playerid);
    }
    else
    {
    format(string, sizeof string, "Welcome %s, you can register by entering your password in the field below:", Player[playerid][Name]);
    ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "Registration", string, "Register", "Abort");
    }
    return 1;
}
Now i can login even if the account doesn't exist. What's wrong?

For reference, this is the login dialog where if user types the correct password, he logins:

pawn Код:
case DIALOG_LOGIN:
        {
            if (!response) return Kick(playerid);

            new hashed_pass[65];
            SHA256_PassHash(inputtext, Player[playerid][Salt], hashed_pass, 65);

            if (strcmp(hashed_pass, Player[playerid][Password]) == 0)
            {
               
                cache_set_active(Player[playerid][Cache_ID]);

                AssignPlayerData(playerid);

                cache_delete(Player[playerid][Cache_ID]);
                Player[playerid][Cache_ID] = MYSQL_INVALID_CACHE;

                KillTimer(Player[playerid][LoginTimer]);
                Player[playerid][LoginTimer] = 0;
                Player[playerid][IsLoggedIn] = true;
            }
Reply
#4

Why are you even making an auto-login based on ips? Most users have dynamic ips instead of static that change everytime someone restarts their router.
Reply
#5

Quote:
Originally Posted by Exhibit
Посмотреть сообщение
Why are you even making an auto-login based on ips?
Why not?

Quote:
Originally Posted by Exhibit
Посмотреть сообщение
Most users have dynamic ips instead of static that change everytime someone restarts their router.
That's not my problem. Im making a mini missions server and it's stupid to login everytime a game changes. I don't think an user will restart their router while a minigame is changing.
Reply
#6

Bump.
Reply
#7

Bump.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)