def snake_enter_score():
status = 'no response'
# make sure scorehash is correct for the given score
score = int(request.form['score'])
scorehash = int(request.form['scorehash'])
if math.sqrt(scorehash - 1337) == score:
if request.form['SNAKE_BLOCK'] == '1':
# create recording string
recTurn = request.form['recTurn']
recFrame = request.form['recFrame']
recFood = request.form['recFood']
recData = urlencode({ 'recTurn':recTurn, 'recFrame':recFrame, 'recFood':recFood })
# add the new score
playerName = g.user.username#request.form['playerName']#re.sub('[&=#<>]', '', request.form['playerName'])
score = Score(player=playerName, score=score, recording=recData)
db.session.add(score)
db.session.commit()
# reset the high scores. the game requests rec#.txt files 0-9 by
# default, so the recid field must be updated for the high scores
# clear out current high scores
for score in Score.query.all():
score.recid = None
db.session.add(score)
db.session.commit()
# update the recid field to set the new high scores
scores = Score.query.order_by(Score.score.desc()).limit(10).all()
for i in range(0, len(scores)):
scores[i].recid = i
db.session.add(scores[i])
db.session.commit()
status = 'ok'
else:
status = 'snake block not present'
else:
status = 'invalid scorehash'
return urlencode({'status':status})
评论列表
文章目录