Restrict RCON by IP
#5

Quote:
Originally Posted by Matnix
Посмотреть сообщение
I don't really understand, is that you want to mean?
pawn Код:
public OnRconLoginAttempt(ip[], password[], success)
{
    new playerIP[16];
    if(IsPlayerConnected(i))
    {
        GetPlayerIp(i, rIP,sizeof(rIP)); // get is ip
        if(!strcmp(rIP, 127.0.0.1, true)) // if is ip is 127.0.0.1
        {
            if(success) // if the pass is correct
            {
                // blablablabla
                return 1;
            }
            else // if the pass is not correct
            {
                // blablabla
                return 1;
            }
            return 1;
        }
        else // is ip is not 127.0.0.1
        {
            // blablablabla
            return 1;
        }
        return 1;
    }
    return 1;
}//matnix
Correct me if I'm wrong
GG you've used 6 useless returns


@Edit Let me just sum it up quick for you then..

pawn Код:
CMD:somecommand(playerid, arg[])
{
    if(IsPlayerAdmin(playerid))
    {
        // We don't need return here it will go to end of function scope and return anyways
    }
    else
    {
        // We don't need return here it will go to end of function scope and return anyways
    }
    return 1;
}
Basically what I'm getting at is you don't need returns when your code is going to return on the next line anyways.

Sometimes you might want to return however such as in a dynamic system

pawn Код:
stock AddSomething(Float:x, Float:y, Float:z)
{
    for(new i = 0; i < MAX_SOMETHING; i++)
    {
        if(Something[i] == -1)
        {
            Something[i] = CreateObject(.... x, y, z);
            // Return array index
            return i;    
        }
    }
    // Return invalid index failure
    return -1;
}
You need to try and avoid using return whenever possible only use it when it makes sense a lot of people don't do that and litter their code with return's that don't need to be there. This can make debugging more difficult because you might not know which line your code returns at and also introduces multiple exit points. Now that is not always bad you just need to choose when and where you do it with purpose
Reply


Messages In This Thread
Restrict RCON by IP - by lesim2005 - 29.10.2013, 22:33
Re: Restrict RCON by IP - by iJumbo - 29.10.2013, 22:49
Re : Restrict RCON by IP - by Matnix - 29.10.2013, 22:56
Re: Restrict RCON by IP - by Vince - 29.10.2013, 23:15
Re: Re : Restrict RCON by IP - by Pottus - 29.10.2013, 23:18
Re : Restrict RCON by IP - by Matnix - 29.10.2013, 23:19
Re: Restrict RCON by IP - by lesim2005 - 31.10.2013, 19:34
Re: Restrict RCON by IP - by lesim2005 - 03.11.2013, 09:22
Re: Restrict RCON by IP - by Hamam - 03.11.2013, 09:29

Forum Jump:


Users browsing this thread: 2 Guest(s)