Commit 10799a04 authored by Chunchi Che's avatar Chunchi Che

fix join room error

parent a3617792
Pipeline #23643 passed with stages
in 15 minutes and 10 seconds
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
{ {
"name":"mycard", "name":"mycard",
"ip":"tiramisu.moecube.com", "ip":"tiramisu.moecube.com",
"port":"7912" "port":"8912"
} }
], ],
"assetsPath":"/neos-assets", "assetsPath":"/neos-assets",
......
...@@ -17,7 +17,7 @@ import { Background, IconFont, Select } from "@/ui/Shared"; ...@@ -17,7 +17,7 @@ import { Background, IconFont, Select } from "@/ui/Shared";
import styles from "./index.module.scss"; import styles from "./index.module.scss";
import { MatchModal, matchStore } from "./MatchModal"; import { MatchModal, matchStore } from "./MatchModal";
import { ReplayModal, replayOpen } from "./ReplayModal"; import { ReplayModal, replayOpen } from "./ReplayModal";
import { connectSrvpro } from "./util"; import { connectSrvpro, getEncryptedPasswd } from "./util";
import { WatchContent } from "./WatchContent"; import { WatchContent } from "./WatchContent";
const { servers: serverList } = useConfig(); const { servers: serverList } = useConfig();
...@@ -80,10 +80,11 @@ export const Component: React.FC = () => { ...@@ -80,10 +80,11 @@ export const Component: React.FC = () => {
(server) => server.name === "mycard", (server) => server.name === "mycard",
); );
if (mcServer) { if (mcServer) {
const passWd = getEncryptedPasswd(watchID, user);
await connectSrvpro({ await connectSrvpro({
ip: mcServer.ip + ":" + mcServer.port, ip: mcServer.ip + ":" + mcServer.port,
player: user.username, player: user.username,
passWd: watchID, passWd,
}); });
} else { } else {
message.error( message.error(
......
...@@ -4,6 +4,7 @@ import { initStrings } from "@/api"; ...@@ -4,6 +4,7 @@ import { initStrings } from "@/api";
import { useConfig } from "@/config"; import { useConfig } from "@/config";
import socketMiddleWare, { socketCmd } from "@/middleware/socket"; import socketMiddleWare, { socketCmd } from "@/middleware/socket";
import sqliteMiddleWare, { sqliteCmd } from "@/middleware/sqlite"; import sqliteMiddleWare, { sqliteCmd } from "@/middleware/sqlite";
import { User } from "@/stores";
const NeosConfig = useConfig(); const NeosConfig = useConfig();
...@@ -49,3 +50,28 @@ export const connectSrvpro = async (params: { ...@@ -49,3 +50,28 @@ export const connectSrvpro = async (params: {
}); });
} }
}; };
export function getEncryptedPasswd(roomID: string, user: User): string {
const optionsBuffer = new Uint8Array(6);
optionsBuffer[1] = 3 << 4;
let checksum = 0;
for (let i = 1; i < optionsBuffer.length; i++) {
checksum -= optionsBuffer[i];
}
optionsBuffer[0] = checksum & 0xff;
const secret = (user.external_id % 65535) + 1;
for (let i = 0; i < optionsBuffer.length; i += 2) {
const value = (optionsBuffer[i + 1] << 8) | optionsBuffer[i];
const xorResult = value ^ secret;
optionsBuffer[i + 1] = (xorResult >> 8) & 0xff;
optionsBuffer[i] = xorResult & 0xff;
}
const base64String = btoa(String.fromCharCode(...optionsBuffer));
return base64String + roomID;
}
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