<commit_before>var sys = require("util")
  , ws = require('./node-websocket-server/lib/ws/server');

var Chat = require('./chat').Chat
var chat = new Chat();

var server = ws.createServer({debug: false});


// Handle WebSocket Requests
server.addListener("connection", function(conn){
    conn.send( JSON.stringify({command: 'init', state: chat.getState()}));

    conn.addListener("message", function(msg){
        try{
            var data = JSON.parse(msg);
            if (data.command === 'new_message') {
                var message = chat.addMessage( conn, data.message );

                server.broadcast( JSON.stringify({command: data.command, message: message}) );
            }
            if (data.command === 'new_member') {
                var member = chat.addMember( conn, data.username, data.gravatar_hash);

                if( member.is_new ) {
                    chat.oldifyMember( conn.id ); 
                    server.broadcast( JSON.stringify({command: data.command, member: member}) );
                } else {
                    server.broadcast( JSON.stringify({command: 'reconnect_member', member_id: member.origin_id}) );
                }
            }
        } catch(e) {
            console.warn(e + 'dropping command for ' + conn.id + ' command: ' + msg);
        }
    });
});

server.addListener("error", function(){
    console.log(Array.prototype.join.call(arguments, ", "));
});

server.addListener("disconnect", function(conn){
    console.log('disconnect');
    member = chat.getMember( conn.id );
    server.broadcast( JSON.stringify( {command: 'remove_member', member_id: member.origin_id }));
});

// game cycle
server.listen(8000, function() {
    console.log("Server Started");
});
<commit_msg>Check if member exists before attempting to remove<commit_after>var sys = require("util")
  , ws = require('./node-websocket-server/lib/ws/server');

var Chat = require('./chat').Chat
var chat = new Chat();

var server = ws.createServer({debug: false});


// Handle WebSocket Requests
server.addListener("connection", function(conn){
    conn.send( JSON.stringify({command: 'init', state: chat.getState()}));

    conn.addListener("message", function(msg){
        try{
            var data = JSON.parse(msg);
            if (data.command === 'new_message') {
                var message = chat.addMessage( conn, data.message );

                server.broadcast( JSON.stringify({command: data.command, message: message}) );
            }
            if (data.command === 'new_member') {
                var member = chat.addMember( conn, data.username, data.gravatar_hash);

                if( member.is_new ) {
                    chat.oldifyMember( conn.id ); 
                    server.broadcast( JSON.stringify({command: data.command, member: member}) );
                } else {
                    server.broadcast( JSON.stringify({command: 'reconnect_member', member_id: member.origin_id}) );
                }
            }
        } catch(e) {
            console.warn(e + 'dropping command for ' + conn.id + ' command: ' + msg);
        }
    });
});

server.addListener("error", function(){
    console.log(Array.prototype.join.call(arguments, ", "));
});

server.addListener("disconnect", function(conn){
    console.log('disconnect');
    member = chat.getMember( conn.id );
    if(member) {
        server.broadcast( JSON.stringify( {command: 'remove_member', member_id: member.origin_id }));
    }
});

// game cycle
server.listen(8000, function() {
    console.log("Server Started");
});

{'fraction_non_alphanumeric': 0.15661971830985916, 'fraction_numerical': 0.0022535211267605635, 'mean_word_length': 2.4779627815866796, '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': '3257342', 'n_tokens_mistral': 1026, 'n_tokens_neox': 989, 'n_words': 204}