Commit 5e9439cf authored by nanahira's avatar nanahira

Merge branch 'master' into koishi

parents fc0adf7f 829ee179
Pipeline #17711 passed with stages
in 10 minutes and 23 seconds
...@@ -12,6 +12,8 @@ room_data = (room)-> ...@@ -12,6 +12,8 @@ room_data = (room)->
options: room.get_roomlist_hostinfo(), # Should be updated when MyCard client updates options: room.get_roomlist_hostinfo(), # Should be updated when MyCard client updates
arena: settings.modules.arena_mode.enabled && room.arena && settings.modules.arena_mode.mode arena: settings.modules.arena_mode.enabled && room.arena && settings.modules.arena_mode.mode
clients = new Set()
init = (http_server, ROOM_all)-> init = (http_server, ROOM_all)->
server = new WebSocketServer server = new WebSocketServer
server: http_server server: http_server
...@@ -21,6 +23,8 @@ init = (http_server, ROOM_all)-> ...@@ -21,6 +23,8 @@ init = (http_server, ROOM_all)->
connection.send JSON.stringify connection.send JSON.stringify
event: 'init' event: 'init'
data: room_data(room) for room in ROOM_all when room and room.established and (connection.filter == 'started' or !room.private) and ((room.duel_stage != 0) == (connection.filter == 'started')) data: room_data(room) for room in ROOM_all when room and room.established and (connection.filter == 'started' or !room.private) and ((room.duel_stage != 0) == (connection.filter == 'started'))
clients.add connection
connection.on('close', () -> clients.delete connection if clients.has connection)
create = (room)-> create = (room)->
broadcast('create', room_data(room), 'waiting') if !room.private broadcast('create', room_data(room), 'waiting') if !room.private
...@@ -43,7 +47,7 @@ broadcast = (event, data, filter)-> ...@@ -43,7 +47,7 @@ broadcast = (event, data, filter)->
message = JSON.stringify message = JSON.stringify
event: event event: event
data: data data: data
for connection in server.clients when connection.filter == filter for connection in Array.from(clients.values()) when connection.filter == filter
try try
connection.send message connection.send message
......
// Generated by CoffeeScript 2.6.1 // Generated by CoffeeScript 2.6.1
(function() { (function() {
var WebSocketServer, _delete, broadcast, create, init, room_data, server, settings, start, update, url; var WebSocketServer, _delete, broadcast, clients, create, init, room_data, server, settings, start, update, url;
WebSocketServer = require('ws').Server; WebSocketServer = require('ws').Server;
...@@ -36,6 +36,8 @@ ...@@ -36,6 +36,8 @@
}; };
}; };
clients = new Set();
init = function(http_server, ROOM_all) { init = function(http_server, ROOM_all) {
server = new WebSocketServer({ server = new WebSocketServer({
server: http_server server: http_server
...@@ -43,7 +45,7 @@ ...@@ -43,7 +45,7 @@
return server.on('connection', function(connection, upgradeReq) { return server.on('connection', function(connection, upgradeReq) {
var room; var room;
connection.filter = url.parse(upgradeReq.url, true).query.filter || 'waiting'; connection.filter = url.parse(upgradeReq.url, true).query.filter || 'waiting';
return connection.send(JSON.stringify({ connection.send(JSON.stringify({
event: 'init', event: 'init',
data: (function() { data: (function() {
var i, len, results; var i, len, results;
...@@ -57,6 +59,12 @@ ...@@ -57,6 +59,12 @@
return results; return results;
})() })()
})); }));
clients.add(connection);
return connection.on('close', function() {
if (clients.has(connection)) {
return clients.delete(connection);
}
});
}); });
}; };
...@@ -98,7 +106,7 @@ ...@@ -98,7 +106,7 @@
event: event, event: event,
data: data data: data
}); });
ref = server.clients; ref = Array.from(clients.values());
results = []; results = [];
for (i = 0, len = ref.length; i < len; i++) { for (i = 0, len = ref.length; i < len; i++) {
connection = ref[i]; connection = ref[i];
......
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