Commit 3ae9ffa2 authored by nanahira's avatar nanahira

fix resp player

parent e84fae99
Pipeline #43329 passed with stages
in 3 minutes and 12 seconds
...@@ -7,6 +7,7 @@ import { ...@@ -7,6 +7,7 @@ import {
YGOProCtosTpResult, YGOProCtosTpResult,
YGOProCtosUpdateDeck, YGOProCtosUpdateDeck,
YGOProMsgResponseBase, YGOProMsgResponseBase,
YGOProMsgRetry,
} from 'ygopro-msg-encode'; } from 'ygopro-msg-encode';
import { Context } from '../app'; import { Context } from '../app';
import { Client } from '../client'; import { Client } from '../client';
...@@ -57,7 +58,27 @@ export class WaitForPlayerProvider { ...@@ -57,7 +58,27 @@ export class WaitForPlayerProvider {
constructor(private ctx: Context) { constructor(private ctx: Context) {
this.ctx.middleware( this.ctx.middleware(
YGOProMsgResponseBase, YGOProMsgResponseBase,
async (_msg, client, next) => { async (msg, client, next) => {
const room = this.getRoom(client);
if (!room || !this.hasTickForRoom(room)) {
return next();
}
try {
return await next();
} finally {
const operatePlayer = room.getIngameOperatingPlayer(
msg.responsePlayer(),
);
this.setWaitForPlayer(room, operatePlayer);
this.refreshLastActiveTime(room);
}
},
true,
);
this.ctx.middleware(
YGOProMsgRetry,
async (msg, client, next) => {
const room = this.getRoom(client); const room = this.getRoom(client);
if (!room || !this.hasTickForRoom(room)) { if (!room || !this.hasTickForRoom(room)) {
return next(); return next();
...@@ -65,7 +86,8 @@ export class WaitForPlayerProvider { ...@@ -65,7 +86,8 @@ export class WaitForPlayerProvider {
try { try {
return await next(); return await next();
} finally { } finally {
this.setWaitForPlayer(room, client); const operatePlayer = room.responsePlayer;
if (operatePlayer) this.setWaitForPlayer(room, operatePlayer);
this.refreshLastActiveTime(room); this.refreshLastActiveTime(room);
} }
}, },
......
...@@ -1752,6 +1752,15 @@ export class Room { ...@@ -1752,6 +1752,15 @@ export class Room {
private matchKilled = false; private matchKilled = false;
private responsePos?: number; private responsePos?: number;
get responsePlayer() {
if (this.responsePos == null) {
return undefined;
}
return this.getIngameOperatingPlayer(
this.getIngameDuelPosByDuelPos(this.responsePos),
);
}
private canAdvance() { private canAdvance() {
return this.duelStage === DuelStage.Dueling && !!this.ocgcore; return this.duelStage === DuelStage.Dueling && !!this.ocgcore;
} }
...@@ -1827,12 +1836,7 @@ export class Room { ...@@ -1827,12 +1836,7 @@ export class Room {
if (this.timerState.runningPos !== this.responsePos) { if (this.timerState.runningPos !== this.responsePos) {
return; return;
} }
if ( if (client !== this.responsePlayer) {
client !==
this.getIngameOperatingPlayer(
this.getIngameDuelPosByDuelPos(this.responsePos),
)
) {
return; return;
} }
...@@ -1863,10 +1867,7 @@ export class Room { ...@@ -1863,10 +1867,7 @@ export class Room {
private async onResponse(client: Client, msg: YGOProCtosResponse) { private async onResponse(client: Client, msg: YGOProCtosResponse) {
if ( if (
this.responsePos == null || this.responsePos == null ||
client !== client !== this.responsePlayer ||
this.getIngameOperatingPlayer(
this.getIngameDuelPosByDuelPos(this.responsePos),
) ||
!this.ocgcore // || this.timerState.awaitingConfirm !this.ocgcore // || this.timerState.awaitingConfirm
) { ) {
return; return;
......
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