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
94b7862d
Commit
94b7862d
authored
Oct 02, 2023
by
Chunchi Che
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add unpack logic
parent
b45308de
Pipeline
#23660
passed with stages
in 15 minutes and 21 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
107 additions
and
86 deletions
+107
-86
src/api/ocgcore/ocgAdapter/packet.ts
src/api/ocgcore/ocgAdapter/packet.ts
+22
-6
src/service/onSocketMessage.ts
src/service/onSocketMessage.ts
+85
-80
No files found.
src/api/ocgcore/ocgAdapter/packet.ts
View file @
94b7862d
...
...
@@ -40,7 +40,7 @@ export class YgoProPacket {
* 返回值可用于业务逻辑处理。
*
* */
static
deserialize
(
array
:
ArrayBuffer
):
YgoProPacket
{
static
deserialize
(
array
:
ArrayBuffer
):
YgoProPacket
[]
{
try
{
if
(
array
.
byteLength
<
PACKET_MIN_LEN
)
{
throw
new
Error
(
...
...
@@ -51,13 +51,29 @@ export class YgoProPacket {
console
.
error
(
e
);
}
const
dataView
=
new
DataView
(
array
);
// 由于srvpro实现问题,目前可能出现粘包的情况,因此这里做下解包
const
packets
=
[];
const
packetLen
=
dataView
.
getInt16
(
0
,
littleEndian
)
;
const
proto
=
dataView
.
getInt8
(
2
);
const
exData
=
array
.
slice
(
3
,
packetLen
+
2
);
let
offset
=
0
;
while
(
true
)
{
const
buffer
=
array
.
slice
(
offset
);
return
new
YgoProPacket
(
packetLen
,
proto
,
new
Uint8Array
(
exData
));
if
(
buffer
.
byteLength
<
PACKET_MIN_LEN
)
{
// 解包结束
break
;
}
const
dataView
=
new
DataView
(
buffer
);
const
packetLen
=
dataView
.
getInt16
(
0
,
littleEndian
);
const
proto
=
dataView
.
getInt8
(
2
);
const
exData
=
buffer
.
slice
(
3
,
packetLen
+
2
);
packets
.
push
(
new
YgoProPacket
(
packetLen
,
proto
,
new
Uint8Array
(
exData
)));
offset
+=
packetLen
+
2
;
}
return
packets
;
}
}
...
...
src/service/onSocketMessage.ts
View file @
94b7862d
...
...
@@ -38,87 +38,92 @@ export default async function handleSocketMessage(e: MessageEvent) {
}
async
function
_handle
(
e
:
MessageEvent
)
{
const
packet
=
YgoProPacket
.
deserialize
(
e
.
data
);
const
pb
=
adaptStoc
(
packet
);
const
packets
=
YgoProPacket
.
deserialize
(
e
.
data
);
switch
(
pb
.
msg
)
{
case
"
stoc_join_game
"
:
{
handleJoinGame
(
pb
);
break
;
}
case
"
stoc_chat
"
:
{
handleChat
(
pb
);
break
;
}
case
"
stoc_hs_player_change
"
:
{
handleHsPlayerChange
(
pb
);
break
;
}
case
"
stoc_hs_watch_change
"
:
{
handleHsWatchChange
(
pb
);
break
;
}
case
"
stoc_hs_player_enter
"
:
{
handleHsPlayerEnter
(
pb
);
break
;
}
case
"
stoc_type_change
"
:
{
handleTypeChange
(
pb
);
break
;
}
case
"
stoc_select_hand
"
:
{
handleSelectHand
(
pb
);
break
;
}
case
"
stoc_hand_result
"
:
{
handleHandResult
(
pb
);
break
;
}
case
"
stoc_select_tp
"
:
{
handleSelectTp
(
pb
);
break
;
}
case
"
stoc_deck_count
"
:
{
handleDeckCount
(
pb
);
break
;
}
case
"
stoc_duel_start
"
:
{
handleDuelStart
(
pb
);
break
;
}
case
"
stoc_duel_end
"
:
{
handleDuelEnd
(
pb
);
break
;
}
case
"
stoc_game_msg
"
:
{
if
(
!
replayStore
.
isReplay
)
{
// 如果不是回放模式,则记录回放数据
replayStore
.
record
(
packet
);
}
await
handleGameMsg
(
pb
);
await
Promise
.
all
(
packets
.
map
(
async
(
packet
)
=>
{
const
pb
=
adaptStoc
(
packet
);
switch
(
pb
.
msg
)
{
case
"
stoc_join_game
"
:
{
handleJoinGame
(
pb
);
break
;
}
case
"
stoc_chat
"
:
{
handleChat
(
pb
);
break
;
}
case
"
stoc_hs_player_change
"
:
{
handleHsPlayerChange
(
pb
);
break
;
}
case
"
stoc_hs_watch_change
"
:
{
handleHsWatchChange
(
pb
);
break
;
}
case
"
stoc_hs_player_enter
"
:
{
handleHsPlayerEnter
(
pb
);
break
;
}
case
"
stoc_type_change
"
:
{
handleTypeChange
(
pb
);
break
;
}
case
"
stoc_select_hand
"
:
{
handleSelectHand
(
pb
);
break
;
}
case
"
stoc_hand_result
"
:
{
handleHandResult
(
pb
);
break
;
}
case
"
stoc_select_tp
"
:
{
handleSelectTp
(
pb
);
break
;
}
case
"
stoc_deck_count
"
:
{
handleDeckCount
(
pb
);
break
;
}
case
"
stoc_duel_start
"
:
{
handleDuelStart
(
pb
);
break
;
}
case
"
stoc_duel_end
"
:
{
handleDuelEnd
(
pb
);
break
;
}
case
"
stoc_game_msg
"
:
{
if
(
!
replayStore
.
isReplay
)
{
// 如果不是回放模式,则记录回放数据
replayStore
.
record
(
packet
);
}
await
handleGameMsg
(
pb
);
break
;
}
case
"
stoc_time_limit
"
:
{
handleTimeLimit
(
pb
.
stoc_time_limit
);
break
;
}
case
"
stoc_error_msg
"
:
{
await
handleErrorMsg
(
pb
.
stoc_error_msg
);
break
;
}
case
"
stoc_change_side
"
:
{
handleChangeSide
(
pb
.
stoc_change_side
);
break
;
}
case
"
stoc_waiting_side
"
:
{
handleWaitingSide
(
pb
.
stoc_waiting_side
);
break
;
}
default
:
{
console
.
log
(
packet
);
break
;
}
case
"
stoc_time_limit
"
:
{
handleTimeLimit
(
pb
.
stoc_time_limit
);
break
;
}
case
"
stoc_error_msg
"
:
{
await
handleErrorMsg
(
pb
.
stoc_error_msg
);
break
;
}
case
"
stoc_change_side
"
:
{
handleChangeSide
(
pb
.
stoc_change_side
);
break
;
}
case
"
stoc_waiting_side
"
:
{
handleWaitingSide
(
pb
.
stoc_waiting_side
);
break
;
}
default
:
{
console
.
log
(
packet
);
break
;
}
}
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