let gameEvents = require('../gameEvents')

let players = [];
let foods = []
let playerConnectionIDCount = 0;

exports.index = (req, res, next) => {
    res.render('game', {})
}

exports.join = (ws, req, next) => {
    ws.id = playerConnectionIDCount++
    console.log('WebSocket was opened')
    console.log(Object.keys(players))
    players[ws.id] = ws
    foods[ws.id] = { id: ws.id, x: 0, y: 0 }
    let gameEvents = gameEvents({ ws, players, foods })

    ws.on('message', msg => {
        var message = JSON.parse(msg)
        gameEvents[message.type](message.payLoad)
    })

    ws.on('close', () => {
        delete players[ws.id];
        console.log('WebSocket was closed')
    })
}
@@ -631,17 +631,44 @@
 s%5Bws.id%5D
-;
+%0A        delete foods%5Bws.id%5D
 %0A       

Remove food on disconnect