<commit_before>var Game = require('./game')
var Room = require('./room')
var Sock = require('./sock')
var util = require('./util')

var rooms = {
  lobby: new Room
}

function numGames() {
  // Don't include the lobby as a game.
  return Object.keys(rooms).length - 1
}

function create(opts) {
  try {
    util.game(opts)
  } catch(err) {
    return this.err(err.message)
  }

  opts.id = this.id
  var g = new Game(opts)
  rooms[g.id] = g
  this.send('route', 'g/' + g.id)
  g.once('kill', kill)
  console.log(`game ${g.id} created, there are now ${numGames()} games`)
}

function join(roomID) {
  var room = rooms[roomID]
  if (!room)
    return this.err(`room ${roomID} not found`)
  this.exit()
  room.join(this)
}

function kill() {
  delete rooms[this.id]
  console.log(`game ${this.id} destroyed, there are now ${numGames()} games`)
}

module.exports = function (ws) {
  var sock = new Sock(ws)
  sock.on('join', join)
  sock.on('create', create)
}<commit_msg>Log the number of connected users<commit_after>var Game = require('./game')
var Room = require('./room')
var Sock = require('./sock')
var util = require('./util')

var rooms = {
  lobby: new Room
}

// All sockets currently connected to the server, useful for broadcasting
// messages.
var socks = []

function numGames() {
  // Don't include the lobby as a game.
  return Object.keys(rooms).length - 1
}

function create(opts) {
  try {
    util.game(opts)
  } catch(err) {
    return this.err(err.message)
  }

  opts.id = this.id
  var g = new Game(opts)
  rooms[g.id] = g
  this.send('route', 'g/' + g.id)
  g.once('kill', kill)
  console.log(`game ${g.id} created, there are now ${numGames()} games`)
}

function join(roomID) {
  var room = rooms[roomID]
  if (!room)
    return this.err(`room ${roomID} not found`)
  this.exit()
  room.join(this)
}

function kill() {
  delete rooms[this.id]
  console.log(`game ${this.id} destroyed, there are now ${numGames()} games`)
}

function printNumSockets() {
  console.log(`there are now ${socks.length} connected users`)
}

module.exports = function (ws) {
  var sock = new Sock(ws)
  sock.on('join', join)
  sock.on('create', create)

  socks.push(sock)
  printNumSockets()
  ws.once('close', ()=> {
    let index = socks.indexOf(sock)
    if (index !== -1) {
      socks.splice(index, 1)
      printNumSockets()
    }
  })
}
{'fraction_non_alphanumeric': 0.1727815699658703, 'fraction_numerical': 0.0017064846416382253, 'mean_word_length': 3.3506493506493507, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7409868', 'n_tokens_mistral': 844, 'n_tokens_neox': 840, 'n_words': 226}