integrate friends into stuff across the server

This commit is contained in:
Jill 2023-01-06 11:09:54 +03:00
parent 94cdbd204e
commit ec1fc7a934
3 changed files with 69 additions and 90 deletions

View File

@ -154,7 +154,17 @@ CrystalGauntlet.endpoints["/getGJLevels21.php"] = ->(context : HTTP::Server::Con
when "12" # followed
# todo
when "13" # friends
# todo
user_id, account_id = Accounts.auth(params)
if !(user_id && account_id)
return "-1"
end
joins << "left join friend_links friend_2 on friend_2.account_id_1 = #{account_id}"
joins << "left join friend_links friend_1 on friend_1.account_id_2 = #{account_id}"
joins << "left join users friend_user_1 on friend_1.account_id_1 = friend_user_1.id"
joins << "left join users friend_user_2 on friend_2.account_id_2 = friend_user_2.id"
queryParams << "levels.user_id = friend_user_1.id or levels.user_id = friend_user_2.id"
when "21" # daily
order = "daily_levels.idx desc"
joins << "join daily_levels on levels.id = daily_levels.level_id"

View File

@ -50,13 +50,19 @@ CrystalGauntlet.endpoints["/getGJLevelScores211.php"] = ->(context : HTTP::Serve
type = params["type"]? ? params["type"] : "1"
joins = [] of String
where_query = ["level_id = ? and daily_id is ?"]
case type
when 0
when "0"
if !(user_id && account_id)
return "-1"
end
# friends
# todo
when 2
joins << "left join friend_links friend on (friend.account_id_1 = #{account_id} or friend.account_id_2 = #{account_id})"
where_query << "level_scores.account_id = friend.account_id_1 or level_scores.account_id = friend.account_id_2"
when "2"
# weekly
where_query << "level_scores.set_at > \"#{(Time.utc - 7.days).to_s(Format::TIME_FORMAT)}\""
end
@ -64,7 +70,7 @@ CrystalGauntlet.endpoints["/getGJLevelScores211.php"] = ->(context : HTTP::Serve
scores = [] of String
i = 0
DATABASE.query_each "select percent, level_scores.coins, set_at, users.username, users.id, users.icon_type, users.color1, users.color2, users.cube, users.ship, users.ball, users.ufo, users.wave, users.robot, users.spider, users.special, users.account_id from level_scores join users on level_scores.account_id = users.account_id where (#{where_query.join(") and (")}) order by percent desc, level_scores.coins desc limit 200", level_id, daily_id do |rs|
DATABASE.query_each "select percent, level_scores.coins, set_at, users.username, users.id, users.icon_type, users.color1, users.color2, users.cube, users.ship, users.ball, users.ufo, users.wave, users.robot, users.spider, users.special, users.account_id from level_scores join users on level_scores.account_id = users.account_id #{joins.join(" ")} where (#{where_query.join(") and (")}) order by percent desc, level_scores.coins desc limit 200", level_id, daily_id do |rs|
i += 1
percent = rs.read(Int32)
coins = rs.read(Int32)

View File

@ -6,90 +6,53 @@ CrystalGauntlet.endpoints["/getGJUserInfo20.php"] = ->(context : HTTP::Server::C
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|
if rs.move_next
id = rs.read(Int32)
username = rs.read(String)
is_admin = rs.read(Int32)
messages_enabled = rs.read(Int32)
friend_requests_enabled = rs.read(Int32)
comments_enabled = rs.read(Int32)
youtube_url = rs.read(String | Nil)
twitter_url = rs.read(String | Nil)
twitch_url = rs.read(String | Nil)
created_at = rs.read(String)
user_id = rs.read(Int32)
stars = rs.read(Int32)
demons = rs.read(Int32)
coins = rs.read(Int32)
user_coins = rs.read(Int32)
diamonds = rs.read(Int32)
orbs = rs.read(Int32)
creator_points = rs.read(Int32)
icon_type = rs.read(Int32)
color1 = rs.read(Int32)
color2 = rs.read(Int32)
glow = rs.read(Int32)
cube = rs.read(Int32)
ship = rs.read(Int32)
ball = rs.read(Int32)
ufo = rs.read(Int32)
wave = rs.read(Int32)
robot = rs.read(Int32)
spider = rs.read(Int32)
explosion = rs.read(Int32)
user_id, account_id = Accounts.auth(params)
# "1:".$user["userName"].":2:".$user["userID"].":13:".$user["coins"].":17:".$user["userCoins"].":10:".$user["color1"].":11:".$user["color2"].":3:".$user["stars"].":46:".$user["diamonds"].":4:".$user["demons"].":8:".$creatorpoints.":18:".$msgstate.":19:".$reqsstate.":50:".$commentstate.":20:".$accinfo["youtubeurl"].":21:".$user["accIcon"].":22:".$user["accShip"].":23:".$user["accBall"].":24:".$user["accBird"].":25:".$user["accDart"].":26:".$user["accRobot"].":28:".$user["accGlow"].":43:".$user["accSpider"].":47:".$user["accExplosion"].":30:".$rank.":16:".$user["extID"].":31:".$friendstate.":44:".$accinfo["twitter"].":45:".$accinfo["twitch"].":29:1:49:".$badge . $appendix;
return CrystalGauntlet::Format.fmt_hash({
1 => username,
2 => user_id,
3 => stars,
4 => demons,
8 => creator_points,
10 => color1,
11 => color2,
13 => coins,
16 => id,
17 => user_coins,
# todo: messages can actually be disabled for _everyone_; this is actually an enum (0: all, 1: only friends, 2: none)
18 => !messages_enabled,
19 => !friend_requests_enabled,
20 => youtube_url || "",
21 => cube,
22 => ship,
23 => ball,
24 => ufo,
25 => wave,
26 => robot,
28 => glow,
# registered or not; always 1 here
29 => 1,
30 => 1, # rank; todo
# 31 = isnt (0) or is (1) friend or (3) incoming request or (4) outgoing request
# todo
31 => 0,
# also w/ friend requests:
# 32 => id,
# 35 => comment,
# 37 => date,
# todo: how many messages you have; exclusive to if you're viewing your own profile
38 => 0,
# todo: above, but friend requests
39 => 0,
# todo: above: but how many new friends the user has
40 => 0,
43 => spider,
44 => twitter_url || "",
45 => twitch_url || "",
46 => diamonds,
48 => explosion,
# badge, todo
49 => 0,
# todo: this is actually also an enum (0: all, 1: only friends, 2: none)
50 => !comments_enabled,
})
else
"-1"
end
end
id, username, is_admin, messages_enabled, friend_requests_enabled, comments_enabled, youtube_url, twitter_url, twitch_url, created_at, user_id, stars, demons, coins, user_coins, diamonds, orbs, creator_points, icon_type, color1, color2, glow, cube, ship, ball, ufo, wave, robot, spider, explosion = DATABASE.query_one("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"], as: {Int32, String, Int32, Int32, Int32, Int32, String?, String?, String?, String, Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32})
return CrystalGauntlet::Format.fmt_hash({
1 => username,
2 => user_id,
3 => stars,
4 => demons,
8 => creator_points,
10 => color1,
11 => color2,
13 => coins,
16 => id,
17 => user_coins,
# todo: messages can actually be disabled for _everyone_; this is actually an enum (0: all, 1: only friends, 2: none)
18 => !messages_enabled,
19 => !friend_requests_enabled,
20 => youtube_url || "",
21 => cube,
22 => ship,
23 => ball,
24 => ufo,
25 => wave,
26 => robot,
28 => glow,
# registered or not; always 1 here
29 => 1,
30 => 1, # rank; todo
# 31 = isnt (0) or is (1) friend or (3) incoming request or (4) outgoing request
# todo
31 => 0,
# also w/ friend requests:
# 32 => id,
# 35 => comment,
# 37 => date,
38 => account_id == id ? DATABASE.scalar("select count(*) from messages where (to_account_id = ? and read_at is null)", id).as(Int64) : 0,
39 => account_id == id ? DATABASE.scalar("select count(*) from friend_requests where (to_account_id = ? and read_at is null)", id).as(Int64) : 0,
40 => account_id == id ? DATABASE.scalar("select count(*) from friend_links where (account_id_1 = ? and read_at_1 is null) or (account_id_2 = ? and read_at_2 is null)", id, id).as(Int64) : 0,
43 => spider,
44 => twitter_url || "",
45 => twitch_url || "",
46 => diamonds,
48 => explosion,
# badge, todo
49 => 0,
# todo: this is actually also an enum (0: all, 1: only friends, 2: none)
50 => !comments_enabled,
})
}