bug fixes
This commit is contained in:
@@ -8,21 +8,20 @@ import (
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func simulateChunk(sessionID string, inputs []Input, totalTicks int, vals map[string]string) (bool, int, []ActiveObstacle) {
|
||||
// --- 1. STATE LADEN ---
|
||||
func simulateChunk(sessionID string, inputs []Input, totalTicks int, vals map[string]string) (bool, int, []ActiveObstacle, PowerUpState, int) {
|
||||
// 1. State laden
|
||||
posY := parseOr(vals["pos_y"], PlayerYBase)
|
||||
velY := parseOr(vals["vel_y"], 0.0)
|
||||
score := int(parseOr(vals["score"], 0))
|
||||
ticksAlive := int(parseOr(vals["total_ticks"], 0)) // Zeit-Basis
|
||||
|
||||
ticksAlive := int(parseOr(vals["total_ticks"], 0))
|
||||
rngStateVal, _ := strconv.ParseInt(vals["rng_state"], 10, 64)
|
||||
|
||||
// Powerups
|
||||
// Powerups laden
|
||||
godLives := int(parseOr(vals["p_god_lives"], 0))
|
||||
hasBat := vals["p_has_bat"] == "1"
|
||||
bootTicks := int(parseOr(vals["p_boot_ticks"], 0))
|
||||
|
||||
// Anti-Cheat State laden (Wichtig für Heuristik über Chunks hinweg)
|
||||
// Anti-Cheat State
|
||||
lastJumpDist := parseOr(vals["ac_last_dist"], 0.0)
|
||||
suspicionScore := int(parseOr(vals["ac_suspicion"], 0))
|
||||
|
||||
@@ -35,11 +34,12 @@ func simulateChunk(sessionID string, inputs []Input, totalTicks int, vals map[st
|
||||
obstacles = []ActiveObstacle{}
|
||||
}
|
||||
|
||||
// DEBUG: Start des Chunks
|
||||
// log.Printf("[%s] Simulating Chunk: %d Ticks, Score: %d", sessionID, totalTicks, score)
|
||||
// --- DEBUG: Chunk Info ---
|
||||
if len(inputs) > 0 {
|
||||
log.Printf("📦 [%s] Processing Chunk: %d Ticks, %d Inputs", sessionID, totalTicks, len(inputs))
|
||||
}
|
||||
|
||||
// --- ANTI-CHEAT 1: SPAM SCHUTZ ---
|
||||
// Wer mehr als 10x pro Sekunde springt, ist ein Bot oder nutzt ein Makro
|
||||
// --- ANTI-CHEAT: Spam Check ---
|
||||
jumpCount := 0
|
||||
for _, inp := range inputs {
|
||||
if inp.Act == "JUMP" {
|
||||
@@ -47,8 +47,8 @@ func simulateChunk(sessionID string, inputs []Input, totalTicks int, vals map[st
|
||||
}
|
||||
}
|
||||
if jumpCount > 10 {
|
||||
log.Printf("🤖BOT-ALARM [%s]: Spammt Sprünge (%d Inputs)", sessionID, jumpCount)
|
||||
return true, score, obstacles // Sofort tot
|
||||
log.Printf("🤖 BOT-ALARM [%s]: Spammt Sprünge (%d)", sessionID, jumpCount)
|
||||
return true, score, obstacles, PowerUpState{}, ticksAlive
|
||||
}
|
||||
|
||||
playerDead := false
|
||||
@@ -57,24 +57,26 @@ func simulateChunk(sessionID string, inputs []Input, totalTicks int, vals map[st
|
||||
for i := 0; i < totalTicks; i++ {
|
||||
ticksAlive++
|
||||
|
||||
// Speed Scaling (Zeitbasiert)
|
||||
// 1. Speed (Zeitbasiert)
|
||||
currentSpeed := BaseSpeed + (float64(ticksAlive)/3000.0)*0.5
|
||||
if currentSpeed > 20.0 {
|
||||
currentSpeed = 20.0
|
||||
if currentSpeed > 12.0 {
|
||||
currentSpeed = 12.0
|
||||
}
|
||||
|
||||
// Jump Power (Boots Powerup)
|
||||
// 2. Powerups Timer
|
||||
currentJumpPower := JumpPower
|
||||
if bootTicks > 0 {
|
||||
currentJumpPower = HighJumpPower
|
||||
bootTicks--
|
||||
}
|
||||
|
||||
// Input
|
||||
// 3. Input Verarbeitung (MIT DEBUG LOG)
|
||||
didJump := false
|
||||
isCrouching := false
|
||||
for _, inp := range inputs {
|
||||
if inp.Tick == i {
|
||||
log.Printf("🕹️ [%s] ACTION at Tick %d: %s", sessionID, ticksAlive, inp.Act)
|
||||
|
||||
if inp.Act == "JUMP" {
|
||||
didJump = true
|
||||
}
|
||||
@@ -84,47 +86,38 @@ func simulateChunk(sessionID string, inputs []Input, totalTicks int, vals map[st
|
||||
}
|
||||
}
|
||||
|
||||
// Physik Status
|
||||
// 4. Physik
|
||||
isGrounded := posY >= PlayerYBase-1.0
|
||||
|
||||
currentHeight := PlayerHeight
|
||||
if isCrouching {
|
||||
currentHeight = PlayerHeight / 2
|
||||
if !isGrounded {
|
||||
velY += 2.0
|
||||
} // Fast fall
|
||||
}
|
||||
}
|
||||
|
||||
// Springen & ANTI-CHEAT 2 (Heuristik)
|
||||
if didJump && isGrounded && !isCrouching {
|
||||
velY = currentJumpPower
|
||||
|
||||
// Wir messen den Abstand zum nächsten Hindernis beim Absprung
|
||||
// Heuristik Anti-Cheat (Abstand messen)
|
||||
var distToObs float64 = -1.0
|
||||
for _, o := range obstacles {
|
||||
if o.X > 50.0 { // Das nächste Hindernis vor uns
|
||||
if o.X > 50.0 {
|
||||
distToObs = o.X - 50.0
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
// Bot Check: Wenn der Abstand IMMER gleich ist (z.B. exakt 75.5px)
|
||||
if distToObs > 0 {
|
||||
diff := math.Abs(distToObs - lastJumpDist)
|
||||
if diff < 1.0 {
|
||||
// Verdächtig perfekt wiederholt
|
||||
suspicionScore++
|
||||
} else {
|
||||
// Menschliche Varianz -> Verdacht senken
|
||||
if suspicionScore > 0 {
|
||||
suspicionScore--
|
||||
}
|
||||
} else if suspicionScore > 0 {
|
||||
suspicionScore--
|
||||
}
|
||||
lastJumpDist = distToObs
|
||||
}
|
||||
}
|
||||
|
||||
// Physik Anwendung
|
||||
velY += Gravity
|
||||
posY += velY
|
||||
if posY > PlayerYBase {
|
||||
@@ -137,7 +130,7 @@ func simulateChunk(sessionID string, inputs []Input, totalTicks int, vals map[st
|
||||
hitboxY = posY + (PlayerHeight - currentHeight)
|
||||
}
|
||||
|
||||
// Hindernisse bewegen & Kollision
|
||||
// 5. Hindernisse & Kollision
|
||||
nextObstacles := []ActiveObstacle{}
|
||||
rightmostX := 0.0
|
||||
|
||||
@@ -148,7 +141,7 @@ func simulateChunk(sessionID string, inputs []Input, totalTicks int, vals map[st
|
||||
continue
|
||||
}
|
||||
|
||||
// Passed Check (Verhindert "Geister-Kollision" von hinten)
|
||||
// Passed Check
|
||||
paddingX := 10.0
|
||||
if obs.X+obs.Width-paddingX < 55.0 {
|
||||
nextObstacles = append(nextObstacles, obs)
|
||||
@@ -186,7 +179,6 @@ func simulateChunk(sessionID string, inputs []Input, totalTicks int, vals map[st
|
||||
}
|
||||
continue
|
||||
} else {
|
||||
// Kollision mit Gegner
|
||||
if hasBat && obs.Type == "teacher" {
|
||||
hasBat = false
|
||||
log.Printf("[%s] ⚾ Bat used on %s", sessionID, obs.ID)
|
||||
@@ -194,10 +186,9 @@ func simulateChunk(sessionID string, inputs []Input, totalTicks int, vals map[st
|
||||
}
|
||||
if godLives > 0 {
|
||||
godLives--
|
||||
log.Printf("[%s] 🛡️ Godmode saved life (%d left)", sessionID, godLives)
|
||||
log.Printf("[%s] 🛡️ Godmode saved life", sessionID)
|
||||
continue
|
||||
}
|
||||
|
||||
log.Printf("💀 DEATH [%s]: Hit %s at Tick %d", sessionID, obs.ID, ticksAlive)
|
||||
playerDead = true
|
||||
}
|
||||
@@ -210,7 +201,7 @@ func simulateChunk(sessionID string, inputs []Input, totalTicks int, vals map[st
|
||||
}
|
||||
obstacles = nextObstacles
|
||||
|
||||
// Spawning
|
||||
// 6. Spawning
|
||||
if rightmostX < GameWidth-10.0 {
|
||||
gap := float64(int(400.0 + rng.NextRange(0, 500)))
|
||||
spawnX := rightmostX + gap
|
||||
@@ -252,7 +243,12 @@ func simulateChunk(sessionID string, inputs []Input, totalTicks int, vals map[st
|
||||
if def != nil {
|
||||
spawnY := GroundY - def.Height - def.YOffset
|
||||
obstacles = append(obstacles, ActiveObstacle{
|
||||
ID: def.ID, Type: def.Type, X: spawnX, Y: spawnY, Width: def.Width, Height: def.Height,
|
||||
ID: def.ID,
|
||||
Type: def.Type,
|
||||
X: spawnX,
|
||||
Y: spawnY,
|
||||
Width: def.Width,
|
||||
Height: def.Height,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -265,13 +261,11 @@ func simulateChunk(sessionID string, inputs []Input, totalTicks int, vals map[st
|
||||
}
|
||||
}
|
||||
|
||||
// --- ANTI-CHEAT CHECK (Ergebnis) ---
|
||||
if suspicionScore > 10 {
|
||||
log.Printf("🤖BOT-ALARM [%s]: Zu perfekte Sprünge (Heuristik Fail)", sessionID)
|
||||
log.Printf("🤖 BOT-ALARM [%s]: Zu perfekte Sprünge (Heuristik)", sessionID)
|
||||
playerDead = true
|
||||
}
|
||||
|
||||
// --- SPEICHERN ---
|
||||
obsJson, _ := json.Marshal(obstacles)
|
||||
batStr := "0"
|
||||
if hasBat {
|
||||
@@ -288,12 +282,18 @@ func simulateChunk(sessionID string, inputs []Input, totalTicks int, vals map[st
|
||||
"p_god_lives": godLives,
|
||||
"p_has_bat": batStr,
|
||||
"p_boot_ticks": bootTicks,
|
||||
// AC Daten speichern für nächsten Chunk
|
||||
"ac_last_dist": fmt.Sprintf("%f", lastJumpDist),
|
||||
"ac_suspicion": suspicionScore,
|
||||
})
|
||||
|
||||
return playerDead, score, obstacles
|
||||
// Return PowerUp State
|
||||
pState := PowerUpState{
|
||||
GodLives: godLives,
|
||||
HasBat: hasBat,
|
||||
BootTicks: bootTicks,
|
||||
}
|
||||
|
||||
return playerDead, score, obstacles, pState, ticksAlive
|
||||
}
|
||||
|
||||
func parseOr(s string, def float64) float64 {
|
||||
|
||||
Reference in New Issue
Block a user