diff --git a/src/common/Debug.ts b/src/common/Debug.ts index 8a497dc..67a2642 100644 --- a/src/common/Debug.ts +++ b/src/common/Debug.ts @@ -14,5 +14,7 @@ export const cardLog = debug('jc:card'); export const sysLog = debug('jc:sys'); +export const matchlog = debug('jc:match'); + export const error = debug('jc:error'); error.log = console.error.bind(console); diff --git a/src/rooms/RankedLobbyRoom.ts b/src/rooms/RankedLobbyRoom.ts index 3492619..0c3d6d8 100644 --- a/src/rooms/RankedLobbyRoom.ts +++ b/src/rooms/RankedLobbyRoom.ts @@ -2,11 +2,13 @@ import { Client, generateId, matchMaker, Room, ServerError } from 'colyseus' import { BaseConst } from '../constants/BaseConst' import { IncomingMessage } from 'http' import { checkMatchTicket } from '../common/WebApi' -import { error } from '../common/Debug' +import { error, matchlog } from '../common/Debug' +import { retry } from 'colyseus/lib/Utils' +import { RoomListingData } from 'colyseus/lib/matchmaker/drivers/Driver' interface MatchmakingGroup { averageRank: number; - clients: ClientStat[]; + clientList: ClientStat[]; priority?: boolean; ready?: boolean; @@ -194,7 +196,7 @@ export class RankedLobbyRoom extends Room { } createGroup() { - let group: MatchmakingGroup = { clients: [], averageRank: 0, count: 0 } + let group: MatchmakingGroup = { clientList: [], averageRank: 0, count: 0 } this.groups.push(group) return group } @@ -231,11 +233,11 @@ export class RankedLobbyRoom extends Room { } stat.group = currentGroup - currentGroup.clients.push(stat) + currentGroup.clientList.push(stat) currentGroup.count += stat.clients.size totalRank += stat.rank - currentGroup.averageRank = totalRank / currentGroup.clients.length + currentGroup.averageRank = totalRank / currentGroup.clientList.length if (currentGroup.count === this.numClientsToMatch) { currentGroup.ready = true currentGroup = this.createGroup() @@ -294,7 +296,7 @@ export class RankedLobbyRoom extends Room { } stat.group = currentGroup - currentGroup.clients.push(stat) + currentGroup.clientList.push(stat) currentGroup.count += stat.clients.size totalRank += stat.rank @@ -340,7 +342,7 @@ export class RankedLobbyRoom extends Room { group.confirmed = 0 let score = 0 let count = 0 - group.clients.map(client => { + group.clientList.map(client => { for (let [, data] of client.clients) { score += (data.options?.score || 0) count++ @@ -350,15 +352,18 @@ export class RankedLobbyRoom extends Room { /** * Create room instance in the server. */ - const room = await matchMaker.createRoom(this.roomToCreate, { - match: this.matchid, - rank: group.averageRank, - score: avaScore, - count: this.numClientsToMatch - group.count - }) + const room = await retry>(async () => { + return matchMaker.createRoom(this.roomToCreate, { + match: this.matchid, + rank: group.averageRank, + score: avaScore, + count: this.numClientsToMatch - group.count + }) + }, 10) + // 预处理数据, 确定座次 let hasGroup = false - for (let client of group.clients) { + for (let client of group.clientList) { if (client.clients.size > 1) { hasGroup = true break @@ -366,14 +371,14 @@ export class RankedLobbyRoom extends Room { } let seat = 0 if (hasGroup) { - for (let client of group.clients) { + for (let client of group.clientList) { if (client.clients.size > 1) { for (let [, sub] of client.clients) { sub.seat = this.generateSeat(seat++) } } } - for (let client of group.clients) { + for (let client of group.clientList) { if (client.clients.size == 1) { for (let [, sub] of client.clients) { sub.seat = this.generateSeat(seat++) @@ -381,8 +386,8 @@ export class RankedLobbyRoom extends Room { } } } else { - group.clients.sort((a, b) => a.rank - b.rank) - for (let client of group.clients) { + group.clientList.sort((a, b) => a.rank - b.rank) + for (let client of group.clientList) { for (let [, sub] of client.clients) { sub.seat = seat++ } @@ -390,7 +395,7 @@ export class RankedLobbyRoom extends Room { } - await Promise.all(group.clients.map(async (client) => { + await Promise.all(group.clientList.map(async (client) => { /** * Send room data for new WebSocket connection! @@ -404,6 +409,8 @@ export class RankedLobbyRoom extends Room { let options: any = { seat: data.seat, rank: data.options.rank } Object.assign(options, matchData) data.client.send('match_success', options) + const mdata = data.options + matchlog(`${mdata.accountid}:${mdata.score}:${mdata.rank}:${data.seat}:${client.waitingTime}`) } })) @@ -422,7 +429,7 @@ export class RankedLobbyRoom extends Room { /** * Notify all clients within the group on how many players are in the queue */ - group.clients.forEach(client => { + group.clientList.forEach(client => { for (let [, data] of client.clients) { data.client.send('clients', group.count) }