Skip to content

Commit

Permalink
MCCP plugin now enables MCCP... The decompression bit needs to be add…
Browse files Browse the repository at this point in the history
…ed, though.
  • Loading branch information
Vultaire committed Feb 21, 2015
1 parent cca355d commit 3e665a7
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 14 deletions.
71 changes: 58 additions & 13 deletions mccp.js
Expand Up @@ -3,27 +3,72 @@ var MCCPFilter;
(function () {
'use strict';

var COMPRESS = 85;
var COMPRESS2 = 86;
var SB = 250;
var WILL = 251;
var DO = 253;
var DONT = 254;
var IAC = 255;

// Drop this... make a base class for pulling telnet codes, then
// specialize for MCCP.
MCCPFilter = _.extend(Object.create(TelnetFilter), {
COMPRESS: 85,
COMPRESS2: 86,
initialize: function () {
TelnetFilter.initialize.call(this);
this.serverWillCompress = false;
this.serverWillCompress2 = false;
this.compress = false;
return this;
},
filter: function (socket, buffer) {
if (this.compress) {
// decompress
// pass through as-is
return buffer;
} else {
return TelnetFilter.filter.call(this, socket, buffer);
}
},
onCode: function (socket) {
console.log('MCCPFilter.onCode:', this.currentCode);
return false;
if (this.currentCode[0] == this.IAC
&& this.currentCode[1] == this.WILL
&& this.currentCode[2] == this.COMPRESS2) {

this.serverWillCompress2 = true;

// Request MCCP version 2
var buff = new ArrayBuffer(3);
var uint8 = new Uint8Array(buff);
uint8[0] = this.IAC;
uint8[1] = this.DO;
uint8[2] = this.COMPRESS2;
socket.send(buff);
}
else if (this.currentCode[0] == this.IAC
&& this.currentCode[1] == this.WILL
&& this.currentCode[2] == this.COMPRESS) {

// Conditionally request MCCP version 1 (if version 2
// is not enabled)
// NOTE: Untested!
var buff = new ArrayBuffer(3);
var uint8 = new Uint8Array(buff);
uint8[0] = this.IAC;
uint8[1] = this.serverWillCompress2 ? this.DONT : this.DO;
uint8[2] = this.COMPRESS;
socket.send(buff);
} else if (this.currentCode[0] == this.IAC
&& this.currentCode[1] == this.SB
&& this.currentCode[2] == this.COMPRESS2
&& this.currentCode[3] == this.IAC
&& this.currentCode[4] == this.SE) {

// MCCP version 2 enabled
this.compress = true;
} else if (this.currentCode[0] == this.IAC
&& this.currentCode[1] == this.SB
&& this.currentCode[2] == this.COMPRESS
&& this.currentCode[3] == this.WILL
&& this.currentCode[4] == this.SE) {

// MCCP version 1 enabled
this.compress = true;
} else {
return false;
}
return true;
},
});
})();
1 change: 0 additions & 1 deletion telnet.js
Expand Up @@ -65,7 +65,6 @@ var TelnetFilter;
}
} else if (this.currentCode.length == 2) {
this.currentCode.push(code);
console.log('Current code:', this.currentCode);
if (this.currentCode[1] === this.SB) {
// Just keep appending bytes until we
// encounter an IAC SE or WILL SE. (WILL SE
Expand Down

0 comments on commit 3e665a7

Please sign in to comment.