<commit_before>"use strict";

var Backend = require('./backend'), pad = require('pad'), dateFormat = require('dateformat'), fs = require('fs');

var backend = new Backend(__dirname + '/../games.json', true);

// Test Logging
(function() {
  var maxLevelSize = 0;
  backend.getEmitter().on('logger.*', function(data) {
    if (data.level) {
      maxLevelSize = Math.max(maxLevelSize, data.level.length);
    }
    var prefix = '[' + dateFormat(data.timestamp) + ']' + ' ' + '[' + pad(data.level.toUpperCase(), maxLevelSize) + ']';
    if (data.message && typeof data.message === 'string') {
      console.log(prefix + ' - ' + data.message);
    } else {
      console.log(prefix, data.message);
    }
  });
})();

module.exports.routes = function(app) {
  var servedHtmlFiles = ['game', 'backdoor'];
  for (var i = 0, c = servedHtmlFiles.length; i < c; i++) {
    (function(servedHtmlFile) {
      app.get('/' + servedHtmlFile + '*', function(req, res) {
        fs.readFile(__dirname + '/../static/' + servedHtmlFile + '.html',
          function(err, data) {
            if (err) {
              res.writeHead(500);
              return res.end('Error loading ' + servedHtmlFile + '.html');
            }
            res.header('Content-Type', 'text/html');
            res.writeHead(200);
            res.end(data);
          }
        );
      });
    })(servedHtmlFiles[i]);
  }
};

module.exports.sockets = function(io) {
  backend.setSocketIO(io);
  io.sockets.on('connection', function(socket) {
    console.log('Client Connected');

    //socket.join(game.id);

    socket.on('message', function(data) {
      //socket.broadcast.emit('server_message', data);
      backend.dispatchMessage(socket, data);
    });

    socket.on('createGame', function(data) {
      backend.createGame(socket, data);
    });

    socket.on('joinGame', function(data) {
      backend.joinGame(socket, data);
    });

    socket.on('preMove', function(data) {
      backend.preMove(socket, data);
    });

    socket.on('move', function(data) {
      backend.move(socket, data);
    });

    socket.on('disconnect', function() {
      backend.deRegisterClient(socket);
    });

    socket.on('registerBackdoor', function(){
      backend.registerBackdoor(socket);
    });

    //socket.broadcast.to(game.id).emit('server_message', {message: 'Player joined [' + game.id + ']', action: 'join'});
  });
};
<commit_msg>Fix broken build 20 (lint issue).<commit_after>"use strict";

var Backend = require('./backend'), pad = require('pad'), dateFormat = require('dateformat'), fs = require('fs');

var backend = new Backend(__dirname + '/../games.json', true);

// Test Logging
(function() {
  var maxLevelSize = 0;
  backend.getEmitter().on('logger.*', function(data) {
    if (data.level) {
      maxLevelSize = Math.max(maxLevelSize, data.level.length);
    }
    var prefix = '[' + dateFormat(data.timestamp) + ']' + ' ' + '[' + pad(data.level.toUpperCase(), maxLevelSize) + ']';
    if (data.message && typeof data.message === 'string') {
      console.log(prefix + ' - ' + data.message);
    } else {
      console.log(prefix, data.message);
    }
  });
})();

module.exports.routes = function(app) {
  var servedHtmlFiles = ['game', 'backdoor'], onRoute = function(servedHtmlFile) {
    app.get('/' + servedHtmlFile + '*', function(req, res) {
      fs.readFile(__dirname + '/../static/' + servedHtmlFile + '.html',
        function(err, data) {
          if (err) {
            res.writeHead(500);
            return res.end('Error loading ' + servedHtmlFile + '.html');
          }
          res.header('Content-Type', 'text/html');
          res.writeHead(200);
          res.end(data);
        }
      );
    });
  };
  for (var i = 0, c = servedHtmlFiles.length; i < c; i++) {
    onRoute(servedHtmlFiles[i]);
  }
};

module.exports.sockets = function(io) {
  backend.setSocketIO(io);
  io.sockets.on('connection', function(socket) {
    console.log('Client Connected');

    //socket.join(game.id);

    socket.on('message', function(data) {
      //socket.broadcast.emit('server_message', data);
      backend.dispatchMessage(socket, data);
    });

    socket.on('createGame', function(data) {
      backend.createGame(socket, data);
    });

    socket.on('joinGame', function(data) {
      backend.joinGame(socket, data);
    });

    socket.on('preMove', function(data) {
      backend.preMove(socket, data);
    });

    socket.on('move', function(data) {
      backend.move(socket, data);
    });

    socket.on('disconnect', function() {
      backend.deRegisterClient(socket);
    });

    socket.on('registerBackdoor', function() {
      backend.registerBackdoor(socket);
    });

    //socket.broadcast.to(game.id).emit('server_message', {message: 'Player joined [' + game.id + ']', action: 'join'});
  });
};

{'fraction_non_alphanumeric': 0.19040697674418605, 'fraction_numerical': 0.003737541528239203, 'mean_word_length': 2.8815471394037067, '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': '1827810', 'n_tokens_mistral': 1549, 'n_tokens_neox': 1513, 'n_words': 260}