integrate friends into stuff across the server
This commit is contained in:
parent
94cdbd204e
commit
ec1fc7a934
|
@ -154,7 +154,17 @@ CrystalGauntlet.endpoints["/getGJLevels21.php"] = ->(context : HTTP::Server::Con
|
||||||
when "12" # followed
|
when "12" # followed
|
||||||
# todo
|
# todo
|
||||||
when "13" # friends
|
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
|
when "21" # daily
|
||||||
order = "daily_levels.idx desc"
|
order = "daily_levels.idx desc"
|
||||||
joins << "join daily_levels on levels.id = daily_levels.level_id"
|
joins << "join daily_levels on levels.id = daily_levels.level_id"
|
||||||
|
|
|
@ -50,13 +50,19 @@ CrystalGauntlet.endpoints["/getGJLevelScores211.php"] = ->(context : HTTP::Serve
|
||||||
|
|
||||||
type = params["type"]? ? params["type"] : "1"
|
type = params["type"]? ? params["type"] : "1"
|
||||||
|
|
||||||
|
joins = [] of String
|
||||||
where_query = ["level_id = ? and daily_id is ?"]
|
where_query = ["level_id = ? and daily_id is ?"]
|
||||||
|
|
||||||
case type
|
case type
|
||||||
when 0
|
when "0"
|
||||||
|
if !(user_id && account_id)
|
||||||
|
return "-1"
|
||||||
|
end
|
||||||
|
|
||||||
# friends
|
# friends
|
||||||
# todo
|
joins << "left join friend_links friend on (friend.account_id_1 = #{account_id} or friend.account_id_2 = #{account_id})"
|
||||||
when 2
|
where_query << "level_scores.account_id = friend.account_id_1 or level_scores.account_id = friend.account_id_2"
|
||||||
|
when "2"
|
||||||
# weekly
|
# weekly
|
||||||
where_query << "level_scores.set_at > \"#{(Time.utc - 7.days).to_s(Format::TIME_FORMAT)}\""
|
where_query << "level_scores.set_at > \"#{(Time.utc - 7.days).to_s(Format::TIME_FORMAT)}\""
|
||||||
end
|
end
|
||||||
|
@ -64,7 +70,7 @@ CrystalGauntlet.endpoints["/getGJLevelScores211.php"] = ->(context : HTTP::Serve
|
||||||
scores = [] of String
|
scores = [] of String
|
||||||
|
|
||||||
i = 0
|
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
|
i += 1
|
||||||
percent = rs.read(Int32)
|
percent = rs.read(Int32)
|
||||||
coins = rs.read(Int32)
|
coins = rs.read(Int32)
|
||||||
|
|
|
@ -6,90 +6,53 @@ CrystalGauntlet.endpoints["/getGJUserInfo20.php"] = ->(context : HTTP::Server::C
|
||||||
params = URI::Params.parse(context.request.body.not_nil!.gets_to_end)
|
params = URI::Params.parse(context.request.body.not_nil!.gets_to_end)
|
||||||
LOG.debug { params.inspect }
|
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|
|
user_id, account_id = Accounts.auth(params)
|
||||||
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)
|
|
||||||
|
|
||||||
# "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;
|
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,
|
return CrystalGauntlet::Format.fmt_hash({
|
||||||
2 => user_id,
|
1 => username,
|
||||||
3 => stars,
|
2 => user_id,
|
||||||
4 => demons,
|
3 => stars,
|
||||||
8 => creator_points,
|
4 => demons,
|
||||||
10 => color1,
|
8 => creator_points,
|
||||||
11 => color2,
|
10 => color1,
|
||||||
13 => coins,
|
11 => color2,
|
||||||
16 => id,
|
13 => coins,
|
||||||
17 => user_coins,
|
16 => id,
|
||||||
# todo: messages can actually be disabled for _everyone_; this is actually an enum (0: all, 1: only friends, 2: none)
|
17 => user_coins,
|
||||||
18 => !messages_enabled,
|
# todo: messages can actually be disabled for _everyone_; this is actually an enum (0: all, 1: only friends, 2: none)
|
||||||
19 => !friend_requests_enabled,
|
18 => !messages_enabled,
|
||||||
20 => youtube_url || "",
|
19 => !friend_requests_enabled,
|
||||||
21 => cube,
|
20 => youtube_url || "",
|
||||||
22 => ship,
|
21 => cube,
|
||||||
23 => ball,
|
22 => ship,
|
||||||
24 => ufo,
|
23 => ball,
|
||||||
25 => wave,
|
24 => ufo,
|
||||||
26 => robot,
|
25 => wave,
|
||||||
28 => glow,
|
26 => robot,
|
||||||
# registered or not; always 1 here
|
28 => glow,
|
||||||
29 => 1,
|
# registered or not; always 1 here
|
||||||
30 => 1, # rank; todo
|
29 => 1,
|
||||||
# 31 = isnt (0) or is (1) friend or (3) incoming request or (4) outgoing request
|
30 => 1, # rank; todo
|
||||||
# todo
|
# 31 = isnt (0) or is (1) friend or (3) incoming request or (4) outgoing request
|
||||||
31 => 0,
|
# todo
|
||||||
# also w/ friend requests:
|
31 => 0,
|
||||||
# 32 => id,
|
# also w/ friend requests:
|
||||||
# 35 => comment,
|
# 32 => id,
|
||||||
# 37 => date,
|
# 35 => comment,
|
||||||
# todo: how many messages you have; exclusive to if you're viewing your own profile
|
# 37 => date,
|
||||||
38 => 0,
|
38 => account_id == id ? DATABASE.scalar("select count(*) from messages where (to_account_id = ? and read_at is null)", id).as(Int64) : 0,
|
||||||
# todo: above, but friend requests
|
39 => account_id == id ? DATABASE.scalar("select count(*) from friend_requests where (to_account_id = ? and read_at is null)", id).as(Int64) : 0,
|
||||||
39 => 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,
|
||||||
# todo: above: but how many new friends the user has
|
43 => spider,
|
||||||
40 => 0,
|
44 => twitter_url || "",
|
||||||
43 => spider,
|
45 => twitch_url || "",
|
||||||
44 => twitter_url || "",
|
46 => diamonds,
|
||||||
45 => twitch_url || "",
|
48 => explosion,
|
||||||
46 => diamonds,
|
# badge, todo
|
||||||
48 => explosion,
|
49 => 0,
|
||||||
# badge, todo
|
# todo: this is actually also an enum (0: all, 1: only friends, 2: none)
|
||||||
49 => 0,
|
50 => !comments_enabled,
|
||||||
# todo: this is actually also an enum (0: all, 1: only friends, 2: none)
|
})
|
||||||
50 => !comments_enabled,
|
|
||||||
})
|
|
||||||
else
|
|
||||||
"-1"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue