/**
 * Multi-User Engine.
 * 
 * @author William Escudero <wescu001@fiu.edu>
 * @version 1.0.0
 */

function Mue(){

    const net = require('net');

    const active_sits = [];

    const server_port = 8181;

    var server_handle = null;

    var client_handle = null;

    var state = null;



    var protocol = {
        digest: function(event, socket){

        }
    };


    this.Server = {

        start: function(){

            // Save current context
            let context = this;

            // Create server
            server_handle = net.createServer(function(client_socket){

                client_socket.on('data', function(data){
                    protocol.digest(data, client_socket);
                });

                client_socket.on('end', function(){
                    // Remove client from active_sits
                    // @TODO
                });
            });

            server_handle.listen(server_port);
        },
        broadcast: function(event){
        }
    },
    this.Client = {
        connect: function(){
            state = "YA";

            console.log("connected");
        },
        emit: function(){
            console.log('this is a test');
        }
    }
}

module.exports = new Mue();