demon difficulty ratings
This commit is contained in:
parent
5ab60007da
commit
d10faa1106
|
@ -22,6 +22,12 @@ allow_registration = true
|
|||
# hasn't been set yet. when set to false, all unrated
|
||||
# levels will be NA
|
||||
allow_votes = true
|
||||
# same as above, but for demon difficulties
|
||||
# this will let people vote and influence a demon'S
|
||||
# difficulty past its original demon rating
|
||||
allow_demon_votes = true
|
||||
# the minimum amount of votes before a level's difficulty
|
||||
# will go from NA to the average
|
||||
min_votes = 10
|
||||
# same as above, but for demon ratings
|
||||
min_demon_votes = 10
|
|
@ -26,11 +26,11 @@ CrystalGauntlet.endpoints["/getGJLevelScores211.php"] = ->(body : String): Strin
|
|||
# todo: fix
|
||||
# progress = XorCrypt.encrypt_string(GDBase64.decode_string(params["s6"]), "41274")
|
||||
coins = params["s9"].to_i - 5819
|
||||
if coins > 3
|
||||
if coins > 3 || coins < 0
|
||||
return "-1"
|
||||
end
|
||||
percent = params["percent"].to_i
|
||||
if percent > 100
|
||||
if percent > 100 || percent < 0
|
||||
return "-1"
|
||||
end
|
||||
|
||||
|
|
|
@ -7,9 +7,12 @@ CrystalGauntlet.endpoints["/rateGJStars211.php"] = ->(body : String): String {
|
|||
puts params.inspect
|
||||
|
||||
level_id = params["levelID"].to_i
|
||||
# todo: clamp this
|
||||
stars = params["stars"].to_i
|
||||
|
||||
if stars > 10 || stars < 1
|
||||
return "-1"
|
||||
end
|
||||
|
||||
# todo: implement this for mod accounts
|
||||
|
||||
if DATABASE.scalar("select count(*) from levels where id = ?", level_id).as(Int64) == 0
|
||||
|
@ -20,12 +23,12 @@ CrystalGauntlet.endpoints["/rateGJStars211.php"] = ->(body : String): String {
|
|||
|
||||
if config_get("voting.allow_votes").as(Bool | Nil) == false
|
||||
return "1"
|
||||
else
|
||||
end
|
||||
|
||||
vote_count = DATABASE.scalar("select count(*) from difficulty_votes where level_id = ?", level_id).as(Int64)
|
||||
|
||||
min_votes = config_get("voting.min_votes").as(Int32 | Nil) || 0
|
||||
min_votes = config_get("voting.min_votes").as(Int64 | Nil) || 1
|
||||
|
||||
# todo: make this configurable
|
||||
if vote_count >= min_votes
|
||||
# todo: cache in some form?
|
||||
votes = DATABASE.query_all("select stars from difficulty_votes where level_id = ?", level_id, as: {Int32})
|
||||
|
@ -36,8 +39,48 @@ CrystalGauntlet.endpoints["/rateGJStars211.php"] = ->(body : String): String {
|
|||
DATABASE.exec("update levels set community_difficulty = ? where id = ?", difficulty.value, level_id)
|
||||
end
|
||||
end
|
||||
|
||||
return "1"
|
||||
}
|
||||
|
||||
CrystalGauntlet.endpoints["/rateGJDemon21.php"] = ->(body : String): String {
|
||||
params = URI::Params.parse(body)
|
||||
puts params.inspect
|
||||
|
||||
level_id = params["levelID"].to_i
|
||||
rating = params["rating"].to_i
|
||||
|
||||
if rating < 1 || rating > 5
|
||||
return "-1"
|
||||
end
|
||||
rating -= 1
|
||||
|
||||
# todo: implement this for mod accounts
|
||||
|
||||
if DATABASE.scalar("select count(*) from levels where id = ?", level_id).as(Int64) == 0
|
||||
return "-1"
|
||||
end
|
||||
|
||||
# todo: remove (here for debugging)
|
||||
return "-1"
|
||||
DATABASE.exec("insert into demon_difficulty_votes (level_id, demon_difficulty) values (?, ?)", level_id, rating)
|
||||
|
||||
if config_get("voting.allow_demon_votes").as(Bool | Nil) == false
|
||||
return "1"
|
||||
end
|
||||
|
||||
vote_count = DATABASE.scalar("select count(*) from demon_difficulty_votes where level_id = ?", level_id).as(Int64)
|
||||
|
||||
min_votes = config_get("voting.min_demon_votes").as(Int64 | Nil) || 1
|
||||
|
||||
if vote_count >= min_votes
|
||||
# todo: cache in some form?
|
||||
votes = DATABASE.query_all("select demon_difficulty from demon_difficulty_votes where level_id = ?", level_id, as: {Int32})
|
||||
avg = votes.sum() / votes.size
|
||||
demon_difficulty = DemonDifficulty.new(Int32.new(avg.round()))
|
||||
|
||||
if demon_difficulty
|
||||
DATABASE.exec("update levels set demon_difficulty = ? where id = ?", demon_difficulty.value, level_id)
|
||||
end
|
||||
end
|
||||
|
||||
return "1"
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue