From d99741d10d3690909d6547fd5ca357b618e0197b Mon Sep 17 00:00:00 2001 From: "Jill \"oatmealine\" Monoids" Date: Thu, 5 Jan 2023 16:43:45 +0300 Subject: [PATCH] gauntlets --- db/migrations/14_gauntlets.sql | 14 ++++++++++++++ src/endpoints/levels/getLevels.cr | 6 ++++-- src/endpoints/packs/getGauntlets.cr | 24 ++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 db/migrations/14_gauntlets.sql create mode 100644 src/endpoints/packs/getGauntlets.cr diff --git a/db/migrations/14_gauntlets.sql b/db/migrations/14_gauntlets.sql new file mode 100644 index 0000000..2ac101b --- /dev/null +++ b/db/migrations/14_gauntlets.sql @@ -0,0 +1,14 @@ +-- +migrate up +CREATE TABLE gauntlets ( + id SERIAL PRIMARY KEY +); + +CREATE TABLE gauntlet_links ( + idx INTEGER NOT NULL DEFAULT 0, -- solely for ordering purposes + gauntlet_id INTEGER NOT NULL REFERENCES gauntlets(id), + level_id INTEGER NOT NULL REFERENCES levels(id) +); + +-- +migrate down +DROP TABLE gauntlets; +DROP TABLE gauntlet_links; \ No newline at end of file diff --git a/src/endpoints/levels/getLevels.cr b/src/endpoints/levels/getLevels.cr index 89b7c3c..1f25918 100644 --- a/src/endpoints/levels/getLevels.cr +++ b/src/endpoints/levels/getLevels.cr @@ -75,7 +75,9 @@ CrystalGauntlet.endpoints["/getGJLevels21.php"] = ->(context : HTTP::Server::Con queryParams << "levels.stars is null" end if params["gauntlet"]? - # todo + order = "gauntlet_links.idx asc" + joins << "left join gauntlet_links on gauntlet_links.level_id = levels.id" + queryParams << "gauntlet_id = #{params["gauntlet"].to_i}" end if params["len"]? # todo @@ -108,7 +110,7 @@ CrystalGauntlet.endpoints["/getGJLevels21.php"] = ->(context : HTTP::Server::Con end # level search type - case params["type"] + case params["type"]? when "0", "15", nil # default sort (gdw is 15) order = "likes desc" when "1" # most downloaded diff --git a/src/endpoints/packs/getGauntlets.cr b/src/endpoints/packs/getGauntlets.cr new file mode 100644 index 0000000..036c7cf --- /dev/null +++ b/src/endpoints/packs/getGauntlets.cr @@ -0,0 +1,24 @@ +require "uri" + +include CrystalGauntlet + +mappacks_per_page = 10 + +CrystalGauntlet.endpoints["/getGJGauntlets21.php"] = ->(context : HTTP::Server::Context): String { + params = URI::Params.parse(context.request.body.not_nil!.gets_to_end) + LOG.debug { params.inspect } + + gauntlets = [] of String + checksum_str = [] of String + + DATABASE.query_all("select id from gauntlets", as: {Int32}).each() do |id| + levels = DATABASE.query_all("select level_id from gauntlet_links where gauntlet_id = ? order by idx", id, as: {Int32}).join(",") + gauntlets << Format.fmt_hash({ + 1 => id, + 3 => levels + }) + checksum_str << (id.to_s + levels) + end + + return gauntlets.join("|") + "#" + Hashes.gen_solo_2(checksum_str.join("")) +}