diff --git a/jstrr.js b/jstrr.js index 00ae1b7..9b5682e 100644 --- a/jstrr.js +++ b/jstrr.js @@ -518,8 +518,6 @@ }, 1000); } } else if (data.scoreinfo) { - //console.log("DSSSS="+JSON.stringify(data.scoreinfo)); - //console.log("STRI="+JSON.stringify(data.scoreinfo.steptrial)); mystate.scoreinfo = data.scoreinfo; updateScoreField(); } else if (data.ranking) { diff --git a/jtserv/jtserv.rb b/jtserv/jtserv.rb index f848522..6ff0013 100755 --- a/jtserv/jtserv.rb +++ b/jtserv/jtserv.rb @@ -441,7 +441,15 @@ end } ws_conn.onopen do - connections[ws_conn] = {} + # First, clean up idling connections + connections.each do |conn, info| + if TIMEOUT < Time.now - (info["stamp"]||info["openat"]) + STDERR.printf("Force Close client %s after long idle\n", conn) + conn.close + end + end + # Start to accept a new client + connections[ws_conn] = {"openat": Time.now} ws_conn.send(JSON.generate({myid: connections.length})) if test(?e, File.expand_path("..", LOCALCSS)) ws_conn.send(JSON.generate({css: LOCALCSS})) @@ -454,16 +462,20 @@ connections.delete(ws_conn) STDERR.printf("CL: %d clients\n", connections.length) end + ## + ## Main Loop + ## ws_conn.onmessage do |msg| begin json = JSON.parse(msg) rescue - return + next ## Skip client that sends invalid JSON end userinfo = connections[ws_conn] user, skey = userinfo['user'], userinfo['skey'] STDERR.printf("RECV%s: [%s]\n", user ? "("+user+")" : "", json.reject{|k,v|k=="Passcode"}.to_json) + userinfo["stamp"] = Time.now # Remember time stamp if skey then userinfo["trial"] = 0 # Reset auth count if json["team"] then