true または false を返す必要があるこの関数があります。問題は、正しく動作していないように見えることです。false が返された場合、クライアントは切断されず、true が返された場合でも "console.log('Disconnecting client...')" が実行されます。私は完全に途方に暮れています。:(これはnode.js mysqlおよびsocket.io用です
コード:
if(!client_to_server_00(header,data,len)){
// should send the server a packet to terminate the connection on
their end...
// It should send 0x00 SERVER->CLIENT (will implement later)
console.log('Disconnecting client...'); // This always shows no matter what
client.emit('disconnect'); // **This does not work!
}else{
console.log('ID VERIFIED! WELCOME!');
}
================================================== ================================
// LOGIN INFORMATION
function client_to_server_00(header, data, len){
// We are already connected to the database
var z = decodeFromHex(data); // find the username
z = returnvalue(z,1,len); // the code was a little off (ill fix it later)
console.log(z); // make sure we have this correct
// In this example. The database returns 'oh' And z = 'oh'
client.query('USE '+TEST_DATABASE);
client.query(
'SELECT * FROM '+TEST_TABLE,
function selectCb(err, results, fields) {
if (err) {
throw err;
}
var first = results[0];
console.log('USRNAME: ['+first['name']+']'); // Make sure we have it
if(first['name'] == z){
console.log('Correct');
return true; // I need client_to_server_00 function to return true if correct
}else{
console.log('Incorrect');
return false; // I need client_to_server_00 function to return false if incorrect
}
})
};