Commit 027d4e8d authored by nanahira's avatar nanahira

no send after disconnect

parent 2ffbaaf2
...@@ -19,6 +19,7 @@ import { I18nService } from './i18n'; ...@@ -19,6 +19,7 @@ import { I18nService } from './i18n';
import { Chnroute } from './chnroute'; import { Chnroute } from './chnroute';
import YGOProDeck from 'ygopro-deck-encode'; import YGOProDeck from 'ygopro-deck-encode';
import PQueue from 'p-queue'; import PQueue from 'p-queue';
import { ClientRoomField } from '../utility/decorators';
export abstract class Client { export abstract class Client {
protected abstract _send(data: Buffer): Promise<void>; protected abstract _send(data: Buffer): Promise<void>;
...@@ -72,7 +73,10 @@ export abstract class Client { ...@@ -72,7 +73,10 @@ export abstract class Client {
return this; return this;
} }
disconnected = false;
disconnect(): undefined { disconnect(): undefined {
this.disconnected = true;
this.disconnectSubject.next(); this.disconnectSubject.next();
this.disconnectSubject.complete(); this.disconnectSubject.complete();
this._disconnect().then(); this._disconnect().then();
...@@ -82,6 +86,9 @@ export abstract class Client { ...@@ -82,6 +86,9 @@ export abstract class Client {
private sendQueue = new PQueue({ concurrency: 1 }); private sendQueue = new PQueue({ concurrency: 1 });
async send(data: YGOProStocBase) { async send(data: YGOProStocBase) {
if (this.disconnected) {
return;
}
return this.sendQueue.add(async () => { return this.sendQueue.add(async () => {
try { try {
await this._send(Buffer.from(data.toFullPayload())); await this._send(Buffer.from(data.toFullPayload()));
...@@ -139,10 +146,15 @@ export abstract class Client { ...@@ -139,10 +146,15 @@ export abstract class Client {
established = false; established = false;
// in room // in room
@ClientRoomField()
roomName?: string; roomName?: string;
@ClientRoomField()
isHost = false; isHost = false;
@ClientRoomField()
pos = -1; pos = -1;
@ClientRoomField()
deck?: YGOProDeck; deck?: YGOProDeck;
@ClientRoomField()
startDeck?: YGOProDeck; startDeck?: YGOProDeck;
async sendTypeChange() { async sendTypeChange() {
......
...@@ -8,3 +8,6 @@ export interface RoomMethodOptions { ...@@ -8,3 +8,6 @@ export interface RoomMethodOptions {
export const RoomMethod = (options: RoomMethodOptions = {}): MethodDecorator => export const RoomMethod = (options: RoomMethodOptions = {}): MethodDecorator =>
Metadata.set('roomMethod', options, 'roomMethodKeys'); Metadata.set('roomMethod', options, 'roomMethodKeys');
export const ClientRoomField = (): PropertyDecorator =>
Metadata.set('clientRoomField', true, 'clientRoomFieldKeys');
...@@ -3,6 +3,7 @@ import type { RoomMethodOptions } from './decorators'; ...@@ -3,6 +3,7 @@ import type { RoomMethodOptions } from './decorators';
interface MetadataMap { interface MetadataMap {
roomMethod: RoomMethodOptions; roomMethod: RoomMethodOptions;
clientRoomField: true;
} }
type MetadataArrayMap = { type MetadataArrayMap = {
......
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