feat(protocols/sdtd): add telnet support for players (#692)

* feat(protocols/sdtd): add telnet support

* docs: update CHANGELOG.md
This commit is contained in:
CosminPerRam 2025-04-27 17:06:23 +03:00 committed by GitHub
parent 4db8a473ff
commit 71ce074866
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 159 additions and 5 deletions

View file

@ -7,6 +7,7 @@ import Logger from '../lib/Logger.js'
import DnsResolver from '../lib/DnsResolver.js'
import { Results } from '../lib/Results.js'
import Promises from '../lib/Promises.js'
import { Telnet } from 'telnet-client'
let uid = 0
@ -27,6 +28,8 @@ export default class Core extends EventEmitter {
this.udpSocket = null
this.shortestRTT = 0
this.usedTcp = false
this.telnetClient = new Telnet()
}
// Runs a single attempt with a timeout and cleans up afterward
@ -336,4 +339,23 @@ export default class Core extends EventEmitter {
requestPromise?.cancel()
}
}
async telnetConnect (params) {
await this.telnetClient.connect({
timeout: 2000,
execTimeout: 2000,
host: this.options.host,
debug: this.debugEnabled,
...params
})
}
async telnetExecute (command) {
return await this.telnetClient.exec(command)
}
async telnetClose () {
await this.telnetClient.end()
await this.telnetClient.destroy()
}
}