...Mysql...
#1

So, once i hired someone to create a mysql login/register script, problem is; he sent me some code that ain't working..
Then he vanished. Although; he didn't get his payment..

Been trying for weeks to get the code working, but no matter what i do, it doesn't work

pawn Код:
public OnPlayerConnect(playerid)
{
    new name[MAX_PLAYER_NAME];
    GetPlayerName(playerid, name, sizeof(name));

    // Login Stuff
    new query[200], pname[24], banned; GetPlayerIp(playerid, PlayerInfo[playerid][IP], 16);
    mysql_real_escape_string(name, pname); // Prevents SQL injection
    format(query, sizeof(query), "SELECT Banned FROM `Playerdata` WHERE `Name` = '%s' AND `AutoLogin` = `1` AND `LastIP` = `%s`", pname, PlayerInfo[playerid][IP]);
    mysql_query(query); //Querys the string
    mysql_store_result(); //Stores the result
    if(mysql_num_rows() != 0) //If the user is found
    {
        if(sscanf(query, "i", banned))
        {
            SendClientMessage(playerid, COLOR_ERROR, "There is a problem with your account, contact a staff member to get the problem fixed.");
            return printf("Error: Auto Login(%s, AUTO:1, %s, BANNED:%i)", pname, PlayerInfo[playerid][IP], banned);
        }
        if(banned){
            new leavemsg[128]; format(leavemsg, 128, "Player %s (ID: %i) was banned by Raptor. Reason: Ban Evading", name, playerid);
            return SendClientMessageToAll(COLOR_CWARN, leavemsg), Ban(playerid);
        }
        OnPlayerLogin(playerid, "");
        mysql_free_result();
    }
    else
    {
        format(query, sizeof(query), "SELECT Banned FROM `Playerdata` WHERE `Name` = '%s'", pname);
        mysql_query(query); //Querys the string
        mysql_store_result(); //Stores the result
        if(mysql_num_rows() != 0) //If the user is found
        {
            if(sscanf(query, "i", banned))
            {
                SendClientMessage(playerid, COLOR_ERROR, "There is a problem with your account, contact a staff member to get the problem fixed.");
                return printf("Error: Auto Login(%s, AUTO:0, %s, BANNED:%i)", pname, PlayerInfo[playerid][IP], banned);
            }
            if(banned){
                new leavemsg[128]; format(leavemsg, 128, "Player %s (ID: %i) was banned by Raptor. Reason: Ban Evading", name, playerid);
                return SendClientMessageToAll(COLOR_CWARN, leavemsg), Ban(playerid);
            }
            SendClientMessage(playerid, 0x009600AA, "This account is registered, please login");
            ShowPlayerDialog(playerid, Login_Dialog, DIALOG_STYLE_INPUT , "Login", "This account is registered, please login", "OK", "Cancel");
        }
        else
        {
            ShowPlayerDialog(playerid, register, DIALOG_STYLE_INPUT , "Register", "This account is not registered, please register!", "OK", "Cancel");
            SendClientMessage(playerid, 0x009600AA, "This account is not registered, please register!");
        }
        mysql_free_result();
    }
    return 1;
}
pawn Код:
CMD:login(playerid, params[])
{
    if(PlayerInfo[playerid][Logged]==true) return SendClientMessage(playerid, COLOR_ERROR, "/!\\ Error: You are already logged in!");
    if(!isnull(params)) return OnPlayerLogin(playerid, params);
    return ShowPlayerDialog(playerid, Login_Dialog, DIALOG_STYLE_INPUT , "Login", "This account is registered, please login", "OK", "Cancel");
}

CMD:register(playerid, params[])
{
    if(PlayerInfo[playerid][Logged]==true) return SendClientMessage(playerid, COLOR_ERROR, "/!\\ Error: You are already logged in!");
    if(!isnull(params)) OnDialogResponse(playerid, register, TRUE, 1, params);
    else ShowPlayerDialog(playerid, register, DIALOG_STYLE_INPUT , "Register", "This account is not registered, please register!", "OK", "Cancel");
    return 1;
}

CMD:level(playerid, params[])
{
    if(PlayerInfo[playerid][Logged]!=true) return SendClientMessage(playerid, COLOR_ERROR, "/!\\ Error: You are not logged in!");
    new stats[128]; format(stats, sizeof(stats), "Details for %s", PlayerInfo[playerid][Name]); SendClientMessage(playerid, COLOR_WHITE, stats);
    format(stats, sizeof(stats), "Alias: %i %s", PlayerInfo[playerid][UseAlias],PlayerInfo[playerid][Alias]); SendClientMessage(playerid, COLOR_WHITE, stats);
    format(stats, sizeof(stats), "Admin: %i       Cash: %i       Level: %i", PlayerInfo[playerid][AdminLvl],PlayerInfo[playerid][Level],PlayerInfo[playerid][Cash]);
    return SendClientMessage(playerid, COLOR_WHITE, stats), SendClientMessage(playerid, COLOR_WHITE, "______________________________________________________________________");
}
pawn Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    switch(dialogid)
    {
        case register:
        {
           if(response)
           {
                if(isnull(inputtext)) //If the player doesn't enter a pass
                {
                    ShowPlayerDialog(playerid, 14600, DIALOG_STYLE_INPUT , "Register", "This account is not registered, please register!", "OK", "Cancel");
                    SendClientMessage(playerid, 0xF60000AA, "Please enter a password");
                }
                new query[200], player[24], passs[100];     GetPlayerName(playerid, PlayerInfo[playerid][Name], 24);
                mysql_real_escape_string(inputtext, passs);   mysql_real_escape_string(PlayerInfo[playerid][Name], player); //Prevents SQL injection
                format(query, sizeof(query), "INSERT INTO `Players` (`Name`, `Password`, 'LastIP') VALUES ('%s', '%s', '%s')", player, passs, PlayerInfo[playerid][IP]);
                mysql_query(query);
                OnPlayerLogin(playerid, "");
            }
            else HidePlayerDialog(playerid);
        }
        case Login_Dialog:
        {
            if(!response) HidePlayerDialog(playerid);
            new query[200], pname[24], player[24];
            GetPlayerName(playerid, pname, 24);
            mysql_real_escape_string(pname, player);
            format(query, sizeof(query), "SELECT * FROM `Players` WHERE `Name` = '%s' AND `password` = '%s'", player, inputtext);
            mysql_query(query);
            mysql_store_result();
            if(!mysql_num_rows())
            {
                SendClientMessage(playerid, 0xF60000AA, "Invalid password!");
                SetPVarInt(playerid, "WrongPass", GetPVarInt(playerid, "WrongPass") + 1);
                ShowPlayerDialog(playerid, 15000, DIALOG_STYLE_INPUT , "Login", "This account is registered, please login", "OK", "Cancel");
                if(GetPVarInt(playerid, "WrongPass") == 3)
                {
                    SendClientMessage(playerid, 0xF60000AA, "Max password tries exceeded!!");
                    Kick(playerid);
                }
            }
            else
            {
                /*if(sscanf(query, "{is[24]}s[36]{s[32]is[16]i}i", PlayerInfo[playerid][Mail], banned))
                {
                    SendClientMessage(playerid, COLOR_ERROR, "There is a problem with your account, contact a staff member to get the problem fixed.");
                    return printf("Error: Login(%s, AUTO:N/A, KEY:N/A, BANNED:%i)", pname, banned);
                }
                if(banned){
                    new leavemsg[128]; format(leavemsg, 128, "Player %s (ID: %i) was banned by Raptor. Reason: Ban Evading", pname, playerid);
                    return SendClientMessageToAll(COLOR_CWARN, leavemsg), Ban(playerid);
                }*/

                OnPlayerLogin(playerid, inputtext);
            }
        }
    }
    return 1;
}
pawn Код:
OnPlayerLogin(playerid, password[])
{
    new query[200];
    if(isnull(password)) // No need to check both password and ip
    {
        format(query, sizeof(query), "SELECT * FROM `Playerdata` WHERE `User` = '%s'", PlayerInfo[playerid][Mail]);
        mysql_query(query); //Queries the result
        mysql_store_result(); //Stores the result
        RetrievePlayerData(playerid, query);
        mysql_free_result();
    }
    else
    {
        new pname[24], player[24];
        GetPlayerName(playerid, pname, 24);
        mysql_real_escape_string(pname, player);
        format(query, sizeof(query), "SELECT * FROM `Playerdata` WHERE `Name` = '%s' AND `Password` = '%s'", player, password);
        mysql_query(query);
        mysql_store_result();
        if(!mysql_num_rows())
        {
            SendClientMessage(playerid, 0xF60000AA, "Invalid password!");
            SetPVarInt(playerid, "WrongPass", GetPVarInt(playerid, "WrongPass") + 1);
            ShowPlayerDialog(playerid, Login_Dialog, DIALOG_STYLE_INPUT , "Login", "This account is registered, please login", "OK", "Cancel");
            if(GetPVarInt(playerid, "WrongPass") == 3)
            {
                new leavemsg[128]; format(leavemsg, 128, "Player %s (ID: %i) was kicked by Raptor. Reason: Too many invalid login attempts!", pname, playerid);
                return SendClientMessageToAll(COLOR_CWARN, leavemsg), Kick(playerid), SendClientMessage(playerid, 0xF60000AA, "/!\\ Error: Exceeded maximum login attempts allowed!!");
            }
        }
        RetrievePlayerData(playerid, query);
        mysql_free_result();
    }
    MoneyCheck[playerid]++;
    TextDrawStyle[playerid][TextDraw_Selector_Main]=TEXTDRAW_STYLE_INFORMATION; // Doesn't matter what it is, as long as it's one of the positive ones
    CreatePlayerTextDraws(playerid);
    return SendClientMessage(playerid, COLOR_GREEN, "      You have been logged in Successfully"), printf("Successfull Login: %s", PlayerInfo[playerid][Name]);
}
pawn Код:
RetrievePlayerData(playerid, const data[])
{
    if(sscanf(data, "{is[24]}s[36]s[32]{is[16]ll}ls[24]iiiiiiiiis[5]iiiifffiiliiiiiiiiiis[11]iiiliiiiiiiiiis[37]", // Swapping lines...
    PlayerInfo[playerid][Mail],PlayerInfo[playerid][UseAlias],PlayerInfo[playerid][Alias],PlayerInfo[playerid][AdminLvl],PlayerInfo[playerid][VIP],PlayerInfo[playerid][Level],                                       // Main <1>  [1]
    PlayerInfo[playerid][Exp],PlayerInfo[playerid][Cash],PlayerInfo[playerid][Bank],PlayerInfo[playerid][Kills],PlayerInfo[playerid][Deaths],PlayerInfo[playerid][Number],                                           // Main  <2>  [2]
    PlayerInfo[playerid][CarKey],PlayerInfo[playerid][CarKeyAlt],PlayerInfo[playerid][Interest],PlayerInfo[playerid][PM_Enabled],                                                                                   // Properties  [3]
    PlayerInfo[playerid][MarkX],PlayerInfo[playerid][MarkY],PlayerInfo[playerid][MarkZ],PlayerInfo[playerid][MarkInt],PlayerInfo[playerid][MarkWorld],PlayerInfo[playerid][UseInt],PlayerInfo[playerid][SpawnPos], // Spawn Pos    [4]
    PlayerInfo[playerid][Missions],PlayerInfo[playerid][StreetRace],PlayerInfo[playerid][Hot_Wire],PlayerInfo[playerid][Cash_Box],PlayerInfo[playerid][Minigames],PlayerInfo[playerid][[Pickups]],                // Mission Stats [5]
    PlayerInfo[playerid][Team],PlayerInfo[playerid][Leader],PlayerInfo[playerid][Skin],PlayerInfo[playerid][Toolbox],PlayerInfo[playerid][LockKey],PlayerInfo[playerid][Color],PlayerInfo[playerid][Marker],     // Misc Part      [6]
    PlayerInfo[playerid][Fighting],PlayerInfo[playerid][Walking],PlayerInfo[playerid][RealCarNames],PlayerInfo[playerid][HighestDeathmatch],PlayerInfo[playerid][HighestDrift],                                 // Minor Stuff     [7]
    PlayerInfo[playerid][GunMeele],PlayerInfo[playerid][GunXXX],PlayerInfo[playerid][Pistol],PlayerInfo[playerid][PistolAmmo],PlayerInfo[playerid][Shotgun],PlayerInfo[playerid][ShotgunAmmo],                 // Weapons 'N' Ammo [8]
    PlayerInfo[playerid][SMG],PlayerInfo[playerid][SMG_Ammo],PlayerInfo[playerid][Assault],PlayerInfo[playerid][Assault_Ammo],PlayerInfo[playerid][MiscGun],PlayerInfo[playerid][MiscAmmo],PlayerInfo[playerid][Para], // TextDraw [9]
    TextDrawStyle[playerid])) // There we go, code cracked
    {
        printf("Error: RetrievePlayerData([%i] %s, [<DATA>])\n", playerid, PlayerInfo[playerid][Name]), printf("DATA: %s", data);
        return SendClientMessage(playerid, COLOR_ERROR, "There is a problem with your account, contact a staff member to get the problem fixed.");
    }
    GivePlayerMoneyEx(playerid, PlayerInfo[playerid][Cash]);
    return printf("Player %s [%i] has retrieved their stats", PlayerInfo[playerid][Name], playerid);
}
pawn Код:
SavePlayerData(playerid, what, Sx[], Si, Float:Fx=0.0, Float:Fy=0.0, Float:Fz=0.0)
{
    if(isnull(Sx)) format(Sx, sizeof(Sx), "N/A");
    switch(what)
    {
        case 0: printf("Testing <Zero Params>");
        /* Example:
        case 1:    // Strings
        case 5:   // Ints
        case 25: // Floats
        */

    }
    return printf("SavePlayerData(%s [%i], What:%i, Sx:%s, Si:%0, Fx:%0.2f, Fy:%0.2f, Fz:%0.2f", PlayerInfo[playerid][Name], playerid, what, Sx, Si, Fx, Fy, Fz);
}
Last part of code was probably meant to be worked on later, which never happened.

Problems:
  1. Can register inifinite times if i want to
  2. Can not login
  3. No saving function
I'd greatly appreciate if someone helped me getting this working


Edit: Whops, was supposed to post this in Scripting Discussion
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)