Commit 5b09d7aa authored by Chunchi Che's avatar Chunchi Che

update handleButtonClick and fmt code

parent d0bdf00f
...@@ -3,8 +3,8 @@ import { ygopro } from "./api/ocgcore"; ...@@ -3,8 +3,8 @@ import { ygopro } from "./api/ocgcore";
export default function JoinHome(props: { addr: string }) { export default function JoinHome(props: { addr: string }) {
const ws = useRef<WebSocket | null>(null); const ws = useRef<WebSocket | null>(null);
const [username, setUsername] = useState(""); const [userName, setUsername] = useState("");
const [passwd, setPasswd] = useState(""); const [passWd, setPasswd] = useState("");
const [isJoined, setJoined] = useState(false); const [isJoined, setJoined] = useState(false);
useEffect(() => { useEffect(() => {
...@@ -26,7 +26,7 @@ export default function JoinHome(props: { addr: string }) { ...@@ -26,7 +26,7 @@ export default function JoinHome(props: { addr: string }) {
return () => { return () => {
if (wsCurrent.readyState == 1) { if (wsCurrent.readyState == 1) {
wsCurrent.close() wsCurrent.close();
} }
}; };
}, [ws]); }, [ws]);
...@@ -47,7 +47,36 @@ export default function JoinHome(props: { addr: string }) { ...@@ -47,7 +47,36 @@ export default function JoinHome(props: { addr: string }) {
} else { } else {
const wsCurrent = ws.current; const wsCurrent = ws.current;
// todo if (
userName != null &&
userName.length != 0 &&
passWd != null &&
passWd.length != 0
) {
console.log(
"ready to send playerInfo and joinGame packet, userName=" +
userName +
", passWd=" +
passWd
);
const playerInfo = new ygopro.YgoCtosMsg({
ctos_player_info: new ygopro.CtosPlayerInfo({
name: userName,
}),
});
wsCurrent.send(playerInfo.serialize());
const joinGame = new ygopro.YgoCtosMsg({
ctos_join_game: new ygopro.CtosJoinGame({
version: 4947,
gameid: 0,
passwd: passWd,
}),
});
wsCurrent.send(joinGame.serialize());
}
} }
}; };
...@@ -57,7 +86,7 @@ export default function JoinHome(props: { addr: string }) { ...@@ -57,7 +86,7 @@ export default function JoinHome(props: { addr: string }) {
<input <input
type="text" type="text"
title="username" title="username"
value={username} value={userName}
onChange={handleUsernameChange} onChange={handleUsernameChange}
></input> ></input>
</p> </p>
...@@ -65,7 +94,7 @@ export default function JoinHome(props: { addr: string }) { ...@@ -65,7 +94,7 @@ export default function JoinHome(props: { addr: string }) {
<input <input
type="text" type="text"
title="passwd" title="passwd"
value={passwd} value={passWd}
onChange={handlePasswdChange} onChange={handlePasswdChange}
></input> ></input>
</p> </p>
......
This diff is collapsed.
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