Commit 70148f4b authored by nanahira's avatar nanahira

put watcher in roomlist

parent 33ae74b7
Pipeline #43309 passed with stages
in 3 minutes and 48 seconds
import { ChatColor } from 'ygopro-msg-encode'; import { ChatColor, NetPlayerType } from 'ygopro-msg-encode';
import { Context } from '../app'; import { Context } from '../app';
import { DialoguesProvider, TipsProvider } from '../feats/resource'; import { DialoguesProvider, TipsProvider } from '../feats/resource';
import { RoomDeathService } from '../feats/room-death-service'; import { RoomDeathService } from '../feats/room-death-service';
...@@ -158,21 +158,32 @@ export class LegacyApiService { ...@@ -158,21 +158,32 @@ export class LegacyApiService {
const roomInfos = await Promise.all( const roomInfos = await Promise.all(
rooms.map(async (room) => { rooms.map(async (room) => {
const info = await room.getInfo(); const info = await room.getInfo();
const users = [...info.players] const users = [
...info.players,
...[...room.watchers].map((watcher) => ({
name: watcher.name,
ip: watcher.ip,
pos: watcher.pos,
score: undefined,
lp: undefined,
cardCount: undefined,
})),
]
.sort((a, b) => a.pos - b.pos) .sort((a, b) => a.pos - b.pos)
.map((player) => ({ .map((member) => ({
id: '-1', id: '-1',
name: player.name, name: member.name,
ip: this.ipResolver.toIpv4(player.ip) || null, ip: this.ipResolver.toIpv4(member.ip) || null,
status: status:
info.duelStage !== DuelStage.Begin info.duelStage !== DuelStage.Begin &&
member.pos !== NetPlayerType.OBSERVER
? { ? {
score: player.score ?? 0, score: member.score ?? 0,
lp: player.lp ?? info.hostinfo.start_lp, lp: member.lp ?? info.hostinfo.start_lp,
cards: player.cardCount ?? info.hostinfo.start_hand, cards: member.cardCount ?? info.hostinfo.start_hand,
} }
: null, : null,
pos: player.pos, pos: member.pos,
})); }));
return { return {
roomid: this.roomIdService.getRoomIdString(info.identifier), roomid: this.roomIdService.getRoomIdString(info.identifier),
......
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