+now_s = ->
+ d = new Date()
+ return d.getTime()
+
+expire_old_games = ->
+ count = 0
+ for slug, g of games
+ count += 1
+ oldest_slug = slug
+ oldest_seen = g.last_seen
+
+ return unless count > 0
+
+ # check all the games
+ # track oldest
+ # delete old ones
+ too_old = now_s() - max_game_idle
+ kills = []
+ for slug, g of games
+ if g.last_seen < oldest_seen
+ oldest_seen = g.last_seen
+ oldest_slug = slug
+ if g.last_seen < too_old
+ kills.push slug
+ if count > max_concurrent_games and kills.length is 0
+ console.log "hit max_concurrent_games, destroying oldest"
+ kills.push oldest_slug
+ for slug in kills
+ console.log "killing game #{slug}"
+ delete games[slug]
+