mirror of
https://codeberg.org/spire/webrcon.git
synced 2026-06-03 09:14:06 +02:00
add disconnect and improved error handling
This commit is contained in:
parent
937a328b6b
commit
b77b780331
3 changed files with 21 additions and 0 deletions
|
|
@ -5,6 +5,9 @@
|
|||
"license": "MIT",
|
||||
"version": "0.1.1",
|
||||
"main": "lib/rcon.js",
|
||||
"scripts": {
|
||||
"build": "babel src --out-dir lib"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/spiretf/webrcon"
|
||||
|
|
|
|||
|
|
@ -11,10 +11,15 @@ export default class Connection {
|
|||
constructor (host, password) {
|
||||
this.host = host;
|
||||
this.password = password;
|
||||
this.errorListeners = [];
|
||||
|
||||
this.init();
|
||||
}
|
||||
|
||||
onError (listener) {
|
||||
this.errorListeners.push(listener);
|
||||
}
|
||||
|
||||
buildRcon () {
|
||||
if (this.rcon) {
|
||||
return;
|
||||
|
|
@ -45,6 +50,11 @@ export default class Connection {
|
|||
}, 100);
|
||||
});
|
||||
this.rcon.on('error', (e) => {
|
||||
if (e == 'not authenticated') {
|
||||
for (let listener of this.errorListeners) {
|
||||
listener(e);
|
||||
}
|
||||
}
|
||||
this.errorCount++;
|
||||
console.log('failed to connect ' + this.errorCount + ' times (' + e + ')');
|
||||
Promise.delay(2500).then(() => {
|
||||
|
|
|
|||
|
|
@ -9,6 +9,14 @@ export default class Rcon {
|
|||
this.connection = new Connection(host, password);
|
||||
}
|
||||
|
||||
disconnect () {
|
||||
this.connection.disconnect();
|
||||
}
|
||||
|
||||
onError (listener) {
|
||||
this.connection.onError(listener);
|
||||
}
|
||||
|
||||
sendString (command) {
|
||||
return this.connection.sendString(command);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue