i have made an event listener for my server which listens for when someone is trying to log on, so i do an sql query and then if the info matches, it logs them on. problem is, its testing if the info matches before it runs the query so it will always return false. here is my code
player.on('checkLogin', function(data)
{
var logIn = "";
connection.query({
sql: "SELECT * FROM users WHERE username = ?",
values: [data.user] },
function(error, results, fields)
{
if (error)
{
console.log(error);
}
if(results)
{
var pass = "";
for (i = 0; i < results.length; i++)
{
pass = (results[i].password);
}
var input = crypto.createHash('md5').update(data.pass).digest("hex");
if (pass == input)
{
logIn = true;
}
}
});
if (logIn == true)
{
this.em.emit('login',
{
id: player.playerid
});
}
}.bind(this));
I heard promises will fix this but is there any easy way around this?, thanks in advance
logIn = true;with whatever code you wanted to run at the bottom.