diff --git a/Server/utilities/mysqlHandler.js b/Server/utilities/mysqlHandler.js index 6cbcba3..2c49041 100644 --- a/Server/utilities/mysqlHandler.js +++ b/Server/utilities/mysqlHandler.js @@ -30,7 +30,8 @@ function returnNodeObjectFromRow(row) { _port: row.port, _location: row.location, _nearbySystems: BufferToJson(row.nearbySystems), - _online: row.online + _online: (row.online === 1) ? true : false, + _connected: (row.connected === 1) ? true : false }); } @@ -113,8 +114,9 @@ exports.addNewNode = (nodeObject, callback) => { port = nodeObject.port, location = nodeObject.location, nearbySystems = utils.JsonToBuffer(nodeObject.nearbySystems), - online = nodeObject.online; - const sqlQuery = `INSERT INTO ${nodesTable} (name, ip, port, location, nearbySystems, online) VALUES ('${name}', '${ip}', ${port}, '${location}', '${nearbySystems}', ${online})`; + online = nodeObject.online, + connected = 0; + const sqlQuery = `INSERT INTO ${nodesTable} (name, ip, port, location, nearbySystems, online, connected) VALUES ('${name}', '${ip}', ${port}, '${location}', '${nearbySystems}', ${online}, ${connected})`; runSQL(sqlQuery, (rows) => { return callback(returnNodeObjectFromRows(rows)); @@ -125,13 +127,14 @@ exports.addNewNode = (nodeObject, callback) => { * @param nodeObject Node information object * @param callback Callback function */ -exports.updateNodeInfo = (nodeObject, callback) => { +exports.updateNodeInfo = (nodeObject, callback = undefined) => { if(!nodeObject.id) throw new Error("Attempted to updated node without providing ID", nodeObject); const name = nodeObject.name, ip = nodeObject.ip, port = nodeObject.port, location = nodeObject.location, - online = nodeObject.online; + online = nodeObject.online, + connected = nodeObject.connected; let queryParams = [], nearbySystems = nodeObject.nearbySystems; @@ -147,9 +150,13 @@ exports.updateNodeInfo = (nodeObject, callback) => { if (online || online === 1) queryParams.push(`online = 1`); else queryParams.push(`online = 0`); } + if (typeof connected === "boolean" || typeof connected === "number") { + if (online || online === 1) queryParams.push(`connected = 1`); + else queryParams.push(`connected = 0`); + } let sqlQuery = `UPDATE ${nodesTable} SET` - if (!queryParams || queryParams.length === 0) return callback(undefined); + if (!queryParams || queryParams.length === 0) return (callback) ? callback(undefined) : undefined; if (queryParams.length === 1) { sqlQuery = `${sqlQuery} ${queryParams[0]}` } else { @@ -169,8 +176,8 @@ exports.updateNodeInfo = (nodeObject, callback) => { sqlQuery = `${sqlQuery} WHERE id = ${nodeObject.id};` runSQL(sqlQuery, (rows) => { - if (rows.affectedRows === 1) return callback(true); - else return callback(returnNodeObjectFromRows(rows)); + if (rows.affectedRows === 1) return (callback) ? callback(true) : true; + else return (callback) ? callback(returnNodeObjectFromRows(rows)) : returnNodeObjectFromRows(rows); }) } diff --git a/Server/utilities/recordHelper.js b/Server/utilities/recordHelper.js index 852d256..f8050e7 100644 --- a/Server/utilities/recordHelper.js +++ b/Server/utilities/recordHelper.js @@ -109,10 +109,11 @@ class nodeObject { * @param {*} param0._ip The IP that the master can contact the node at * @param {*} param0._port The port that the client is listening on * @param {*} param0._location The physical location of the node - * @param {*} param0._online An integer representation of the online status of the bot, ie 0=off, 1=on - * @param {*} param0._nearbySystems An object array of nearby systems + * @param {*} param0._online True/False if the node is online or offline + * @param {*} param0._connected True/False if the bot is connected to discord or not + * @param {*} param0._nearbySystems An object array of nearby systems */ - constructor({ _id = null, _name = null, _ip = null, _port = null, _location = null, _nearbySystems = null, _online = null }) { + constructor({ _id = null, _name = null, _ip = null, _port = null, _location = null, _nearbySystems = null, _online = null, _connected = null }) { this.id = _id; this.name = _name; this.ip = _ip; @@ -120,6 +121,7 @@ class nodeObject { this.location = _location; this.nearbySystems = _nearbySystems; this.online = _online; + this.connected = _connected; } }