store user's persistent id in bigquery

This commit is contained in:
evanpelle
2024-12-17 14:30:16 -08:00
parent 722165c401
commit 1417808c14
10 changed files with 126 additions and 92 deletions
+7 -2
View File
@@ -22,6 +22,8 @@ export async function archive(gameRecord: GameRecord) {
players: gameRecord.players.map(p => ({
username: p.username,
ip: p.ip,
persistentID: p.persistentID,
clientID: p.clientID,
})),
};
@@ -32,8 +34,11 @@ export async function archive(gameRecord: GameRecord) {
console.log(`wrote game metadata to BigQuery: ${gameRecord.id}`);
if (gameRecord.turns.length > 0) {
// Players will see this so make sure to clear PII.
gameRecord.players.forEach(p => p.ip = "REDACTED")
// Players may see this so make sure to clear PII.
gameRecord.players.forEach(p => {
p.ip = "REDACTED"
p.persistentID = "REDACTED"
})
console.log(`writing game ${gameRecord.id} to gcs`)
const bucket = storage.bucket("openfront-games");
const file = bucket.file(gameRecord.id);
+1
View File
@@ -10,6 +10,7 @@ export class Client {
public readonly clientID: ClientID,
public readonly persistentID: string,
public readonly ip: string | null,
public readonly username: string,
public readonly ws: WebSocket,
) { }
}
+12 -2
View File
@@ -166,9 +166,19 @@ export class GameServer {
const playerRecords: PlayerRecord[] = Array.from(this.allClients.values()).map(client => ({
ip: client.ip,
clientID: client.clientID,
username: client.username,
persistentID: client.persistentID,
}));
const record = CreateGameRecord(this.id, this.gameConfig, playerRecords, this.turns, this._startTime, Date.now())
archive(record)
archive(
CreateGameRecord(
this.id,
this.gameConfig,
playerRecords,
this.turns,
this._startTime,
Date.now()
)
)
} else {
console.log(`${this.id}: no clients joined, not archiving game`)
}
+1
View File
@@ -115,6 +115,7 @@ wss.on('connection', (ws, req) => {
clientMsg.clientID,
clientMsg.persistentID,
ip,
clientMsg.username,
ws
),
clientMsg.gameID,