<commit_before>'use strict';

var net = require( 'net' );
var fs = require( 'fs' );

var client = require( 'client' );
var clients = [];
var appDir = process.cwd();
var serverConfig = {};

initialize();

var server = net.createServer( function( sock ) {
  sock.write( serverConfig.configuration.MOTD, 'utf8' );

  var chatClient = new client.Client( sock );
  clients.push( chatClient );

  sock.setEncoding( 'utf8' );
  sock.setTimeout( 0 );

  sock.on( 'data', function( data ) {
    console.log( '>> ' + data );
  });

  sock.on( 'error', function( e ) {
    console.log( e );
  });
});

function initialize() {

  //server config check
  var serverConfigPath = appDir + '/config.json';
  var configFile = checkForFileExistence( serverConfigPath, '{"configuration":{"MOTD":"Hello to trollbox server..."}}\n' );
  serverConfig = JSON.parse( configFile );

  //user database check
  var userDBPath = appDir + '/users/userDB.json';
  var userDB = checkForFileExistence( userDBPath, '{"users":[]}\n' );
}


function checkForFileExistence( filename, defaultContent) {
  try {
    return fs.readFileSync( filename );
    //console.log('[DEBUG]file exists...');
  } catch( e ) {
    fs.writeFileSync( filename, defaultContent );
    return fs.readFileSync( filename );
    //console.log( '[DEBUG]file does not exist' );
  }
}

server.listen( 6666 );<commit_msg>Update server.js<commit_after>'use strict';

var net = require( 'net' );
var fs = require( 'fs' );

var client = require( 'client' );
var clients = [];
var appDir = process.cwd();

var serverConfig = {};
var userDB = {};

initialize();

var server = net.createServer( function( sock ) {
  sock.write( serverConfig.configuration.MOTD, 'utf8' );

  var chatClient = new client.Client( sock );
  clients.push( chatClient );

  sock.setEncoding( 'utf8' );
  sock.setTimeout( 0 );

  sock.on( 'data', function( data ) {
    console.log( '>> ' + data );
  });

  sock.on( 'error', function( e ) {
    console.log( e );
  });
});

function initialize() {

  //server config check
  var serverConfigPath = appDir + '/config.json';
  var configFile = checkForFileExistence( serverConfigPath, '{"configuration":{"MOTD":"Hello to trollbox server..."}}\n' );
  serverConfig = JSON.parse( configFile );

  //user database check
  var userDBPath = appDir + '/users/userDB.json';
  var userDBFile = checkForFileExistence( userDBPath, '{"users":[]}\n' );
  userDB = JSON.parse( userDBFile );
}


function checkForFileExistence( filename, defaultContent) {
  try {
    return fs.readFileSync( filename );
  } catch( e ) {
    fs.writeFileSync( filename, defaultContent );
    return fs.readFileSync( filename );
  }
}

server.listen( 6666 );
{'fraction_non_alphanumeric': 0.1659828422230511, 'fraction_numerical': 0.005221932114882507, 'mean_word_length': 3.763765541740675, 'pattern_counts': {'":': 6, '<': 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': '38963', 'n_tokens_mistral': 885, 'n_tokens_neox': 860, 'n_words': 219}