@@ -67,6 +67,7 @@ let gameNode: ChildProcessWithoutNullStreams | null = null;
6767const client = new NTPClient ( "time.google.com" , 123 , { timeout : 5000 } ) ;
6868
6969let registry : Planet [ ] ;
70+ let accessiblePlanets : Planet [ ] ;
7071let remoteNode : NodeInfo ;
7172let geoBlock : { ip : string ; country : string ; isWhitelist ?: boolean } ;
7273
@@ -176,14 +177,16 @@ async function initializeConfig() {
176177 if ( ! Array . isArray ( registry ) || registry . length <= 0 ) {
177178 throw Error ( "Registry is empty or invalid. No planets found." ) ;
178179 }
180+ accessiblePlanets = await filterAccessiblePlanets ( registry ) ;
181+
179182 const planet =
180- registry . find ( ( v ) => v . id === remoteConfig . Planet ) ??
183+ accessiblePlanets . find ( ( v ) => v . id === remoteConfig . Planet ) ??
181184 ( ( ) => {
182185 console . log (
183186 "No matching PlanetID found in registry. Using the first planet." ,
184187 ) ;
185- remoteConfig . Planet = registry [ 0 ] . id ;
186- return registry [ 0 ] ;
188+ remoteConfig . Planet = accessiblePlanets [ 0 ] . id ;
189+ return accessiblePlanets [ 0 ] ;
187190 } ) ( ) ;
188191
189192 remoteNode = await initializeNode ( planet . rpcEndpoints , true ) ;
@@ -348,6 +351,29 @@ function initializeIpc() {
348351 }
349352 } ) ;
350353
354+ ipcMain . on ( "get-aws-sink-cloudwatch-guid" , async ( event ) => {
355+ const localAppData = process . env . localappdata ;
356+ if ( process . platform === "win32" && localAppData !== undefined ) {
357+ const guidPath = path . join (
358+ localAppData ,
359+ "planetarium" ,
360+ ".aws_sink_cloudwatch_guid" ,
361+ ) ;
362+
363+ if ( fs . existsSync ( guidPath ) ) {
364+ event . returnValue = await fs . promises . readFile ( guidPath , {
365+ encoding : "utf-8" ,
366+ } ) ;
367+ } else {
368+ event . returnValue = null ;
369+ }
370+
371+ return ;
372+ }
373+
374+ event . returnValue = "Not supported platform." ;
375+ } ) ;
376+
351377 ipcMain . on ( "online-status-changed" , ( event , status : "online" | "offline" ) => {
352378 console . log ( `online-status-changed: ${ status } ` ) ;
353379 if ( status === "offline" ) {
@@ -358,10 +384,10 @@ function initializeIpc() {
358384 ipcMain . handle ( "get-planetary-info" , async ( ) => {
359385 // Synchronously wait until registry / remote node initialized
360386 // This should return, otherwise entry point of renderer will stuck in white screen.
361- while ( ! registry || ! remoteNode ) {
387+ while ( ! registry || ! remoteNode || ! accessiblePlanets ) {
362388 await utils . sleep ( 100 ) ;
363389 }
364- return [ registry , remoteNode ] ;
390+ return [ registry , remoteNode , accessiblePlanets ] ;
365391 } ) ;
366392
367393 ipcMain . handle ( "check-geoblock" , async ( ) => {
@@ -557,3 +583,37 @@ async function initGeoBlocking() {
557583 } ) ;
558584 }
559585}
586+
587+ async function filterAccessiblePlanets ( planets : Planet [ ] ) : Promise < Planet [ ] > {
588+ const accessiblePlanets : Planet [ ] = [ ] ;
589+
590+ for ( const planet of planets ) {
591+ const endpoints = Object . values ( planet . rpcEndpoints [ "headless.gql" ] ) . flat ( ) ;
592+ // GraphQL 쿼리 정의
593+ const query = `
594+ query {
595+ nodeStatus {
596+ bootstrapEnded
597+ }
598+ }
599+ ` ;
600+ // 모든 endpoint에 대해 병렬로 요청을 보냅니다.
601+ const requests = endpoints . map ( ( endpoint ) =>
602+ axios . post ( endpoint , { query } ) . then (
603+ ( response ) => response . status === 200 ,
604+ ( ) => false , // 요청 실패 시 false 반환
605+ ) ,
606+ ) ;
607+
608+ try {
609+ const results = await Promise . all ( requests ) ;
610+ if ( results . some ( ( isAccessible ) => isAccessible ) ) {
611+ accessiblePlanets . push ( planet ) ;
612+ }
613+ } catch ( error ) {
614+ console . error ( `Error checking endpoints for planet ${ planet . id } :` , error ) ;
615+ }
616+ }
617+
618+ return accessiblePlanets ;
619+ }
0 commit comments