Commit 01a9fdf5 authored by Dennis Willers's avatar Dennis Willers 🏀

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

parent 02019657
Pipeline #433 passed with stages
in 2 minutes and 49 seconds
...@@ -83,10 +83,9 @@ server.on('connection',function(socket){ ...@@ -83,10 +83,9 @@ server.on('connection',function(socket){
const req = JSON.parse(data); const req = JSON.parse(data);
hf.addMapToClient(clients, socket, req['mapId'], newClientList => { hf.addMapToClient(clients, socket, req['mapId'], newClientList => {
clients = newClientList.slice(); clients = newClientList.slice();
socket.write(JSON.stringify(res.data) + '\n');
if (hf.checkIfRequestHasVote(data)) { if (hf.checkIfRequestHasVote(data)) {
sendToAllClientsAtSameMap(res, req['mapId']); sendToAllClientsAtSameMap(res, req['mapId'], socket);
} else {
socket.write(JSON.stringify(res.data) + '\n');
} }
}); });
//var is_kernel_buffer_full = socket.write(JSON.stringify(res.data) + '\n'); //var is_kernel_buffer_full = socket.write(JSON.stringify(res.data) + '\n');
...@@ -151,11 +150,12 @@ server.on('connection',function(socket){ ...@@ -151,11 +150,12 @@ server.on('connection',function(socket){
} }
// Send a message to all clients playing the same map // 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)); console.log("JSON: ", JSON.stringify(res.data));
clients.forEach(function (client) { clients.forEach(function (client) {
// Don't want to send it to sender const resJson = res.data;
if (client.mapId === mapId) client.write(JSON.stringify(res.data) + '\n'); 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)); console.log("Write Message to all at " + mapId +": " + JSON.stringify(res.data));
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment