Commit 4ed935df authored by nanahira's avatar nanahira

async for room list

parent 580377da
...@@ -3586,26 +3586,35 @@ if settings.modules.http ...@@ -3586,26 +3586,35 @@ 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)->
roomid: room.process_pid.toString(), if !(room and room.established)
roomname: if pass_validated then room.name else room.name.split('$', 2)[0], done()
roommode: room.hostinfo.mode, return
needpass: (room.name.indexOf('$') != -1).toString(), roomsjson.push({
users: _.sortBy((for player in room.players when player.pos? roomid: room.process_pid.toString(),
id: (-1).toString(), roomname: if pass_validated then room.name else room.name.split('$', 2)[0],
name: player.name, roommode: room.hostinfo.mode,
ip: if settings.modules.http.show_ip and pass_validated and !player.is_local then player.ip.slice(7) else null, needpass: (room.name.indexOf('$') != -1).toString(),
status: if settings.modules.http.show_info and room.duel_stage != ygopro.constants.DUEL_STAGE.BEGIN and player.pos != 7 then ( users: _.sortBy((for player in room.players when player.pos?
score: room.scores[player.name_vpass], id: (-1).toString(),
lp: if player.lp? then player.lp else room.hostinfo.start_lp, name: player.name,
cards: if room.hostinfo.mode != 2 then (if player.card_count? then player.card_count else room.hostinfo.start_hand) else null ip: if settings.modules.http.show_ip and pass_validated and !player.is_local then player.ip.slice(7) else null,
) else null, status: if settings.modules.http.show_info and room.duel_stage != ygopro.constants.DUEL_STAGE.BEGIN and player.pos != 7 then (
pos: player.pos score: room.scores[player.name_vpass],
), "pos"), lp: if player.lp? then player.lp else room.hostinfo.start_lp,
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' cards: if room.hostinfo.mode != 2 then (if player.card_count? then player.card_count else room.hostinfo.start_hand) else null
), null, 2 ) else null,
response.end(addCallback(u.query.callback, roomsjson)) pos: player.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'
})
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,49 +4584,49 @@ ...@@ -4584,49 +4584,49 @@
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 len2, m, ref2, results;
var len3, n, ref2, results1; ref2 = room.players;
ref2 = room.players; results = [];
results1 = []; for (m = 0, len2 = ref2.length; m < len2; m++) {
for (n = 0, len3 = ref2.length; n < len3; n++) { player = ref2[m];
player = ref2[n]; if (player.pos != null) {
if (player.pos != null) { results.push({
results1.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, status: settings.modules.http.show_info && room.duel_stage !== ygopro.constants.DUEL_STAGE.BEGIN && player.pos !== 7 ? {
status: settings.modules.http.show_info && room.duel_stage !== ygopro.constants.DUEL_STAGE.BEGIN && player.pos !== 7 ? { score: room.scores[player.name_vpass],
score: room.scores[player.name_vpass], lp: player.lp != null ? player.lp : room.hostinfo.start_lp,
lp: player.lp != null ? player.lp : room.hostinfo.start_lp, cards: room.hostinfo.mode !== 2 ? (player.card_count != null ? player.card_count : room.hostinfo.start_hand) : null
cards: room.hostinfo.mode !== 2 ? (player.card_count != null ? player.card_count : room.hostinfo.start_hand) : null } : null,
} : null, pos: player.pos
pos: player.pos });
}); }
}
}
return results1;
})(), "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'
});
} }
} return results;
return results; })(), "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'
}, null, 2); });
response.end(addCallback(u.query.callback, roomsjson)); return done();
}, function() {
response.writeHead(200);
return response.end(addCallback(u.query.callback, JSON.stringify({
rooms: 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