Commit 47e27eae authored by Chunchi Che's avatar Chunchi Che

支持233服

parent f80a8f42
......@@ -4,7 +4,8 @@
{
"name":"koishi",
"ip":"koishi.momobako.com",
"port":"7211"
"port":"7211",
"ssl": true
}
],
"assetsPath":"/neos-assets",
......
......@@ -4,7 +4,8 @@
{
"name":"koishi",
"ip":"koishi.momobako.com",
"port":"7211"
"port":"7211",
"ssl": true
}
],
"assetsPath":"/neos-assets",
......
......@@ -12,8 +12,12 @@ export class WebSocketStream {
public ws: WebSocket;
stream: ReadableStream;
constructor(ip: string, onWsOpen?: (ws: WebSocket, ev: Event) => any) {
this.ws = new WebSocket("wss://" + ip);
constructor(
ip: string,
ssl: boolean,
onWsOpen?: (ws: WebSocket, ev: Event) => any,
) {
this.ws = new WebSocket((ssl ? "wss://" : "ws://") + ip);
if (onWsOpen) {
this.ws.onopen = (e) => onWsOpen(this.ws, e);
}
......
......@@ -25,6 +25,7 @@ export interface socketAction {
ip: string;
player: string;
passWd: string;
ssl: boolean;
};
isReplay?: boolean; // 是否是回放模式
replayInfo?: {
......@@ -43,13 +44,14 @@ export default async function (action: socketAction) {
case socketCmd.CONNECT: {
const { initInfo: info, isReplay, replayInfo } = action;
if (info) {
ws = new WebSocketStream(info.ip, (conn, _event) =>
ws = new WebSocketStream(info.ip, info.ssl, (conn, _event) =>
handleSocketOpen(conn, info.ip, info.player, info.passWd),
);
await ws.execute(handleSocketMessage);
} else if (isReplay && replayInfo) {
ws = new WebSocketStream(replayInfo.Url, (conn, _event) => {
// 回放模式必定支持ssl
ws = new WebSocketStream(replayInfo.Url, true, (conn, _event) => {
console.info("replay websocket open.");
conn.binaryType = "arraybuffer";
conn.send(replayInfo.data);
......
import { App, Button, Input, Modal } from "antd";
import { App, Button, Checkbox, Input, Modal, Space } from "antd";
import { CheckboxChangeEvent } from "antd/es/checkbox";
import React, { ChangeEvent, useEffect, useState } from "react";
import { useNavigate } from "react-router-dom";
import { proxy, useSnapshot } from "valtio";
......@@ -36,22 +37,25 @@ export const MatchModal: React.FC = ({}) => {
const [server, setServer] = useState(
`${serverConfig[0].ip}:${serverConfig[0].port}`,
);
const [ssl, setSSL] = useState(true);
const [confirmLoading, setConfirmLoading] = useState(false);
const navigate = useNavigate();
let handlePlayerChange = (event: ChangeEvent<HTMLInputElement>) => {
const handlePlayerChange = (event: ChangeEvent<HTMLInputElement>) => {
setPlayer(event.target.value);
};
let handleServerChange = (event: ChangeEvent<HTMLInputElement>) => {
const handleServerChange = (event: ChangeEvent<HTMLInputElement>) => {
setServer(event.target.value);
};
let handlePasswdChange = (event: ChangeEvent<HTMLInputElement>) => {
const handlePasswdChange = (event: ChangeEvent<HTMLInputElement>) => {
setPasswd(event.target.value);
};
const handleSSLCheck = (event: CheckboxChangeEvent) =>
setSSL(event.target.checked);
const handleSubmit = async () => {
setConfirmLoading(true);
await connectSrvpro({ player, ip: server, passWd: passwd });
await connectSrvpro({ player, ip: server, passWd: passwd, ssl });
};
useEffect(() => {
......@@ -99,6 +103,7 @@ export const MatchModal: React.FC = ({}) => {
onChange={handlePlayerChange}
required
/>
<Space.Compact>
<Input
className={styles.input}
type="text"
......@@ -107,6 +112,14 @@ export const MatchModal: React.FC = ({}) => {
onChange={handleServerChange}
required
/>
<Checkbox
checked={ssl}
onChange={handleSSLCheck}
defaultChecked={true}
>
SSL
</Checkbox>
</Space.Compact>
<Input
className={styles.input}
type="text"
......
......@@ -49,6 +49,7 @@ export const ReplayModal: React.FC = () => {
ip: "",
player: "",
passWd: "",
ssl: true,
replay: true,
replayData: replay,
});
......
......@@ -55,6 +55,7 @@ export const Component: React.FC = () => {
ip: matchInfo.address + ":" + (matchInfo.port + 1),
player: user.username,
passWd: matchInfo.password,
ssl: true,
});
} else {
message.error("匹配失败T_T");
......@@ -71,6 +72,7 @@ export const Component: React.FC = () => {
ip: server,
player: user?.name ?? "Guest",
passWd: "AI",
ssl: true,
});
};
......
......@@ -12,6 +12,7 @@ export const connectSrvpro = async (params: {
ip: string;
player: string;
passWd: string;
ssl: boolean;
replay?: boolean;
replayData?: ArrayBuffer;
}) => {
......
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