Commit 223d6dc0 authored by chechunchi's avatar chechunchi

add 408 hint

parent 3ae86dcb
Pipeline #30313 passed with stages
in 7 minutes and 18 seconds
......@@ -8,10 +8,13 @@ export class WebSocketStream {
public ws: WebSocket;
stream: ReadableStream;
constructor(ip: string, onWsOpen?: (ws: WebSocket, ev: Event) => any) {
constructor(
ip: string,
onWsOpen?: (conn: WebSocketStream, ev: Event) => any,
) {
this.ws = new WebSocket("wss://" + ip);
if (onWsOpen) {
this.ws.onopen = (e) => onWsOpen(this.ws, e);
this.ws.onopen = (e) => onWsOpen(this, e);
}
this.ws.onerror = (e) => {
if (e instanceof ErrorEvent) {
......
......@@ -13,11 +13,13 @@ export function initSocket(initInfo: {
ip: string;
player: string;
passWd: string;
customOnConnected?: (conn: WebSocketStream) => void;
}): WebSocketStream {
const { ip, player, passWd } = initInfo;
return new WebSocketStream(ip, (conn, _event) =>
handleSocketOpen(conn, ip, player, passWd),
);
const { ip, player, passWd, customOnConnected } = initInfo;
return new WebSocketStream(ip, (conn, _event) => {
handleSocketOpen(conn, ip, player, passWd);
customOnConnected && customOnConnected(conn);
});
}
export function initReplaySocket(replayInfo: {
......@@ -27,8 +29,8 @@ export function initReplaySocket(replayInfo: {
const { url, data } = replayInfo;
return new WebSocketStream(url, (conn, _event) => {
console.info("replay websocket open.");
conn.binaryType = "arraybuffer";
conn.send(data);
conn.ws.binaryType = "arraybuffer";
conn.ws.send(data);
});
}
......
......@@ -4,6 +4,7 @@
* */
import { sendJoinGame, sendPlayerInfo } from "@/api";
import { useConfig } from "@/config";
import { WebSocketStream } from "@/infra";
const NeosConfig = useConfig();
/*
......@@ -12,17 +13,17 @@ const NeosConfig = useConfig();
*
* */
export default function handleSocketOpen(
ws: WebSocket | undefined,
conn: WebSocketStream | undefined,
_ip: string,
player: string,
passWd: string,
) {
console.log("WebSocket opened.");
if (ws && ws.readyState === 1) {
ws.binaryType = "arraybuffer";
if (conn && conn.ws.readyState === 1) {
conn.ws.binaryType = "arraybuffer";
sendPlayerInfo(ws, player);
sendJoinGame(ws, NeosConfig.version, passWd);
sendPlayerInfo(conn.ws, player);
sendJoinGame(conn.ws, NeosConfig.version, passWd);
}
}
......@@ -4,7 +4,9 @@ import { useTranslation } from "react-i18next";
import { useNavigate } from "react-router-dom";
import { proxy, useSnapshot } from "valtio";
import { sendChat } from "@/api";
import { useConfig } from "@/config";
import { WebSocketStream } from "@/infra";
import { accountStore, roomStore } from "@/stores";
import { Select } from "@/ui/Shared";
......@@ -55,6 +57,16 @@ export const MatchModal: React.FC = ({}) => {
const handlePasswdChange = (event: ChangeEvent<HTMLInputElement>) => {
setPasswd(event.target.value);
};
const send408Hint = (conn: WebSocketStream) => {
setTimeout(
() =>
sendChat(
conn,
"由于技术原因,408环境卡池内可用卡牌暂无法直接标出,某些卡片实际使用的是旧效果,例如混沌之黑魔术师、多尔·多拉、死之卡组破坏病毒...",
),
1000,
);
};
const handleSubmit = async () => {
setConfirmLoading(true);
......@@ -63,6 +75,7 @@ export const MatchModal: React.FC = ({}) => {
ip: genServerAddress(serverId),
passWd: passwd,
enableKuriboh,
customOnConnected: serverId === ENV_408 ? send408Hint : undefined,
});
};
......
......@@ -3,6 +3,7 @@ import rustInit from "rust-src";
import { initStrings, initSuperPrerelease } from "@/api";
import { useConfig } from "@/config";
import { getUIContainer, initUIContainer } from "@/container/compat";
import { WebSocketStream } from "@/infra";
import { initReplaySocket, initSocket } from "@/middleware/socket";
import {
pollSocketLooper,
......@@ -21,6 +22,7 @@ export const connectSrvpro = async (params: {
enableKuriboh?: boolean;
replay?: boolean;
replayData?: ArrayBuffer;
customOnConnected?: (conn: WebSocketStream) => void;
}) => {
// 初始化wasm
const url =
......
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