Skip to content

Commit 212b2ec

Browse files
committed
feat: Hardware + PHP Reporting
Updated to FP 10.1
1 parent cc61df4 commit 212b2ec

4 files changed

Lines changed: 243 additions & 53 deletions

File tree

package.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,18 @@
2424
"default": false,
2525
"description": "Enables collection of Game launch statistics. (Game Launches)"
2626
},
27+
"com.analytics.php-reporting": {
28+
"title": "PHP Reporting",
29+
"description": "Helps with repacking Legacy Games into zips. Listens for Games trying to load files from the PHP server and reports the ID and URL pair.",
30+
"type": "boolean",
31+
"default": false
32+
},
33+
"com.analytics.hardware": {
34+
"title": "Simplified Hardware Info",
35+
"description": "Sends back simplified hardware info, includes Operating System version and Total System Memory",
36+
"type": "boolean",
37+
"default": false
38+
},
2739
"com.analytics.delete-button": {
2840
"title": "Submit Deletion Request",
2941
"description": "Opens the deletion form in browser, disables all analytics and randomizes a new User ID.",

src/ext.ts

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@ import * as flashpoint from 'flashpoint-launcher';
22
import ua from 'universal-analytics';
33
import { v4 as uuid } from 'uuid';
44
import open from 'open';
5+
import * as os from 'os';
56

67
export async function activate(context: flashpoint.ExtensionContext) {
78
const registerSub = (d: flashpoint.Disposable) => { flashpoint.registerDisposable(context.subscriptions, d)};
89

910
const config = {
1011
basic: () => flashpoint.getExtConfigValue('com.analytics.basic'),
11-
games: () => flashpoint.getExtConfigValue('com.analytics.games')
12+
games: () => flashpoint.getExtConfigValue('com.analytics.games'),
13+
phpReporting: () => flashpoint.getExtConfigValue('com.analytics.php-reporting'),
14+
hardware: () => flashpoint.getExtConfigValue('com.analytics.hardware'),
15+
hardwareSent: () => flashpoint.getExtConfigValue('com.analytics.hardware-sent'),
1216
}
1317

1418
const firstLaunch = !flashpoint.getExtConfigValue('com.analytics.setup-complete');
@@ -20,7 +24,8 @@ export async function activate(context: flashpoint.ExtensionContext) {
2024
'When you launch Flashpoint',
2125
'How long you use Flashpoint for',
2226
'The version of Flashpoint you are running',
23-
'What games you launch'
27+
'What games you launch',
28+
'Which URLs games request, to help with repacking legacy games',
2429
];
2530
const res = await flashpoint.dialogs.showMessageBox({
2631
message: `Enable the collection of Flashpoint Analytics?\nThese are listed below and configurable on the Config page.\n\n - ${trackingInfoHuman.join('\n - ')}\n\nThis information is tied to a randomized User ID, no personally identifitable information is collected however you can request deletion via the Config page.\n\nAbsolutely NOTHING will be tracked if you click Disable All.\nIf you want to delete this extension to be sure, go to /Data/Extensions and delete the Analytics folder.`,
@@ -29,12 +34,16 @@ export async function activate(context: flashpoint.ExtensionContext) {
2934
});
3035
if (res === 1) {
3136
await flashpoint.setExtConfigValue('com.analytics.basic', true);
37+
await flashpoint.setExtConfigValue('com.analytics.hardware', true);
3238
await flashpoint.setExtConfigValue('com.analytics.games', true);
39+
await flashpoint.setExtConfigValue('com.analytics.php-reporting', true);
3340
} else {
3441
await flashpoint.setExtConfigValue('com.analytics.basic', false);
42+
await flashpoint.setExtConfigValue('com.analytics.hardware', false);
3543
await flashpoint.setExtConfigValue('com.analytics.games', false);
44+
await flashpoint.setExtConfigValue('com.analytics.php-reporting', false);
3645
}
37-
flashpoint.setExtConfigValue('com.analytics.setup-complete', true);
46+
await flashpoint.setExtConfigValue('com.analytics.setup-complete', true);
3847
}
3948

4049
if (config.basic()) {
@@ -48,16 +57,54 @@ export async function activate(context: flashpoint.ExtensionContext) {
4857
visitor.event('Basic', 'launch').send();
4958
visitor.event('Basic', 'version', flashpoint.dataVersion || '?');
5059

60+
if (config.hardware() && !config.hardwareSent()) {
61+
let totalmem = os.totalmem();
62+
let simplifiedTotalMem = "unknown";
63+
if (totalmem > 17179000000) { simplifiedTotalMem = '>= 16GB'; }
64+
else if (totalmem > 8589900000) { simplifiedTotalMem = '>= 8GB < 16GB'; }
65+
else if (totalmem > 4294900000) { simplifiedTotalMem = '>= 4GB < 8GB'; }
66+
else if (totalmem > 2147400000) { simplifiedTotalMem = '>= 2GB < 4GB'; }
67+
else if (totalmem > 10000) { simplifiedTotalMem = '< 2GB'; }
68+
visitor.event('Hardware', 'arch', os.arch()).send();
69+
visitor.event('Hardware', 'operatingSystem', os.version()).send();
70+
visitor.event('Hardware', 'memory', simplifiedTotalMem).send();
71+
await flashpoint.setExtConfigValue('com.analytics.hardware-sent', true);
72+
}
73+
5174
registerSub(flashpoint.games.onDidLaunchGame((game) => {
5275
if (config.games()) {
5376
visitor.event('Games', 'gameLaunch', game.id).send();
5477
}
5578
}));
79+
flashpoint.log.onLog((entry) => {
80+
if (entry.source === 'Server') {
81+
let urlSubstring = "";
82+
const baseIdx = entry.content.indexOf('Serving File From Base URLs:');
83+
if (baseIdx !== -1) {
84+
urlSubstring = entry.content.substring(baseIdx + 'Serving File From Base URLs:'.length + 2);
85+
} else {
86+
const htdocsIdx = entry.content.indexOf('Serving File From HTDOCS:');
87+
if (htdocsIdx !== -1) {
88+
urlSubstring = entry.content.substring(htdocsIdx + 'Serving File From HTDOCS:'.length + 8);
89+
}
90+
}
91+
if (urlSubstring && config.phpReporting()) {
92+
// Check if a singular game is running
93+
const games = flashpoint.services.getServices().filter(s => s.id.startsWith('game.'));
94+
if (games.length === 1) {
95+
const gameId = games[0].id.substring(5);
96+
visitor.event('Repack', 'phpReport', `gameId:${gameId}, path:${urlSubstring}`).send();
97+
}
98+
}
99+
}
100+
});
56101
}
57102

58103
registerSub(flashpoint.commands.registerCommand('com.analytics.deletion-request', async () => {
59104
await flashpoint.setExtConfigValue('com.analytics.basic', false);
60105
await flashpoint.setExtConfigValue('com.analytics.games', false);
106+
await flashpoint.setExtConfigValue('com.analytics.hardware', false);
107+
await flashpoint.setExtConfigValue('com.analytics.php-reporting', false);
61108
let userId = flashpoint.getExtConfigValue('com.analytics.user-id');
62109
const deletionFormUrl = `https://docs.google.com/forms/d/e/1FAIpQLScPeAKFmieGuHdu3FcyiSXqDdfcEFAfjIpM7nzlUsJbi9NYuw/viewform?entry.818267307=${userId}`;
63110
userId = uuid();
@@ -66,5 +113,5 @@ export async function activate(context: flashpoint.ExtensionContext) {
66113
}))
67114

68115
}
69-
})
116+
});
70117
}

0 commit comments

Comments
 (0)