diff --git a/src/crystal-gauntlet.cr b/src/crystal-gauntlet.cr index 376cce0..58fd587 100644 --- a/src/crystal-gauntlet.cr +++ b/src/crystal-gauntlet.cr @@ -41,7 +41,7 @@ module CrystalGauntlet DATABASE = DB.open(ENV["DATABASE_URL"]) - @@endpoints = Hash(String, (String -> String)).new + @@endpoints = Hash(String, (HTTP::Server::Context -> String)).new def self.endpoints @@endpoints @@ -89,7 +89,7 @@ module CrystalGauntlet class GDHandler include HTTP::Handler - def call(context) + def call(context : HTTP::Server::Context) # expunge trailing slashes path = context.request.path.chomp("/") @@ -100,9 +100,9 @@ module CrystalGauntlet if CrystalGauntlet.endpoints.has_key?(path) && context.request.method == "POST" && body func = CrystalGauntlet.endpoints[path] begin - value = func.call(body.gets_to_end) + value = func.call(context) rescue err - LOG.error { "error while handling #{path}:" } + LOG.error { "error while handling #{path.colorize(:white)}:" } LOG.error { err.to_s } is_relevant = true err.backtrace.each do |str| diff --git a/src/endpoints/accounts/loginAccount.cr b/src/endpoints/accounts/loginAccount.cr index c2a3254..ab7fe02 100644 --- a/src/endpoints/accounts/loginAccount.cr +++ b/src/endpoints/accounts/loginAccount.cr @@ -4,8 +4,8 @@ require "crypto/bcrypt/password" include CrystalGauntlet -CrystalGauntlet.endpoints["/accounts/loginGJAccount.php"] = ->(body : String): String { - params = URI::Params.parse(body) +CrystalGauntlet.endpoints["/accounts/loginGJAccount.php"] = ->(context : HTTP::Server::Context): String { + params = URI::Params.parse(context.request.body.not_nil!.gets_to_end) LOG.debug { params.inspect } username = params["userName"] diff --git a/src/endpoints/accounts/registerAccount.cr b/src/endpoints/accounts/registerAccount.cr index c9d420d..2a707c5 100644 --- a/src/endpoints/accounts/registerAccount.cr +++ b/src/endpoints/accounts/registerAccount.cr @@ -4,8 +4,8 @@ require "crypto/bcrypt/password" include CrystalGauntlet -CrystalGauntlet.endpoints["/accounts/registerGJAccount.php"] = ->(body : String): String { - params = URI::Params.parse(body) +CrystalGauntlet.endpoints["/accounts/registerGJAccount.php"] = ->(context : HTTP::Server::Context): String { + params = URI::Params.parse(context.request.body.not_nil!.gets_to_end) LOG.debug { params.inspect } if config_get("accounts.allow_registration").as(Bool | Nil) == false diff --git a/src/endpoints/accounts/updateAccountSettings.cr b/src/endpoints/accounts/updateAccountSettings.cr index 626b3a7..3321964 100644 --- a/src/endpoints/accounts/updateAccountSettings.cr +++ b/src/endpoints/accounts/updateAccountSettings.cr @@ -2,8 +2,8 @@ require "uri" include CrystalGauntlet -CrystalGauntlet.endpoints["/updateGJUserScore22.php"] = ->(body : String): String { - params = URI::Params.parse(body) +CrystalGauntlet.endpoints["/updateGJUserScore22.php"] = ->(context : HTTP::Server::Context): String { + params = URI::Params.parse(context.request.body.not_nil!.gets_to_end) LOG.debug { params.inspect } user_id, account_id = Accounts.auth(params) diff --git a/src/endpoints/levels/addLevelComment.cr b/src/endpoints/levels/addLevelComment.cr index cea1763..15bff2c 100644 --- a/src/endpoints/levels/addLevelComment.cr +++ b/src/endpoints/levels/addLevelComment.cr @@ -2,8 +2,8 @@ require "uri" include CrystalGauntlet -CrystalGauntlet.endpoints["/uploadGJComment21.php"] = ->(body : String): String { - params = URI::Params.parse(body) +CrystalGauntlet.endpoints["/uploadGJComment21.php"] = ->(context : HTTP::Server::Context): String { + params = URI::Params.parse(context.request.body.not_nil!.gets_to_end) LOG.debug { params.inspect } user_id, account_id = Accounts.auth(params) diff --git a/src/endpoints/levels/deleteLevel.cr b/src/endpoints/levels/deleteLevel.cr index 9860575..d1abd84 100644 --- a/src/endpoints/levels/deleteLevel.cr +++ b/src/endpoints/levels/deleteLevel.cr @@ -2,8 +2,8 @@ require "uri" include CrystalGauntlet -CrystalGauntlet.endpoints["/deleteGJLevelUser20.php"] = ->(body : String): String { - params = URI::Params.parse(body) +CrystalGauntlet.endpoints["/deleteGJLevelUser20.php"] = ->(context : HTTP::Server::Context): String { + params = URI::Params.parse(context.request.body.not_nil!.gets_to_end) user_id, account_id = Accounts.auth(params) if !(user_id && account_id) diff --git a/src/endpoints/levels/downloadLevel.cr b/src/endpoints/levels/downloadLevel.cr index 06d569d..c28049f 100644 --- a/src/endpoints/levels/downloadLevel.cr +++ b/src/endpoints/levels/downloadLevel.cr @@ -3,8 +3,8 @@ require "base64" include CrystalGauntlet -CrystalGauntlet.endpoints["/downloadGJLevel22.php"] = ->(body : String): String { - params = URI::Params.parse(body) +CrystalGauntlet.endpoints["/downloadGJLevel22.php"] = ->(context : HTTP::Server::Context): String { + params = URI::Params.parse(context.request.body.not_nil!.gets_to_end) LOG.debug { params.inspect } response = [] of String diff --git a/src/endpoints/levels/getLevelComments.cr b/src/endpoints/levels/getLevelComments.cr index d91ee38..561be24 100644 --- a/src/endpoints/levels/getLevelComments.cr +++ b/src/endpoints/levels/getLevelComments.cr @@ -4,8 +4,8 @@ include CrystalGauntlet comments_per_page = 10 -CrystalGauntlet.endpoints["/getGJComments21.php"] = ->(body : String): String { - params = URI::Params.parse(body) +CrystalGauntlet.endpoints["/getGJComments21.php"] = ->(context : HTTP::Server::Context): String { + params = URI::Params.parse(context.request.body.not_nil!.gets_to_end) LOG.debug { params.inspect } level_id = params["levelID"].to_i diff --git a/src/endpoints/levels/getLevels.cr b/src/endpoints/levels/getLevels.cr index d8b498f..9f31bba 100644 --- a/src/endpoints/levels/getLevels.cr +++ b/src/endpoints/levels/getLevels.cr @@ -6,8 +6,8 @@ include CrystalGauntlet # things might break if you modify this levels_per_page = 10 -CrystalGauntlet.endpoints["/getGJLevels21.php"] = ->(body : String): String { - params = URI::Params.parse(body) +CrystalGauntlet.endpoints["/getGJLevels21.php"] = ->(context : HTTP::Server::Context): String { + params = URI::Params.parse(context.request.body.not_nil!.gets_to_end) LOG.debug { params.inspect } can_see_unlisted = false diff --git a/src/endpoints/levels/levelScores.cr b/src/endpoints/levels/levelScores.cr index ec5b2b8..2288434 100644 --- a/src/endpoints/levels/levelScores.cr +++ b/src/endpoints/levels/levelScores.cr @@ -2,8 +2,8 @@ require "uri" include CrystalGauntlet -CrystalGauntlet.endpoints["/getGJLevelScores211.php"] = ->(body : String): String { - params = URI::Params.parse(body) +CrystalGauntlet.endpoints["/getGJLevelScores211.php"] = ->(context : HTTP::Server::Context): String { + params = URI::Params.parse(context.request.body.not_nil!.gets_to_end) LOG.debug { params.inspect } user_id, account_id = Accounts.auth(params) diff --git a/src/endpoints/levels/rateLevel.cr b/src/endpoints/levels/rateLevel.cr index d27ee16..19bc139 100644 --- a/src/endpoints/levels/rateLevel.cr +++ b/src/endpoints/levels/rateLevel.cr @@ -2,8 +2,8 @@ require "uri" include CrystalGauntlet -CrystalGauntlet.endpoints["/rateGJStars211.php"] = ->(body : String): String { - params = URI::Params.parse(body) +CrystalGauntlet.endpoints["/rateGJStars211.php"] = ->(context : HTTP::Server::Context): String { + params = URI::Params.parse(context.request.body.not_nil!.gets_to_end) LOG.debug { params.inspect } level_id = params["levelID"].to_i @@ -43,8 +43,8 @@ CrystalGauntlet.endpoints["/rateGJStars211.php"] = ->(body : String): String { return "1" } -CrystalGauntlet.endpoints["/rateGJDemon21.php"] = ->(body : String): String { - params = URI::Params.parse(body) +CrystalGauntlet.endpoints["/rateGJDemon21.php"] = ->(context : HTTP::Server::Context): String { + params = URI::Params.parse(context.request.body.not_nil!.gets_to_end) LOG.debug { params.inspect } level_id = params["levelID"].to_i diff --git a/src/endpoints/levels/uploadLevel.cr b/src/endpoints/levels/uploadLevel.cr index 5a95597..8a3be4a 100644 --- a/src/endpoints/levels/uploadLevel.cr +++ b/src/endpoints/levels/uploadLevel.cr @@ -2,8 +2,8 @@ require "uri" include CrystalGauntlet -CrystalGauntlet.endpoints["/uploadGJLevel21.php"] = ->(body : String): String { - params = URI::Params.parse(body) +CrystalGauntlet.endpoints["/uploadGJLevel21.php"] = ->(context : HTTP::Server::Context): String { + params = URI::Params.parse(context.request.body.not_nil!.gets_to_end) LOG.debug { params.inspect } # todo: green user fixes? pretty please? diff --git a/src/endpoints/misc/likeItem.cr b/src/endpoints/misc/likeItem.cr index ad87a4e..9dce5af 100644 --- a/src/endpoints/misc/likeItem.cr +++ b/src/endpoints/misc/likeItem.cr @@ -4,8 +4,8 @@ require "crypto/bcrypt/password" include CrystalGauntlet -CrystalGauntlet.endpoints["/likeGJItem211.php"] = ->(body : String): String { - params = URI::Params.parse(body) +CrystalGauntlet.endpoints["/likeGJItem211.php"] = ->(context : HTTP::Server::Context): String { + params = URI::Params.parse(context.request.body.not_nil!.gets_to_end) LOG.debug { params.inspect } if !params.has_key?("itemID") diff --git a/src/endpoints/packs/getMapPacks.cr b/src/endpoints/packs/getMapPacks.cr index a0ea994..0dbf0ac 100644 --- a/src/endpoints/packs/getMapPacks.cr +++ b/src/endpoints/packs/getMapPacks.cr @@ -6,8 +6,8 @@ include CrystalGauntlet mappacks_per_page = 10 -CrystalGauntlet.endpoints["/getGJMapPacks21.php"] = ->(body : String): String { - params = URI::Params.parse(body) +CrystalGauntlet.endpoints["/getGJMapPacks21.php"] = ->(context : HTTP::Server::Context): String { + params = URI::Params.parse(context.request.body.not_nil!.gets_to_end) LOG.debug { params.inspect } page = params["page"].to_i32 diff --git a/src/endpoints/songs/getSongInfo.cr b/src/endpoints/songs/getSongInfo.cr index 2d93712..0b3441b 100644 --- a/src/endpoints/songs/getSongInfo.cr +++ b/src/endpoints/songs/getSongInfo.cr @@ -4,8 +4,8 @@ require "digest/sha256" include CrystalGauntlet -CrystalGauntlet.endpoints["/getGJSongInfo.php"] = ->(body : String): String { - params = URI::Params.parse(body) +CrystalGauntlet.endpoints["/getGJSongInfo.php"] = ->(context : HTTP::Server::Context): String { + params = URI::Params.parse(context.request.body.not_nil!.gets_to_end) LOG.debug { params.inspect } song_id = params["songID"].to_i32 diff --git a/src/endpoints/users/addProfileComment.cr b/src/endpoints/users/addProfileComment.cr index 9f8e212..36d4406 100644 --- a/src/endpoints/users/addProfileComment.cr +++ b/src/endpoints/users/addProfileComment.cr @@ -2,8 +2,8 @@ require "uri" include CrystalGauntlet -CrystalGauntlet.endpoints["/uploadGJAccComment20.php"] = ->(body : String): String { - params = URI::Params.parse(body) +CrystalGauntlet.endpoints["/uploadGJAccComment20.php"] = ->(context : HTTP::Server::Context): String { + params = URI::Params.parse(context.request.body.not_nil!.gets_to_end) LOG.debug { params.inspect } user_id, account_id = Accounts.auth(params) diff --git a/src/endpoints/users/deleteProfileComment.cr b/src/endpoints/users/deleteProfileComment.cr index e904735..c6f9441 100644 --- a/src/endpoints/users/deleteProfileComment.cr +++ b/src/endpoints/users/deleteProfileComment.cr @@ -2,8 +2,8 @@ require "uri" include CrystalGauntlet -CrystalGauntlet.endpoints["/deleteGJAccComment20.php"] = ->(body : String): String { - params = URI::Params.parse(body) +CrystalGauntlet.endpoints["/deleteGJAccComment20.php"] = ->(context : HTTP::Server::Context): String { + params = URI::Params.parse(context.request.body.not_nil!.gets_to_end) LOG.debug { params.inspect } user_id, account_id = Accounts.auth(params) diff --git a/src/endpoints/users/getProfileComments.cr b/src/endpoints/users/getProfileComments.cr index 4d6fbfb..e329699 100644 --- a/src/endpoints/users/getProfileComments.cr +++ b/src/endpoints/users/getProfileComments.cr @@ -4,8 +4,8 @@ include CrystalGauntlet comments_per_page = 10 -CrystalGauntlet.endpoints["/getGJAccountComments20.php"] = ->(body : String): String { - params = URI::Params.parse(body) +CrystalGauntlet.endpoints["/getGJAccountComments20.php"] = ->(context : HTTP::Server::Context): String { + params = URI::Params.parse(context.request.body.not_nil!.gets_to_end) LOG.debug { params.inspect } account_id = params["accountID"].to_i diff --git a/src/endpoints/users/getUser.cr b/src/endpoints/users/getUser.cr index 502ee2a..c25c08d 100644 --- a/src/endpoints/users/getUser.cr +++ b/src/endpoints/users/getUser.cr @@ -2,8 +2,8 @@ require "uri" include CrystalGauntlet -CrystalGauntlet.endpoints["/getGJUserInfo20.php"] = ->(body : String): String { - params = URI::Params.parse(body) +CrystalGauntlet.endpoints["/getGJUserInfo20.php"] = ->(context : HTTP::Server::Context): String { + params = URI::Params.parse(context.request.body.not_nil!.gets_to_end) LOG.debug { params.inspect } DATABASE.query("select accounts.id, accounts.username, is_admin, messages_enabled, friend_requests_enabled, comments_enabled, youtube_url, twitter_url, twitch_url, accounts.created_at, users.id, stars, demons, coins, user_coins, diamonds, orbs, creator_points, icon_type, color1, color2, glow, cube, ship, ball, ufo, wave, robot, spider, explosion from accounts join users on accounts.id = users.account_id where accounts.id = ?", params["targetAccountID"]) do |rs| diff --git a/src/endpoints/users/getUsers.cr b/src/endpoints/users/getUsers.cr index c11da7e..c7a161a 100644 --- a/src/endpoints/users/getUsers.cr +++ b/src/endpoints/users/getUsers.cr @@ -4,8 +4,8 @@ require "crypto/bcrypt/password" include CrystalGauntlet -CrystalGauntlet.endpoints["/getGJUsers20.php"] = ->(body : String): String { - params = URI::Params.parse(body) +CrystalGauntlet.endpoints["/getGJUsers20.php"] = ->(context : HTTP::Server::Context): String { + params = URI::Params.parse(context.request.body.not_nil!.gets_to_end) LOG.debug { params.inspect } page = params["page"].to_i diff --git a/src/endpoints/users/updateUser.cr b/src/endpoints/users/updateUser.cr index c5d3f69..134fbf1 100644 --- a/src/endpoints/users/updateUser.cr +++ b/src/endpoints/users/updateUser.cr @@ -2,8 +2,8 @@ require "uri" include CrystalGauntlet -CrystalGauntlet.endpoints["/updateGJUserScore22.php"] = ->(body : String): String { - params = URI::Params.parse(body) +CrystalGauntlet.endpoints["/updateGJUserScore22.php"] = ->(context : HTTP::Server::Context): String { + params = URI::Params.parse(context.request.body.not_nil!.gets_to_end) LOG.debug { params.inspect } user_id, account_id = Accounts.auth(params)