diff --git a/Anetha/helpers.js b/Anetha/helpers.js new file mode 100644 index 0000000..e88b204 --- /dev/null +++ b/Anetha/helpers.js @@ -0,0 +1,52 @@ +let wss; +const orm = require('../models/index.model'); +const {v4: uuid} = require('uuid'); + + + +function invoke(command, params, dongleId, accountId) { + const websocket = wss.retropilotFunc.findFromDongle(dongleId); + + if (!websocket) { + wss.retropilotFunc.actionLogger(accountId, null, "ATHENA_USER_INVOKE__FAILED_DISCONNECTED", null, null, null, dongleId); + return { connected: false } + } + const uniqueID = uuid(); + + wss.retropilotFunc.actionLogger(accountId, websocket.device_id, "ATHENA_USER_INVOKE__ISSUED", null, websocket._socket.remoteAddress, JSON.stringify({ command, params, uniqueID }), websocket.dongleId); + + + orm.models.athena_returned_data.create({ + device_id: websocket.device_id, + type: command, + created_at: Date.now(), + uuid: uniqueID + }) + + + websocket.send(JSON.stringify(wss.retropilotFunc.commandBuilder(command, params, uniqueID))) + + return { dispatched: true, heartbeat: websocket.heartbeat, id: uniqueID } + +} + + +function isDeviceConnected(accountId, deviceId, dongleId) { + const websocket = wss.retropilotFunc.findFromDongle(dongleId); + wss.retropilotFunc.actionLogger(accountId, deviceId, "ATHENA_USER_STATUS__IS_CONNECTED", null, websocket ? websocket._socket.remoteAddress : null, JSON.stringify({ connected: websocket ? true : false, heartbeat: websocket ? websocket.heartbeat : null }), dongleId); + + if (!websocket) return { connected: false } + + return { connected: true, heartbeat: websocket.heartbeat }; +} + + + +module.exports = (websocketServer) => { + wss = websocketServer; + + return { + isDeviceConnected, + invoke + } +} diff --git a/ecosystem.config.js b/ecosystem.config.js new file mode 100644 index 0000000..8fa1f23 --- /dev/null +++ b/ecosystem.config.js @@ -0,0 +1,10 @@ +module.exports = { + apps : [{ + name : "Retropilot Service", + script : "./server.js", + + env_development: { + NODE_ENV: "development", + } + }], +} diff --git a/exit b/exit new file mode 100644 index 0000000..53f6255 --- /dev/null +++ b/exit @@ -0,0 +1,133 @@ +commit 751742acf6acd427573ca5e943b86b3ad6ec762a (HEAD -> dev, origin/dev) +Reflog: HEAD@{0} (AdamSBlack ) +Reflog message: commit: updated readme +Author: AdamSBlack +Date: Fri Oct 29 21:46:48 2021 +0100 + + updated readme + +commit f4cb1ef1424c263e441522ce4915efac353d9227 +Reflog: HEAD@{1} (AdamSBlack ) +Reflog message: commit: Athena, logging, etc +Author: AdamSBlack +Date: Fri Oct 29 21:45:15 2021 +0100 + + Athena, logging, etc + +commit 32325111c6bd2d0b6f7e583be45032e33290233a (main) +Reflog: HEAD@{2} (AdamSBlack ) +Reflog message: checkout: moving from main to dev +Author: AdamSBlack +Date: Tue Oct 26 23:38:31 2021 +0100 + + Added new tables to database, + added logging to athena + +commit 32325111c6bd2d0b6f7e583be45032e33290233a (main) +Reflog: HEAD@{3} (AdamSBlack ) +Reflog message: commit: Added new tables to database, +Author: AdamSBlack +Date: Tue Oct 26 23:38:31 2021 +0100 + + Added new tables to database, + added logging to athena + +commit 9361043d836e821499fade16537a7091169ce5e3 +Reflog: HEAD@{4} (AdamSBlack ) +Reflog message: commit: Added proof of concept for Athena +Author: AdamSBlack +Date: Mon Oct 25 22:56:40 2021 +0100 + + Added proof of concept for Athena + +commit 4075e5730a3a74610da52b95e0c9f83c65efb40a (origin/main, origin/HEAD) +Reflog: HEAD@{5} (AdamSBlack ) +Reflog message: commit: Fixed admin API's middleware to not filter through +Author: AdamSBlack +Date: Wed Oct 13 19:06:46 2021 +0100 + + Fixed admin API's middleware to not filter through + other routes + +commit 3596013e2fc868636243d04220f24a70b3ad8207 +Reflog: HEAD@{6} (AdamSBlack ) +Reflog message: commit: TODO: Fix admin api auth catching any undefined routes +Author: AdamSBlack +Date: Mon Oct 11 19:37:58 2021 +0100 + + TODO: Fix admin api auth catching any undefined routes + Removed pointlessly stateful controllers, admin api fleshed out + +commit e33b10e7d0e7954c6a1e649a958317662d8d303f +Reflog: HEAD@{7} (AdamSBlack ) +Reflog message: commit: disable useradminapi +Author: AdamSBlack +Date: Sun Oct 3 17:48:52 2021 +0100 + + disable useradminapi + +commit acf084743df3e868af0f4733f0db38818e93216c +Reflog: HEAD@{8} (AdamSBlack ) +Reflog message: commit: updated database, sessions managed via signed JWT +Author: AdamSBlack +Date: Sun Oct 3 17:44:43 2021 +0100 + + updated database, sessions managed via signed JWT + token. + + TODO: sign tokens based user unique token, instead of + global salt key + +commit 7590e9b64473d8a0e59fdba072262f7e0efee517 +Reflog: HEAD@{9} (AdamSBlack ) +Reflog message: commit: userAdminApi now allows users to change their +Author: AdamSBlack +Date: Sun Oct 3 15:35:44 2021 +0100 + + userAdminApi now allows users to change their + password + +commit f642360a5d6cb3015082041f805ef04ba51631c1 +Reflog: HEAD@{10} (AdamSBlack ) +Reflog message: commit: Device pair logic removed from route +Author: AdamSBlack +Date: Sun Oct 3 14:11:34 2021 +0100 + + Device pair logic removed from route + and moved into devices controller using + ORM now, not 100% tested + +commit aaedd0bfd6db7a699640345d1444e686fa059d36 +Reflog: HEAD@{11} (AdamSBlack ) +Reflog message: commit: minor +Author: AdamSBlack +Date: Sun Oct 3 00:08:21 2021 +0100 + + minor + +commit f5a0fc8c0dcac6edb3c63950cd319c0ae34a7e3e +Reflog: HEAD@{12} (AdamSBlack ) +Reflog message: commit: include new models +Author: AdamSBlack +Date: Sat Oct 2 23:11:51 2021 +0100 + + include new models + +commit cbea324a05abc8d65d26506aeb14c4c346dcf068 +Reflog: HEAD@{13} (AdamSBlack ) +Reflog message: commit: Implemented Sequelize ORM, moved over users.js +Author: AdamSBlack +Date: Sat Oct 2 23:08:56 2021 +0100 + + Implemented Sequelize ORM, moved over users.js + to new ORM + +commit 6521cda85a69ad4442ffb55ddcf46e86f947adfa +Reflog: HEAD@{14} (AdamSBlack ) +Reflog message: clone: from https://github.com/AdamSBlack/retropilot-server.git +Author: AdamSBlack +Date: Thu Sep 30 20:18:37 2021 +0100 + + Created branch "cursed" + + Modified pairing to support new registrations