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
1
Issues
1
List
Boards
Labels
Service Desk
Milestones
Merge Requests
2
Merge Requests
2
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
MyCard
Neos
Commits
f2104bbc
Commit
f2104bbc
authored
Oct 18, 2022
by
chechunchi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add aip/helper.ts and service
parent
39268956
Pipeline
#17256
passed with stage
in 2 minutes and 4 seconds
Changes
4
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
88 additions
and
81 deletions
+88
-81
src/api/helper.ts
src/api/helper.ts
+53
-0
src/middleware/socket.ts
src/middleware/socket.ts
+11
-41
src/service/onSocketOpen.ts
src/service/onSocketOpen.ts
+17
-0
src/ui/WaitRoom.tsx
src/ui/WaitRoom.tsx
+7
-40
No files found.
src/api/helper.ts
0 → 100644
View file @
f2104bbc
import
{
ygopro
}
from
"
./idl/ocgcore
"
;
import
socketMiddleWare
,
{
socketCmd
}
from
"
../middleware/socket
"
;
import
{
IDeck
}
from
"
./Card
"
;
export
function
sendUpdateDeck
(
deck
:
IDeck
)
{
const
updateDeck
=
new
ygopro
.
YgoCtosMsg
({
ctos_update_deck
:
new
ygopro
.
CtosUpdateDeck
({
main
:
deck
.
main
,
extra
:
deck
.
extra
,
side
:
deck
.
side
,
}),
});
socketMiddleWare
({
cmd
:
socketCmd
.
SEND
,
payload
:
updateDeck
});
}
export
function
sendHsReady
()
{
const
hasReady
=
new
ygopro
.
YgoCtosMsg
({
ctos_hs_ready
:
new
ygopro
.
CtosHsReady
({}),
});
socketMiddleWare
({
cmd
:
socketCmd
.
SEND
,
payload
:
hasReady
});
}
export
function
sendHsStart
()
{
const
hasStart
=
new
ygopro
.
YgoCtosMsg
({
ctos_hs_start
:
new
ygopro
.
CtosHsStart
({}),
});
socketMiddleWare
({
cmd
:
socketCmd
.
SEND
,
payload
:
hasStart
});
}
export
function
sendPlayerInfo
(
ws
:
WebSocket
,
player
:
string
)
{
const
playerInfo
=
new
ygopro
.
YgoCtosMsg
({
ctos_player_info
:
new
ygopro
.
CtosPlayerInfo
({
name
:
player
,
}),
});
ws
.
send
(
playerInfo
.
serialize
());
}
export
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
());
}
src/middleware/socket.ts
View file @
f2104bbc
...
@@ -14,6 +14,8 @@ import {
...
@@ -14,6 +14,8 @@ import {
observerChange
,
observerChange
,
updateIsHost
,
updateIsHost
,
}
from
"
../reducers/playerSlice
"
;
}
from
"
../reducers/playerSlice
"
;
import
{
sendPlayerInfo
,
sendJoinGame
}
from
"
../api/helper
"
;
import
handleSocketOpen
from
"
../service/onSocketOpen
"
;
export
enum
socketCmd
{
export
enum
socketCmd
{
CONNECT
,
CONNECT
,
...
@@ -23,10 +25,11 @@ export enum socketCmd {
...
@@ -23,10 +25,11 @@ export enum socketCmd {
export
interface
socketAction
{
export
interface
socketAction
{
cmd
:
socketCmd
;
cmd
:
socketCmd
;
ip
?:
string
;
initInfo
?:
{
player
?:
string
;
ip
:
string
;
version
?:
number
;
player
:
string
;
passWd
?:
string
;
passWd
:
string
;
};
payload
?:
ygopro
.
YgoCtosMsg
;
payload
?:
ygopro
.
YgoCtosMsg
;
}
}
...
@@ -38,22 +41,12 @@ const NO_READY_STATE = "not ready";
...
@@ -38,22 +41,12 @@ const NO_READY_STATE = "not ready";
export
default
function
(
action
:
socketAction
)
{
export
default
function
(
action
:
socketAction
)
{
switch
(
action
.
cmd
)
{
switch
(
action
.
cmd
)
{
case
socketCmd
.
CONNECT
:
{
case
socketCmd
.
CONNECT
:
{
const
ip
=
action
.
ip
;
const
info
=
action
.
initInfo
;
const
player
=
action
.
player
;
if
(
info
)
{
const
version
=
action
.
version
;
ws
=
new
WebSocket
(
"
ws://
"
+
info
.
ip
);
const
passWd
=
action
.
passWd
;
if
(
ip
&&
player
&&
version
&&
passWd
)
{
ws
=
new
WebSocket
(
"
ws://
"
+
ip
);
ws
.
onopen
=
()
=>
{
ws
.
onopen
=
()
=>
{
console
.
log
(
"
WebSocket open.
"
);
handleSocketOpen
(
ws
,
info
.
ip
,
info
.
player
,
info
.
passWd
);
if
(
ws
&&
ws
.
readyState
==
1
)
{
ws
.
binaryType
=
"
arraybuffer
"
;
sendPlayerInfo
(
ws
,
player
);
sendJoinGame
(
ws
,
version
,
passWd
);
}
};
};
ws
.
onclose
=
()
=>
{
ws
.
onclose
=
()
=>
{
console
.
log
(
"
WebSocket closed.
"
);
console
.
log
(
"
WebSocket closed.
"
);
...
@@ -221,26 +214,3 @@ export default function (action: socketAction) {
...
@@ -221,26 +214,3 @@ export default function (action: socketAction) {
}
}
}
}
}
}
// todo: move to api/*
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
());
}
src/service/onSocketOpen.ts
0 → 100644
View file @
f2104bbc
import
{
sendJoinGame
,
sendPlayerInfo
}
from
"
../api/helper
"
;
export
default
function
handleSocketOpen
(
ws
:
WebSocket
|
null
,
ip
:
string
,
player
:
string
,
passWd
:
string
)
{
console
.
log
(
"
WebSocket opened.
"
);
if
(
ws
&&
ws
.
readyState
==
1
)
{
ws
.
binaryType
=
"
arraybuffer
"
;
sendPlayerInfo
(
ws
,
player
);
sendJoinGame
(
ws
,
4947
,
passWd
);
// todo: version use config
}
}
src/ui/WaitRoom.tsx
View file @
f2104bbc
...
@@ -12,7 +12,7 @@ import {
...
@@ -12,7 +12,7 @@ import {
selectPlayer1
,
selectPlayer1
,
selectObserverCount
,
selectObserverCount
,
}
from
"
../reducers/playerSlice
"
;
}
from
"
../reducers/playerSlice
"
;
import
{
sendUpdateDeck
,
sendHsReady
,
sendHsStart
}
from
"
../api/helper
"
;
import
socketMiddleWare
,
{
socketCmd
}
from
"
../middleware/socket
"
;
import
socketMiddleWare
,
{
socketCmd
}
from
"
../middleware/socket
"
;
const
READY_STATE
=
"
ready
"
;
const
READY_STATE
=
"
ready
"
;
...
@@ -28,18 +28,14 @@ export default function WaitRoom() {
...
@@ -28,18 +28,14 @@ export default function WaitRoom() {
const
{
player
,
passWd
,
ip
}
=
params
;
const
{
player
,
passWd
,
ip
}
=
params
;
useEffect
(()
=>
{
useEffect
(()
=>
{
if
(
if
(
ip
&&
player
&&
player
.
length
!=
0
&&
passWd
&&
passWd
.
length
!=
0
)
{
player
!=
null
&&
player
.
length
!=
0
&&
passWd
!=
null
&&
passWd
.
length
!=
0
)
{
socketMiddleWare
({
socketMiddleWare
({
cmd
:
socketCmd
.
CONNECT
,
cmd
:
socketCmd
.
CONNECT
,
initInfo
:
{
ip
,
ip
,
player
,
player
,
version
:
4947
,
passWd
,
passWd
,
},
});
});
}
}
},
[]);
},
[]);
...
@@ -114,32 +110,3 @@ export default function WaitRoom() {
...
@@ -114,32 +110,3 @@ export default function WaitRoom() {
</
div
>
</
div
>
);
);
}
}
// todo: move to api/*
function
sendUpdateDeck
(
deck
:
IDeck
)
{
const
updateDeck
=
new
ygopro
.
YgoCtosMsg
({
ctos_update_deck
:
new
ygopro
.
CtosUpdateDeck
({
main
:
deck
.
main
,
extra
:
deck
.
extra
,
side
:
deck
.
side
,
}),
});
socketMiddleWare
({
cmd
:
socketCmd
.
SEND
,
payload
:
updateDeck
});
}
function
sendHsReady
()
{
const
hasReady
=
new
ygopro
.
YgoCtosMsg
({
ctos_hs_ready
:
new
ygopro
.
CtosHsReady
({}),
});
socketMiddleWare
({
cmd
:
socketCmd
.
SEND
,
payload
:
hasReady
});
}
function
sendHsStart
()
{
const
hasStart
=
new
ygopro
.
YgoCtosMsg
({
ctos_hs_start
:
new
ygopro
.
CtosHsStart
({}),
});
socketMiddleWare
({
cmd
:
socketCmd
.
SEND
,
payload
:
hasStart
});
}
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