Private
Public Access
1
0

add pics
All checks were successful
Dynamic Branch Deploy / build-and-deploy (push) Successful in 1m11s

This commit is contained in:
Sebastian Unterschütz
2025-11-25 19:28:08 +01:00
parent 553f4c2944
commit 36a4847381
10 changed files with 248 additions and 140 deletions

View File

@@ -3,23 +3,18 @@ package main
import (
"encoding/json"
"fmt"
"log"
"math"
"strconv"
)
// Führt die Physik-Simulation durch und prüft auf Cheats
func simulateChunk(sessionID string, inputs []Input, totalTicks int, vals map[string]string) (bool, int, []ActiveObstacle) {
// State parsen
posY := parseOr(vals["pos_y"], PlayerYBase)
velY := parseOr(vals["vel_y"], 0.0)
score := int(parseOr(vals["score"], 0))
rngStateVal, _ := strconv.ParseInt(vals["rng_state"], 10, 64)
// Anti-Cheat State laden
lastJumpDist := parseOr(vals["ac_last_dist"], 0.0)
suspicionScore := int(parseOr(vals["ac_suspicion"], 0))
godLives := int(parseOr(vals["p_god_lives"], 0))
hasBat := vals["p_has_bat"] == "1"
bootTicks := int(parseOr(vals["p_boot_ticks"], 0))
rng := NewRNG(rngStateVal)
@@ -30,24 +25,20 @@ func simulateChunk(sessionID string, inputs []Input, totalTicks int, vals map[st
obstacles = []ActiveObstacle{}
}
// --- ANTI-CHEAT STUFE 2: SPAM SCHUTZ ---
jumpCount := 0
for _, inp := range inputs {
if inp.Act == "JUMP" {
jumpCount++
}
}
if jumpCount > 8 { // Wer mehr als 8x pro Sekunde springt, ist ein Bot
log.Printf("🤖 BOT ALARM (Spam): %s sprang %d mal!", sessionID, jumpCount)
return true, score, obstacles // Player Dead
}
playerDead := false
// --- SIMULATION LOOP ---
for i := 0; i < totalTicks; i++ {
currentSpeed := BaseSpeed + (float64(score)/500.0)*0.5
if currentSpeed > 12.0 {
currentSpeed = 12.0
}
currentJumpPower := JumpPower
if bootTicks > 0 {
currentJumpPower = HighJumpPower
bootTicks--
}
// A. INPUT
didJump := false
isCrouching := false
for _, inp := range inputs {
@@ -61,39 +52,7 @@ func simulateChunk(sessionID string, inputs []Input, totalTicks int, vals map[st
}
}
// Physik Check
isGrounded := posY >= PlayerYBase-1.0
if didJump && isGrounded && !isCrouching {
velY = JumpPower
// --- ANTI-CHEAT STUFE 3: HEURISTIK (Perfektes Springen) ---
// Wir messen den Abstand zum nächsten Hindernis beim Absprung
nextObsDist := -1.0
for _, o := range obstacles {
if o.X > 50.0 { // Erstes Hindernis vor uns
nextObsDist = o.X - 50.0
break
}
}
if nextObsDist > 0 {
// Bot-Check: Springt er immer exakt bei "75.5" Pixel Abstand?
diff := math.Abs(nextObsDist - lastJumpDist)
if diff < 1.0 {
// Abstand ist fast identisch zum letzten Sprung -> Verdächtig
suspicionScore++
} else {
// Menschliche Varianz -> Reset (oder verringern)
if suspicionScore > 0 {
suspicionScore--
}
}
lastJumpDist = nextObsDist
}
}
// ... (Restliche Physik wie gehabt) ...
currentHeight := PlayerHeight
if isCrouching {
currentHeight = PlayerHeight / 2
@@ -102,9 +61,12 @@ func simulateChunk(sessionID string, inputs []Input, totalTicks int, vals map[st
}
}
if didJump && isGrounded && !isCrouching {
velY = currentJumpPower
}
velY += Gravity
posY += velY
if posY > PlayerYBase {
posY = PlayerYBase
velY = 0
@@ -115,62 +77,92 @@ func simulateChunk(sessionID string, inputs []Input, totalTicks int, vals map[st
hitboxY = posY + (PlayerHeight - currentHeight)
}
// B. OBSTACLES
nextObstacles := []ActiveObstacle{}
rightmostX := 0.0
for _, obs := range obstacles {
obs.X -= GameSpeed
obs.X -= currentSpeed
if obs.X+obs.Width < 50.0 {
if obs.X+obs.Width < -50.0 {
continue
}
// Hitbox
paddingX := 5.0
paddingY_Top := 5.0
paddingY_Bottom := 5.0
pLeft, pRight := 50.0+paddingX, 50.0+30.0-paddingX
pTop, pBottom := hitboxY+paddingY_Top, hitboxY+currentHeight-paddingY_Bottom
oLeft, oRight := obs.X+paddingX, obs.X+obs.Width-paddingX
oTop, oBottom := obs.Y+paddingY_Top, obs.Y+obs.Height-paddingY_Bottom
if pRight > oLeft && pLeft < oRight && pBottom > oTop && pTop < oBottom {
playerDead = true
paddingX := 10.0
paddingY_Top := 10.0
if obs.Type == "teacher" {
paddingY_Top = 25.0
}
if obs.X+obs.Width > -100 {
nextObstacles = append(nextObstacles, obs)
if obs.X+obs.Width > rightmostX {
rightmostX = obs.X + obs.Width
pLeft, pRight := 50.0+paddingX, 50.0+30.0-paddingX
pTop, pBottom := hitboxY+paddingY_Top, hitboxY+currentHeight-5.0
oLeft, oRight := obs.X+paddingX, obs.X+obs.Width-paddingX
oTop, oBottom := obs.Y+paddingY_Top, obs.Y+obs.Height-5.0
isCollision := pRight > oLeft && pLeft < oRight && pBottom > oTop && pTop < oBottom
if isCollision {
if obs.Type == "coin" {
score += 2000
continue
} else if obs.Type == "powerup" {
if obs.ID == "p_god" {
godLives = 3
}
if obs.ID == "p_bat" {
hasBat = true
}
if obs.ID == "p_boot" {
bootTicks = 600
}
continue
} else {
if hasBat && obs.Type == "teacher" {
hasBat = false
continue
}
if godLives > 0 {
godLives--
continue
}
playerDead = true
}
}
nextObstacles = append(nextObstacles, obs)
if obs.X+obs.Width > rightmostX {
rightmostX = obs.X + obs.Width
}
}
obstacles = nextObstacles
// C. SPAWNING
if rightmostX < GameWidth-10.0 {
rawGap := 400.0 + rng.NextRange(0, 500)
gap := float64(int(rawGap))
gap := float64(int(400.0 + rng.NextRange(0, 500)))
spawnX := rightmostX + gap
if spawnX < GameWidth {
spawnX = GameWidth
}
isBossPhase := (score % 1500) > 1200
var possibleDefs []ObstacleDef
for _, d := range defaultConfig.Obstacles {
if d.ID == "eraser" {
if score >= 500 {
if isBossPhase {
if d.ID == "principal" || d.ID == "trashcan" {
possibleDefs = append(possibleDefs, d)
}
} else {
if d.ID == "principal" {
continue
}
if d.ID == "eraser" && score < 500 {
continue
}
possibleDefs = append(possibleDefs, d)
}
}
def := rng.PickDef(possibleDefs)
if def != nil && def.CanTalk {
if rng.NextFloat() > 0.7 {
rng.NextFloat()
@@ -178,14 +170,21 @@ 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,
X: spawnX,
Y: spawnY,
Width: def.Width,
Height: def.Height,
})
if def.Type == "powerup" && rng.NextFloat() > 0.1 {
def = nil
}
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,
})
}
}
}
@@ -196,23 +195,21 @@ func simulateChunk(sessionID string, inputs []Input, totalTicks int, vals map[st
}
}
// Ban Hammer für Bots
if suspicionScore > 8 {
log.Printf("🤖 BOT ALARM (Heuristik): %s springt zu perfekt!", sessionID)
playerDead = true
obsJson, _ := json.Marshal(obstacles)
batStr := "0"
if hasBat {
batStr = "1"
}
// State speichern
obsJson, _ := json.Marshal(obstacles)
rdb.HSet(ctx, "session:"+sessionID, map[string]interface{}{
"score": score,
"pos_y": fmt.Sprintf("%f", posY),
"vel_y": fmt.Sprintf("%f", velY),
"rng_state": rng.State,
"obstacles": string(obsJson),
// Anti-Cheat Daten mitspeichern
"ac_last_dist": fmt.Sprintf("%f", lastJumpDist),
"ac_suspicion": suspicionScore,
"score": score,
"pos_y": fmt.Sprintf("%f", posY),
"vel_y": fmt.Sprintf("%f", velY),
"rng_state": rng.State,
"obstacles": string(obsJson),
"p_god_lives": godLives,
"p_has_bat": batStr,
"p_boot_ticks": bootTicks,
})
return playerDead, score, obstacles