<commit_before>'use strict';

var nickNames = {};
var namesUsed = [];
var guestNumber = 1;

exports.init = function() {
};

exports.getUserBySocket = function(socket) {
  return getUserBySocketId(socket.id);
};

function getUserBySocketId(socketId) {
  return nickNames[socketId];
};

exports.getInitialNick = function(socket, nickFromCookie) {
  var nick;
  if (nickFromCookie && !namesUsed[nickFromCookie]) {
    nick = nickFromCookie;
  } else {
    var nick = 'Guest' + guestNumber;
    guestNumber++;
  }
  setNickName(socket, nick);
  namesUsed.push(nick);
  return nick;
};

function setNickName(socket, nick) {
  nickNames[socket.id] = nick;
};

exports.isAllowed = function(name) {
  return name.indexOf('Guest') != 0;
};

exports.isAvailable = function(name) {
  return namesUsed.indexOf(name) === -1;
};

exports.rename = function(socket, name) {
  var previousName = module.exports.getUserBySocket(socket);
  var previousNameIndex = namesUsed.indexOf(previousName);
  namesUsed.push(name);
  setNickName(socket, name);
  delete namesUsed[previousNameIndex];
};

exports.onUserDisconnect = function(socket) {
  var nick = module.exports.getUserBySocket(socket);
  console.log(nick + ' disconnected.');
  var nameIndex = namesUsed.indexOf(nick);
  delete namesUsed[nameIndex];
  delete nickNames[socket.id];
};<commit_msg>remove console.log<commit_after>'use strict';

var nickNames = {};
var namesUsed = [];
var guestNumber = 1;

exports.init = function() {
};

exports.getUserBySocket = function(socket) {
  return getUserBySocketId(socket.id);
};

function getUserBySocketId(socketId) {
  return nickNames[socketId];
};

exports.getInitialNick = function(socket, nickFromCookie) {
  var nick;
  if (nickFromCookie && !namesUsed[nickFromCookie]) {
    nick = nickFromCookie;
  } else {
    var nick = 'Guest' + guestNumber;
    guestNumber++;
  }
  setNickName(socket, nick);
  namesUsed.push(nick);
  return nick;
};

function setNickName(socket, nick) {
  nickNames[socket.id] = nick;
};

exports.isAllowed = function(name) {
  return name.indexOf('Guest') != 0;
};

exports.isAvailable = function(name) {
  return namesUsed.indexOf(name) === -1;
};

exports.rename = function(socket, name) {
  var previousName = module.exports.getUserBySocket(socket);
  var previousNameIndex = namesUsed.indexOf(previousName);
  namesUsed.push(name);
  setNickName(socket, name);
  delete namesUsed[previousNameIndex];
};

exports.onUserDisconnect = function(socket) {
  var nick = module.exports.getUserBySocket(socket);
  var nameIndex = namesUsed.indexOf(nick);
  delete namesUsed[nameIndex];
  delete nickNames[socket.id];
};
{'fraction_non_alphanumeric': 0.13807531380753138, 'fraction_numerical': 0.002282236591860023, 'mean_word_length': 5.102088167053364, 'pattern_counts': {'":': 0, '<': 3, '<?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': '6018227', 'n_tokens_mistral': 858, 'n_tokens_neox': 847, 'n_words': 165}