fix game
All checks were successful
Dynamic Branch Deploy / build-and-deploy (push) Successful in 7m3s
All checks were successful
Dynamic Branch Deploy / build-and-deploy (push) Successful in 7m3s
This commit is contained in:
@@ -106,6 +106,52 @@ func (lb *Leaderboard) AddScore(name, code string, score int) (bool, string) {
|
||||
return true, proofCode
|
||||
}
|
||||
|
||||
// AdminLeaderboardEntry ist ein LeaderboardEntry mit zusätzlichem Key und Validierungsstatus
|
||||
type AdminLeaderboardEntry struct {
|
||||
game.LeaderboardEntry
|
||||
Key string `json:"key"`
|
||||
Valid bool `json:"valid"`
|
||||
}
|
||||
|
||||
// GetAll gibt alle Leaderboard-Einträge zurück (für Admin-Panel)
|
||||
func (lb *Leaderboard) GetAll() []AdminLeaderboardEntry {
|
||||
raw, err := lb.rdb.HGetAll(lb.ctx, "leaderboard:entries").Result()
|
||||
if err != nil {
|
||||
log.Printf("⚠️ Fehler beim Abrufen aller Einträge: %v", err)
|
||||
return nil
|
||||
}
|
||||
|
||||
entries := make([]AdminLeaderboardEntry, 0, len(raw))
|
||||
for key, dataStr := range raw {
|
||||
var e game.LeaderboardEntry
|
||||
if err := json.Unmarshal([]byte(dataStr), &e); err != nil {
|
||||
continue
|
||||
}
|
||||
expected := GenerateProofCode(e.PlayerCode, e.Score, e.Timestamp)
|
||||
entries = append(entries, AdminLeaderboardEntry{
|
||||
LeaderboardEntry: e,
|
||||
Key: key,
|
||||
Valid: e.ProofCode == expected,
|
||||
})
|
||||
}
|
||||
|
||||
// Absteigend nach Score sortieren
|
||||
for i := 0; i < len(entries); i++ {
|
||||
for j := i + 1; j < len(entries); j++ {
|
||||
if entries[j].Score > entries[i].Score {
|
||||
entries[i], entries[j] = entries[j], entries[i]
|
||||
}
|
||||
}
|
||||
}
|
||||
return entries
|
||||
}
|
||||
|
||||
// DeleteEntry löscht einen Eintrag aus Leaderboard (Hash + Sorted Set)
|
||||
func (lb *Leaderboard) DeleteEntry(key string) error {
|
||||
lb.rdb.ZRem(lb.ctx, leaderboardKey, key)
|
||||
return lb.rdb.HDel(lb.ctx, "leaderboard:entries", key).Err()
|
||||
}
|
||||
|
||||
func (lb *Leaderboard) GetTop10() []game.LeaderboardEntry {
|
||||
// Hole Top 10 (höchste Scores zuerst)
|
||||
uniqueKeys, err := lb.rdb.ZRevRange(lb.ctx, leaderboardKey, 0, 9).Result()
|
||||
|
||||
Reference in New Issue
Block a user