Merge pull request 'Miscellaneous fixes' (#10) from rya/crystal-gauntlet:main into main

Reviewed-on: #10
This commit is contained in:
Jill 2024-02-03 17:26:13 +01:00
commit a8a3798e96
8 changed files with 21 additions and 4 deletions

View File

@ -30,5 +30,5 @@ shards:
toml:
git: https://github.com/crystal-community/toml.cr.git
version: 0.7.0+git.commit.4b6325e2a378bac4abc98ee4d5734d57a6a55554
version: 0.7.0+git.commit.299f81a890bc01f3edca4fe3b29f9d08e86e538f

View File

@ -21,6 +21,7 @@ dependencies:
toml:
github: crystal-community/toml.cr
branch: master
commit: 299f81a
http-session:
github: straight-shoota/http-session
athena-routing:

View File

@ -59,7 +59,7 @@ module CrystalGauntlet
config_get(key).as?(typeof(default)) || default
end
DATABASE = DB.open(ENV["DATABASE_URL"]? || "sqlite3://./crystal-gauntlet.db")
DATABASE = DB.open(ENV["DATABASE_URL"]? || "sqlite3://./data/crystal-gauntlet.db")
# todo: unhardcore
DATA_FOLDER = Path.new("data")

View File

@ -38,6 +38,10 @@ CrystalGauntlet.endpoints["/getGJCommentHistory.php"] = ->(context : HTTP::Serve
amount = DATABASE.scalar("select count(*) from comments where user_id = ?", params["userID"].to_i).as(Int64)
if amount == 0
return "-2"
end
comments_str = [] of String
DATABASE.query("select comments.id, comment, comments.created_at, likes, level_id, users.username, users.icon_type, users.color1, users.color2, users.cube, users.ship, users.ball, users.ufo, users.wave, users.robot, users.spider, users.special from comments join users on users.id = user_id where user_id = ? order by comments.created_at desc limit #{comments_per_page} offset #{comment_offset}", params["userID"]) do |rs|

View File

@ -14,6 +14,10 @@ CrystalGauntlet.endpoints["/getGJComments21.php"] = ->(context : HTTP::Server::C
amount = DATABASE.scalar("select count(*) from comments where level_id = ?", level_id)
if amount == 0
return "-2"
end
comments_str = [] of String
users_str = [] of String
has_users_str = false

View File

@ -14,6 +14,10 @@ CrystalGauntlet.endpoints["/getGJAccountComments20.php"] = ->(context : HTTP::Se
amount = DATABASE.scalar("select count(*) from account_comments where account_id = ?", account_id)
if amount == 0
return "-2"
end
users_str = [] of String
DATABASE.query("select id, comment, created_at, likes from account_comments where account_id = ? order by created_at desc limit #{comments_per_page} offset #{comment_offset}", account_id) do |rs|

View File

@ -8,7 +8,9 @@ CrystalGauntlet.endpoints["/updateGJUserScore22.php"] = ->(context : HTTP::Serve
user_id, account_id = Accounts.auth(params)
if !(user_id && account_id)
return "-1"
# we assume this is an unregistered user
# since the client expects the returned value to be ...its own user id? we just return 0
return "0"
end
# todo: keep track of stat changes to look out for leaderboard cheating & whatnot

View File

@ -7,6 +7,8 @@ module CrystalGauntlet::Server
def call(context : HTTP::Server::Context)
# expunge trailing slashes
path = context.request.path.chomp("/")
# remove slashes at the beginning of the path, if there are more than one
path = path.sub(/^\/*(?!\/)/, "/")
path = path.sub(config_get("general.append_path").as(String | Nil) || "", "")
@ -29,7 +31,7 @@ module CrystalGauntlet::Server
end
end
context.response.content_type = "text/plain"
context.response.respond_with_status(500, "-1")
context.response.respond_with_status(500, "uh oh!!! server did a fucky wucky")
else
max_size = 2048