Server don't turn on.
#6

public OnPlayerConnect(playerid)
{
new query[128]; //We use this variable to format our query
GetPlayerName(playerid, Name[playerid], 24); //Getting player's name
GetPlayerIp(playerid, IP[playerid], 16); //Getting layer's IP
new mquery[1200]; //We use this variable to format our query (Maro's query)
mysql_format(mysql, mquery, sizeof(mquery),"SELECT * FROM `Bans` WHERE `pBannedPlayer` = '%s' OR `pIP` = '%s'", PlayerName(playerid), IP[playerid]); //Selecting all form the ban list to check if the player name is in the ban list.
mysql_tquery(mysql, mquery, "ThreadBan", "i", playerid);
mysql_format(mysql, query, sizeof(query),"SELECT `Password`, `ID` FROM `players` WHERE `Username` = '%e' LIMIT 1", Name[playerid]);
// - We use mysql_format instead of format because we can use an %e specifier. %e specifier escapes a string so we can avoid sql injection which means we don't have to use mysql_real_escape_string
// - Formatting our query; SELECT `Password`, `ID` FROM `players` WHERE `Username`='%e' means we are selecting a Password and ID's column in the table that has player's name in Username column.
// - LIMIT 1; we only need 1 result to be shown
mysql_tquery(mysql, query, "OnAccountCheck", "i", playerid);

//lets execute the formatted query and when the execution is done, a callback OnAccountCheck will be called
//You can name the callback however you like
return 1;
}

//OnAccountCheck is a custom callback which means it has to be forwarded.
forward OnAccountCheck(playerid);

//Now once the query has been processed;
public OnAccountCheck(playerid)
{
new rows, fields; //a variable that will be used to retrieve rows and fields in the database.
cache_get_data(rows, fields, mysql);//let's get the rows and fields from the database.
if(rows) //if there is row
{//then
cache_get_field_content(0, "Password", pInfo[playerid][Password], mysql, 40);
//we will load player's password into pInfo[playerid][Password] to be used in logging in
pInfo[playerid][ID] = cache_get_field_content_int(0, "ID"); //now let's load player's ID into pInfo[playerid][ID] so we can use it later
printf("%s", pInfo[playerid][Password]); //OPTIONAL: Just for debugging. If it didn't show your password, then there must be something wrong while getting player's password
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "PRISIJUNGIMAS","Prisijunkite: {ff0000}(Įveskite slaptažodį ir niekam jo nesakykite!)", "Jungtis", "Išeiti");//And since we found a result from the database, which means, there is an account; we will show a login dialog
}
else //if we didn't find any rows from the database, that means, no accounts were found
{
ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "REGISTRACIJA","Užsiregistruokite: {ff0000}(Įveskite jūsų sugalvotą slaptažodį ir niekam jo nesakykite!","Jungtis", "Išeiti");
//So we show them a dialog register
}
return 1;
}
Reply


Messages In This Thread
Server don't turn on. - by Er1kas - 02.11.2014, 14:01
Re: Server don't turn on. - by DanishHaq - 02.11.2014, 14:01
Re: Server don't turn on. - by Er1kas - 02.11.2014, 14:03
Re: Server don't turn on. - by Er1kas - 02.11.2014, 14:33
Re: Server don't turn on. - by Quickie - 03.11.2014, 00:13
Re: Server don't turn on. - by Er1kas - 03.11.2014, 11:05

Forum Jump:


Users browsing this thread: 1 Guest(s)