Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Couple of fixes and an examples/server.js.

  • Loading branch information...
commit 6377c5de7796215275caa58a7d237e4078a3a0de 1 parent 5449b6c
Eduard Burtescu authored
Showing with 29 additions and 3 deletions.
  1. +26 −0 examples/server.js
  2. +1 −1  lib/ClientSocket.js
  3. +2 −2 lib/Server.js
View
26 examples/server.js
@@ -0,0 +1,26 @@
+#!/usr/bin/env node
+
+var mc = require('../'), packets = mc.protocol.packets;
+
+var server = mc.createServer(function(c) {
+ c.on('login', function(u) {
+ console.log(u+' just logged in');
+ c.write(packets.LOGIN, {playerEID: server.lastEID++, height: 128, maxPlayers: 100});
+ c.write(packets.CHAT, {message: 'Hi '+u+' and welcome to a demo server of node-mcsmp :).'});
+ c.write(packets.PRE_CHUNK, {x: 0, z: 0, load: true});
+ c.write(packets.BLOCK_CHANGE, {x: 0, y: 63, z: 0, blockType: 1});
+ c.write(packets.PLAYER_POS, {x: 0, y: 64, stance: 65.7, z: 0});
+ });
+ c.on('close', function(m) {
+ console.log(c.username+' just logged out ('+m+')');
+ });
+ c.on('error', function(e) {
+ c.write(packets.DISCONNECT, {message:e});
+ console.log(c.username+' just logged out ('+e+')');
+ });
+});
+
+server.listen(process.argv[2]);
+console.log('Listening on '+(process.argv[2] || 25565)+'...');
+
+server.lastEID = 1;
View
2  lib/ClientSocket.js
@@ -41,7 +41,7 @@ Socket.prototype.connect = function connect(server, username, password, protoVer
this.on('close', function() {
if(this.posEmitter)
clearInterval(this.posEmitter);
- this.sock.end(proto.pack({type:proto.packets.DISCONNECT}));
+ this.sock.end(proto.pack({type:proto.packets.DISCONNECT}, this.proto.client2server));
}.bind(this));
this.write(proto.packets.HANDSHAKE, {username: username});
}.bind(this));
View
4 lib/Server.js
@@ -12,7 +12,7 @@ Server.prototype.protoVersion = 17; // Latest stable (1.8.1).
Server.prototype.on = function on(event, f) {
if(event == 'connection')
- return net.Server.prototype.on.call(this, event, function(socket) {return f(new Socket(socket), this);}.bind(this));
+ return net.Server.prototype.on.call(this, event, function(socket) {return f(new Socket(socket, this));}.bind(this));
return net.Server.prototype.on.apply(this, arguments);
};
@@ -40,7 +40,7 @@ function Socket(sock, server) {
this.on('close', function() {
if(this.posEmitter)
clearInterval(this.posEmitter);
- this.sock.end(proto.pack({type:proto.packets.DISCONNECT}));
+ this.sock.end(proto.pack({type:proto.packets.DISCONNECT}, this.proto.server2client));
}.bind(this));
}.bind(this));
}
Please sign in to comment.
Something went wrong with that request. Please try again.