MySQL crashing server, Threaded, logging in.
#1

OnPlayerConnect
pawn Код:
format(query, sizeof(query), "SELECT `id` FROM `accounts` WHERE `PlayerName` = '%s' LIMIT 1", escape);
        mysql_function_query(dbHandle, query, true, "OnPlayerDataLoad", "i", playerid);
OnPlayerDataLoad
pawn Код:
forward OnPlayerDataLoad(playerid);
public OnPlayerDataLoad(playerid)
{
    new rows, fields;
    cache_get_data(rows, fields);
    if(!rows)
    {
        new string[256];
        format(string, sizeof(string), "Welcome to %s\n\nPlease create an account by entering a password below:", HOSTNAME);
        ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "Register Here", string, "Register", "Leave");
    }
    else
    {
        new string[256];
        format(string,sizeof(string),"Welcome to Los Santos City Roleplay.");
        SendClientMessage(playerid, COLOUR_GREY,string);
        format(string, sizeof(string), "Welcome to %s.\nPlease enter your password below:", HOSTNAME);
        new temp[12];
        cache_get_row(0, 0, temp);
        PlayerSQLID[playerid] = strval(temp);
        printf("PlayerSQLID: %d", PlayerSQLID[playerid]);
        ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Los Santos City Roleplay.", string, "Login", "Leave");
    }
    return 1;
}
pawn Код:
forward CheckPass(playerid, intext[]);
public CheckPass(playerid, intext[])
{
    new inpass[256];
    cache_get_row(0, 3, inpass);
    new buf[129];
    WP_Hash(buf, sizeof(buf), intext);
    printf("%s pass", inpass);
    new string[300];
    format(string, sizeof(string), "Welcome to %s\n\nYou entered a wrong password, please try again:", HOSTNAME);
    if(isnull(intext))return ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Please retry your password", string, "Login", "Leave");
    if(strcmp(inpass, buf, false) == 0)
    {

        LoggedIn[playerid] = 1;
        new QueryString[500];
        format(QueryString, sizeof(QueryString), "SELECT * FROM accounts WHERE `id` = %d LIMIT 1", PlayerSQLID[playerid]);
        mysql_function_query(dbHandle, QueryString, true, "LoadAccount", "i", playerid);
        new skin = GetPlayerSkinEx(playerid);
        SetSpawnInfo(playerid, 0, skin,379.7936,-2032.1964,7.8301,92.7040, 0,0,0,0,0,0);
        PlayerBanned[playerid] = MySQL_GetValue(PlayerSQLID[playerid], "Banned", "accounts");

        SpawnPlayer(playerid);
        SetCameraBehindPlayer(playerid);

        GivePlayerWeaponEx(playerid);
        AutoSaveTimer[playerid] = SetTimerEx("WeaponSaveTimer", 60000, true,"i", playerid);
        Streamer_Update(playerid);
        for(new h = 1; h < MAX_HOUSES; h++)
        {
            if(HouseOwner[h] == PlayerSQLID[playerid] && BreachedOff[h] == 1)
            {
                format(string, sizeof(string), ""COL_RED"ALERT"COL_WHITE": Your owned property, %s, detected a perimeter breach when you were offline.", HouseName[h]);
                SendClientMessage(playerid, COLOUR_WHITE, string);
                BreachedOff[h] = 0;
                MySQL_SetInteger(h, "BreachedOff", 0, "houses");

            }
        }


        if(WasDead[playerid] == 1)
        {
            new string2[128];
            format(string2, sizeof(string2), "You have been automatically admin jailed for 60 minutes, Reason: logging to avoid death.");
            SendClientMessage(playerid, COLOUR_LIGHTBLUE, string2);

            format(string2, sizeof(string2), "[Auto-Jail]%s has been admin jailed [Reason: Logging to avoid death.]", GetNameEx(playerid));
            SendClientMessageToAll(COLOUR_LIGHTBLUE, string2);

            AdminJail[playerid] += 60;
            SetPlayerPos(playerid, 264.58, 77.38, 1001.04);
            SetPlayerInterior(playerid, 6);
            SetPlayerVirtualWorld(playerid, 0);
            MySQL_SetInteger(PlayerSQLID[playerid], "AdminJail",AdminJail[playerid], "accounts");
            MySQL_SetInteger(PlayerSQLID[playerid], "WasDead", 0, "accounts");
            WasDead[playerid] = 0;
        }

        if(AdminJail[playerid] >= 1)
        {
            new string2[128];
            format(string2, sizeof(string2), "You have %d minute(s) left in Admin Jail.", AdminJail[playerid]);
            SendClientMessage(playerid, COLOUR_GREY, string2);

            SetPlayerPos(playerid, 264.58, 77.38, 1001.04);
            SetPlayerInterior(playerid, 6);
            SetPlayerVirtualWorld(playerid, 0);
        }
        if(Jail[playerid] >= 1)
        {
            SetPlayerPos(playerid, 319.5663,311.9558,999.1484);
            SetPlayerInterior(playerid, 5);
            SetPlayerVirtualWorld(playerid, 0);

            new string2[128];
            format(string2, sizeof(string2), "You still have %d minute(s) of jail time to serve.", Jail[playerid]);
            SendClientMessage(playerid, COLOUR_GREY, string2);
        }

        new param1[64], param2[64];
        if(Faction[playerid] == 0) {
            param1 = "Civilian (0)";
            param2 = "N/A";
        }
        else
        {
            strcpy(param1, FactionName[Faction[playerid]], sizeof(param1));
            switch(FRank[playerid])
            { // strcpy(dest, source, length);
                case 1: strcpy(param2, FactionRank1[Faction[playerid]], sizeof(param2));
                case 2: strcpy(param2, FactionRank2[Faction[playerid]], sizeof(param2));
                case 3: strcpy(param2, FactionRank3[Faction[playerid]], sizeof(param2));
                case 4: strcpy(param2, FactionRank4[Faction[playerid]], sizeof(param2));
                case 5: strcpy(param2, FactionRank5[Faction[playerid]], sizeof(param2));
                case 6: strcpy(param2, FactionRank6[Faction[playerid]], sizeof(param2));
                case 7: strcpy(param2, FactionRank7[Faction[playerid]], sizeof(param2));
            }
        }
        format(string, sizeof(string), "Welcome back to Los Santos City Roleplay, %s. Level: %d | Money: $%s | Admin Level: %d | Donator Level %d |", GetNameEx(playerid), PlayerLevel[playerid],AddCommas(PlayerMoney[playerid]), AdminLevel[playerid], Donator[playerid]);
        SendClientMessage(playerid, 0xFFD99FFF, string);
        format(string, sizeof(string), "Faction Name: %s | Faction Rank: %s (%d) | Rank Pay: $%s |", param1, param2, FRank[playerid], AddCommas(GetRankPay(playerid)));
        SendClientMessage(playerid, 0xFFD99FFF, string);
        format(string, sizeof(string), "Misc: Total Time Played (minutes): %d | Total House Break Ins: %d | Total Vehicle Break Ins: %d | Total Hotwires %d | Kills %d | Deaths %d |", TotalTime[playerid], TotalHouseBI[playerid], TotalVehBI[playerid], TotalHotwires[playerid], PlayerKills[playerid], PlayerDeaths[playerid]);
        SendClientMessage(playerid,0xFFD99FFF, string);
        format(string, sizeof(string), "Skills: Thief Level: %d | Crafting Level: %d", ThiefLevel[playerid], CraftingLevel[playerid]);
        SendClientMessage(playerid,0xFFD99FFF, string);

    }
    else
    {
        format(string, sizeof(string), "Welcome to %s\n\nYou entered a wrong password, please try again:", HOSTNAME);
        ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Please retry your password", string, "Login", "Leave");
    }
    return 1;
}
LOGIN

pawn Код:
if(dialogid == DIALOG_LOGIN)
    {
        if(response == 0)
        {
            Kick(playerid);
        }
        else
        {
            new query[512];
            format(query, sizeof(query), "SELECT `Password` FROM `accounts` WHERE id = %d", PlayerSQLID[playerid]);
            mysql_function_query(dbHandle, query, true, "CheckPass", "is",playerid,inputtext);
        }
    }
This is what I use to check the password, the ID returns correctly.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)