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