Private
Public Access
Add WebAssembly support for assets and chunks, implement gameover screen rendering, and enhance server gameplay logic with dynamic speeds, team naming, and score components.
This commit is contained in:
1 parent
ce51a2ba4f
commit
95d61bf66e
68 files changed
+913
-424
No files matched your search
@@ -2,7 +2,10 @@ package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
@@ -39,17 +42,31 @@ func InitLeaderboard(redisAddr string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (lb *Leaderboard) AddScore(name, code string, score int) bool {
|
||||
// GenerateProofCode erstellt einen kryptografisch sicheren Proof-Code
|
||||
func GenerateProofCode(playerCode string, score int, timestamp int64) string {
|
||||
// Secret Salt (sollte eigentlich aus Config kommen, aber für Demo hier hardcoded)
|
||||
secret := "EscapeFromTeacher_Secret_2026"
|
||||
data := fmt.Sprintf("%s:%d:%d:%s", playerCode, score, timestamp, secret)
|
||||
hash := sha256.Sum256([]byte(data))
|
||||
// Nehme erste 12 Zeichen des Hex-Hash
|
||||
return hex.EncodeToString(hash[:])[:12]
|
||||
}
|
||||
|
||||
func (lb *Leaderboard) AddScore(name, code string, score int) (bool, string) {
|
||||
// Erstelle eindeutigen Key für diesen Score: PlayerCode + Timestamp
|
||||
timestamp := time.Now().Unix()
|
||||
uniqueKey := code + "_" + time.Now().Format("20060102_150405")
|
||||
|
||||
// Generiere Proof-Code
|
||||
proofCode := GenerateProofCode(code, score, timestamp)
|
||||
|
||||
// Score speichern
|
||||
entry := game.LeaderboardEntry{
|
||||
PlayerName: name,
|
||||
PlayerCode: code,
|
||||
Score: score,
|
||||
Timestamp: timestamp,
|
||||
ProofCode: proofCode,
|
||||
}
|
||||
|
||||
data, _ := json.Marshal(entry)
|
||||
@@ -61,8 +78,8 @@ func (lb *Leaderboard) AddScore(name, code string, score int) bool {
|
||||
Member: uniqueKey,
|
||||
})
|
||||
|
||||
log.Printf("🏆 Leaderboard: %s mit %d Punkten (Entry: %s)", name, score, uniqueKey)
|
||||
return true
|
||||
log.Printf("🏆 Leaderboard: %s mit %d Punkten (Entry: %s, Proof: %s)", name, score, uniqueKey, proofCode)
|
||||
return true, proofCode
|
||||
}
|
||||
|
||||
func (lb *Leaderboard) GetTop10() []game.LeaderboardEntry {
|
||||
|
||||
Reference in new issue
Block a user