增加匹配成功的日志记录
This commit is contained in:
parent
c1ce8662d3
commit
3f1802c35c
@ -14,5 +14,7 @@ export const cardLog = debug('jc:card');
|
|||||||
|
|
||||||
export const sysLog = debug('jc:sys');
|
export const sysLog = debug('jc:sys');
|
||||||
|
|
||||||
|
export const matchlog = debug('jc:match');
|
||||||
|
|
||||||
export const error = debug('jc:error');
|
export const error = debug('jc:error');
|
||||||
error.log = console.error.bind(console);
|
error.log = console.error.bind(console);
|
||||||
|
@ -2,11 +2,13 @@ import { Client, generateId, matchMaker, Room, ServerError } from 'colyseus'
|
|||||||
import { BaseConst } from '../constants/BaseConst'
|
import { BaseConst } from '../constants/BaseConst'
|
||||||
import { IncomingMessage } from 'http'
|
import { IncomingMessage } from 'http'
|
||||||
import { checkMatchTicket } from '../common/WebApi'
|
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 {
|
interface MatchmakingGroup {
|
||||||
averageRank: number;
|
averageRank: number;
|
||||||
clients: ClientStat[];
|
clientList: ClientStat[];
|
||||||
priority?: boolean;
|
priority?: boolean;
|
||||||
|
|
||||||
ready?: boolean;
|
ready?: boolean;
|
||||||
@ -194,7 +196,7 @@ export class RankedLobbyRoom extends Room {
|
|||||||
}
|
}
|
||||||
|
|
||||||
createGroup() {
|
createGroup() {
|
||||||
let group: MatchmakingGroup = { clients: [], averageRank: 0, count: 0 }
|
let group: MatchmakingGroup = { clientList: [], averageRank: 0, count: 0 }
|
||||||
this.groups.push(group)
|
this.groups.push(group)
|
||||||
return group
|
return group
|
||||||
}
|
}
|
||||||
@ -231,11 +233,11 @@ export class RankedLobbyRoom extends Room {
|
|||||||
}
|
}
|
||||||
|
|
||||||
stat.group = currentGroup
|
stat.group = currentGroup
|
||||||
currentGroup.clients.push(stat)
|
currentGroup.clientList.push(stat)
|
||||||
currentGroup.count += stat.clients.size
|
currentGroup.count += stat.clients.size
|
||||||
|
|
||||||
totalRank += stat.rank
|
totalRank += stat.rank
|
||||||
currentGroup.averageRank = totalRank / currentGroup.clients.length
|
currentGroup.averageRank = totalRank / currentGroup.clientList.length
|
||||||
if (currentGroup.count === this.numClientsToMatch) {
|
if (currentGroup.count === this.numClientsToMatch) {
|
||||||
currentGroup.ready = true
|
currentGroup.ready = true
|
||||||
currentGroup = this.createGroup()
|
currentGroup = this.createGroup()
|
||||||
@ -294,7 +296,7 @@ export class RankedLobbyRoom extends Room {
|
|||||||
}
|
}
|
||||||
|
|
||||||
stat.group = currentGroup
|
stat.group = currentGroup
|
||||||
currentGroup.clients.push(stat)
|
currentGroup.clientList.push(stat)
|
||||||
currentGroup.count += stat.clients.size
|
currentGroup.count += stat.clients.size
|
||||||
|
|
||||||
totalRank += stat.rank
|
totalRank += stat.rank
|
||||||
@ -340,7 +342,7 @@ export class RankedLobbyRoom extends Room {
|
|||||||
group.confirmed = 0
|
group.confirmed = 0
|
||||||
let score = 0
|
let score = 0
|
||||||
let count = 0
|
let count = 0
|
||||||
group.clients.map(client => {
|
group.clientList.map(client => {
|
||||||
for (let [, data] of client.clients) {
|
for (let [, data] of client.clients) {
|
||||||
score += (data.options?.score || 0)
|
score += (data.options?.score || 0)
|
||||||
count++
|
count++
|
||||||
@ -350,15 +352,18 @@ export class RankedLobbyRoom extends Room {
|
|||||||
/**
|
/**
|
||||||
* Create room instance in the server.
|
* Create room instance in the server.
|
||||||
*/
|
*/
|
||||||
const room = await matchMaker.createRoom(this.roomToCreate, {
|
const room = await retry<Promise<RoomListingData>>(async () => {
|
||||||
match: this.matchid,
|
return matchMaker.createRoom(this.roomToCreate, {
|
||||||
rank: group.averageRank,
|
match: this.matchid,
|
||||||
score: avaScore,
|
rank: group.averageRank,
|
||||||
count: this.numClientsToMatch - group.count
|
score: avaScore,
|
||||||
})
|
count: this.numClientsToMatch - group.count
|
||||||
|
})
|
||||||
|
}, 10)
|
||||||
|
|
||||||
// 预处理数据, 确定座次
|
// 预处理数据, 确定座次
|
||||||
let hasGroup = false
|
let hasGroup = false
|
||||||
for (let client of group.clients) {
|
for (let client of group.clientList) {
|
||||||
if (client.clients.size > 1) {
|
if (client.clients.size > 1) {
|
||||||
hasGroup = true
|
hasGroup = true
|
||||||
break
|
break
|
||||||
@ -366,14 +371,14 @@ export class RankedLobbyRoom extends Room {
|
|||||||
}
|
}
|
||||||
let seat = 0
|
let seat = 0
|
||||||
if (hasGroup) {
|
if (hasGroup) {
|
||||||
for (let client of group.clients) {
|
for (let client of group.clientList) {
|
||||||
if (client.clients.size > 1) {
|
if (client.clients.size > 1) {
|
||||||
for (let [, sub] of client.clients) {
|
for (let [, sub] of client.clients) {
|
||||||
sub.seat = this.generateSeat(seat++)
|
sub.seat = this.generateSeat(seat++)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (let client of group.clients) {
|
for (let client of group.clientList) {
|
||||||
if (client.clients.size == 1) {
|
if (client.clients.size == 1) {
|
||||||
for (let [, sub] of client.clients) {
|
for (let [, sub] of client.clients) {
|
||||||
sub.seat = this.generateSeat(seat++)
|
sub.seat = this.generateSeat(seat++)
|
||||||
@ -381,8 +386,8 @@ export class RankedLobbyRoom extends Room {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
group.clients.sort((a, b) => a.rank - b.rank)
|
group.clientList.sort((a, b) => a.rank - b.rank)
|
||||||
for (let client of group.clients) {
|
for (let client of group.clientList) {
|
||||||
for (let [, sub] of client.clients) {
|
for (let [, sub] of client.clients) {
|
||||||
sub.seat = seat++
|
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!
|
* 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 }
|
let options: any = { seat: data.seat, rank: data.options.rank }
|
||||||
Object.assign(options, matchData)
|
Object.assign(options, matchData)
|
||||||
data.client.send('match_success', options)
|
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
|
* 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) {
|
for (let [, data] of client.clients) {
|
||||||
data.client.send('clients', group.count)
|
data.client.send('clients', group.count)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user