Commit 7fdc5008 authored by Chunchi Che's avatar Chunchi Che

add ssl

parent f80a8f42
Pipeline #23616 passed with stages
in 14 minutes and 53 seconds
......@@ -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);
......
......@@ -51,7 +51,7 @@ export const MatchModal: React.FC = ({}) => {
const handleSubmit = async () => {
setConfirmLoading(true);
await connectSrvpro({ player, ip: server, passWd: passwd });
await connectSrvpro({ player, ip: server, passWd: passwd, ssl: true });
};
useEffect(() => {
......
......@@ -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