mirror of
https://github.com/PrismarineJS/node-minecraft-protocol.git
synced 2024-11-30 03:05:37 -05:00
added hook for before client receives ping
createServer takes additional option 'beforePing' which is a function receiving the response to send back to the client and the client object, and returning a modified response to send back. The client now has the serverHost, serverPort, and protocolVersion pulled from the handshake packet. This can be used to proxy the client to different backend servers depending on the domain name.
This commit is contained in:
parent
273f685267
commit
a773bb13e7
1 changed files with 10 additions and 0 deletions
10
src/index.js
10
src/index.js
|
@ -44,6 +44,9 @@ function createServer(options) {
|
|||
var kickTimeout = options.kickTimeout || 10 * 1000;
|
||||
var checkTimeoutInterval = options.checkTimeoutInterval || 4 * 1000;
|
||||
var onlineMode = options['online-mode'] == null ? true : options['online-mode'];
|
||||
// a function receiving the default status object and the client
|
||||
// and returning a modified response object.
|
||||
var beforePing = options.beforePing || null;
|
||||
|
||||
var serverKey = ursa.generatePrivateKey(1024);
|
||||
|
||||
|
@ -117,6 +120,10 @@ function createServer(options) {
|
|||
"favicon": server.favicon
|
||||
};
|
||||
|
||||
if (beforePing) {
|
||||
response = beforePing(response, client) || response;
|
||||
}
|
||||
|
||||
client.once([states.STATUS, 0x01], function(packet) {
|
||||
client.write(0x01, { time: packet.time });
|
||||
client.end();
|
||||
|
@ -151,6 +158,9 @@ function createServer(options) {
|
|||
}
|
||||
|
||||
function onHandshake(packet) {
|
||||
client.serverHost = packet.serverHost;
|
||||
client.serverPort = packet.serverPort;
|
||||
client.protocolVersion = packet.protocolVersion;
|
||||
if (packet.nextState == 1) {
|
||||
client.state = states.STATUS;
|
||||
} else if (packet.nextState == 2) {
|
||||
|
|
Loading…
Reference in a new issue