@@ -768,6 +768,32 @@ export class GameRoom implements BrothersFinder {
768768 throw new Error ( "Unexpected room redirect received or error while querying map details" ) ;
769769 }
770770
771+ /**
772+ * Connects to the admin server to fetch map details with user context.
773+ * This version passes user information to the admin API to get user-specific settings.
774+ */
775+ private static async getMapDetailsWithUser ( roomUrl : string , user : User ) : Promise < MapDetailsData > {
776+ if ( ! ADMIN_API_URL ) {
777+ // Fall back to the regular method if no admin API
778+ return GameRoom . getMapDetails ( roomUrl ) ;
779+ }
780+
781+ const userId = user . uuid ;
782+ const result = isMapDetailsData . safeParse ( await adminApi . fetchMapDetails ( roomUrl , userId ) ) ;
783+
784+ if ( result . success ) {
785+ return result . data ;
786+ }
787+
788+ console . error ( result . error . issues ) ;
789+ console . error ( "Unexpected room redirect or error received while querying map details with user" , result ) ;
790+ Sentry . captureException ( result . error . issues ) ;
791+ Sentry . captureException (
792+ `Unexpected room redirect or error received while querying map details with user ${ JSON . stringify ( result ) } `
793+ ) ;
794+ throw new Error ( "Unexpected room redirect received or error while querying map details with user" ) ;
795+ }
796+
771797 private mapPromise : Promise < ITiledMap > | undefined ;
772798
773799 /**
@@ -1050,17 +1076,47 @@ export class GameRoom implements BrothersFinder {
10501076 return undefined ;
10511077 }
10521078
1053- public getBbbSettings ( ) : MapBbbData | undefined {
1079+ public async getBbbSettings ( user ?: User ) : Promise < MapBbbData | undefined > {
1080+ // If we have a user, try to get fresh settings from admin API
1081+ if ( user && ADMIN_API_URL ) {
1082+ try {
1083+ console . log ( `Attempting to fetch fresh BBB settings for user: ${ user . name } (${ user . uuid } )` ) ;
1084+ const mapDetails = await GameRoom . getMapDetailsWithUser ( this . _roomUrl , user ) ;
1085+ if ( mapDetails . thirdParty ?. bbb ) {
1086+ console . log ( `Using fresh BBB settings from Admin API for user: ` , {
1087+ url : mapDetails . thirdParty . bbb . url ,
1088+ secret : "[REDACTED]" ,
1089+ } ) ;
1090+ return mapDetails . thirdParty . bbb ;
1091+ }
1092+ } catch ( e ) {
1093+ console . warn ( "Failed to fetch fresh BBB settings, falling back to stored settings" , e ) ;
1094+ }
1095+ }
1096+
1097+ // Fall back to stored settings
10541098 const bbb = this . thirdParty ?. bbb ;
10551099 if ( bbb ) {
1100+ console . log ( `Using stored BBB settings from Admin API: ` , {
1101+ url : bbb . url ,
1102+ secret : "[REDACTED]" ,
1103+ } ) ;
10561104 return bbb ;
10571105 }
1106+
1107+ // Environment variable fallback
10581108 if ( BBB_URL && BBB_SECRET ) {
1109+ console . log ( `Using BBB settings from environment variables: ` , {
1110+ url : BBB_URL ,
1111+ secret : "[REDACTED]" ,
1112+ } ) ;
10591113 return {
10601114 url : BBB_URL ,
10611115 secret : BBB_SECRET ,
10621116 } ;
10631117 }
1118+
1119+ console . log ( `No BBB settings available` ) ;
10641120 return undefined ;
10651121 }
10661122
0 commit comments