Login System Buggy?

Wichtiger Hinweis: Bitte ändert nicht manuell die Schriftfarbe auf schwarz sondern belasst es bei der Standardeinstellung. Somit tragt ihr dazu bei dass euer Text auch bei Verwendung unseren dunklen Forenstils noch lesbar ist!

Tipp: Ihr wollt längere Codeausschnitte oder Logfiles bereitstellen? Benutzt unseren eigenen PasteBin-Dienst Link
  • Hallo Leute,


    Ich habe ein Problem mit meinem Login System, man kann zwar wunderbar mit /register [Passwort} einen Account erstellen und er wird auch in den Scriptfiles Gespeichert..mein Problem ist nur wenn ich mich einloggen will mit /login [Passwort] wird mir die Naricht gesendet damit ich bereits Eingeloggt bin. Der loggt sich immer alleine ein und das will ich nicht. Kann mir jemand helfen.....


    forward OnPlayerUpdate(playerid);
    forward Encrypt(string[]);
    forward OnPlayerLogin(playerid,const string[]);


    enum pInfo
    {
    pPassword[128],
    pAdmin,
    };


    new PlayerInfo[MAX_PLAYERS][pInfo];
    new gPlayerLogged[MAX_PLAYERS];
    new gPlayerAccount[MAX_PLAYERS];


    public OnPlayerConnect(playerid)
    {


    new pName[MAX_PLAYER_NAME];
    new string[48];
    new playrname[MAX_PLAYER_NAME];
    new connect[128];
    GetPlayerName(playerid, playrname, sizeof(playrname));
    format(connect, sizeof(connect), "Accounts/%s.ini", playrname);
    if(fexist(connect))
    {
    gPlayerAccount[playerid] = 1;
    SendClientMessage(playerid, COLOR_YELLOW, "Der Account wurde gefunden!");
    SendClientMessage(playerid, COLOR_YELLOW, "Bitte Logge dich ein!");
    }
    else
    {
    gPlayerAccount[playerid] = 0;
    SendClientMessage(playerid, COLOR_YELLOW, "Dein Account muss erstellt werden, bitte Registriere dich!");
    SendClientMessage(playerid, COLOR_WHITE, "Drücke \"t\" und gib /register [passwort]");
    SendClientMessage(playerid, COLOR_YELLOW, "Herzlichen Glückwunsch dein Account wurde Erstellt");
    SendClientMessage(playerid, COLOR_YELLOW, "Bitte Logge dich ein!");
    }
    GetPlayerName(playerid, pName, sizeof(pName));
    format(string, sizeof(string), "%s hat den Server betreten.", pName);
    SendClientMessageToAll(0x931B00FF, string);
    return 1;
    }


    public OnPlayerDisconnect(playerid, reason)
    {
    new pName[MAX_PLAYER_NAME], string[56];
    GetPlayerName(playerid, pName, sizeof(pName));
    switch(reason)
    {
    case 0: format(string, sizeof(string), "%s hat den Server verlassen. (timeout)", pName);
    case 1: format(string, sizeof(string), "%s hat den Server verlassen.", pName);
    case 2: format(string, sizeof(string), "%s hat den Server verlassen. (Kick)", pName);
    }
    SendClientMessageToAll(COLOR_GRAD5, string);
    OnPlayerUpdate(playerid);
    gPlayerLogged[playerid] = 0;
    return 1;
    }


    public OnPlayerCommandText(playerid, cmdtext[])
    {
    new cmd[256];
    new idx;
    cmd = strtok(cmdtext, idx);
    new tmp[256];
    new playername[MAX_PLAYER_NAME];
    if (strcmp(cmd, "/login", true) ==0 )
    {
    if(IsPlayerConnected(playerid))
    {
    new tmppass[64];
    if(gPlayerLogged[playerid] == 1)
    {
    SendClientMessage(playerid, COLOR_GREY, "Du bist bereits eingeloggt!");
    return 1;
    }
    tmp = strtok(cmdtext, idx);
    if(!strlen(tmp))
    {
    SendClientMessage(playerid, COLOR_GREY, "Benutze: /login [password]");
    return 1;
    }
    strmid(tmppass, tmp, 0, strlen(cmdtext), 255);
    Encrypt(tmppass);
    OnPlayerLogin(playerid,tmppass);
    }
    return 1;
    }
    if (strcmp(cmd, "/register", true)==0)
    {
    new string[265];
    tmp = strtok(cmdtext, idx);
    if(!strlen(tmp))
    {
    SendClientMessage(playerid, COLOR_GREY, "Benutze: /register [password]");
    return 1;
    }
    if (gPlayerAccount[playerid] == 1)
    {
    SendClientMessage(playerid, COLOR_GREY, " Der Name ist bereits registriert");
    return 1;
    }


    strmid(PlayerInfo[playerid][pPassword], tmp, 0, strlen(cmdtext), 255);
    Encrypt(PlayerInfo[playerid][pPassword]);
    GetPlayerName(playerid, playername, sizeof(playername));
    format(string, sizeof(string), "Accounts/%s.ini", playername);
    new File: file = fopen(string, io_read);
    if (file)
    {
    SendClientMessage(playerid, COLOR_GREY, " Der Name ist bereits registriert");
    fclose(file);
    return 1;
    }
    new File:hFile;
    hFile = fopen(string, io_append);
    new var[32];//
    format(var, 32, "%s\n", PlayerInfo[playerid][pPassword]);fwrite(hFile, var);
    format(var, 32, "Admin=%d\n",PlayerInfo[playerid][pAdmin]);fwrite(hFile, var);
    fclose(hFile);
    SendClientMessage(playerid, COLOR_WHITE, "Erfolgreich registriert!");
    SendClientMessage(playerid, COLOR_WHITE, "Gebe nächstes mal /login <password> zum einloggen ein.");
    OnPlayerLogin(playerid,PlayerInfo[playerid][pPassword]);
    return 1;
    }


    public OnPlayerLogin(playerid,const string[])
    {
    new pname2[MAX_PLAYER_NAME];
    new pname3[MAX_PLAYER_NAME];
    new string2[64];
    new string3[128];
    GetPlayerName(playerid, pname2, sizeof(pname2));
    format(string2, sizeof(string2), "Accounts/%s.ini", pname2);
    new File: UserFile = fopen(string2, io_read);


    if (UserFile)
    {
    new valtmp[128];
    fread(UserFile, valtmp);strmid(PlayerInfo[playerid][pPassword], valtmp, 0, strlen(valtmp)-1, 255);


    if ((strcmp(PlayerInfo[playerid][pPassword], string, true, strlen(valtmp)-1) == 0))
    {
    new key[256],val[256];
    new Data[128];
    while(fread(UserFile,Data,sizeof(Data)))
    {
    key = ini_GetKey(Data);
    if( strcmp( key , "Admin" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerInfo[playerid][pAdmin] = strval( val ); }
    }
    fclose(UserFile);
    gPlayerLogged[playerid] = 1;
    gPlayerAccount[playerid] = 1;
    GetPlayerName(playerid, pname3, sizeof(pname3));
    format(string3, sizeof(string3), "Willkommen %s, du bist bereits eingeloggt!", pname3);
    SendClientMessage(playerid, COLOR_WHITE,string3);
    }
    else
    {
    SendClientMessage(playerid, COLOR_GREY, " Falsches Passwort");
    fclose(UserFile);
    }
    }
    return 1;
    }

    public OnPlayerUpdate(playerid)
    {
    if(IsPlayerConnected(playerid))
    {
    if(gPlayerLogged[playerid])
    {
    new string3[32];
    new pname3[MAX_PLAYER_NAME];
    GetPlayerName(playerid, pname3, sizeof(pname3));
    format(string3, sizeof(string3), "Accounts/%s.ini", pname3);
    new File: pFile = fopen(string3, io_write);
    if (pFile)
    {
    new var[32];
    format(var, 32, "%s\n", PlayerInfo[playerid][pPassword]);fwrite(pFile, var);
    fclose(pFile);
    new File: hFile = fopen(string3, io_append);
    format(var, 32, "Admin=%d\n",PlayerInfo[playerid][pAdmin]);fwrite(hFile, var);
    fclose(hFile);
    }
    }
    }
    return 1;
    }


    stock ini_GetKey( line[] )
    {
    new keyRes[128];
    keyRes[0] = 0;
    if ( strfind( line , "=" , true ) == -1 ) return keyRes;
    strmid( keyRes , line , 0 , strfind( line , "=" , true ) , sizeof( keyRes) );
    return keyRes;
    }


    stock ini_GetValue( line[] )
    {
    new valRes[128];
    valRes[0]=0;
    if ( strfind( line , "=" , true ) == -1 ) return valRes;
    strmid( valRes , line , strfind( line , "=" , true )+1 , strlen( line ) , sizeof( valRes ) );
    return valRes;
    }


    public Encrypt(string[])
    {
    for(new x=0; x < strlen(string); x++)
    {
    string[x] += (3^x) * (x % 15);
    if(string[x] > (0xff))
    {
    string[x] -= 64;
    }
    }
    return 1;
    }

  • Vielleichts liegts dadran im register command? (ganz unten)


    OnPlayerLogin(playerid,PlayerInfo[playerid][pPassword]);



    Entfern das mal und kuck ob es immernoch so ist^^

  • Füg das mal beim Register CMD unten ein..


    gPlayerLogged[playerid] = 0;



    aber kA obs funkioniert ;)

  • nimm das hier leicht brauchst garnichts machen kein bugs



    #include <a_samp>


    #define FILTERSCRIPT


    #if defined FILTERSCRIPT
    #define COLOR_GREY 0xBEBEBEAA
    #define COLOR_WHITE 0xFFFFFFAA
    #define COLOR_GREEN 0x33AA33AA
    #define COLOR_GRAD5 0xE3E3E3FF
    #define COLOR_GRAD1 0xB4B5B7FF


    forward ShowStats(playerid,targetid);
    forward OnPlayerUpdate(playerid);
    forward Encrypt(string[]);
    forward OnPlayerLogin(playerid,const string[]);


    enum pInfo
    {
    pPassword[128],
    pKills,
    pDeaths,
    pCash,
    };


    new PlayerInfo[MAX_PLAYERS][pInfo];
    new gPlayerLogged[MAX_PLAYERS];
    new gPlayerAccount[MAX_PLAYERS];



    public OnFilterScriptInit()
    {
    print("\n$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$");
    print("Login/Register Filterscript by [KIS]Clan");
    print("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n");
    return 1;
    }


    public OnFilterScriptExit()
    {
    return 1;
    }


    public OnPlayerRequestClass(playerid, classid)
    {
    return 1;
    }


    public OnPlayerRequestSpawn(playerid)
    {
    return 1;
    }


    public OnPlayerConnect(playerid)
    {
    return 1;
    }


    public OnPlayerDisconnect(playerid, reason)
    {
    OnPlayerUpdate(playerid);
    gPlayerLogged[playerid] = 0;
    return 1;
    }


    public OnPlayerSpawn(playerid)
    {
    return 1;
    }


    public OnPlayerDeath(playerid, killerid, reason)
    {
    new kills = PlayerInfo[playerid][pKills];
    SetPlayerScore(playerid, kills);
    new Float:Health;
    GetPlayerHealth(playerid, Health);
    if(Health == 0.0)
    {
    PlayerInfo[playerid][pDeaths] += 3;
    }
    GivePlayerMoney(killerid,1000);
    PlayerInfo[killerid][pKills] = PlayerInfo[killerid][pKills] + 3;
    return 1;
    }


    public OnPlayerCommandText(playerid, cmdtext[])
    {
    new cmd[256];
    new idx;
    cmd = strtok(cmdtext, idx);
    new tmp[256];
    new playername[MAX_PLAYER_NAME];
    if (strcmp(cmd, "/login", true) ==0 )
    {
    if(IsPlayerConnected(playerid))
    {
    new tmppass[64];
    if(gPlayerLogged[playerid] == 1)
    {
    SendClientMessage(playerid, COLOR_GREY, " Du bist eingeloggt|You are already logged in");
    return 1;
    }
    tmp = strtok(cmdtext, idx);
    if(!strlen(tmp))
    {
    SendClientMessage(playerid, COLOR_GREY, "SERVER:/login [password]");
    return 1;
    }
    strmid(tmppass, tmp, 0, strlen(cmdtext), 255);
    Encrypt(tmppass);
    OnPlayerLogin(playerid,tmppass);
    }
    return 1;
    }
    if (strcmp(cmd, "/register", true)==0)
    {
    new string[265];
    tmp = strtok(cmdtext, idx);
    if(!strlen(tmp))
    {
    SendClientMessage(playerid, COLOR_GREY, "SERVER: /register [password]");
    return 1;
    }
    if (gPlayerAccount[playerid] == 1)
    {
    SendClientMessage(playerid, COLOR_GREY, "Dieser Name ist bereits registriert|That name is already registered");
    return 1;
    }


    strmid(PlayerInfo[playerid][pPassword], tmp, 0, strlen(cmdtext), 255);
    Encrypt(PlayerInfo[playerid][pPassword]);
    GetPlayerName(playerid, playername, sizeof(playername));
    format(string, sizeof(string), "%s.cer", playername);
    new File: file = fopen(string, io_read);
    if (file)
    {
    SendClientMessage(playerid, COLOR_GREY, "Dieser Name ist bereits registriert|That name is already registered");
    fclose(file);
    return 1;
    }
    new File:hFile;
    hFile = fopen(string, io_append);
    new var[32];//
    format(var, 32, "%s\n", PlayerInfo[playerid][pPassword]);fwrite(hFile, var);
    format(var, 32, "Kills=%d\n",PlayerInfo[playerid][pKills]);fwrite(hFile, var);
    format(var, 32, "Deaths=%d\n",PlayerInfo[playerid][pDeaths]);fwrite(hFile, var);
    PlayerInfo[playerid][pCash] = GetPlayerMoney(playerid);
    format(var, 32, "Money=%d\n",PlayerInfo[playerid][pCash]);fwrite(hFile, var);
    fclose(hFile);
    SendClientMessage(playerid, COLOR_WHITE, "Erfolgreich registriert|Succesfully Registered");
    SendClientMessage(playerid, COLOR_WHITE, "Wenn Sie das nächste Mal Connecten, geben Sie / login <password> zum anmelden|Next time you connect, type /login <password> to log in.");
    OnPlayerLogin(playerid,PlayerInfo[playerid][pPassword]);
    return 1;
    }
    if (strcmp(cmd, "/stats", true) == 0)
    {
    if(IsPlayerConnected(playerid))
    {
    if (gPlayerLogged[playerid] != 0)
    {
    ShowStats(playerid,playerid);
    }
    else
    {
    SendClientMessage(playerid, COLOR_GRAD1, "Du bist nicht eingeloggt|You are not Logged in !");
    }
    }
    return 1;
    }
    return 0;
    }


    public Encrypt(string[])
    {
    for(new x=0; x < strlen(string); x++)
    {
    string[x] += (3^x) * (x % 15);
    if(string[x] > (0xff))
    {
    string[x] -= 64;
    }
    }
    return 1;
    }



    public OnPlayerLogin(playerid,const string[])
    {
    new pname2[MAX_PLAYER_NAME];
    new pname3[MAX_PLAYER_NAME];
    new string2[64];
    new string3[128];
    GetPlayerName(playerid, pname2, sizeof(pname2));
    format(string2, sizeof(string2), "%s.cer", pname2);
    new File: UserFile = fopen(string2, io_read);


    if (UserFile)
    {
    new valtmp[128];
    fread(UserFile, valtmp);strmid(PlayerInfo[playerid][pPassword], valtmp, 0, strlen(valtmp)-1, 255);


    if ((strcmp(PlayerInfo[playerid][pPassword], string, true, strlen(valtmp)-1) == 0))
    {
    new key[128],val[128];
    new Data[128];
    while(fread(UserFile,Data,sizeof(Data)))
    {
    key = ini_GetKey(Data);
    if( strcmp( key , "Kills|Kills" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerInfo[playerid][pKills] = strval( val ); }
    if( strcmp( key , "Tode|Deaths" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerInfo[playerid][pDeaths] = strval( val ); }
    if( strcmp( key , "Geld|Money" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerInfo[playerid][pCash] = strval( val ); }
    GivePlayerMoney(playerid,PlayerInfo[playerid][pCash]);
    }
    fclose(UserFile);
    gPlayerLogged[playerid] = 1;
    gPlayerAccount[playerid] = 1;
    new kills = PlayerInfo[playerid][pKills];
    SetPlayerScore(playerid, kills);
    GetPlayerName(playerid, pname3, sizeof(pname3));
    format(string3, sizeof(string3), "Welcome %s, you have been succesfully logged in!", pname3);
    SendClientMessage(playerid, COLOR_WHITE,string3);
    }
    else
    {
    SendClientMessage(playerid, COLOR_GREY, "Passwort stimmt nicht mit Ihrem Namen|Password does not match your name");
    fclose(UserFile);
    }
    }
    return 1;
    }


    public OnPlayerUpdate(playerid)
    {
    if(IsPlayerConnected(playerid))
    {
    if(gPlayerLogged[playerid])
    {
    new string3[32];
    new pname3[MAX_PLAYER_NAME];
    GetPlayerName(playerid, pname3, sizeof(pname3));
    format(string3, sizeof(string3), "%s.cer", pname3);
    new File: pFile = fopen(string3, io_write);
    if (pFile)
    {
    new var[32];
    format(var, 32, "%s\n", PlayerInfo[playerid][pPassword]);fwrite(pFile, var);
    fclose(pFile);
    new File: hFile = fopen(string3, io_append);
    PlayerInfo[playerid][pCash] = GetPlayerMoney(playerid);
    format(var, 32, "Kills|Kills=%d\n",PlayerInfo[playerid][pKills]);fwrite(hFile, var);
    format(var, 32, "Tode|Deaths=%d\n",PlayerInfo[playerid][pDeaths]);fwrite(hFile, var);
    format(var, 32, "Geld|Money=%d\n",PlayerInfo[playerid][pCash]);fwrite(hFile, var);
    fclose(hFile);
    }
    }
    }
    return 1;
    }


    stock ini_GetKey( line[] )
    {
    new keyRes[128];
    keyRes[0] = 0;
    if ( strfind( line , "=" , true ) == -1 ) return keyRes;
    strmid( keyRes , line , 0 , strfind( line , "=" , true ) , sizeof( keyRes) );
    return keyRes;
    }


    stock ini_GetValue( line[] )
    {
    new valRes[128];
    valRes[0]=0;
    if ( strfind( line , "=" , true ) == -1 ) return valRes;
    strmid( valRes , line , strfind( line , "=" , true )+1 , strlen( line ) , sizeof( valRes ) );
    return valRes;
    }



    strtok(const string[], &index)
    {
    new length = strlen(string);
    while ((index < length) && (string[index] <= ' '))
    {
    index++;
    }


    new offset = index;
    new result[20];
    while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
    {
    result[index - offset] = string[index];
    index++;
    }
    result[index - offset] = EOS;
    return result;
    }


    public ShowStats(playerid,targetid)
    {
    if(IsPlayerConnected(playerid)&&IsPlayerConnected(targetid))
    {
    new cash = GetPlayerMoney(targetid);
    new deaths = PlayerInfo[targetid][pDeaths];
    new kills = PlayerInfo[targetid][pKills];
    new name[MAX_PLAYER_NAME];
    GetPlayerName(targetid, name, sizeof(name));
    new Float:px,Float:py,Float:pz;
    GetPlayerPos(targetid, px, py, pz);
    new coordsstring[256];
    SendClientMessage(playerid, COLOR_GREEN,"_______________________________________");
    format(coordsstring, sizeof(coordsstring),"*** %s ***",name);
    SendClientMessage(playerid, COLOR_WHITE,coordsstring);
    format(coordsstring, sizeof(coordsstring), "Kills|Kills:[%d] Tode|Deaths:[%d] Geld|Cash:[$%d]",kills,deaths,cash);
    SendClientMessage(playerid, COLOR_GRAD5,coordsstring);
    SendClientMessage(playerid, COLOR_GREEN,"_______________________________________");
    }
    }


    #endif