mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-13 02:26:07 +00:00
store client ips in bigquery table
This commit is contained in:
@@ -16,8 +16,6 @@ import { JoinPrivateLobbyModal } from "./JoinPrivateLobbyModal";
|
||||
class Client {
|
||||
private gameStop: () => void
|
||||
|
||||
private ip: Promise<string | null> = null
|
||||
|
||||
private usernameInput: UsernameInput | null = null;
|
||||
|
||||
private joinModal: JoinPrivateLobbyModal
|
||||
@@ -37,7 +35,6 @@ class Client {
|
||||
});
|
||||
|
||||
setFavicon()
|
||||
this.ip = getClientIP()
|
||||
document.addEventListener('join-lobby', this.handleJoinLobby.bind(this));
|
||||
document.addEventListener('leave-lobby', this.handleLeaveLobby.bind(this));
|
||||
document.addEventListener('single-player', this.handleSinglePlayer.bind(this));
|
||||
@@ -65,8 +62,6 @@ class Client {
|
||||
private async handleJoinLobby(event: CustomEvent) {
|
||||
const lobby = event.detail.lobby
|
||||
console.log(`joining lobby ${lobby.id}`)
|
||||
const clientIP = await this.ip
|
||||
console.log(`got ip ${clientIP}`)
|
||||
if (this.gameStop != null) {
|
||||
console.log('joining lobby, stopping existing game')
|
||||
this.gameStop()
|
||||
@@ -76,7 +71,6 @@ class Client {
|
||||
gameType: event.detail.gameType,
|
||||
playerName: (): string => this.usernameInput.getCurrentUsername(),
|
||||
gameID: lobby.id,
|
||||
ip: clientIP,
|
||||
map: event.detail.map,
|
||||
difficulty: event.detail.difficulty,
|
||||
},
|
||||
@@ -98,37 +92,6 @@ class Client {
|
||||
}
|
||||
}
|
||||
|
||||
async function getClientIP(timeoutMs: number = 1000): Promise<string | null> {
|
||||
const controller = new AbortController();
|
||||
const timeoutId = setTimeout(() => controller.abort(), timeoutMs);
|
||||
|
||||
try {
|
||||
const response: Response = await fetch('https://api.ipify.org?format=json', {
|
||||
signal: controller.signal
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
|
||||
const data: { ip: string } = await response.json();
|
||||
return data.ip;
|
||||
} catch (error) {
|
||||
if (error instanceof Error) {
|
||||
if (error.name === 'AbortError') {
|
||||
console.error('Request timed out');
|
||||
} else {
|
||||
console.error('Error fetching IP:', error.message);
|
||||
}
|
||||
} else {
|
||||
console.error('An unknown error occurred');
|
||||
}
|
||||
return null;
|
||||
} finally {
|
||||
clearTimeout(timeoutId);
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize the client when the DOM is loaded
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
new Client().initialize();
|
||||
|
||||
Reference in New Issue
Block a user