Mercurial > hg > rlgwebd
diff rlgwebd.js @ 169:6f4b7e1b32e8
rlgwebd.js: clean up TermSession parameters.
Use the player name instead of a login key that has already been
verified and resolved to a player name.
author | John "Elwin" Edwards |
---|---|
date | Fri, 09 Jan 2015 09:43:21 -0500 |
parents | 0ceaca924b4c |
children | 50e4c9feeac2 |
line wrap: on
line diff
--- a/rlgwebd.js Fri Jan 09 08:55:38 2015 -0500 +++ b/rlgwebd.js Fri Jan 09 09:43:21 2015 -0500 @@ -67,8 +67,8 @@ var gamemux = new events.EventEmitter(); /* Constructor. A TermSession handles a pty and the game running on it. - * game: (String) Name of the game to launch. - * lkey: (String, key) The user's id, a key into logins. + * gname: (String) Name of the game to launch. + * pname: (String) The player's name. * dims: (Array [Number, Number]) Height and width of the pty. * handlers: (Object) Key-value pairs, event names and functions to * install to handle them. @@ -76,28 +76,21 @@ * "data": Data generated by child. Parameters: buf (Buffer) * "exit": Child terminated. Parameters: none */ -function TermSession(game, lkey, dims, handlers) { +function TermSession(gname, pname, dims, handlers) { var ss = this; /* Subclass EventEmitter to do the hard work. */ events.EventEmitter.call(this); for (var evname in handlers) this.on(evname, handlers[evname]); /* Don't launch anything that's not a real game. */ - if (game in games) { - this.game = games[game]; + if (gname in games) { + this.game = games[gname]; } else { this.failed = true; return; } - if (lkey in logins) { - this.key = lkey; - this.pname = logins[lkey].name; - } - else { - this.failed = true; - return; - } + this.pname = pname; /* Grab a spot in the sessions table. */ sessions[this.game.uname + "/" + this.pname] = this; /* Set up the sizes. */ @@ -322,8 +315,8 @@ "d": session.framebuf.toString("hex", 0, session.frameoff)})); } -function wsPlay(wsReq, game, lkey, dims) { - tslog("wsPlay: running for %s/%s", game, logins[lkey].name); +function wsPlay(wsReq, game, pname, dims) { + tslog("wsPlay: running for %s/%s", game, pname); tslog("Request is for %s", logins[wsReq.resourceURL.query["key"]].name); var conn; var session; @@ -360,7 +353,7 @@ session.removeListener('exit', exitH); } var handlers = {'data': dataH, 'exit': exitH}; - session = new TermSession(game, lkey, dims, handlers); + session = new TermSession(game, pname, dims, handlers); if (!session.failed) { var tag = session.game.uname + "/" + session.pname; var reply = {"t": "s", "tag": tag, "w": session.w, "h": session.h, @@ -407,7 +400,7 @@ tslog("%s is already playing %s", pname, gname); } else - wsPlay(wsReq, gname, lkey, dims); + wsPlay(wsReq, gname, pname, dims); }; checkprogress(pname, games[gname], progcallback, []); }