나는이 함수를 true 또는 false로 반환해야합니다. 문제는 제대로 작동하지 않는 것입니다. false를 반환하면 클라이언트 연결이 끊어지지 않으며 true를 반환하면 "console.log ('Disconnecting client ...')"나는 완전히 손실됩니다. ========================JS 노드 - mysql bools 이상한 행동
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!');
}
: :(이 Node.js를 mysql을위한 것이며
코드를 Socket.IO에 ========================================================================================================== . ========는
// 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
}
})
};