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
76900b5b
Commit
76900b5b
authored
Oct 18, 2022
by
chechunchi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
migrate service
parent
f2104bbc
Pipeline
#17258
passed with stage
in 2 minutes and 1 second
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
160 additions
and
159 deletions
+160
-159
src/middleware/socket.ts
src/middleware/socket.ts
+6
-159
src/service/onSocketMessage.ts
src/service/onSocketMessage.ts
+154
-0
No files found.
src/middleware/socket.ts
View file @
76900b5b
import
{
ygopro
}
from
"
../api/idl/ocgcore
"
;
import
{
setJoined
}
from
"
../reducers/joinSlice
"
;
import
{
postChat
}
from
"
../reducers/chatSlice
"
;
import
{
store
}
from
"
../store
"
;
import
{
player0Enter
,
player1Enter
,
player0Update
,
player1Update
,
player0Leave
,
player1Leave
,
hostChange
,
observerIncrement
,
observerChange
,
updateIsHost
,
}
from
"
../reducers/playerSlice
"
;
import
{
sendPlayerInfo
,
sendJoinGame
}
from
"
../api/helper
"
;
import
handleSocketOpen
from
"
../service/onSocketOpen
"
;
import
handleSocketMessage
from
"
../service/onSocketMessage
"
;
export
enum
socketCmd
{
CONNECT
,
...
...
@@ -35,9 +20,6 @@ export interface socketAction {
let
ws
:
WebSocket
|
null
=
null
;
const
READY_STATE
=
"
ready
"
;
const
NO_READY_STATE
=
"
not ready
"
;
export
default
function
(
action
:
socketAction
)
{
switch
(
action
.
cmd
)
{
case
socketCmd
.
CONNECT
:
{
...
...
@@ -52,153 +34,16 @@ export default function (action: socketAction) {
console
.
log
(
"
WebSocket closed.
"
);
ws
=
null
;
};
ws
.
onmessage
=
(
e
)
=>
{
const
pb
=
ygopro
.
YgoStocMsg
.
deserializeBinary
(
e
.
data
);
const
dispatch
=
store
.
dispatch
;
switch
(
pb
.
msg
)
{
case
"
stoc_join_game
"
:
{
const
msg
=
pb
.
stoc_join_game
;
// todo
dispatch
(
setJoined
());
break
;
}
case
"
stoc_chat
"
:
{
const
chat
=
pb
.
stoc_chat
;
dispatch
(
postChat
(
chat
.
msg
));
break
;
}
case
"
stoc_hs_player_change
"
:
{
const
change
=
pb
.
stoc_hs_player_change
;
if
(
change
.
pos
>
1
)
{
console
.
log
(
"
Currently only supported 2v2 mode.
"
);
}
else
{
switch
(
change
.
state
)
{
case
ygopro
.
StocHsPlayerChange
.
State
.
UNKNOWN
:
{
console
.
log
(
"
Unknown HsPlayerChange State
"
);
break
;
ws
.
onmessage
=
handleSocketMessage
;
}
case
ygopro
.
StocHsPlayerChange
.
State
.
MOVE
:
{
console
.
log
(
"
Player
"
+
change
.
pos
+
"
moved to
"
+
change
.
moved_pos
);
let
src
=
change
.
pos
;
let
dst
=
change
.
moved_pos
;
// todo
// if (src === 0 && dst === 1) {
// setPlayer1(player0);
// setPlayer0({});
// } else if (src === 1 && dst === 0) {
// setPlayer0(player1);
// setPlayer1({});
// }
break
;
}
case
ygopro
.
StocHsPlayerChange
.
State
.
READY
:
{
change
.
pos
==
0
?
dispatch
(
player0Update
(
READY_STATE
))
:
dispatch
(
player1Update
(
READY_STATE
));
break
;
}
case
ygopro
.
StocHsPlayerChange
.
State
.
NO_READY
:
{
change
.
pos
==
0
?
dispatch
(
player0Update
(
NO_READY_STATE
))
:
dispatch
(
player1Update
(
NO_READY_STATE
));
break
;
}
case
ygopro
.
StocHsPlayerChange
.
State
.
LEAVE
:
{
change
.
pos
==
0
?
dispatch
(
player0Leave
)
:
dispatch
(
player1Leave
);
break
;
}
case
ygopro
.
StocHsPlayerChange
.
State
.
TO_OBSERVER
:
{
change
.
pos
==
0
?
dispatch
(
player0Leave
)
:
dispatch
(
player1Leave
);
dispatch
(
observerIncrement
());
break
;
}
default
:
{
break
;
}
}
}
break
;
}
case
"
stoc_hs_watch_change
"
:
{
const
count
=
pb
.
stoc_hs_watch_change
.
count
;
dispatch
(
observerChange
(
count
));
break
;
}
case
"
stoc_hs_player_enter
"
:
{
const
name
=
pb
.
stoc_hs_player_enter
.
name
;
const
pos
=
pb
.
stoc_hs_player_enter
.
pos
;
if
(
pos
>
1
)
{
console
.
log
(
"
Currently only supported 2v2 mode.
"
);
}
else
{
pos
==
0
?
dispatch
(
player0Enter
(
name
))
:
dispatch
(
player1Enter
(
name
));
}
break
;
}
case
"
stoc_type_change
"
:
{
const
selfType
=
pb
.
stoc_type_change
.
self_type
;
const
assertHost
=
pb
.
stoc_type_change
.
is_host
;
dispatch
(
updateIsHost
(
assertHost
));
if
(
assertHost
)
{
switch
(
selfType
)
{
case
ygopro
.
StocTypeChange
.
SelfType
.
PLAYER1
:
{
dispatch
(
hostChange
(
0
));
dispatch
(
player0Update
(
NO_READY_STATE
));
break
;
}
case
ygopro
.
StocTypeChange
.
SelfType
.
PLAYER2
:
{
dispatch
(
hostChange
(
0
));
dispatch
(
player1Update
(
NO_READY_STATE
));
break
;
}
default
:
{
break
;
}
}
}
break
;
}
default
:
{
break
;
}
}
};
}
break
;
}
case
socketCmd
.
DISCONNECT
:
{
if
(
ws
)
{
ws
.
close
();
}
break
;
}
case
socketCmd
.
SEND
:
{
...
...
@@ -206,10 +51,12 @@ export default function (action: socketAction) {
if
(
ws
&&
pb
)
{
ws
.
send
(
pb
.
serialize
());
}
break
;
}
default
:
{
console
.
log
(
"
Unhandled socket command:
"
+
action
.
cmd
);
break
;
}
}
...
...
src/service/onSocketMessage.ts
0 → 100644
View file @
76900b5b
import
{
ygopro
}
from
"
../api/idl/ocgcore
"
;
import
{
store
}
from
"
../store
"
;
import
{
setJoined
}
from
"
../reducers/joinSlice
"
;
import
{
postChat
}
from
"
../reducers/chatSlice
"
;
import
{
player0Enter
,
player1Enter
,
player0Update
,
player1Update
,
player0Leave
,
player1Leave
,
hostChange
,
observerIncrement
,
observerChange
,
updateIsHost
,
}
from
"
../reducers/playerSlice
"
;
const
READY_STATE
=
"
ready
"
;
const
NO_READY_STATE
=
"
not ready
"
;
export
default
function
handleSocketMessage
(
e
:
MessageEvent
)
{
const
pb
=
ygopro
.
YgoStocMsg
.
deserializeBinary
(
e
.
data
);
const
dispatch
=
store
.
dispatch
;
switch
(
pb
.
msg
)
{
case
"
stoc_join_game
"
:
{
const
msg
=
pb
.
stoc_join_game
;
// todo
dispatch
(
setJoined
());
break
;
}
case
"
stoc_chat
"
:
{
const
chat
=
pb
.
stoc_chat
;
dispatch
(
postChat
(
chat
.
msg
));
break
;
}
case
"
stoc_hs_player_change
"
:
{
const
change
=
pb
.
stoc_hs_player_change
;
if
(
change
.
pos
>
1
)
{
console
.
log
(
"
Currently only supported 2v2 mode.
"
);
}
else
{
switch
(
change
.
state
)
{
case
ygopro
.
StocHsPlayerChange
.
State
.
UNKNOWN
:
{
console
.
log
(
"
Unknown HsPlayerChange State
"
);
break
;
}
case
ygopro
.
StocHsPlayerChange
.
State
.
MOVE
:
{
console
.
log
(
"
Player
"
+
change
.
pos
+
"
moved to
"
+
change
.
moved_pos
);
let
src
=
change
.
pos
;
let
dst
=
change
.
moved_pos
;
// todo
// if (src === 0 && dst === 1) {
// setPlayer1(player0);
// setPlayer0({});
// } else if (src === 1 && dst === 0) {
// setPlayer0(player1);
// setPlayer1({});
// }
break
;
}
case
ygopro
.
StocHsPlayerChange
.
State
.
READY
:
{
change
.
pos
==
0
?
dispatch
(
player0Update
(
READY_STATE
))
:
dispatch
(
player1Update
(
READY_STATE
));
break
;
}
case
ygopro
.
StocHsPlayerChange
.
State
.
NO_READY
:
{
change
.
pos
==
0
?
dispatch
(
player0Update
(
NO_READY_STATE
))
:
dispatch
(
player1Update
(
NO_READY_STATE
));
break
;
}
case
ygopro
.
StocHsPlayerChange
.
State
.
LEAVE
:
{
change
.
pos
==
0
?
dispatch
(
player0Leave
)
:
dispatch
(
player1Leave
);
break
;
}
case
ygopro
.
StocHsPlayerChange
.
State
.
TO_OBSERVER
:
{
change
.
pos
==
0
?
dispatch
(
player0Leave
)
:
dispatch
(
player1Leave
);
dispatch
(
observerIncrement
());
break
;
}
default
:
{
break
;
}
}
}
break
;
}
case
"
stoc_hs_watch_change
"
:
{
const
count
=
pb
.
stoc_hs_watch_change
.
count
;
dispatch
(
observerChange
(
count
));
break
;
}
case
"
stoc_hs_player_enter
"
:
{
const
name
=
pb
.
stoc_hs_player_enter
.
name
;
const
pos
=
pb
.
stoc_hs_player_enter
.
pos
;
if
(
pos
>
1
)
{
console
.
log
(
"
Currently only supported 2v2 mode.
"
);
}
else
{
pos
==
0
?
dispatch
(
player0Enter
(
name
))
:
dispatch
(
player1Enter
(
name
));
}
break
;
}
case
"
stoc_type_change
"
:
{
const
selfType
=
pb
.
stoc_type_change
.
self_type
;
const
assertHost
=
pb
.
stoc_type_change
.
is_host
;
dispatch
(
updateIsHost
(
assertHost
));
if
(
assertHost
)
{
switch
(
selfType
)
{
case
ygopro
.
StocTypeChange
.
SelfType
.
PLAYER1
:
{
dispatch
(
hostChange
(
0
));
dispatch
(
player0Update
(
NO_READY_STATE
));
break
;
}
case
ygopro
.
StocTypeChange
.
SelfType
.
PLAYER2
:
{
dispatch
(
hostChange
(
0
));
dispatch
(
player1Update
(
NO_READY_STATE
));
break
;
}
default
:
{
break
;
}
}
}
break
;
}
default
:
{
break
;
}
}
}
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