<commit_before>var restify = require('restify');
var CookieParser = require('restify-cookies');
const uuidv4 = require('uuid/v4');

function checkCookie(req, res, next) {
    if (!req.cookies['userid']) {
	res.setCookie('userid', uuidv4());
    }
    return next();
}

function codeGen(codeLength) {
    const chars = '0123456789abcdefghijklmnopqrstuvwxyz';
    var code = '';
    for (var i = 0; i < codeLength; ++i) {
	code += chars[Math.ceil(Math.random() * (chars.length)) - 1];
    }
    return code;
}

function GameRoom(creator, code) {
    this.code = code;
    this.creator = creator;
    this.players = [creator];
}

var gameRoomList = [];

function createRoom(req, res, next) {
    var code = codeGen(5);
    var newGameRoom  = new GameRoom(req.body.username, code);
    gameRoomList.push(newGameRoom);
    res.json(newGameRoom);

    //console.log(req.body);
    console.log(gameRoomList);
    console.log('\n');

    return next();
}

function joinRoom(req, res, next) {
    //console.log(req.body);
    for (var game of gameRoomList){
	if (req.body.code == game.code){
	    game.players.push(req.body.username);
	    res.json(game);

	    console.log(gameRoomList);
	    console.log('\n');

	    return next();
	}
    }
    return next();
}

var server = restify.createServer({name: 'Game Lounge'});
server.use(CookieParser.parse); //restify cookie handler
server.use(checkCookie); //our handler for verifying/creating cookies
server.use(restify.plugins.bodyParser()); //restify handler for parsing post body params

server.post('/new-room/', createRoom);
server.post('/join-room/', joinRoom);

server.get(/.*/, restify.plugins.serveStatic({
    'directory': __dirname,
    'default': 'home.html'
}));<commit_msg>change variable game to gameRoom in server.js<commit_after>var restify = require('restify');
var CookieParser = require('restify-cookies');
const uuidv4 = require('uuid/v4');

function checkCookie(req, res, next) {
    if (!req.cookies['userid']) {
	res.setCookie('userid', uuidv4());
    }
    return next();
}

function codeGen(codeLength) {
    const chars = '0123456789abcdefghijklmnopqrstuvwxyz';
    var code = '';
    for (var i = 0; i < codeLength; ++i) {
	code += chars[Math.ceil(Math.random() * (chars.length)) - 1];
    }
    return code;
}

function GameRoom(creator, code) {
    this.code = code;
    this.creator = creator;
    this.players = [creator];
}

var gameRoomList = [];

function createRoom(req, res, next) {
    var code = codeGen(5);
    var newGameRoom  = new GameRoom(req.body.username, code);
    gameRoomList.push(newGameRoom);
    res.json(newGameRoom);

    //console.log(req.body);
    console.log(gameRoomList);
    console.log('\n');

    return next();
}

function joinRoom(req, res, next) {
    //console.log(req.body);
    for (var gameRoom of gameRoomList){
	if (req.body.code == gameRoom.code){
	    gameRoom.players.push(req.body.username);
	    res.json(gameRoom);

	    console.log(gameRoomList);
	    console.log('\n');

	    return next();
	}
    }
    return next();
}

var server = restify.createServer({name: 'Game Lounge'});
server.use(CookieParser.parse); //restify cookie handler
server.use(checkCookie); //our handler for verifying/creating cookies
server.use(restify.plugins.bodyParser()); //restify handler for parsing post body params

server.post('/new-room/', createRoom);
server.post('/join-room/', joinRoom);

server.get(/.*/, restify.plugins.serveStatic({
    'directory': __dirname,
    'default': 'home.html'
}));
{'fraction_non_alphanumeric': 0.16533409480296973, 'fraction_numerical': 0.009137635636778984, 'mean_word_length': 3.7083333333333335, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '2669128', 'n_tokens_mistral': 1222, 'n_tokens_neox': 1179, 'n_words': 252}