@@ -63,84 +63,88 @@ export async function activate(context: flashpoint.ExtensionContext) {
6363 }
6464
6565 // Create Session
66- session = new Session ( userId ) ;
67- await session . connect ( ) ;
68- session . event ( 'Basic' , 'launch' , '' ) ;
69- if ( flashpoint . dataVersion ) {
70- session . event ( 'Basic' , 'version' , flashpoint . dataVersion ) ;
71- }
72-
73- // Hardware
74- if ( config . hardware ( ) && ! config . hardwareSent ( ) ) {
75- let totalmem = os . totalmem ( ) ;
76- let simplifiedTotalMem = "unknown" ;
77- if ( totalmem > 17179000000 ) { simplifiedTotalMem = '>= 16GB' ; }
78- else if ( totalmem > 8589900000 ) { simplifiedTotalMem = '>= 8GB < 16GB' ; }
79- else if ( totalmem > 4294900000 ) { simplifiedTotalMem = '>= 4GB < 8GB' ; }
80- else if ( totalmem > 2147400000 ) { simplifiedTotalMem = '>= 2GB < 4GB' ; }
81- else if ( totalmem > 10000 ) { simplifiedTotalMem = '< 2GB' ; }
82- Promise . all ( [
83- session . event ( 'Hardware' , 'arch' , arch ( ) ) ,
84- session . event ( 'Hardware' , 'operatingSystem' , os . version ( ) ) ,
85- session . event ( 'Hardware' , 'memory' , simplifiedTotalMem )
86- ] )
87- . then ( ( ) => {
88- flashpoint . setExtConfigValue ( 'com.analytics.hardware-sent' , true ) ;
89- } )
90- . catch ( ( err ) => {
91- flashpoint . log . error ( 'Error sending Hardware stats, will send on next startup.' ) ;
92- } )
93- }
66+ try {
67+ session = new Session ( userId ) ;
68+ await session . connect ( ) ;
69+ session . event ( 'Basic' , 'launch' , '' ) ;
70+ if ( flashpoint . dataVersion ) {
71+ session . event ( 'Basic' , 'version' , flashpoint . dataVersion ) ;
72+ }
9473
95- // Game Launch
96- registerSub ( flashpoint . games . onDidLaunchGame ( ( game ) => {
97- if ( config . games ( ) ) {
98- session . event ( 'Games' , 'gameLaunch' , game . id ) ;
99- const timeStart = Date . now ( ) ;
100- const listener = flashpoint . services . onServiceRemove ( ( process ) => {
101- if ( process . id === 'game.' + game . id ) {
102- session . event ( 'GameTime' , 'gameId' , ( ( Date . now ( ) - timeStart ) / 1000 ) . toString ( ) ) ;
103- flashpoint . dispose ( listener ) ;
104- }
74+ // Hardware
75+ if ( config . hardware ( ) && ! config . hardwareSent ( ) ) {
76+ let totalmem = os . totalmem ( ) ;
77+ let simplifiedTotalMem = "unknown" ;
78+ if ( totalmem > 17179000000 ) { simplifiedTotalMem = '>= 16GB' ; }
79+ else if ( totalmem > 8589900000 ) { simplifiedTotalMem = '>= 8GB < 16GB' ; }
80+ else if ( totalmem > 4294900000 ) { simplifiedTotalMem = '>= 4GB < 8GB' ; }
81+ else if ( totalmem > 2147400000 ) { simplifiedTotalMem = '>= 2GB < 4GB' ; }
82+ else if ( totalmem > 10000 ) { simplifiedTotalMem = '< 2GB' ; }
83+ Promise . all ( [
84+ session . event ( 'Hardware' , 'arch' , arch ( ) ) ,
85+ session . event ( 'Hardware' , 'operatingSystem' , os . version ( ) ) ,
86+ session . event ( 'Hardware' , 'memory' , simplifiedTotalMem )
87+ ] )
88+ . then ( ( ) => {
89+ flashpoint . setExtConfigValue ( 'com.analytics.hardware-sent' , true ) ;
90+ } )
91+ . catch ( ( err ) => {
92+ flashpoint . log . error ( 'Error sending Hardware stats, will send on next startup.' ) ;
10593 } )
10694 }
107- } ) ) ;
10895
109- flashpoint . log . onLog ( ( entry ) => {
110- if ( entry . source === 'Server' ) {
111- let urlSubstring = "" ;
112- const baseIdx = entry . content . indexOf ( 'Serving File From Base URLs:' ) ;
113- if ( baseIdx !== - 1 ) {
114- urlSubstring = entry . content . substring ( baseIdx + 'Serving File From Base URLs:' . length + 2 ) ;
115- } else {
116- const htdocsIdx = entry . content . indexOf ( 'Serving File From HTDOCS:' ) ;
117- if ( htdocsIdx !== - 1 ) {
118- urlSubstring = entry . content . substring ( htdocsIdx + 'Serving File From HTDOCS:' . length + 8 ) ;
119- }
96+ // Game Launch
97+ registerSub ( flashpoint . games . onDidLaunchGame ( ( game ) => {
98+ if ( config . games ( ) ) {
99+ session . event ( 'Games' , 'gameLaunch' , game . id ) ;
100+ const timeStart = Date . now ( ) ;
101+ const listener = flashpoint . services . onServiceRemove ( ( process ) => {
102+ if ( process . id === 'game.' + game . id ) {
103+ session . event ( 'GameTime' , 'gameId' , ( ( Date . now ( ) - timeStart ) / 1000 ) . toString ( ) ) ;
104+ flashpoint . dispose ( listener ) ;
105+ }
106+ } )
120107 }
121- if ( urlSubstring && config . phpReporting ( ) ) {
122- // Check if a singular game is running
123- const games = flashpoint . services . getServices ( ) . filter ( s => s . id . startsWith ( 'game.' ) ) ;
124- if ( games . length === 1 ) {
125- const gameId = games [ 0 ] . id . substring ( 5 ) ;
126- session . event ( 'Repack' , gameId , urlSubstring ) ;
108+ } ) ) ;
109+
110+ flashpoint . log . onLog ( ( entry ) => {
111+ if ( entry . source === 'Server' ) {
112+ let urlSubstring = "" ;
113+ const baseIdx = entry . content . indexOf ( 'Serving File From Base URLs:' ) ;
114+ if ( baseIdx !== - 1 ) {
115+ urlSubstring = entry . content . substring ( baseIdx + 'Serving File From Base URLs:' . length + 2 ) ;
116+ } else {
117+ const htdocsIdx = entry . content . indexOf ( 'Serving File From HTDOCS:' ) ;
118+ if ( htdocsIdx !== - 1 ) {
119+ urlSubstring = entry . content . substring ( htdocsIdx + 'Serving File From HTDOCS:' . length + 8 ) ;
120+ }
121+ }
122+ if ( urlSubstring && config . phpReporting ( ) ) {
123+ // Check if a singular game is running
124+ const games = flashpoint . services . getServices ( ) . filter ( s => s . id . startsWith ( 'game.' ) ) ;
125+ if ( games . length === 1 ) {
126+ const gameId = games [ 0 ] . id . substring ( 5 ) ;
127+ session . event ( 'Repack' , gameId , urlSubstring ) ;
128+ }
127129 }
128130 }
129- }
130- } ) ;
131+ } ) ;
131132
132- // Wipe User Data
133- registerSub ( flashpoint . commands . registerCommand ( 'com.analytics.deletion-request' , async ( ) => {
134- await flashpoint . setExtConfigValue ( 'com.analytics.basic' , false ) ;
135- await flashpoint . setExtConfigValue ( 'com.analytics.games' , false ) ;
136- await flashpoint . setExtConfigValue ( 'com.analytics.hardware' , false ) ;
137- await flashpoint . setExtConfigValue ( 'com.analytics.php-reporting' , false ) ;
138- let userId = flashpoint . getExtConfigValue ( 'com.analytics.user-id' ) ;
139- const deletionFormUrl = `https://docs.google.com/forms/d/e/1FAIpQLScPeAKFmieGuHdu3FcyiSXqDdfcEFAfjIpM7nzlUsJbi9NYuw/viewform?entry.818267307=${ userId } ` ;
140- userId = uuid ( ) ;
141- await flashpoint . setExtConfigValue ( 'com.analytics.user-id' , userId ) ;
142- open ( deletionFormUrl ) ;
143- } ) ) ;
133+ // Wipe User Data
134+ registerSub ( flashpoint . commands . registerCommand ( 'com.analytics.deletion-request' , async ( ) => {
135+ await flashpoint . setExtConfigValue ( 'com.analytics.basic' , false ) ;
136+ await flashpoint . setExtConfigValue ( 'com.analytics.games' , false ) ;
137+ await flashpoint . setExtConfigValue ( 'com.analytics.hardware' , false ) ;
138+ await flashpoint . setExtConfigValue ( 'com.analytics.php-reporting' , false ) ;
139+ let userId = flashpoint . getExtConfigValue ( 'com.analytics.user-id' ) ;
140+ const deletionFormUrl = `https://docs.google.com/forms/d/e/1FAIpQLScPeAKFmieGuHdu3FcyiSXqDdfcEFAfjIpM7nzlUsJbi9NYuw/viewform?entry.818267307=${ userId } ` ;
141+ userId = uuid ( ) ;
142+ await flashpoint . setExtConfigValue ( 'com.analytics.user-id' , userId ) ;
143+ open ( deletionFormUrl ) ;
144+ } ) ) ;
145+ } catch ( error ) {
146+ flashpoint . log . error ( 'Error connecting to Analytics server.' ) ;
147+ }
144148 }
145149 }
146150 } ) ;
0 commit comments