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
e12e744e
Commit
e12e744e
authored
Oct 23, 2022
by
Chunchi Che
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add playerInfo adapt
parent
5f82895f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
67 additions
and
1 deletion
+67
-1
src/api/ocgcore/ocgAdapter.ts
src/api/ocgcore/ocgAdapter.ts
+64
-0
src/api/ocgcore/ocgHelper.ts
src/api/ocgcore/ocgHelper.ts
+3
-1
No files found.
src/api/ocgcore/ocgAdapter.ts
0 → 100644
View file @
e12e744e
import
{
ygopro
}
from
"
./idl/ocgcore
"
;
const
PACKET_MIN_LEN
=
3
;
const
littleEndian
:
boolean
=
true
;
const
CtosPlayerInfo
=
16
;
class
ygoProPacket
{
packetLen
:
number
;
proto
:
number
;
exData
:
Uint8Array
;
constructor
(
packetLen
:
number
,
proto
:
number
,
exData
:
Uint8Array
)
{
this
.
packetLen
=
packetLen
;
this
.
proto
=
proto
;
this
.
exData
=
exData
;
}
serialize
():
Uint8Array
{
const
packetLen
=
this
.
packetLen
||
0
;
const
proto
=
this
.
proto
||
0
;
const
exData
=
this
.
exData
||
new
Uint8Array
();
const
array
=
new
Uint8Array
(
packetLen
+
2
);
const
dataView
=
new
DataView
(
array
);
dataView
.
setUint16
(
0
,
packetLen
,
littleEndian
);
dataView
.
setUint8
(
2
,
proto
);
array
.
slice
(
3
,
packetLen
+
2
).
set
(
exData
);
return
array
;
}
}
export
class
ygoArrayBuilder
extends
ygoProPacket
{
constructor
(
array
:
Uint8Array
)
{
try
{
if
(
array
.
length
<
PACKET_MIN_LEN
)
{
throw
new
Error
(
"
Packet length too short, length =
"
+
array
.
length
);
}
else
{
const
dataView
=
new
DataView
(
array
);
const
packetLen
=
dataView
.
getInt16
(
0
,
littleEndian
);
const
proto
=
dataView
.
getInt8
(
2
);
const
exData
=
array
.
slice
(
3
,
packetLen
+
2
);
super
(
packetLen
,
proto
,
exData
);
}
}
catch
(
e
)
{
console
.
log
(
"
[e][ygoProPacket][constructor]
"
+
e
);
}
}
}
export
class
playerInfoPacket
extends
ygoProPacket
{
constructor
(
pb
:
ygopro
.
YgoCtosMsg
)
{
const
encoder
=
new
TextEncoder
();
const
player
=
pb
.
ctos_player_info
.
name
;
const
exData
=
encoder
.
encode
(
player
);
super
(
exData
.
length
+
1
,
CtosPlayerInfo
,
exData
);
}
}
src/api/ocgcore/ocgHelper.ts
View file @
e12e744e
import
{
ygopro
}
from
"
./idl/ocgcore
"
;
import
socketMiddleWare
,
{
socketCmd
}
from
"
../../middleware/socket
"
;
import
{
IDeck
}
from
"
../Card
"
;
import
{
playerInfoPacket
}
from
"
./ocgAdapter
"
;
export
function
sendUpdateDeck
(
deck
:
IDeck
)
{
const
updateDeck
=
new
ygopro
.
YgoCtosMsg
({
...
...
@@ -36,8 +37,9 @@ export function sendPlayerInfo(ws: WebSocket, player: string) {
name
:
player
,
}),
});
const
packet
=
new
playerInfoPacket
(
playerInfo
);
ws
.
send
(
p
layerInfo
.
serialize
());
ws
.
send
(
p
acket
.
serialize
());
}
export
function
sendJoinGame
(
ws
:
WebSocket
,
version
:
number
,
passWd
:
string
)
{
...
...
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