Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
N
Neos
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
love_飞影
Neos
Commits
af753793
Commit
af753793
authored
Oct 04, 2022
by
Chunchi Che
Committed by
GitHub
Oct 04, 2022
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #8 from DarkNeos/dev
Dev
parents
bcbb998f
a4c9a8a7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
58 additions
and
27 deletions
+58
-27
src/JoinRoom.tsx
src/JoinRoom.tsx
+6
-6
src/WaitRoom.tsx
src/WaitRoom.tsx
+52
-21
No files found.
src/JoinRoom.tsx
View file @
af753793
...
...
@@ -29,17 +29,17 @@ export default function JoinRoom() {
<
p
>
<
input
type=
"text"
title=
"
passwd
"
value=
{
passWd
}
onChange=
{
handle
Passwd
Change
}
title=
"
ip
"
value=
{
ip
}
onChange=
{
handle
Ip
Change
}
></
input
>
</
p
>
<
p
>
<
input
type=
"text"
title=
"
ip
"
value=
{
ip
}
onChange=
{
handle
Ip
Change
}
title=
"
passwd
"
value=
{
passWd
}
onChange=
{
handle
Passwd
Change
}
></
input
>
</
p
>
<
button
>
...
...
src/WaitRoom.tsx
View file @
af753793
import
React
,
{
useRef
,
useEffect
}
from
"
react
"
;
import
React
,
{
useRef
,
useEffect
,
useState
}
from
"
react
"
;
import
{
useParams
}
from
"
react-router-dom
"
;
import
{
ygopro
}
from
"
./api/idl/ocgcore
"
;
...
...
@@ -9,6 +9,9 @@ export default function WaitRoom() {
ip
?:
string
;
}
>
();
const
[
joined
,
setJoined
]
=
useState
<
string
>
(
"
false
"
);
const
[
chat
,
setChat
]
=
useState
<
string
>
(
""
);
const
ws
=
useRef
<
WebSocket
|
null
>
(
null
);
const
{
player
,
passWd
,
ip
}
=
params
;
...
...
@@ -29,23 +32,10 @@ export default function WaitRoom() {
)
{
const
wsCurrent
=
ws
.
current
;
const
playerInfo
=
new
ygopro
.
YgoCtosMsg
({
ctos_player_info
:
new
ygopro
.
CtosPlayerInfo
({
name
:
player
})
});
wsCurrent
.
send
(
playerInfo
.
serialize
());
wsCurrent
.
binaryType
=
"
arraybuffer
"
;
const
joinGame
=
new
ygopro
.
YgoCtosMsg
({
ctos_join_game
:
new
ygopro
.
CtosJoinGame
({
version
:
4947
,
// todo: use config
gameid
:
0
,
passwd
:
passWd
})
});
wsCurrent
.
send
(
joinGame
.
serialize
());
sendPlayerInfo
(
wsCurrent
,
player
);
sendJoinGame
(
wsCurrent
,
4947
,
passWd
);
}
};
...
...
@@ -54,7 +44,27 @@ export default function WaitRoom() {
};
ws
.
current
.
onmessage
=
e
=>
{
console
.
log
(
"
websocket read message:
"
+
e
.
data
);
const
pb
=
ygopro
.
YgoStocMsg
.
deserializeBinary
(
e
.
data
);
switch
(
pb
.
msg
)
{
case
"
stoc_join_game
"
:
{
const
msg
=
pb
.
stoc_join_game
;
console
.
log
(
"
joinGame msg=
"
+
msg
);
setJoined
(
"
true
"
);
break
;
}
case
"
stoc_chat
"
:
{
const
chat
=
pb
.
stoc_chat
;
setChat
(
chat
.
msg
);
break
;
}
default
:
{
break
;
}
}
};
const
wsCurrent
=
ws
.
current
;
...
...
@@ -68,9 +78,30 @@ export default function WaitRoom() {
return
(
<
div
>
<
p
>
player:
{
params
.
player
}
</
p
>
<
p
>
passwd:
{
params
.
passWd
}
</
p
>
<
p
>
ip:
{
params
.
ip
}
</
p
>
<
p
>
joined:
{
joined
}
</
p
>
<
p
>
chat:
{
chat
}
</
p
>
</
div
>
);
}
function
sendPlayerInfo
(
ws
:
WebSocket
,
player
:
string
)
{
const
playerInfo
=
new
ygopro
.
YgoCtosMsg
({
ctos_player_info
:
new
ygopro
.
CtosPlayerInfo
({
name
:
player
})
});
ws
.
send
(
playerInfo
.
serialize
());
}
function
sendJoinGame
(
ws
:
WebSocket
,
version
:
number
,
passWd
:
string
)
{
const
joinGame
=
new
ygopro
.
YgoCtosMsg
({
ctos_join_game
:
new
ygopro
.
CtosJoinGame
({
version
,
// todo: use config
gameid
:
0
,
passwd
:
passWd
})
});
ws
.
send
(
joinGame
.
serialize
());
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment