Commit 4ed935df authored by nanahira's avatar nanahira

async for room list

parent 580377da
...@@ -3586,8 +3586,12 @@ if settings.modules.http ...@@ -3586,8 +3586,12 @@ if settings.modules.http
response.writeHead(200) response.writeHead(200)
response.end(addCallback(u.query.callback, '{"rooms":[{"roomid":"0","roomname":"密码错误","needpass":"true"}]}')) response.end(addCallback(u.query.callback, '{"rooms":[{"roomid":"0","roomname":"密码错误","needpass":"true"}]}'))
else else
response.writeHead(200) roomsjson = [];
roomsjson = JSON.stringify rooms: (for room in ROOM_all when room and room.established _async.each(ROOM_all, (room, done)->
if !(room and room.established)
done()
return
roomsjson.push({
roomid: room.process_pid.toString(), roomid: room.process_pid.toString(),
roomname: if pass_validated then room.name else room.name.split('$', 2)[0], roomname: if pass_validated then room.name else room.name.split('$', 2)[0],
roommode: room.hostinfo.mode, roommode: room.hostinfo.mode,
...@@ -3604,8 +3608,13 @@ if settings.modules.http ...@@ -3604,8 +3608,13 @@ if settings.modules.http
pos: player.pos pos: player.pos
), "pos"), ), "pos"),
istart: if room.duel_stage != ygopro.constants.DUEL_STAGE.BEGIN then (if settings.modules.http.show_info then ("Duel:" + room.duel_count + " " + (if room.duel_stage == ygopro.constants.DUEL_STAGE.SIDING then "Siding" else "Turn:" + (if room.turn? then room.turn else 0) + (if room.death then "/" + (if room.death > 0 then room.death - 1 else "Death") else ""))) else 'start') else 'wait' istart: if room.duel_stage != ygopro.constants.DUEL_STAGE.BEGIN then (if settings.modules.http.show_info then ("Duel:" + room.duel_count + " " + (if room.duel_stage == ygopro.constants.DUEL_STAGE.SIDING then "Siding" else "Turn:" + (if room.turn? then room.turn else 0) + (if room.death then "/" + (if room.death > 0 then room.death - 1 else "Death") else ""))) else 'start') else 'wait'
), null, 2 })
response.end(addCallback(u.query.callback, roomsjson)) done()
, ()->
response.writeHead(200)
response.end(addCallback(u.query.callback, JSON.stringify({rooms: roomsjson})))
)
else if u.pathname == '/api/duellog' and settings.modules.tournament_mode.enabled else if u.pathname == '/api/duellog' and settings.modules.tournament_mode.enabled
if !auth.auth(u.query.username, u.query.pass, "duel_log", "duel_log") if !auth.auth(u.query.username, u.query.pass, "duel_log", "duel_log")
......
...@@ -4575,7 +4575,7 @@ ...@@ -4575,7 +4575,7 @@
return callback + "( " + text + " );"; return callback + "( " + text + " );";
}; };
requestListener = function(request, response) { requestListener = function(request, response) {
var archive_args, archive_name, archive_process, check, death_room_found, duellog, error, filename, getpath, len2, len3, m, n, parseQueryString, pass_validated, player, ref2, replay, room, rooms, roomsjson, u; var archive_args, archive_name, archive_process, check, death_room_found, duellog, error, filename, getpath, len2, len3, m, n, parseQueryString, pass_validated, ref2, replay, room, rooms, roomsjson, u;
parseQueryString = true; parseQueryString = true;
u = url.parse(request.url, parseQueryString); u = url.parse(request.url, parseQueryString);
if (u.pathname === '/api/getrooms') { if (u.pathname === '/api/getrooms') {
...@@ -4584,27 +4584,26 @@ ...@@ -4584,27 +4584,26 @@
response.writeHead(200); response.writeHead(200);
response.end(addCallback(u.query.callback, '{"rooms":[{"roomid":"0","roomname":"密码错误","needpass":"true"}]}')); response.end(addCallback(u.query.callback, '{"rooms":[{"roomid":"0","roomname":"密码错误","needpass":"true"}]}'));
} else { } else {
response.writeHead(200); roomsjson = [];
roomsjson = JSON.stringify({ _async.each(ROOM_all, function(room, done) {
rooms: (function() { var player;
var len2, m, results; if (!(room && room.established)) {
results = []; done();
for (m = 0, len2 = ROOM_all.length; m < len2; m++) { return;
room = ROOM_all[m]; }
if (room && room.established) { roomsjson.push({
results.push({
roomid: room.process_pid.toString(), roomid: room.process_pid.toString(),
roomname: pass_validated ? room.name : room.name.split('$', 2)[0], roomname: pass_validated ? room.name : room.name.split('$', 2)[0],
roommode: room.hostinfo.mode, roommode: room.hostinfo.mode,
needpass: (room.name.indexOf('$') !== -1).toString(), needpass: (room.name.indexOf('$') !== -1).toString(),
users: _.sortBy((function() { users: _.sortBy((function() {
var len3, n, ref2, results1; var len2, m, ref2, results;
ref2 = room.players; ref2 = room.players;
results1 = []; results = [];
for (n = 0, len3 = ref2.length; n < len3; n++) { for (m = 0, len2 = ref2.length; m < len2; m++) {
player = ref2[n]; player = ref2[m];
if (player.pos != null) { if (player.pos != null) {
results1.push({ results.push({
id: (-1).toString(), id: (-1).toString(),
name: player.name, name: player.name,
ip: settings.modules.http.show_ip && pass_validated && !player.is_local ? player.ip.slice(7) : null, ip: settings.modules.http.show_ip && pass_validated && !player.is_local ? player.ip.slice(7) : null,
...@@ -4617,16 +4616,17 @@ ...@@ -4617,16 +4616,17 @@
}); });
} }
} }
return results1; return results;
})(), "pos"), })(), "pos"),
istart: room.duel_stage !== ygopro.constants.DUEL_STAGE.BEGIN ? (settings.modules.http.show_info ? "Duel:" + room.duel_count + " " + (room.duel_stage === ygopro.constants.DUEL_STAGE.SIDING ? "Siding" : "Turn:" + (room.turn != null ? room.turn : 0) + (room.death ? "/" + (room.death > 0 ? room.death - 1 : "Death") : "")) : 'start') : 'wait' istart: room.duel_stage !== ygopro.constants.DUEL_STAGE.BEGIN ? (settings.modules.http.show_info ? "Duel:" + room.duel_count + " " + (room.duel_stage === ygopro.constants.DUEL_STAGE.SIDING ? "Siding" : "Turn:" + (room.turn != null ? room.turn : 0) + (room.death ? "/" + (room.death > 0 ? room.death - 1 : "Death") : "")) : 'start') : 'wait'
}); });
} return done();
} }, function() {
return results; response.writeHead(200);
})() return response.end(addCallback(u.query.callback, JSON.stringify({
}, null, 2); rooms: roomsjson
response.end(addCallback(u.query.callback, roomsjson)); })));
});
} }
} else if (u.pathname === '/api/duellog' && settings.modules.tournament_mode.enabled) { } else if (u.pathname === '/api/duellog' && settings.modules.tournament_mode.enabled) {
if (!auth.auth(u.query.username, u.query.pass, "duel_log", "duel_log")) { if (!auth.auth(u.query.username, u.query.pass, "duel_log", "duel_log")) {
......
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