<commit_before>{app, server, nowjs} = require './ServerListener.js'

{DiceFace}  = require './DiceFace.js'
DICEFACESYMBOLS = DiceFace.symbols

{Game} = require './Game.js'
{Player} = require './Player.js'

everyone = nowjs.initialize(server)


game = new Game([])

everyone.now.addClient = () -> #called by client when connected
  if(!game.isFull())
    # add the player, tell him he was accepted and give him his playerId (i.e. index) for the game
    this.now.acceptPlayer(game.addClient(this.user.clientId), DICEFACESYMBOLS)
    #now see if the game is full after adding him (i.e see if is the last player)
    if(game.isFull())
      everyone.now.receiveStartGame(game.players, game.state.unallocated, game.getFirstTurnPlayer())
  else
    # else the game is already full, so tell him - tough luck

    
 
everyone.now.receiveGoal = (goalArray) -> #recieves the goal array from client
  #need to validate goal array at some point
  if !(this.user.clientId == game.playerSocketIds[game.goalSetter])
    throw "Unauthorised goal setter"
  try
    game.setGoal(goalArray)
  catch e #catches when parser returns error for goal
    this.now.badGoal(e.message)
  
<commit_msg>started on rooms<commit_after>{app, server, nowjs} = require './ServerListener.js'

{DiceFace}  = require './DiceFace.js'
DICEFACESYMBOLS = DiceFace.symbols

{Game} = require './Game.js'
{Player} = require './Player.js'

everyone = nowjs.initialize(server)

rooms = []
game = new Game([])

everyone.now.addClient = () -> #called by client when connected
  if(!game.isFull())
    # add the player, tell him he was accepted and give him his playerId (i.e. index) for the game
    this.now.acceptPlayer(game.addClient(this.user.clientId), DICEFACESYMBOLS)
    #now see if the game is full after adding him (i.e see if is the last player)
    if(game.isFull())
      everyone.now.receiveStartGame(game.players, game.state.unallocated, game.getFirstTurnPlayer())
  else
    # else the game is already full, so tell him - tough luck

    
 
everyone.now.receiveGoal = (goalArray) -> #recieves the goal array from client
  #need to validate goal array at some point
  if !(this.user.clientId == game.playerSocketIds[game.goalSetter])
    throw "Unauthorised goal setter"
  try
    game.setGoal(goalArray)
  catch e #catches when parser returns error for goal
    this.now.badGoal(e.message)
  

{'fraction_non_alphanumeric': 0.11393477340110122, 'fraction_numerical': 0.0, 'mean_word_length': 3.771717171717172, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '4478431', 'n_tokens_mistral': 787, 'n_tokens_neox': 770, 'n_words': 235}