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(); var gamemux = new events.EventEmitter();
/* Constructor. A TermSession handles a pty and the game running on it. /* Constructor. A TermSession handles a pty and the game running on it.
* game: (String) Name of the game to launch. * gname: (String) Name of the game to launch.
* lkey: (String, key) The user's id, a key into logins. * pname: (String) The player's name.
* dims: (Array [Number, Number]) Height and width of the pty. * dims: (Array [Number, Number]) Height and width of the pty.
* handlers: (Object) Key-value pairs, event names and functions to * handlers: (Object) Key-value pairs, event names and functions to
* install to handle them. * install to handle them.
@ -76,28 +76,21 @@ var gamemux = new events.EventEmitter();
* "data": Data generated by child. Parameters: buf (Buffer) * "data": Data generated by child. Parameters: buf (Buffer)
* "exit": Child terminated. Parameters: none * "exit": Child terminated. Parameters: none
*/ */
function TermSession(game, lkey, dims, handlers) { function TermSession(gname, pname, dims, handlers) {
var ss = this; var ss = this;
/* Subclass EventEmitter to do the hard work. */ /* Subclass EventEmitter to do the hard work. */
events.EventEmitter.call(this); events.EventEmitter.call(this);
for (var evname in handlers) for (var evname in handlers)
this.on(evname, handlers[evname]); this.on(evname, handlers[evname]);
/* Don't launch anything that's not a real game. */ /* Don't launch anything that's not a real game. */
if (game in games) { if (gname in games) {
this.game = games[game]; this.game = games[gname];
}
else {
this.failed = true;
return;
}
if (lkey in logins) {
this.key = lkey;
this.pname = logins[lkey].name;
} }
else { else {
this.failed = true; this.failed = true;
return; return;
} }
this.pname = pname;
/* Grab a spot in the sessions table. */ /* Grab a spot in the sessions table. */
sessions[this.game.uname + "/" + this.pname] = this; sessions[this.game.uname + "/" + this.pname] = this;
/* Set up the sizes. */ /* Set up the sizes. */
@ -322,8 +315,8 @@ function wsWatcher(conn, session) {
"d": session.framebuf.toString("hex", 0, session.frameoff)})); "d": session.framebuf.toString("hex", 0, session.frameoff)}));
} }
function wsPlay(wsReq, game, lkey, dims) { function wsPlay(wsReq, game, pname, dims) {
tslog("wsPlay: running for %s/%s", game, logins[lkey].name); tslog("wsPlay: running for %s/%s", game, pname);
tslog("Request is for %s", logins[wsReq.resourceURL.query["key"]].name); tslog("Request is for %s", logins[wsReq.resourceURL.query["key"]].name);
var conn; var conn;
var session; var session;
@ -360,7 +353,7 @@ function wsPlay(wsReq, game, lkey, dims) {
session.removeListener('exit', exitH); session.removeListener('exit', exitH);
} }
var handlers = {'data': dataH, '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) { if (!session.failed) {
var tag = session.game.uname + "/" + session.pname; var tag = session.game.uname + "/" + session.pname;
var reply = {"t": "s", "tag": tag, "w": session.w, "h": session.h, 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); tslog("%s is already playing %s", pname, gname);
} }
else else
wsPlay(wsReq, gname, lkey, dims); wsPlay(wsReq, gname, pname, dims);
}; };
checkprogress(pname, games[gname], progcallback, []); checkprogress(pname, games[gname], progcallback, []);
} }