From 4a4bb390e861cabeef28d185c5a8425fff1a817d Mon Sep 17 00:00:00 2001 From: "John \"Elwin\" Edwards" Date: Tue, 20 Jan 2015 16:06:12 -0500 Subject: [PATCH] Client: improve messages at the end of watching a game. The messages differentiate between the user stopping watching and the watched game coming to an end. --- rlgterm.js | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/rlgterm.js b/rlgterm.js index e978ec5..0a614e8 100644 --- a/rlgterm.js +++ b/rlgterm.js @@ -30,6 +30,10 @@ var session = { /* Login name and key are now in sessionStorage. */ /* Whether the game is being played or just watched. */ playing: false, + /* If watching, the name of the player. */ + playername: null, + /* Whether the Stop button was pushed. */ + leaving: false, /* WebSocket for communication */ sock: null }; @@ -656,6 +660,7 @@ function startwatching(tag) { termemu.toAltBuf(); var pname = msgObject.p; var gname = games[msgObject.g].name; + session.playername = pname; message("You are now watching " + pname + " play " + gname + "."); } else if (msgObject.t == 'd') { @@ -725,12 +730,23 @@ function gameover() { if (!session.connect) return; /* TODO IFACE2 If the end was unexpected, tell player the game was saved. */ - if (session.playing) + if (session.playing) { message("Finished playing."); - else - message("Finished watching."); + } + else { + if (session.leaving) { + /* Client-initiated: the user stopped watching. */ + message("Finished watching " + session.playername + "."); + } + else { + /* Server-initiated: end of game. */ + message(session.playername + " has finished playing."); + } + session.playername = null; + } session.connect = false; session.playing = false; + session.leaving = false; termemu.toNormBuf(); if ("lcred" in sessionStorage) setmode("choose"); @@ -745,11 +761,11 @@ function logout() { setmode("login"); } -/* TODO determine whether this is needed */ function stop() { if (!session.connect) return; if (session.sock) { + session.leaving = true; session.sock.close(); return; }