mirror of
https://github.com/unmojang/node-minecraft-protocol.git
synced 2025-09-29 14:13:45 -04:00
Add checkTimeoutInterval
This commit is contained in:
parent
0569f51d61
commit
df8cfa5c4c
@ -1,5 +1,9 @@
|
|||||||
# History
|
# History
|
||||||
|
|
||||||
|
## 0.16.1 (unreleased)
|
||||||
|
|
||||||
|
* add checkTimeoutInterval to createClient
|
||||||
|
|
||||||
## 0.16.0
|
## 0.16.0
|
||||||
|
|
||||||
* cross version support exposed : version option in createClient and createServer
|
* cross version support exposed : version option in createClient and createServer
|
||||||
|
@ -72,6 +72,7 @@ Returns a `Client` instance and perform login.
|
|||||||
* clientToken : generated if a password is given
|
* clientToken : generated if a password is given
|
||||||
* accessToken : generated if a password is given
|
* accessToken : generated if a password is given
|
||||||
* keepAlive : send keep alive packets : default to true
|
* keepAlive : send keep alive packets : default to true
|
||||||
|
* checkTimeoutInterval : default to `10*1000` (10s), check if keepalive received at that period, disconnect otherwise.
|
||||||
* version : 1.8 or 1.9 : default to 1.8
|
* version : 1.8 or 1.9 : default to 1.8
|
||||||
|
|
||||||
## mc.Client(isServer,version)
|
## mc.Client(isServer,version)
|
||||||
|
@ -37,6 +37,7 @@ function createClient(options) {
|
|||||||
assert.ok(options.username, "username is required");
|
assert.ok(options.username, "username is required");
|
||||||
var haveCredentials = options.password != null || (clientToken != null && options.session != null);
|
var haveCredentials = options.password != null || (clientToken != null && options.session != null);
|
||||||
var keepAlive = options.keepAlive == null ? true : options.keepAlive;
|
var keepAlive = options.keepAlive == null ? true : options.keepAlive;
|
||||||
|
var checkTimeoutInterval = options.checkTimeoutInterval || 10 * 1000;
|
||||||
|
|
||||||
var optVersion = options.version || require("./version").defaultVersion;
|
var optVersion = options.version || require("./version").defaultVersion;
|
||||||
var mcData=require("minecraft-data")(optVersion);
|
var mcData=require("minecraft-data")(optVersion);
|
||||||
@ -103,8 +104,11 @@ function createClient(options) {
|
|||||||
function onCompressionRequest(packet) {
|
function onCompressionRequest(packet) {
|
||||||
client.compressionThreshold = packet.threshold;
|
client.compressionThreshold = packet.threshold;
|
||||||
}
|
}
|
||||||
|
var timeout = null;
|
||||||
function onKeepAlive(packet) {
|
function onKeepAlive(packet) {
|
||||||
|
if (timeout)
|
||||||
|
clearTimeout(timeout);
|
||||||
|
timeout = setTimeout(() => client.end(), checkTimeoutInterval);
|
||||||
client.write('keep_alive', {
|
client.write('keep_alive', {
|
||||||
keepAliveId: packet.keepAliveId
|
keepAliveId: packet.keepAliveId
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user