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 ...@@ -35,7 +35,7 @@ export const app = core
.provide(ClientVersionCheck) .provide(ClientVersionCheck)
.define(); .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(`Welcome ${client.name_vpass || client.name}!`);
await client.sendChat(`Your IP: ${client.ip}`); await client.sendChat(`Your IP: ${client.ip}`);
await client.sendChat(`Your physical IP: ${client.physicalIp()}`); await client.sendChat(`Your physical IP: ${client.physicalIp()}`);
......
import { IncomingMessage } from 'node:http'; import { IncomingMessage } from 'node:http';
import { Socket } from 'node:net'; import { Socket } from 'node:net';
import { Observable, filter, fromEvent, map, merge } from 'rxjs'; import { Observable, fromEvent, merge } from 'rxjs';
import { take } from 'rxjs/operators'; import { map, take } from 'rxjs/operators';
import WebSocket, { RawData } from 'ws'; import WebSocket, { RawData } from 'ws';
import { Context } from '../../app'; import { Context } from '../../app';
import { Client } from '../../client'; import { Client } from '../../client';
...@@ -28,18 +28,26 @@ export class WsClient extends Client { ...@@ -28,18 +28,26 @@ export class WsClient extends Client {
} }
protected _receive(): Observable<Buffer> { protected _receive(): Observable<Buffer> {
return fromEvent<[RawData, boolean]>(this.sock, 'message').pipe( return new Observable<Buffer>((subscriber) => {
filter(([, isBinary]) => isBinary), const handler = (data: RawData, isBinary: boolean) => {
map(([data]) => { if (!isBinary) {
if (Buffer.isBuffer(data)) { return;
return data;
} }
if (Array.isArray(data)) { if (Buffer.isBuffer(data)) {
return Buffer.concat(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> { 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