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
08eae211
Commit
08eae211
authored
Mar 10, 2024
by
Chunchi Che
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add getCreateRoomPasswd
parent
0bb9debe
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
53 additions
and
9 deletions
+53
-9
src/api/mycard/room.ts
src/api/mycard/room.ts
+53
-9
No files found.
src/api/mycard/room.ts
View file @
08eae211
...
@@ -18,24 +18,68 @@ export function getEncryptedPasswd(
...
@@ -18,24 +18,68 @@ export function getEncryptedPasswd(
):
string
{
):
string
{
const
optionsBuffer
=
new
Uint8Array
(
6
);
const
optionsBuffer
=
new
Uint8Array
(
6
);
optionsBuffer
[
1
]
=
3
<<
4
;
optionsBuffer
[
1
]
=
3
<<
4
;
encryptBuffer
(
optionsBuffer
,
external_id
);
const
base64String
=
btoa
(
String
.
fromCharCode
(...
optionsBuffer
));
return
base64String
+
roomID
;
}
// 获取创建房间的密码
export
function
getCreateRoomPasswd
(
options
:
Options
,
roomID
:
string
,
external_id
:
number
,
_private
:
boolean
=
false
,
)
{
// ref: https://docs.google.com/document/d/1rvrCGIONua2KeRaYNjKBLqyG9uybs9ZI-AmzZKNftOI/edit
const
optionsBuffer
=
new
Uint8Array
(
6
);
optionsBuffer
[
1
]
=
((
_private
?
2
:
1
)
<<
4
)
|
(
options
.
duel_rule
<<
1
)
|
(
options
.
auto_death
?
0x1
:
0
);
optionsBuffer
[
2
]
=
(
options
.
rule
<<
5
)
|
(
options
.
mode
<<
3
)
|
(
options
.
no_check_deck
?
1
<<
1
:
0
)
|
(
options
.
no_shuffle_deck
?
1
:
0
);
writeUInt16LE
(
optionsBuffer
,
3
,
options
.
start_lp
);
optionsBuffer
[
5
]
=
(
options
.
start_hand
<<
4
)
|
options
.
draw_count
;
encryptBuffer
(
optionsBuffer
,
external_id
);
const
base64String
=
btoa
(
String
.
fromCharCode
(...
optionsBuffer
));
return
base64String
+
roomID
;
}
// 填充校验码和加密
function
encryptBuffer
(
buffer
:
Uint8Array
,
external_id
:
number
)
{
let
checksum
=
0
;
let
checksum
=
0
;
for
(
let
i
=
1
;
i
<
optionsB
uffer
.
length
;
i
++
)
{
for
(
let
i
=
1
;
i
<
b
uffer
.
length
;
i
++
)
{
checksum
-=
optionsB
uffer
[
i
];
checksum
-=
b
uffer
[
i
];
}
}
optionsB
uffer
[
0
]
=
checksum
&
0xff
;
b
uffer
[
0
]
=
checksum
&
0xff
;
const
secret
=
(
external_id
%
65535
)
+
1
;
const
secret
=
(
external_id
%
65535
)
+
1
;
for
(
let
i
=
0
;
i
<
optionsB
uffer
.
length
;
i
+=
2
)
{
for
(
let
i
=
0
;
i
<
b
uffer
.
length
;
i
+=
2
)
{
const
value
=
(
optionsBuffer
[
i
+
1
]
<<
8
)
|
optionsBuffer
[
i
]
;
const
value
=
readUInt16LE
(
buffer
,
i
)
;
const
xorResult
=
value
^
secret
;
const
xorResult
=
value
^
secret
;
optionsBuffer
[
i
+
1
]
=
(
xorResult
>>
8
)
&
0xff
;
writeUInt16LE
(
buffer
,
i
,
xorResult
);
optionsBuffer
[
i
]
=
xorResult
&
0xff
;
}
}
}
const
base64String
=
btoa
(
String
.
fromCharCode
(...
optionsBuffer
));
/* 一些辅助函数 */
return
base64String
+
roomID
;
function
readUInt16LE
(
buffer
:
Uint8Array
,
offset
:
number
):
number
{
return
(
buffer
[
offset
+
1
]
<<
8
)
|
buffer
[
offset
];
}
function
writeUInt16LE
(
buffer
:
Uint8Array
,
offset
:
number
,
value
:
number
)
{
buffer
[
offset
]
=
value
&
0xff
;
buffer
[
offset
+
1
]
=
(
value
>>
8
)
&
0xff
;
}
}
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