mirror of
https://github.com/unmojang/node-minecraft-protocol.git
synced 2025-09-29 22:23:21 -04:00
writePacket -> write
This commit is contained in:
parent
f70110a646
commit
62e66be053
@ -25,9 +25,7 @@ Supports Minecraft version 1.4.7pre
|
||||
|
||||
## Usage
|
||||
|
||||
### Echo example
|
||||
|
||||
Listen for chat messages and echo them back.
|
||||
### Echo client example
|
||||
|
||||
```js
|
||||
var mc = require('minecraft-protocol');
|
||||
@ -39,8 +37,9 @@ var client = mc.createClient({
|
||||
password: "12345678", // online-mode=true servers
|
||||
});
|
||||
client.on(0x03, function(packet) {
|
||||
// Listen for chat messages and echo them back.
|
||||
if (packet.message.indexOf(client.session.username) !== -1) return;
|
||||
client.writePacket(0x03, {
|
||||
client.write(0x03, {
|
||||
message: packet.message,
|
||||
});
|
||||
});
|
||||
|
@ -14,5 +14,5 @@ client.on(0x03, function(packet) {
|
||||
var username = match[1];
|
||||
var msg = match[2];
|
||||
if (username === client.username) return;
|
||||
client.writePacket(0x03, {message: msg});
|
||||
client.write(0x03, {message: msg});
|
||||
});
|
14
index.js
14
index.js
@ -26,7 +26,7 @@ function createClient(options) {
|
||||
var client = new Client();
|
||||
client.username = options.username;
|
||||
client.on('connect', function() {
|
||||
client.writePacket(0x02, {
|
||||
client.write(0x02, {
|
||||
protocolVersion: packets.meta.protocolVersion,
|
||||
username: options.username,
|
||||
serverHost: host,
|
||||
@ -34,14 +34,14 @@ function createClient(options) {
|
||||
});
|
||||
});
|
||||
client.on(0x00, onKeepAlive);
|
||||
client.on(0xFC, onEncryptionKeyResponse);
|
||||
client.on(0xFD, onEncryptionKeyRequest);
|
||||
client.once(0xFC, onEncryptionKeyResponse);
|
||||
client.once(0xFD, onEncryptionKeyRequest);
|
||||
client.connect(port, host);
|
||||
|
||||
return client;
|
||||
|
||||
function onKeepAlive(packet) {
|
||||
client.writePacket(0x00, {
|
||||
client.write(0x00, {
|
||||
keepAliveId: packet.keepAliveId
|
||||
});
|
||||
}
|
||||
@ -120,7 +120,7 @@ function createClient(options) {
|
||||
var encryptedVerifyTokenBuffer = new Buffer(encryptedVerifyToken, 'base64');
|
||||
client.cipher = crypto.createCipheriv('aes-128-cfb8', sharedSecret, sharedSecret);
|
||||
client.decipher = crypto.createDecipheriv('aes-128-cfb8', sharedSecret, sharedSecret);
|
||||
client.writePacket(0xfc, {
|
||||
client.write(0xfc, {
|
||||
sharedSecret: encryptedSharedSecretBuffer,
|
||||
verifyToken: encryptedVerifyTokenBuffer,
|
||||
});
|
||||
@ -132,7 +132,7 @@ function createClient(options) {
|
||||
assert.strictEqual(packet.sharedSecret.length, 0);
|
||||
assert.strictEqual(packet.verifyToken.length, 0);
|
||||
client.encryptionEnabled = true;
|
||||
client.writePacket(0xcd, { payload: 0 });
|
||||
client.write(0xcd, { payload: 0 });
|
||||
}
|
||||
}
|
||||
|
||||
@ -179,7 +179,7 @@ Client.prototype.end = function() {
|
||||
this.socket.end();
|
||||
};
|
||||
|
||||
Client.prototype.writePacket = function(packetId, params) {
|
||||
Client.prototype.write = function(packetId, params) {
|
||||
var buffer = createPacketBuffer(packetId, params);
|
||||
var out = this.encryptionEnabled ? new Buffer(this.cipher.update(buffer), 'binary') : buffer;
|
||||
this.socket.write(out);
|
||||
|
@ -128,7 +128,7 @@ describe("minecraft protocol", function() {
|
||||
assert.strictEqual(packet.difficulty, 1);
|
||||
assert.strictEqual(packet.dimension, 0);
|
||||
assert.strictEqual(packet.gameMode, 0);
|
||||
client.writePacket(0x03, {
|
||||
client.write(0x03, {
|
||||
message: "hello everyone; I have logged in."
|
||||
});
|
||||
});
|
||||
@ -162,7 +162,7 @@ describe("minecraft protocol", function() {
|
||||
assert.strictEqual(packet.difficulty, 1);
|
||||
assert.strictEqual(packet.dimension, 0);
|
||||
assert.strictEqual(packet.gameMode, 0);
|
||||
client.writePacket(0x03, {
|
||||
client.write(0x03, {
|
||||
message: "hello everyone; I have logged in."
|
||||
});
|
||||
});
|
||||
@ -200,7 +200,7 @@ describe("minecraft protocol", function() {
|
||||
username: process.env.MC_USERNAME,
|
||||
});
|
||||
client.on(0x01, function(packet) {
|
||||
client.writePacket(0x03, {
|
||||
client.write(0x03, {
|
||||
message: "hello everyone; I have logged in."
|
||||
});
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user