abaiao-r / ft_transcendence

Website with a real-time multiplayer Pong contest with Python (Django) backend, JavaScript (Bootstrap Toolkit) frontend, and various modules for enhanced features like tournaments, blockchain integration, AI opponents, and more.
6 stars 2 forks source link

Stats Not Saving Properly #64

Closed IcQuackson closed 5 months ago

IcQuackson commented 5 months ago

Problem: Stats are saved based on the user's display name, which the host can change, leading to incorrect stat recording.

Proposed Solution: Use a new player data structure to handle player information more reliably.

player = {
    displayName: string,  // Display name in game
    username: string,     // Username if host
    isHost: boolean,      // Host flag
    isAi: boolean         // AI flag
};

Implementation: Due to refactoring issues, this structure isn't used throughout the code so I added a new field "PlayerInfo" in the backend data to not mess up other features:

{
    "AI": player1AI,
    "Name": player1.displayName,
    "Avatar": getTournamentPlayerAvatar(player1),
    "Side": 0,
    "Score": 0,
    "Bounces": 0,
    "PlayerInfo": player1  // Player object
}

Request: @pedperei, please update the stat-saving logic in the match-history endpoint to use this new Player object.