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.
This commit is contained in:
John "Elwin" Edwards 2015-01-09 09:43:21 -05:00
parent ee8782bbf4
commit ef4cb9ac8d

View file

@ -67,8 +67,8 @@ var allowlogin = true;
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 @@ var gamemux = new events.EventEmitter();
* "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];
}
else {
this.failed = true;
return;
}
if (lkey in logins) {
this.key = lkey;
this.pname = logins[lkey].name;
if (gname in games) {
this.game = games[gname];
}
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 @@ function wsWatcher(conn, session) {
"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 @@ function wsPlay(wsReq, game, lkey, dims) {
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 @@ function wsStart(wsReq) {
tslog("%s is already playing %s", pname, gname);
}
else
wsPlay(wsReq, gname, lkey, dims);
wsPlay(wsReq, gname, pname, dims);
};
checkprogress(pname, games[gname], progcallback, []);
}