Login registration (spawn when Logged == 0)
#1

Hello,

I have encountered a bug, which I then decided to fix. If a player were at login screen and typed wrong password, the "< > Spawn" would appear at the bottom of his screen, and if he clicked spawn, he would bypass the login system, and log in to the account even if it isn't his account.

I then tried to fix that problem, tested it on my lan server, and it worked just perfect. Then I tried to upload the changes to my online server and it just doesn't work. Here's my code, hope someone can point out the problem, even though it's weird since it works on LAN, but not on my online host...

pawn Код:
new Logged[MAX_PLAYERS];

stock resetVars(playerid)
{
        PlayerInfo[playerid][Adminlevel] = 0;
        PlayerInfo[playerid][Banned] = 0;
        PlayerInfo[playerid][MaskOn] = 0;
        PlayerInfo[playerid][Kills] = 0;
        PlayerInfo[playerid][Cash] = 0;
        PlayerInfo[playerid][Deaths] = 0;
        PlayerInfo[playerid][Donator] = 0;
        PlayerInfo[playerid][Score] = 0;
        PlayerInfo[playerid][Muted] = 0;
        PlayerInfo[playerid][MuteTime] = 0;
        PlayerInfo[playerid][Reason] = 0;
        PlayerInfo[playerid][BannedBy] = 0;
        CalledPackage[playerid] = 0;
        TogPM[ playerid ] = 0;
        AdminDuty[ playerid ] = 0;
        Logged[playerid] = 0;
        return 1;
}

public OnPlayerConnect(playerid)
{
resetVars(playerid);
SetPlayerMapIcon( playerid, 1, 1367.0291, -1279.7354, 13.5469, 18, -1, MAPICON_GLOBAL ); // LS AMMU
SetPlayerMapIcon(playerid, 2, 2648.8464, -2386.3140, 13.6328, 43, -1, MAPICON_LOCAL);
SetPlayerMapIcon(playerid, 3, 2025.4236, -1403.0571, 17.2115, 43, -1, MAPICON_LOCAL);
SetPlayerMapIcon(playerid, 4, 1568.7642, -1691.4093, 5.8906, 43, -1, MAPICON_LOCAL);
SetPlayerMapIcon(playerid, 5, 743.2963, -1355.5403, 13.5000, 43, -1, MAPICON_LOCAL);
SetPlayerMapIcon(playerid, 6, 2158.1477, -2278.9236, 13.3442, 43, -1, MAPICON_LOCAL);
SetPlayerMapIcon(playerid, 7, 952.3995, -909.5219, 45.7656, 43, -1, MAPICON_LOCAL);
SetPlayerMapIcon(playerid, 8, 2495.2341, -1687.3982, 13.5153, 43, -1, MAPICON_LOCAL);
Logged[playerid] = 0;
    if(fexist(UserPath(playerid)))
    {
        INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
        ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,":: Login", "ZTDM(v1.0) \nPlease enter your password below to start the game!", "Login", "Exit");
    }
    else
    {
        ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT,":: Register" , "ZTDM(v1.0) \nYou are not registered, \nPlease enter a password below to register your account!", "Register", "Exit");
    }


public OnPlayerDisconnect(playerid, reason)
{
    if(Logged[playerid] == 1) {
    new INI:File = INI_Open(UserPath(playerid));
    INI_SetTag(File,"data");
    INI_WriteInt(File,"Cash",GetPlayerMoney(playerid));
    INI_WriteInt(File,"Kills",PlayerInfo[playerid][Kills]);
    INI_WriteInt(File,"Deaths",PlayerInfo[playerid][Deaths]);
    INI_WriteInt(File,"Adminlevel",PlayerInfo[playerid][Adminlevel]);
    INI_WriteInt(File,"Donator",PlayerInfo[playerid][Donator]);
    INI_WriteInt(File,"Score",GetPlayerScore(playerid));
    INI_WriteInt(File,"Banned",PlayerInfo[playerid][Banned]);
    INI_WriteInt(File,"MaskOn",PlayerInfo[playerid][MaskOn]);
    INI_WriteInt(File,"Muted",PlayerInfo[playerid][Muted]);
    INI_WriteInt(File,"MuteTime",PlayerInfo[playerid][MuteTime]);
    INI_Close(File);
                                }
    resetVars(playerid);
    return 1;
}

public OnPlayerRequestClass(playerid, classid)
{
if(Logged[playerid] == 0) return SendClientMessage(playerid, COLOR_YELLOW, "You're not logged in");
        SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
        SetPlayerCameraPos(playerid, 1963.0435, 1342.9009, 16.6642);
        SetPlayerCameraLookAt(playerid, 1962.0388, 1342.8906, 16.5992);
        TogglePlayerControllable(playerid, 0);
}

// LOADS OF MORE STUFF OnPlayerRequestClass -  not important

public OnPlayerSpawn(playerid)
{
    if(Logged[playerid] == 0) return SendClientMessage(playerid,COLOR_YELLOW,"Please login!");
    SetPlayerSkillLevel(playerid, WEAPONSKILL_SAWNOFF_SHOTGUN, 1);
    HealXD(playerid);
    SetPlayerScore(playerid,PlayerInfo[playerid][Score]);
    SetPlayerToTeamColor(playerid);
    ShowPlayerDialog(playerid, 13, DIALOG_STYLE_LIST, "Arm up!", "Quick Armup\nMelee weapons\nHandguns\nShotguns\nSubmachine guns\nAssault Rifles\nRifles", "Ok", "Cancel");
    return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    switch( dialogid )
    {
        case DIALOG_REGISTER:
        {
            if (!response) return Kick(playerid);
            if(response)
            {
                if(!strlen(inputtext)) return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, ""#COL_WHITE"Registering...",""#COL_RED"You have entered an invalid password.\n"#COL_WHITE"Type your password below to register a new account.","Register","Quit");
                new INI:File = INI_Open(UserPath(playerid));
                INI_SetTag(File,"data");
                INI_WriteInt(File,"Password",udb_hash(inputtext));
                INI_WriteInt(File,"Cash",0);
                INI_WriteInt(File,"Kills",0);
                INI_WriteInt(File,"Deaths",0);
                INI_WriteInt(File,"Adminlevel",0);
                INI_WriteInt(File,"Donator",0);
                INI_WriteInt(File,"Score",0);
                INI_WriteInt(File,"Banned",0);
                INI_WriteInt(File,"MaskOn",0);
                INI_WriteInt(File,"Muted",0);
                INI_WriteInt(File,"MuteTime",0);
                INI_Close(File);
                Logged[playerid] = 1;
                SetSpawnInfo(playerid, 0, 0, 1958.33, 1343.12, 15.36, 269.15, 0, 0, 0, 0, 0, 0);
                TogglePlayerControllable(playerid, 0);
                GameTextForPlayer( playerid, "~b~PLEASE RECONNECT!", 10000, 4 );
                ShowPlayerDialog(playerid, DIALOG_SUCCESS_1, DIALOG_STYLE_MSGBOX,""COL_WHITE"Success!",""COL_GREEN"Great! You have successfully registered - please relog to save your account!","Ok","");
               
               

                        }
        }

case DIALOG_LOGIN:
        {
            if (!response) return Kick(playerid);
            if( response )
            {
                if(udb_hash(inputtext) == PlayerInfo[playerid][Password])
                {
                    Logged[playerid] = 1;
                    INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
                    GivePlayerMoney(playerid, PlayerInfo[playerid][Cash]);
                }
                else
                {
                    ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,""#COL_WHITE"Login",""#COL_RED"You have entered an incorrect password.\n"#COL_WHITE"Type your password below to login.","Login","Quit");
                }
                return 1;
            }
        }
    }
My online server is running on Linux. Any suggestions?
Reply
#2

pawn Код:
public OnPlayerRequestSpawn(playerid)
{
    return (Logged[playerid]);
}
It should work - give it a try.
Reply
#3

I also have that problem. But I fixed it using TogglePlayerSpectating(playerid, 1);. If password is wrong then enable it, if password is correct disable toggleplayerspectating. If you need help I can clearly tell you where you need to put that.
Reply
#4

@Emmet: Didn't work
@RedJohn: Didn't work, unless I placed them wrong - it would be very appreciated if you can tell me where to put those lines, even though I think I got it right!
Reply
#5

pawn Код:
public OnPlayerConnect(playerid)
{
    TogglePlayerSpectating(playerid, 1);
    return 1;
}
pawn Код:
case DIALOG_REGISTER
{
    //you yini savings
    TogglePlayerSpectating(playerid, 0);
}
pawn Код:
case DIALOG_LOGIN
{
    //you yini loadings
    TogglePlayerSpectating(playerid, 0);
}
Reply
#6

Works like a charm! Thank you very much - repped. On another note, if you can help me on this. I have scripted a /gmx cmd, but when it SendRconCommand("gmx"); does it save players statistics, because I don't have anything in that line, and I am unaware of if rcon gmx saves player files.
Reply
#7

Can you please show us your /gmx?
Reply
#8

pawn Код:
public gmx(playerid)
{
    //resetVars(playerid);
    SendRconCommand("gmx");

}

CMD:gmx(playerid, params[])
{
    if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid,WARNINGCOLOR,""#WARNINGMESSAGE"");
    SendClientMessage(playerid, COLOR_RED,"");
    SendClientMessage(playerid, COLOR_RED," ");
    SendClientMessage(playerid, COLOR_RED," ");
    SendClientMessage(playerid, COLOR_RED," ");
    SendClientMessage(playerid, COLOR_RED," ");
    SendClientMessage(playerid, COLOR_RED,"========================================================================");
    SendClientMessage(playerid, COLOR_GREEN,"THE SERVER IS ABOUT TO RESTART FOR A FEW SECONDS - DO NOT DISCONNECT!");
    SendClientMessage(playerid, COLOR_RED,"========================================================================");
    SendClientMessage(playerid, COLOR_RED," ");
    SendClientMessage(playerid, COLOR_RED," ");
    SendClientMessage(playerid, COLOR_RED," ");
    SendClientMessage(playerid, COLOR_RED," ");
    SendClientMessage(playerid, COLOR_RED," ");
    SetTimer("gmx", 5000, false);
    return 1;
}
Reply
#9

pawn Код:
public gmx(playerid)
{
    //resetVars(playerid);
    new INI:File = INI_Open(UserPath(playerid));
    INI_SetTag(File,"data");
    INI_WriteInt(File,"Cash",GetPlayerMoney(playerid));
    INI_WriteInt(File,"Kills",PlayerInfo[playerid][Kills]);
    INI_WriteInt(File,"Deaths",PlayerInfo[playerid][Deaths]);
    INI_WriteInt(File,"Adminlevel",PlayerInfo[playerid][Adminlevel]);
    INI_WriteInt(File,"Donator",PlayerInfo[playerid][Donator]);
    INI_WriteInt(File,"Score",GetPlayerScore(playerid));
    INI_WriteInt(File,"Banned",PlayerInfo[playerid][Banned]);
    INI_WriteInt(File,"MaskOn",PlayerInfo[playerid][MaskOn]);
    INI_WriteInt(File,"Muted",PlayerInfo[playerid][Muted]);
    INI_WriteInt(File,"MuteTime",PlayerInfo[playerid][MuteTime]);
    INI_Close(File);
    SendRconCommand("gmx");

}

CMD:gmx(playerid, params[])
{
    if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid,WARNINGCOLOR,""#WARNINGMESSAGE"");
    SendClientMessage(playerid, COLOR_RED,"");
    SendClientMessage(playerid, COLOR_RED," ");
    SendClientMessage(playerid, COLOR_RED," ");
    SendClientMessage(playerid, COLOR_RED," ");
    SendClientMessage(playerid, COLOR_RED," ");
    SendClientMessage(playerid, COLOR_RED,"========================================================================");
    SendClientMessage(playerid, COLOR_GREEN,"THE SERVER IS ABOUT TO RESTART FOR A FEW SECONDS - DO NOT DISCONNECT!");
    SendClientMessage(playerid, COLOR_RED,"========================================================================");
    SendClientMessage(playerid, COLOR_RED," ");
    SendClientMessage(playerid, COLOR_RED," ");
    SendClientMessage(playerid, COLOR_RED," ");
    SendClientMessage(playerid, COLOR_RED," ");
    SendClientMessage(playerid, COLOR_RED," ");
    SetTimer("gmx", 5000, false);
    return 1;
}
TRY THAT
Reply
#10

pawn Код:
forward Restart(playerid)

public Restart(playerid)
{
    if(Logged[playerid] == 1)
    {
        new INI:File = INI_Open(UserPath(playerid));
        INI_SetTag(File,"data");
        INI_WriteInt(File,"Cash",GetPlayerMoney(playerid));
        INI_WriteInt(File,"Kills",PlayerInfo[playerid][Kills]);
        INI_WriteInt(File,"Deaths",PlayerInfo[playerid][Deaths]);
        INI_WriteInt(File,"Adminlevel",PlayerInfo[playerid][Adminlevel]);
        INI_WriteInt(File,"Donator",PlayerInfo[playerid][Donator]);
        INI_WriteInt(File,"Score",GetPlayerScore(playerid));
        INI_WriteInt(File,"Banned",PlayerInfo[playerid][Banned]);
        INI_WriteInt(File,"MaskOn",PlayerInfo[playerid][MaskOn]);
        INI_WriteInt(File,"Muted",PlayerInfo[playerid][Muted]);
        INI_WriteInt(File,"MuteTime",PlayerInfo[playerid][MuteTime]);
        INI_Close(File);       
    }
    SendRconCommand("gmx");
}

CMD:gmx(playerid, params[])
{
    if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid,WARNINGCOLOR,""#WARNINGMESSAGE"");
    SendClientMessage(playerid, COLOR_RED,"");
    SendClientMessage(playerid, COLOR_RED," ");
    SendClientMessage(playerid, COLOR_RED," ");
    SendClientMessage(playerid, COLOR_RED," ");
    SendClientMessage(playerid, COLOR_RED," ");
    SendClientMessage(playerid, COLOR_RED,"========================================================================");
    SendClientMessage(playerid, COLOR_GREEN,"THE SERVER IS ABOUT TO RESTART FOR A FEW SECONDS - DO NOT DISCONNECT!");
    SendClientMessage(playerid, COLOR_RED,"========================================================================");
    SendClientMessage(playerid, COLOR_RED," ");
    SendClientMessage(playerid, COLOR_RED," ");
    SendClientMessage(playerid, COLOR_RED," ");
    SendClientMessage(playerid, COLOR_RED," ");
    SendClientMessage(playerid, COLOR_RED," ");
    SetTimer("Restart", 5000, false);
    return 1;
}
Check if he's logged in.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)