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'
23
34/**
45 * Random generate a new token by uuid v4. It can be client or auth token.
@@ -8,13 +9,22 @@ export function newToken() {
89 return v4 ( ) . replace ( / - / g, '' )
910}
1011
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+
1121/**
1222 * Create an offline auth. It'll ensure the user game profile's `uuid` is the same for the same `username`.
1323 *
1424 * @param username The username you want to have in-game.
1525 */
1626export 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 ) )
1828 const prof = {
1929 id,
2030 name : username ,
You can’t perform that action at this time.
0 commit comments