<commit_before>const login = require('./login');
const startUserServer = require('./start-user-server');
const { genSid, hashSid, getSession, _setNewSession, delSession } = require('./session');


function ipc(entranceProcess){

  
  entranceProcess.on('message', function(msgObj){

    function _send(sendData){
      if(sendData){
        sendData.id = msgObj.id;
        entranceProcess.send(sendData);
      }
    }

    if(msgObj.type === 'login'){
      _handleMsgLogin(msgObj.data, _send);
    } else if(msgObj.type === 'logout'){
      _handleMsgLogout(msgObj.data, _send);
    } else if(msgObj.type === 'getSession'){
      _handleMsgGetSession(msgObj.data, _send);
    }
    
  })

}

function _handleMsgLogin(data, send){
  loginAndStartUserServer(data, function(err, result){
    if(err){
      send({
        type: 'error',
        message: err.message
      });
      return;
    }

    send({
      type: 'success',
      data: result
    });
  })
}

function _handleMsgLogout({sid, username}, send){
  delSession(sid, username);
  send({
    type: 'success'
  })
}

function _handleMsgGetSession(sid, send){
  const session = getSession(sid);
  let sendData = {
    type: 'success',
  }
  if(session){
    sendData.data = {
      hash: session.hash,
      users: Array.from(session.userMap.keys())
    }
  } else {
    sendData.data = null;
  }
  send(sendData);
}

function loginAndStartUserServer({username, password, ip}, callback){
  
  const term = login({
    username,
    password,
    ip,
    end(err) {

      if(err){
        return callback(err);
      }
<commit_msg>type 2 status<commit_after>const login = require('./login');
const startUserServer = require('./start-user-server');
const { genSid, hashSid, getSession, _setNewSession, delSession } = require('./session');


function ipc(entranceProcess){

  
  entranceProcess.on('message', function(msgObj){

    function _send(sendData){
      if(sendData){
        sendData.id = msgObj.id;
        entranceProcess.send(sendData);
      }
    }

    if(msgObj.type === 'login'){
      _handleMsgLogin(msgObj.data, _send);
    } else if(msgObj.type === 'logout'){
      _handleMsgLogout(msgObj.data, _send);
    } else if(msgObj.type === 'getSession'){
      _handleMsgGetSession(msgObj.data, _send);
    }
    
  })

}

function _handleMsgLogin(data, send){
  loginAndStartUserServer(data, function(err, result){
    if(err){
      send({
        status: 'error',
        message: err.message
      });
      return;
    }

    send({
      status: 'success',
      data: result
    });
  })
}

function _handleMsgLogout({sid, username}, send){
  delSession(sid, username);
  send({
    status: 'success'
  })
}

function _handleMsgGetSession(sid, send){
  const session = getSession(sid);
  let sendData = {
    status: 'success',
  }
  if(session){
    sendData.data = {
      hash: session.hash,
      users: Array.from(session.userMap.keys())
    }
  } else {
    sendData.data = null;
  }
  send(sendData);
}

function loginAndStartUserServer({username, password, ip}, callback){
  
  const term = login({
    username,
    password,
    ip,
    end(err) {

      if(err){
        return callback(err);
      }

{'fraction_non_alphanumeric': 0.14696685428392744, 'fraction_numerical': 0.00031269543464665416, 'mean_word_length': 2.8403361344537816, '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': '2671163', 'n_tokens_mistral': 1062, 'n_tokens_neox': 1052, 'n_words': 200}