Skip to content

Commit

Permalink
Fixed client negotiation weirdness
Browse files Browse the repository at this point in the history
Windows crlfs... *facepalm*
  • Loading branch information
shawncplus committed Jan 12, 2012
1 parent f9c2653 commit 6619a91
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 15 deletions.
14 changes: 7 additions & 7 deletions data/motd
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

o o o o o o o o-o
|\ | | |\ /| | | | \
| \ | o-o o-O o-o | O | | | | O
| \| | | | | |-' | | | | | /
o o o-o o-o o-o o o o-o o-o

o o o o o o o o-o
|\ | | |\ /| | | | \
| \ | o-o o-O o-o | O | | | | O
| \| | | | | |-' | | | | | /
o o o-o o-o o-o o o o-o o-o
4 changes: 4 additions & 0 deletions src/3rdparty/telnet.js
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ TelnetStream.prototype.processIncomingData = function (buf)
emitData();

var cmd = buf[i + 1];
if (typeof cmd !== 'undefined')
switch (cmd) {
case EOF:
case IP:
Expand Down Expand Up @@ -372,6 +373,8 @@ TelnetStream.prototype.processIncomingData = function (buf)
break;
case OPT_WINDOW_SIZE:
// they will send the window size via SB
// sbiddle: Or maybe they won't
call_next_neg(this);
break;
case OPT_BINARY:
this.binary = true;
Expand Down Expand Up @@ -416,6 +419,7 @@ TelnetStream.prototype.processIncomingData = function (buf)
console.log("unknown opcode %d", buf[i+1]);
eat(2);
}
else { eat(1); call_next_neg(this); }
}

if (buf.length) {
Expand Down
2 changes: 1 addition & 1 deletion src/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ var Commands = {
},
where: function (args, player)
{
player.write(rooms.getAt(player.getLocation()).getArea() + "\n");
player.write(rooms.getAt(player.getLocation()).getArea() + "\r\n");
},
who: function (args, player)
{
Expand Down
20 changes: 15 additions & 5 deletions src/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,19 +92,27 @@ var Events = {
break;
case 'login':
if (!dontwelcome) {
arg.write("Welcome, what is your name?");
arg.write("Welcome, what is your name? ");
}

arg.once('data', function (name) {
// swallow any data that's not from player input i.e., doesn't end with a newline
if (name[name.length - 1] !== 0x0a) {
// Windows can s@#* a d@#$
var negot = false;
if (name[name.length - 1] === 0x0a) {
negot = true;
} else if (name[name.length - 1] === 0x0d) {
negot = true;
}

if (!negot) {
next(arg, 'login', true);
return;
}

var name = name.toString().trim();
if (/[^a-z]/i.test(name) || !name) {
arg.write("That's not really your name, now is it?\n");
arg.write("That's not really your name, now is it?\r\n");
return repeat();
}

Expand Down Expand Up @@ -247,7 +255,7 @@ var Events = {
}

if (check === 'n') {
arg.write("Goodbye!\n");
arg.write("Goodbye!\r\n");
arg.end();
return false;
}
Expand All @@ -265,7 +273,7 @@ var Events = {
};
locale = locale.toString().trim().toLowerCase();
if (!(locale in locales)) {
arg.write("Sorry, that's not a valid language.\n");
arg.write("Sorry, that's not a valid language.\r\n");
return repeat();
}

Expand Down Expand Up @@ -298,6 +306,8 @@ var Events = {
arg.say(L('NAME_TAKEN'));
return repeat();
}
console.log(util.inspect(name));
arg.getSocket().write(util.inspect(name));

// Always give them a name like Shawn instead of sHaWn
arg.setName(name[0].toUpperCase() + name.toLowerCase().substr(1));
Expand Down
4 changes: 2 additions & 2 deletions src/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ var Player = function(socket) {
self.say = function (data, color) {
color = color || true;
if (!color) ansi.disable();
socket.write(ansi.parse(data) + "\n");
socket.write(ansi.parse(data) + "\r\n");
ansi.enable();
};

Expand All @@ -125,7 +125,7 @@ var Player = function(socket) {
* Display the configured prompt to the player
*/
self.prompt = function () {
self.write("\n" + self.getPromptString());
self.write("\r\n" + self.getPromptString());
};


Expand Down

0 comments on commit 6619a91

Please sign in to comment.