<commit_before># Requires
coffee = require 'coffee-script'
nowjs = require 'now'
tasks = require './tasks'
redis = require 'redis'
redis_client = redis.createClient()

# ComCenter
class ComCenter

    # Server
    server: null
    everyone: null
    port: null
    connectedClients: {}
    groupData: {}


    # Initialise
    constructor: (server,ioserver) ->
        # Prepare
        @server = server


        #Create the everyone object for nowjs.  clientWrite determines whether client can change server scope variables
        @everyone = nowjs.initialize(@server, {clientWrite:true}, ioserver)


        #Setup up routes for access to the comCenter
        @server.use tasks(@)

        @setupComCenter()


    setupComCenter: ->
        comCenter = @
        connectedClients = @connectedClients
        groupData = @groupData

        #Trigger when each client connects
        @everyone.on 'connect', ->
            console.log("Connected: " + @user.clientId)

        @everyone.on 'disconnect', ->
            #Remove client from the connectedClients object
            delete connectedClients[@now.name]


            console.log("Left: " + @now.name)



        @everyone.now.handshake = ->
            #Add client to the connectedClients object
            connectedClients[@now.name] = @user.clientId
            console.log 'showing connected clients after handshake'
            console.log '=========================================='
            console.log JSON.stringify(connectedClients)

            console.log("Joined: " + @now.name)

        nowjs.on('disconnect', ->
            if @now.group?
                nowjs.getGroup(@now.group).now.receiveMessage({fromUser:"server", message:"#{@now.name} has left the session.", messageType:'serverMessage'})

            if groupData[@now.group].hostClientId == @user.clientId
                groupData[@now.group].hostConnected == false


            #remove the client from any rooms he's currently in
            nowjs.getGroup(@now.group).removeUser(@user.clientId)

        )

        @everyone.now.joinGroup = (groupName) ->
            console.log('groupname: ' + groupName)
            #remove the client from any rooms he's currently in
            nowjs.getGroup(@now.group).removeUser(@user.clientId)

            #add the client to the new group
            nowjs.getGroup(groupName).addUser(@user.clientId)
            @now.group = groupName

            console.log 'joining group...'
            console.log '==========================='
            console.log JSON.stringify(@now.group)

            #Create the groupData storage object if it doesn't already exist
            if not groupData[@now.group]?
                groupData[@now.group] = {}


            if @now.group?
                nowjs.getGroup(@now.group).now.receiveMessage({fromUser:"server", message:"#{@now.name} has joined the session.", messageType:'serverMessage'})
<commit_msg>fixes<commit_after># Requires
coffee = require 'coffee-script'
nowjs = require 'now'
tasks = require './tasks'
redis = require 'redis'
redis_client = redis.createClient()

# ComCenter
class ComCenter

    # Server
    server: null
    everyone: null
    port: null
    connectedClients: {}
    groupData: {}


    # Initialise
    constructor: (server,ioserver) ->
        # Prepare
        @server = server


        #Create the everyone object for nowjs.  clientWrite determines whether client can change server scope variables
        @everyone = nowjs.initialize(@server, {clientWrite:true}, ioserver)


        #Setup up routes for access to the comCenter
        @server.use tasks(@)

        @setupComCenter()


    setupComCenter: ->
        comCenter = @
        connectedClients = @connectedClients
        groupData = @groupData

        #Trigger when each client connects
        @everyone.on 'connect', ->
            console.log("Connected: " + @user.clientId)

        @everyone.on 'disconnect', ->
            #Remove client from the connectedClients object
            delete connectedClients[@now.name]

            console.log 'h1'
            console.log("Left: " + @now.name)



        @everyone.now.handshake = ->
            #Add client to the connectedClients object
            connectedClients[@now.name] = @user.clientId
            console.log 'showing connected clients after handshake'
            console.log '=========================================='
            console.log JSON.stringify(connectedClients)

            console.log("Joined: " + @now.name)

        nowjs.on('disconnect', ->
            if @now.group?
                nowjs.getGroup(@now.group).now.receiveMessage({fromUser:"server", message:"#{@now.name} has left the session.", messageType:'serverMessage'})

            if groupData[@now.group].hostClientId == @user.clientId
                groupData[@now.group].hostConnected = false

            #remove the client from any rooms he's currently in
            nowjs.getGroup(@now.group).removeUser(@user.clientId)

        )

        @everyone.now.joinGroup = (groupName) ->
            console.log('groupname: ' + groupName)
            #remove the client from any rooms he's currently in
            nowjs.getGroup(@now.group).removeUser(@user.clientId)

            #add the client to the new group
            nowjs.getGroup(groupName).addUser(@user.clientId)
            @now.group = groupName

            console.log 'joining group...'
            console.log '==========================='
            console.log JSON.stringify(@now.group)

            #Create the groupData storage object if it doesn't already exist
            if not groupData[@now.group]?
                groupData[@now.group] = {}


            if @now.group?
                nowjs.getGroup(@now.group).now.receiveMessage({fromUser:"server", message:"#{@now.name} has joined the session.", messageType:'serverMessage'})

{'fraction_non_alphanumeric': 0.12953543574092913, 'fraction_numerical': 0.00016954899966090201, 'mean_word_length': 2.2992170022371363, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, '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': '1029034', 'n_tokens_mistral': 1615, 'n_tokens_neox': 1530, 'n_words': 380}