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 @@ ...@@ -4,7 +4,8 @@
{ {
"name":"koishi", "name":"koishi",
"ip":"koishi.momobako.com", "ip":"koishi.momobako.com",
"port":"7211" "port":"7211",
"ssl": true
} }
], ],
"assetsPath":"/neos-assets", "assetsPath":"/neos-assets",
......
...@@ -4,7 +4,8 @@ ...@@ -4,7 +4,8 @@
{ {
"name":"koishi", "name":"koishi",
"ip":"koishi.momobako.com", "ip":"koishi.momobako.com",
"port":"7211" "port":"7211",
"ssl": true
} }
], ],
"assetsPath":"/neos-assets", "assetsPath":"/neos-assets",
......
...@@ -12,8 +12,12 @@ export class WebSocketStream { ...@@ -12,8 +12,12 @@ export class WebSocketStream {
public ws: WebSocket; public ws: WebSocket;
stream: ReadableStream; stream: ReadableStream;
constructor(ip: string, onWsOpen?: (ws: WebSocket, ev: Event) => any) { constructor(
this.ws = new WebSocket("wss://" + ip); ip: string,
ssl: boolean,
onWsOpen?: (ws: WebSocket, ev: Event) => any,
) {
this.ws = new WebSocket(ssl ? "wss://" : "ws://" + ip);
if (onWsOpen) { if (onWsOpen) {
this.ws.onopen = (e) => onWsOpen(this.ws, e); this.ws.onopen = (e) => onWsOpen(this.ws, e);
} }
......
...@@ -25,6 +25,7 @@ export interface socketAction { ...@@ -25,6 +25,7 @@ export interface socketAction {
ip: string; ip: string;
player: string; player: string;
passWd: string; passWd: string;
ssl: boolean;
}; };
isReplay?: boolean; // 是否是回放模式 isReplay?: boolean; // 是否是回放模式
replayInfo?: { replayInfo?: {
...@@ -43,13 +44,14 @@ export default async function (action: socketAction) { ...@@ -43,13 +44,14 @@ export default async function (action: socketAction) {
case socketCmd.CONNECT: { case socketCmd.CONNECT: {
const { initInfo: info, isReplay, replayInfo } = action; const { initInfo: info, isReplay, replayInfo } = action;
if (info) { 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), handleSocketOpen(conn, info.ip, info.player, info.passWd),
); );
await ws.execute(handleSocketMessage); await ws.execute(handleSocketMessage);
} else if (isReplay && replayInfo) { } 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."); console.info("replay websocket open.");
conn.binaryType = "arraybuffer"; conn.binaryType = "arraybuffer";
conn.send(replayInfo.data); conn.send(replayInfo.data);
......
...@@ -51,7 +51,7 @@ export const MatchModal: React.FC = ({}) => { ...@@ -51,7 +51,7 @@ export const MatchModal: React.FC = ({}) => {
const handleSubmit = async () => { const handleSubmit = async () => {
setConfirmLoading(true); setConfirmLoading(true);
await connectSrvpro({ player, ip: server, passWd: passwd }); await connectSrvpro({ player, ip: server, passWd: passwd, ssl: true });
}; };
useEffect(() => { useEffect(() => {
......
...@@ -49,6 +49,7 @@ export const ReplayModal: React.FC = () => { ...@@ -49,6 +49,7 @@ export const ReplayModal: React.FC = () => {
ip: "", ip: "",
player: "", player: "",
passWd: "", passWd: "",
ssl: true,
replay: true, replay: true,
replayData: replay, replayData: replay,
}); });
......
...@@ -55,6 +55,7 @@ export const Component: React.FC = () => { ...@@ -55,6 +55,7 @@ export const Component: React.FC = () => {
ip: matchInfo.address + ":" + (matchInfo.port + 1), ip: matchInfo.address + ":" + (matchInfo.port + 1),
player: user.username, player: user.username,
passWd: matchInfo.password, passWd: matchInfo.password,
ssl: true,
}); });
} else { } else {
message.error("匹配失败T_T"); message.error("匹配失败T_T");
...@@ -71,6 +72,7 @@ export const Component: React.FC = () => { ...@@ -71,6 +72,7 @@ export const Component: React.FC = () => {
ip: server, ip: server,
player: user?.name ?? "Guest", player: user?.name ?? "Guest",
passWd: "AI", passWd: "AI",
ssl: true,
}); });
}; };
......
...@@ -12,6 +12,7 @@ export const connectSrvpro = async (params: { ...@@ -12,6 +12,7 @@ export const connectSrvpro = async (params: {
ip: string; ip: string;
player: string; player: string;
passWd: string; passWd: string;
ssl: boolean;
replay?: boolean; replay?: boolean;
replayData?: ArrayBuffer; 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