File tree Expand file tree Collapse file tree 7 files changed +24
-12
lines changed
Expand file tree Collapse file tree 7 files changed +24
-12
lines changed Original file line number Diff line number Diff line change @@ -2,12 +2,14 @@ import { decodeJwt } from "jose";
22import { z } from "zod" ;
33import { TokenPayload , TokenPayloadSchema } from "../core/ApiSchemas" ;
44import { base64urlToUuid } from "../core/Base64" ;
5+ import { generateID } from "../core/Util" ;
56import { getApiBase , getAudience } from "./Api" ;
67import { generateCryptoRandomUUID } from "./Utils" ;
78
89export type UserAuth = { jwt : string ; claims : TokenPayload } | false ;
910
1011const PERSISTENT_ID_KEY = "player_persistent_id" ;
12+ const CLIENT_ID_KEY = "client_join_id" ;
1113
1214let __jwt : string | null = null ;
1315
@@ -209,6 +211,16 @@ export function getPersistentID(): string {
209211 return base64urlToUuid ( sub ) ;
210212}
211213
214+ export function getPersistentClientID ( ) : string {
215+ const value = sessionStorage . getItem ( CLIENT_ID_KEY ) ;
216+ if ( value && / ^ [ A - Z a - z 0 - 9 ] { 8 } $ / . test ( value ) ) {
217+ return value ;
218+ }
219+ const newID = generateID ( ) ;
220+ sessionStorage . setItem ( CLIENT_ID_KEY , newID ) ;
221+ return newID ;
222+ }
223+
212224// WARNING: DO NOT EXPOSE THIS ID
213225function getPersistentIDFromLocalStorage ( ) : string {
214226 // Try to get existing localStorage
Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ import {
2222 isValidGameID ,
2323} from "../core/Schemas" ;
2424import { generateID } from "../core/Util" ;
25+ import { getPersistentClientID } from "./Auth" ;
2526import "./components/baseComponents/Modal" ;
2627import { BaseModal } from "./components/BaseModal" ;
2728import "./components/CopyButton" ;
@@ -694,7 +695,7 @@ export class HostLobbyModal extends BaseModal {
694695 }
695696
696697 protected onOpen ( ) : void {
697- this . lobbyCreatorClientID = generateID ( ) ;
698+ this . lobbyCreatorClientID = getPersistentClientID ( ) ;
698699
699700 createLobby ( this . lobbyCreatorClientID )
700701 . then ( async ( lobby ) => {
Original file line number Diff line number Diff line change @@ -8,10 +8,10 @@ import {
88 GameInfo ,
99 GameRecordSchema ,
1010} from "../core/Schemas" ;
11- import { generateID } from "../core/Util" ;
1211import { getServerConfigFromClient } from "../core/configuration/ConfigLoader" ;
1312import { GameMapSize , GameMode } from "../core/game/Game" ;
1413import { getApiBase } from "./Api" ;
14+ import { getPersistentClientID } from "./Auth" ;
1515import { JoinLobbyEvent } from "./Main" ;
1616import { terrainMapFileLoader } from "./TerrainMapFileLoader" ;
1717import { BaseModal } from "./components/BaseModal" ;
@@ -426,7 +426,7 @@ export class JoinPrivateLobbyModal extends BaseModal {
426426 new CustomEvent ( "join-lobby" , {
427427 detail : {
428428 gameID : lobbyId ,
429- clientID : generateID ( ) ,
429+ clientID : getPersistentClientID ( ) ,
430430 } as JoinLobbyEvent ,
431431 bubbles : true ,
432432 composed : true ,
@@ -482,7 +482,7 @@ export class JoinPrivateLobbyModal extends BaseModal {
482482 detail : {
483483 gameID : lobbyId ,
484484 gameRecord : parsed . data ,
485- clientID : generateID ( ) ,
485+ clientID : getPersistentClientID ( ) ,
486486 } as JoinLobbyEvent ,
487487 bubbles : true ,
488488 composed : true ,
Original file line number Diff line number Diff line change @@ -17,7 +17,6 @@ import {
1717 getClanTag ,
1818 replacer ,
1919} from "../core/Util" ;
20- import { getPersistentID } from "./Auth" ;
2120import { LobbyConfig } from "./ClientGameRunner" ;
2221import { ReplaySpeedChangeEvent } from "./InputHandler" ;
2322import { defaultReplaySpeedMultiplier } from "./utilities/ReplaySpeedMultiplier" ;
@@ -209,7 +208,7 @@ export class LocalServer {
209208 }
210209 const players : PlayerRecord [ ] = [
211210 {
212- persistentID : getPersistentID ( ) ,
211+ persistentID : null ,
213212 username : this . lobbyConfig . playerName ,
214213 clientID : this . lobbyConfig . clientID ,
215214 stats : this . allPlayersStats [ this . lobbyConfig . clientID ] ,
Original file line number Diff line number Diff line change @@ -2,9 +2,8 @@ import { html, LitElement } from "lit";
22import { customElement , query , state } from "lit/decorators.js" ;
33import { UserMeResponse } from "../core/ApiSchemas" ;
44import { getServerConfigFromClient } from "../core/configuration/ConfigLoader" ;
5- import { generateID } from "../core/Util" ;
65import { getUserMe } from "./Api" ;
7- import { getPlayToken } from "./Auth" ;
6+ import { getPersistentClientID , getPlayToken } from "./Auth" ;
87import { BaseModal } from "./components/BaseModal" ;
98import "./components/Difficulties" ;
109import "./components/PatternButton" ;
@@ -228,7 +227,7 @@ export class MatchmakingModal extends BaseModal {
228227 new CustomEvent ( "join-lobby" , {
229228 detail : {
230229 gameID : this . gameID ,
231- clientID : generateID ( ) ,
230+ clientID : getPersistentClientID ( ) ,
232231 } as JoinLobbyEvent ,
233232 bubbles : true ,
234233 composed : true ,
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ import {
1111 Trios ,
1212} from "../core/game/Game" ;
1313import { GameID , GameInfo } from "../core/Schemas" ;
14- import { generateID } from "../core/Util " ;
14+ import { getPersistentClientID } from "./Auth " ;
1515import { PublicLobbySocket } from "./LobbySocket" ;
1616import { JoinLobbyEvent } from "./Main" ;
1717import { terrainMapFileLoader } from "./TerrainMapFileLoader" ;
@@ -362,7 +362,7 @@ export class PublicLobby extends LitElement {
362362 new CustomEvent ( "join-lobby" , {
363363 detail : {
364364 gameID : lobby . gameID ,
365- clientID : generateID ( ) ,
365+ clientID : getPersistentClientID ( ) ,
366366 source : "public" ,
367367 publicLobbyInfo : lobby ,
368368 } as JoinLobbyEvent ,
Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ import { UserSettings } from "../core/game/UserSettings";
1919import { TeamCountConfig } from "../core/Schemas" ;
2020import { generateID } from "../core/Util" ;
2121import { hasLinkedAccount } from "./Api" ;
22+ import { getPersistentClientID } from "./Auth" ;
2223import "./components/baseComponents/Button" ;
2324import "./components/baseComponents/Modal" ;
2425import { BaseModal } from "./components/BaseModal" ;
@@ -899,7 +900,7 @@ export class SinglePlayerModal extends BaseModal {
899900 console . log (
900901 `Starting single player game with map: ${ GameMapType [ this . selectedMap as keyof typeof GameMapType ] } ${ this . useRandomMap ? " (Randomly selected)" : "" } ` ,
901902 ) ;
902- const clientID = generateID ( ) ;
903+ const clientID = getPersistentClientID ( ) ;
903904 const gameID = generateID ( ) ;
904905
905906 const usernameInput = document . querySelector (
You can’t perform that action at this time.
0 commit comments