Commit 01a9fdf5 authored by Dennis Willers's avatar Dennis Willers
Browse files

Only response vote to the client who want to know his own vote

parent 02019657
Loading
Loading
Loading
Loading
+6 −6
Original line number Diff line number Diff line
@@ -83,10 +83,9 @@ server.on('connection',function(socket){
                    const req = JSON.parse(data);
                    hf.addMapToClient(clients, socket, req['mapId'], newClientList => {
                        clients = newClientList.slice();
                        if (hf.checkIfRequestHasVote(data)) {
                            sendToAllClientsAtSameMap(res, req['mapId']);
                        } else {
                        socket.write(JSON.stringify(res.data) + '\n');
                        if (hf.checkIfRequestHasVote(data)) {
                            sendToAllClientsAtSameMap(res, req['mapId'], socket);
                        }
                    });
                    //var is_kernel_buffer_full = socket.write(JSON.stringify(res.data) + '\n');
@@ -151,11 +150,12 @@ server.on('connection',function(socket){
    }

    // Send a message to all clients playing the same map
    function sendToAllClientsAtSameMap(res, mapId) {
    function sendToAllClientsAtSameMap(res, mapId, currentClient) {
        console.log("JSON: ", JSON.stringify(res.data));
        clients.forEach(function (client) {
            // Don't want to send it to sender
            if (client.mapId === mapId) client.write(JSON.stringify(res.data) + '\n');
            const resJson = res.data;
            delete resJson['vote'];
            if (client.mapId === mapId && client.name !== currentClient) client.write(JSON.stringify(resJson) + '\n');
        });
        console.log("Write Message to all at " + mapId +": " + JSON.stringify(res.data));
    }