mirror of
https://github.com/unmojang/node-minecraft-protocol.git
synced 2025-09-29 06:03:33 -04:00
don't write after end and unpipe everything when ending. fix #110
This commit is contained in:
parent
4fc80bd1c6
commit
b30522188e
@ -22,6 +22,7 @@ class Client extends EventEmitter
|
|||||||
isServer;
|
isServer;
|
||||||
version;
|
version;
|
||||||
protocolState=states.HANDSHAKING;
|
protocolState=states.HANDSHAKING;
|
||||||
|
ended=true;
|
||||||
|
|
||||||
constructor(isServer,version) {
|
constructor(isServer,version) {
|
||||||
super();
|
super();
|
||||||
@ -123,12 +124,12 @@ class Client extends EventEmitter
|
|||||||
}
|
}
|
||||||
|
|
||||||
setSocket(socket) {
|
setSocket(socket) {
|
||||||
var ended = false;
|
this.ended = false;
|
||||||
|
|
||||||
// TODO : A lot of other things needs to be done.
|
// TODO : A lot of other things needs to be done.
|
||||||
var endSocket = () => {
|
var endSocket = () => {
|
||||||
if(ended) return;
|
if(this.ended) return;
|
||||||
ended = true;
|
this.ended = true;
|
||||||
this.socket.removeListener('close', endSocket);
|
this.socket.removeListener('close', endSocket);
|
||||||
this.socket.removeListener('end', endSocket);
|
this.socket.removeListener('end', endSocket);
|
||||||
this.socket.removeListener('timeout', endSocket);
|
this.socket.removeListener('timeout', endSocket);
|
||||||
@ -162,6 +163,8 @@ class Client extends EventEmitter
|
|||||||
|
|
||||||
end(reason) {
|
end(reason) {
|
||||||
this._endReason = reason;
|
this._endReason = reason;
|
||||||
|
if(this.cipher) this.cipher.unpipe();
|
||||||
|
if(this.framer) this.framer.unpipe();
|
||||||
if(this.socket) this.socket.end();
|
if(this.socket) this.socket.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -195,12 +198,16 @@ class Client extends EventEmitter
|
|||||||
}
|
}
|
||||||
|
|
||||||
write(name, params) {
|
write(name, params) {
|
||||||
|
if(this.ended)
|
||||||
|
return;
|
||||||
debug("writing packet " + this.state + "." + name);
|
debug("writing packet " + this.state + "." + name);
|
||||||
debug(params);
|
debug(params);
|
||||||
this.serializer.write({ name, params });
|
this.serializer.write({ name, params });
|
||||||
}
|
}
|
||||||
|
|
||||||
writeRaw(buffer) {
|
writeRaw(buffer) {
|
||||||
|
if(this.ended)
|
||||||
|
return;
|
||||||
if (this.compressor === null)
|
if (this.compressor === null)
|
||||||
this.framer.write(buffer);
|
this.framer.write(buffer);
|
||||||
else
|
else
|
||||||
|
Loading…
x
Reference in New Issue
Block a user