Adding Server Checkin

- Update client handler to check IP
- Add checkin to startup
- Add acceptable commands
- Needs linux command
- Needs testing
This commit is contained in:
Logan Cusano
2023-04-30 04:42:04 -04:00
parent 95c99971a2
commit 0cefdba00f
4 changed files with 39 additions and 4 deletions

View File

@@ -1,9 +1,11 @@
// Debug
// const { DebugBuilder } = require("../utilities/debugBuilder.js");
// const log = new DebugBuilder("client", "clientController");
const { DebugBuilder } = require("../utilities/debugBuilder.js");
const log = new DebugBuilder("client", "clientController");
// Configs
const config = require("../config/clientConfig");
const modes = require("../config/modes");
// Modules
const { executeAsyncConsoleCommand } = require("../utilities/executeConsoleCommands.js");
// Utilities
const updateConfig = require("../utilities/updateConfig");
const updatePreset = require("../utilities/updatePresets");
@@ -29,6 +31,34 @@ function checkBodyForPresetFields(req, res, callback) {
return callback();
}
async function checkLocalIP() {
let ipAddr;
if (process.platform === "win32") {
// Windows
var networkConfig = executeAsyncConsoleCommand("ipconfig");
log.DEBUG('Network Config: ', networkConfig);
var networkConfigLines = networkConfig.split("\n").filter(line => {
if (!line.includes(":")) return false;
line = line.split(":");
if (!line.length === 2) return false;
return true;
}).map(line => {
line = line.split(':');
line[0] = line[0].replace(".", "");
return line;
});
log.DEBUG("Parsed IP Config Results: ", networkConfigLines);
return networkConfigLines['IPv4 Address'];
}
else {
// Linux
var networkConfig = executeAsyncConsoleCommand("ip addr");
}
}
/** Check in with the server
* If the bot has a saved ID, check in with the server to update any information or just check back in
* If the bot does not have a saved ID, it will attempt to request a new ID from the server
@@ -40,6 +70,7 @@ exports.checkIn = async () => {
// ID was not found in the config, creating a new node
reqOptions = new requests.requestOptions("/nodes/newNode", "POST");
delete config.clientConfig.id;
client.clientConfig.ip = checkLocalIP();
requests.sendHttpRequest(reqOptions, JSON.stringify(config.clientConfig), (responseObject) => {
// Update the client's ID if the server accepted it
if (responseObject.statusCode === 202) {