(MySQL) Login crashes server
#1

I've been working on a test script for a few hours now, but it seems I've come face to face with a brick wall.
Whatever I do, the server crashes whenever my character logs in. Whenever it's registration, it is fine...

Code:
public OnPlayerConnect(playerid)
{
	TogglePlayerSpectating(playerid, true); // This prevents the "SPAWN << >>" arrows appearing at the bottom of a player's screen.
	SetTimerEx("ConnectionCameraSet", 1000, false, "dd", playerid);
	IsPlayerRegistered(playerid);
	return 1;
}
Code:
stock IsPlayerRegistered(playerid)
{
	new string[70];
	format(string, sizeof string, "SELECT * FROM `players` WHERE `Name` = '%s'", GetBaseName(playerid));
	mysql_query(string);
	mysql_store_result();
	if(mysql_num_rows() == 0) {
	    registerNewPlayer(playerid);
	    return 0;
	}
	else {
		printf("%s is registered.", GetBaseName(playerid));
		playerLogin(playerid);
	}
	
	return 1;
}
Code:
stock playerLogin(playerid)
{
    printf("%s is registered.", GetBaseName(playerid));
    new query[65];
    format(query, sizeof(query), "SELECT * FROM `players` WHERE `Name` = '%s'", GetBaseName(playerid));
    mysql_query(query);
    mysql_store_result();
    MySQL_LoadPlayer(playerid);
    ShowPlayerDialog(playerid, 2, DIALOG_STYLE_INPUT, "Account Login", "Please enter your account password below to proceed.", "Login", "Cancel");
}
Now, the dialog doesn't even appear, so I assume it is an issue with MySQL_LoadPlayer.

Code:
stock MySQL_LoadPlayer(playerid)
{
    new queryStr[300], pname[24], savingstring[20];
    GetPlayerName(playerid, pname, 24);
    format(queryStr, sizeof(queryStr), "SELECT * FROM `players` WHERE Name = '%s'", pname);
    mysql_query(queryStr);
    mysql_store_result();
    print("test");
    while(mysql_fetch_row_format(queryStr,"|"))
    {
        mysql_fetch_field_row(savingstring, "Password"); format(PlayerInfo[playerid][Password], 16, savingstring);
        mysql_fetch_field_row(savingstring, "TutorialStage"); PlayerInfo[playerid][TutorialStage] = strval(savingstring);
        mysql_fetch_field_row(savingstring, "Gender"); PlayerInfo[playerid][Gender] = strval(savingstring);
        mysql_fetch_field_row(savingstring, "Age"); PlayerInfo[playerid][Age] = strval(savingstring);
        mysql_fetch_field_row(savingstring, "Money"); PlayerInfo[playerid][Money] = strval(savingstring);
        mysql_fetch_field_row(savingstring, "BankMoney"); PlayerInfo[playerid][BankMoney] = strval(savingstring);
        
        mysql_fetch_field_row(savingstring, "PosX"); PlayerInfo[playerid][PosX] = floatstr(savingstring);
        mysql_fetch_field_row(savingstring, "PosY"); PlayerInfo[playerid][PosY] = floatstr(savingstring);
        mysql_fetch_field_row(savingstring, "PosZ"); PlayerInfo[playerid][PosZ] = floatstr(savingstring);
        
        mysql_fetch_field_row(savingstring, "Skin"); PlayerInfo[playerid][Skin] = strval(savingstring);
        
        
	}
	printf("%s has successfully logged in and loaded.", GetBaseName(playerid));
}
Any and all help is appreciated.
Reply
#2

pawn Code:
stock playerLogin(playerid)
{
    printf("%s is registered.", GetBaseName(playerid));
    new query[65];
    format(query, sizeof(query), "SELECT * FROM `players` WHERE `Name` = '%s'", GetBaseName(playerid));
    mysql_query(query);
    mysql_store_result();
    MySQL_LoadPlayer(playerid);
    ShowPlayerDialog(playerid, 2, DIALOG_STYLE_INPUT, "Account Login", "Please enter your account password below to proceed.", "Login", "Cancel");
}
pawn Code:
stock MySQL_LoadPlayer(playerid)
{
    new queryStr[300], pname[24], savingstring[20];
    GetPlayerName(playerid, pname, 24);
    format(queryStr, sizeof(queryStr), "SELECT * FROM `players` WHERE Name = '%s'", pname);
    mysql_query(queryStr);
    mysql_store_result();
    print("test");
    while(mysql_fetch_row_format(queryStr,"|"))
    {
        mysql_fetch_field_row(savingstring, "Password"); format(PlayerInfo[playerid][Password], 16, savingstring);
        mysql_fetch_field_row(savingstring, "TutorialStage"); PlayerInfo[playerid][TutorialStage] = strval(savingstring);
        mysql_fetch_field_row(savingstring, "Gender"); PlayerInfo[playerid][Gender] = strval(savingstring);
        mysql_fetch_field_row(savingstring, "Age"); PlayerInfo[playerid][Age] = strval(savingstring);
        mysql_fetch_field_row(savingstring, "Money"); PlayerInfo[playerid][Money] = strval(savingstring);
        mysql_fetch_field_row(savingstring, "BankMoney"); PlayerInfo[playerid][BankMoney] = strval(savingstring);
       
        mysql_fetch_field_row(savingstring, "PosX"); PlayerInfo[playerid][PosX] = floatstr(savingstring);
        mysql_fetch_field_row(savingstring, "PosY"); PlayerInfo[playerid][PosY] = floatstr(savingstring);
        mysql_fetch_field_row(savingstring, "PosZ"); PlayerInfo[playerid][PosZ] = floatstr(savingstring);
       
        mysql_fetch_field_row(savingstring, "Skin"); PlayerInfo[playerid][Skin] = strval(savingstring);
       
       
    }
    printf("%s has successfully logged in and loaded.", GetBaseName(playerid));
}
Why you select the data twice ?
Reply
#3

I don't know, I didn't realize.
I've removed it now.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)