Added error handling
This commit is contained in:
parent
dbd77dde34
commit
e9c9ca8d34
@ -50,41 +50,46 @@ class RconManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async connect(server_id, server) {
|
async connect(server_id, server) {
|
||||||
let rcon_connection = null;
|
|
||||||
rcon_connection = new Rcon({ host: server.serverIP, port: server.serverPort, timeout: 5000 });
|
|
||||||
console.log("CONNECTING RCON", server_id, server.serverIP, server.serverPort);
|
|
||||||
|
|
||||||
// Set a timeout for the authentication process
|
|
||||||
const authenticationTimeout = setTimeout(async () => {
|
|
||||||
console.error('RCON Authentication timed out', server_id);
|
|
||||||
try {
|
|
||||||
await this.disconnect_rcon(server_id); // Disconnect the RCON connection
|
|
||||||
console.log('Timed out, disconnected RCON', server_id);
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error disconnecting RCON', server_id, error);
|
|
||||||
}
|
|
||||||
}, 10000);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await rcon_connection.authenticate(server.rconPassword);
|
let rcon_connection = null;
|
||||||
clearTimeout(authenticationTimeout);
|
rcon_connection = new Rcon({ host: server.serverIP, port: server.serverPort, timeout: 5000 });
|
||||||
console.log('RCON Authenticated', server_id, server.serverIP, server.serverPort);
|
console.log("CONNECTING RCON", server_id, server.serverIP, server.serverPort);
|
||||||
} catch (error) {
|
|
||||||
clearTimeout(authenticationTimeout);
|
|
||||||
console.error('RCON Authentication failed', server_id, error);
|
|
||||||
// Handle the authentication error here as needed.
|
|
||||||
}
|
|
||||||
|
|
||||||
this.rcons[server_id] = rcon_connection;
|
// Set a timeout for the authentication process
|
||||||
this.details[server_id] = {
|
const authenticationTimeout = setTimeout(async () => {
|
||||||
host: server.serverIP,
|
console.error('RCON Authentication timed out', server_id);
|
||||||
port: server.serverPort,
|
try {
|
||||||
rcon_password: server.rconPassword,
|
await this.disconnect_rcon(server_id); // Disconnect the RCON connection
|
||||||
connected: rcon_connection.isConnected(),
|
console.log('Timed out, disconnected RCON', server_id);
|
||||||
authenticated: rcon_connection.isAuthenticated()
|
} catch (error) {
|
||||||
};
|
console.error('Error disconnecting RCON', server_id, error);
|
||||||
this.details[server_id].heartbeat_interval = setInterval(async () => this.send_heartbeat(server_id, server), 5000);
|
}
|
||||||
return;
|
}, 10000);
|
||||||
|
|
||||||
|
try {
|
||||||
|
await rcon_connection.authenticate(server.rconPassword);
|
||||||
|
clearTimeout(authenticationTimeout);
|
||||||
|
console.log('RCON Authenticated', server_id, server.serverIP, server.serverPort);
|
||||||
|
} catch (error) {
|
||||||
|
clearTimeout(authenticationTimeout);
|
||||||
|
console.error('RCON Authentication failed', server_id, error);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.rcons[server_id] = rcon_connection;
|
||||||
|
this.details[server_id] = {
|
||||||
|
host: server.serverIP,
|
||||||
|
port: server.serverPort,
|
||||||
|
rcon_password: server.rconPassword,
|
||||||
|
connected: rcon_connection.isConnected(),
|
||||||
|
authenticated: rcon_connection.isAuthenticated()
|
||||||
|
};
|
||||||
|
if (rcon_connection.isConnected() && rcon_connection.isAuthenticated()) {
|
||||||
|
this.details[server_id].heartbeat_interval = setInterval(async () => this.send_heartbeat(server_id, server), 5000);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
} catch (error) {
|
||||||
|
console.error('[CONNECTION ERROR]', error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async disconnect_rcon(server_id) {
|
async disconnect_rcon(server_id) {
|
||||||
|
@ -282,14 +282,18 @@ function execute_cfg_on_server(server_id, cfg_path) {
|
|||||||
const exported_lines = splitByByteLength(data, 512)
|
const exported_lines = splitByByteLength(data, 512)
|
||||||
|
|
||||||
function execute_next_item(item) {
|
function execute_next_item(item) {
|
||||||
if (item < exported_lines.length) {
|
try {
|
||||||
console.log(exported_lines[item]);
|
if (item < exported_lines.length) {
|
||||||
rcon.rcons[server_id].execute(exported_lines[item]);
|
console.log(exported_lines[item]);
|
||||||
|
rcon.rcons[server_id].execute(exported_lines[item]);
|
||||||
|
|
||||||
// Wait for 200ms before moving to the next iteration
|
// Wait for 200ms before moving to the next iteration
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
execute_next_item(item + 1);
|
execute_next_item(item + 1);
|
||||||
}, 200);
|
}, 200);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.log("[execute_next_item] Error:", error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
execute_next_item(0);
|
execute_next_item(0);
|
||||||
|
Loading…
Reference in New Issue
Block a user