Commit e200c465 authored by Chunchi Che's avatar Chunchi Che Committed by GitHub

Merge pull request #1 from DarkNeos/dev

Dev
parents 7baabff9 5b09d7aa
...@@ -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(() => {
...@@ -24,8 +24,12 @@ export default function JoinHome(props: { addr: string }) { ...@@ -24,8 +24,12 @@ export default function JoinHome(props: { addr: string }) {
const wsCurrent = ws.current; const wsCurrent = ws.current;
return () => wsCurrent.close(); return () => {
}, []); if (wsCurrent.readyState == 1) {
wsCurrent.close();
}
};
}, [ws]);
let handleUsernameChange = (event: ChangeEvent<HTMLInputElement>) => { let handleUsernameChange = (event: ChangeEvent<HTMLInputElement>) => {
setUsername(event.target.value); setUsername(event.target.value);
...@@ -43,7 +47,36 @@ export default function JoinHome(props: { addr: string }) { ...@@ -43,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());
}
} }
}; };
...@@ -53,7 +86,7 @@ export default function JoinHome(props: { addr: string }) { ...@@ -53,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>
...@@ -61,7 +94,7 @@ export default function JoinHome(props: { addr: string }) { ...@@ -61,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>
......
...@@ -5,17 +5,21 @@ option go_package = "DarkNeos/ygopropb"; ...@@ -5,17 +5,21 @@ option go_package = "DarkNeos/ygopropb";
message YgoCtosMsg { message YgoCtosMsg {
oneof msg { oneof msg {
CtosPlayerInfo ctos_player_info = 2; CtosPlayerInfo ctos_player_info = 1;
CtosJoinGame ctos_join_game = 3; CtosJoinGame ctos_join_game = 2;
CtosUpdateDeck ctos_update_deck = 4; CtosUpdateDeck ctos_update_deck = 3;
StocJoinGame stoc_join_game = 101;
StocChat stoc_chat = 102;
StocHsPlayerEnter stoc_hs_player_enter = 103;
StocTypeChange stoc_type_change = 104;
} }
} }
message YgoStocMsg {
oneof msg {
StocJoinGame stoc_join_game = 1;
StocChat stoc_chat = 2;
StocHsPlayerEnter stoc_hs_player_enter = 3;
StocTypeChange stoc_type_change = 4;
}
}
// ----- CTOS ----- // ----- CTOS -----
message CtosPlayerInfo { message CtosPlayerInfo {
......
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