Skip to content

Instantly share code, notes, and snippets.

@quantumpotato
Created September 6, 2011 02:24
Show Gist options
  • Save quantumpotato/1196415 to your computer and use it in GitHub Desktop.
Save quantumpotato/1196415 to your computer and use it in GitHub Desktop.
Adding, sending and writing messages from a queue on a player(client).
//We store chat messages for the player until they send us their input
//Otherwise the message will get sent and terminal writes it *next to* whatever they are typing!
function StreamHandler() {
this.addMessage = function(player, message) {
player.messages.push(message);
}
this.writeMessage = function(player, cb) {
if (player.messages.length > 0) {
var message = player.messages[0];
player.stream.write(message + lineEnd);
player.messages.splice(0,1);
cb(player,cb);
}
}
this.sendMessages = function(player) {
var messages = player.messages;
this.writeMessage(player, this.writeMessage);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment