Commit d103fef3 authored by nanahira's avatar nanahira

fix

parent 788acbca
Pipeline #43120 passed with stages
in 42 seconds
......@@ -35,7 +35,7 @@ export const app = core
.provide(ClientVersionCheck)
.define();
app.middleware(YGOProCtosJoinGame, async (msg, client, next) => {
app.middleware(YGOProCtosJoinGame, async (msg, client, _next) => {
await client.sendChat(`Welcome ${client.name_vpass || client.name}!`);
await client.sendChat(`Your IP: ${client.ip}`);
await client.sendChat(`Your physical IP: ${client.physicalIp()}`);
......
import { IncomingMessage } from 'node:http';
import { Socket } from 'node:net';
import { Observable, filter, fromEvent, map, merge } from 'rxjs';
import { take } from 'rxjs/operators';
import { Observable, fromEvent, merge } from 'rxjs';
import { map, take } from 'rxjs/operators';
import WebSocket, { RawData } from 'ws';
import { Context } from '../../app';
import { Client } from '../../client';
......@@ -28,18 +28,26 @@ export class WsClient extends Client {
}
protected _receive(): Observable<Buffer> {
return fromEvent<[RawData, boolean]>(this.sock, 'message').pipe(
filter(([, isBinary]) => isBinary),
map(([data]) => {
if (Buffer.isBuffer(data)) {
return data;
return new Observable<Buffer>((subscriber) => {
const handler = (data: RawData, isBinary: boolean) => {
if (!isBinary) {
return;
}
if (Array.isArray(data)) {
return Buffer.concat(data);
if (Buffer.isBuffer(data)) {
subscriber.next(data);
} else if (Array.isArray(data)) {
subscriber.next(Buffer.concat(data));
} else {
subscriber.next(Buffer.from(data));
}
return Buffer.from(data);
}),
);
};
this.sock.on('message', handler);
return () => {
this.sock.off('message', handler);
};
});
}
protected async _disconnect(): Promise<void> {
......
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