mirror of
https://github.com/unmojang/node-minecraft-protocol.git
synced 2025-09-29 14:13:45 -04:00
Move onKeepAlive to client/keepalive
This commit is contained in:
parent
cbaaeb8eb2
commit
a727829a98
15
src/client/keepalive.js
Normal file
15
src/client/keepalive.js
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
module.exports = function(client) {
|
||||||
|
client.on('keep_alive', onKeepAlive);
|
||||||
|
|
||||||
|
var timeout = null;
|
||||||
|
|
||||||
|
function onKeepAlive(packet) {
|
||||||
|
if (timeout)
|
||||||
|
clearTimeout(timeout);
|
||||||
|
timeout = setTimeout(() => client.end(), checkTimeoutInterval);
|
||||||
|
client.write('keep_alive', {
|
||||||
|
keepAliveId: packet.keepAliveId
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
@ -8,6 +8,7 @@ var states = require("./states");
|
|||||||
var debug = require("./debug");
|
var debug = require("./debug");
|
||||||
var UUID = require('uuid-1345');
|
var UUID = require('uuid-1345');
|
||||||
var encrypt = require('./client/encrypt');
|
var encrypt = require('./client/encrypt');
|
||||||
|
var keepalive = require('./client/keepalive');
|
||||||
|
|
||||||
module.exports=createClient;
|
module.exports=createClient;
|
||||||
|
|
||||||
@ -45,7 +46,7 @@ function createClient(options) {
|
|||||||
|
|
||||||
var client = new Client(false,version.majorVersion);
|
var client = new Client(false,version.majorVersion);
|
||||||
client.on('connect', onConnect);
|
client.on('connect', onConnect);
|
||||||
if(keepAlive) client.on('keep_alive', onKeepAlive);
|
if(keepAlive) keepalive(client);
|
||||||
encrypt(client);
|
encrypt(client);
|
||||||
client.once('success', onLogin);
|
client.once('success', onLogin);
|
||||||
client.once("compress", onCompressionRequest);
|
client.once("compress", onCompressionRequest);
|
||||||
@ -85,7 +86,6 @@ function createClient(options) {
|
|||||||
client.connect(port, host);
|
client.connect(port, host);
|
||||||
}
|
}
|
||||||
|
|
||||||
var timeout = null;
|
|
||||||
return client;
|
return client;
|
||||||
|
|
||||||
function onConnect() {
|
function onConnect() {
|
||||||
@ -104,14 +104,6 @@ function createClient(options) {
|
|||||||
function onCompressionRequest(packet) {
|
function onCompressionRequest(packet) {
|
||||||
client.compressionThreshold = packet.threshold;
|
client.compressionThreshold = packet.threshold;
|
||||||
}
|
}
|
||||||
function onKeepAlive(packet) {
|
|
||||||
if (timeout)
|
|
||||||
clearTimeout(timeout);
|
|
||||||
timeout = setTimeout(() => client.end(), checkTimeoutInterval);
|
|
||||||
client.write('keep_alive', {
|
|
||||||
keepAliveId: packet.keepAliveId
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function onLogin(packet) {
|
function onLogin(packet) {
|
||||||
client.state = states.PLAY;
|
client.state = states.PLAY;
|
||||||
@ -119,17 +111,3 @@ function createClient(options) {
|
|||||||
client.username = packet.username;
|
client.username = packet.username;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function mcPubKeyToURsa(mcPubKeyBuffer) {
|
|
||||||
var pem = "-----BEGIN PUBLIC KEY-----\n";
|
|
||||||
var base64PubKey = mcPubKeyBuffer.toString('base64');
|
|
||||||
var maxLineLength = 65;
|
|
||||||
while(base64PubKey.length > 0) {
|
|
||||||
pem += base64PubKey.substring(0, maxLineLength) + "\n";
|
|
||||||
base64PubKey = base64PubKey.substring(maxLineLength);
|
|
||||||
}
|
|
||||||
pem += "-----END PUBLIC KEY-----\n";
|
|
||||||
return ursa.createPublicKey(pem, 'utf8');
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user