Created
September 6, 2011 02:24
-
-
Save quantumpotato/1196415 to your computer and use it in GitHub Desktop.
Adding, sending and writing messages from a queue on a player(client).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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