File tree Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change 1
- import { v3 , v4 } from 'uuid'
1
+ import { createHash } from 'crypto'
2
+ import { v4 } from 'uuid'
2
3
3
4
/**
4
5
* Random generate a new token by uuid v4. It can be client or auth token.
@@ -8,13 +9,22 @@ export function newToken() {
8
9
return v4 ( ) . replace ( / - / g, '' )
9
10
}
10
11
12
+ export function getUUIDOfOfflinePlayer ( username : string ) {
13
+ const md5Bytes = createHash ( 'md5' ) . update ( `OfflinePlayer:${ username } ` ) . digest ( )
14
+ md5Bytes [ 6 ] &= 0x0f /* clear version */
15
+ md5Bytes [ 6 ] |= 0x30 /* set to version 3 */
16
+ md5Bytes [ 8 ] &= 0x3f /* clear variant */
17
+ md5Bytes [ 8 ] |= 0x80 /* set to IETF variant */
18
+ return md5Bytes . toString ( 'hex' )
19
+ }
20
+
11
21
/**
12
22
* Create an offline auth. It'll ensure the user game profile's `uuid` is the same for the same `username`.
13
23
*
14
24
* @param username The username you want to have in-game.
15
25
*/
16
26
export function offline ( username : string , uuid ?: string ) {
17
- const id = ( uuid || v3 ( username , '00000000-0000-0000-0000-000000000000' ) ) . replace ( / - / g , '' )
27
+ const id = ( uuid || getUUIDOfOfflinePlayer ( username ) )
18
28
const prof = {
19
29
id,
20
30
name : username ,
You can’t perform that action at this time.
0 commit comments