2016-05-28 18:24:39 +00:00
|
|
|
package peppy
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
|
2016-08-15 11:45:42 +00:00
|
|
|
"github.com/jmoiron/sqlx"
|
2017-02-02 12:40:28 +00:00
|
|
|
"github.com/valyala/fasthttp"
|
2016-05-28 18:24:39 +00:00
|
|
|
"gopkg.in/thehowl/go-osuapi.v1"
|
2019-02-23 13:09:10 +00:00
|
|
|
"github.com/osuYozora/rippleapi/common"
|
2017-02-02 12:40:28 +00:00
|
|
|
"zxq.co/x/getrank"
|
2016-05-28 18:24:39 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// GetUserRecent retrieves an user's recent scores.
|
2017-02-02 12:40:28 +00:00
|
|
|
func GetUserRecent(c *fasthttp.RequestCtx, db *sqlx.DB) {
|
|
|
|
getUserX(c, db, "ORDER BY scores.time DESC", common.InString(1, query(c, "limit"), 50, 10))
|
2016-05-28 18:24:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetUserBest retrieves an user's best scores.
|
2017-02-02 12:40:28 +00:00
|
|
|
func GetUserBest(c *fasthttp.RequestCtx, db *sqlx.DB) {
|
2016-05-28 18:24:39 +00:00
|
|
|
var sb string
|
2017-02-02 12:40:28 +00:00
|
|
|
if rankable(query(c, "m")) {
|
2016-05-28 18:24:39 +00:00
|
|
|
sb = "scores.pp"
|
|
|
|
} else {
|
|
|
|
sb = "scores.score"
|
|
|
|
}
|
2017-02-02 12:40:28 +00:00
|
|
|
getUserX(c, db, "AND completed = '3' ORDER BY "+sb+" DESC", common.InString(1, query(c, "limit"), 100, 10))
|
2016-05-28 18:24:39 +00:00
|
|
|
}
|
|
|
|
|
2017-02-02 12:40:28 +00:00
|
|
|
func getUserX(c *fasthttp.RequestCtx, db *sqlx.DB, orderBy string, limit int) {
|
2016-05-28 18:24:39 +00:00
|
|
|
whereClause, p := genUser(c, db)
|
2017-02-02 12:40:28 +00:00
|
|
|
sqlQuery := fmt.Sprintf(
|
2016-07-03 19:55:03 +00:00
|
|
|
`SELECT
|
2016-05-28 18:24:39 +00:00
|
|
|
beatmaps.beatmap_id, scores.score, scores.max_combo,
|
|
|
|
scores.300_count, scores.100_count, scores.50_count,
|
|
|
|
scores.gekis_count, scores.katus_count, scores.misses_count,
|
|
|
|
scores.full_combo, scores.mods, users.id, scores.time,
|
|
|
|
scores.pp, scores.accuracy
|
|
|
|
FROM scores
|
|
|
|
LEFT JOIN beatmaps ON beatmaps.beatmap_md5 = scores.beatmap_md5
|
2016-05-28 21:48:29 +00:00
|
|
|
LEFT JOIN users ON scores.userid = users.id
|
2016-07-03 19:55:03 +00:00
|
|
|
WHERE %s AND scores.play_mode = ? AND users.privileges & 1 > 0
|
2016-05-28 18:24:39 +00:00
|
|
|
%s
|
|
|
|
LIMIT %d`, whereClause, orderBy, limit,
|
|
|
|
)
|
|
|
|
scores := make([]osuapi.GUSScore, 0, limit)
|
2017-02-02 12:40:28 +00:00
|
|
|
m := genmodei(query(c, "m"))
|
|
|
|
rows, err := db.Query(sqlQuery, p, m)
|
2016-05-28 18:24:39 +00:00
|
|
|
if err != nil {
|
2017-02-02 12:40:28 +00:00
|
|
|
json(c, 200, defaultResponse)
|
|
|
|
common.Err(c, err)
|
2016-05-28 18:24:39 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
for rows.Next() {
|
|
|
|
var (
|
|
|
|
curscore osuapi.GUSScore
|
2016-08-19 15:02:51 +00:00
|
|
|
rawTime common.UnixTimestamp
|
2016-05-28 18:24:39 +00:00
|
|
|
acc float64
|
|
|
|
fc bool
|
|
|
|
mods int
|
2016-05-28 18:31:46 +00:00
|
|
|
bid *int
|
2016-05-28 18:24:39 +00:00
|
|
|
)
|
|
|
|
err := rows.Scan(
|
2016-05-28 18:31:46 +00:00
|
|
|
&bid, &curscore.Score.Score, &curscore.MaxCombo,
|
2016-05-28 18:24:39 +00:00
|
|
|
&curscore.Count300, &curscore.Count100, &curscore.Count50,
|
|
|
|
&curscore.CountGeki, &curscore.CountKatu, &curscore.CountMiss,
|
|
|
|
&fc, &mods, &curscore.UserID, &rawTime,
|
|
|
|
&curscore.PP, &acc,
|
|
|
|
)
|
|
|
|
if err != nil {
|
2017-02-02 12:40:28 +00:00
|
|
|
json(c, 200, defaultResponse)
|
|
|
|
common.Err(c, err)
|
2016-05-28 18:24:39 +00:00
|
|
|
return
|
|
|
|
}
|
2016-05-28 18:31:46 +00:00
|
|
|
if bid == nil {
|
|
|
|
curscore.BeatmapID = 0
|
|
|
|
} else {
|
|
|
|
curscore.BeatmapID = *bid
|
|
|
|
}
|
2016-05-28 18:24:39 +00:00
|
|
|
curscore.FullCombo = osuapi.OsuBool(fc)
|
|
|
|
curscore.Mods = osuapi.Mods(mods)
|
2016-08-19 15:02:51 +00:00
|
|
|
curscore.Date = osuapi.MySQLDate(rawTime)
|
2016-05-28 18:24:39 +00:00
|
|
|
curscore.Rank = strings.ToUpper(getrank.GetRank(
|
|
|
|
osuapi.Mode(m),
|
|
|
|
curscore.Mods,
|
|
|
|
acc,
|
|
|
|
curscore.Count300,
|
|
|
|
curscore.Count100,
|
|
|
|
curscore.Count50,
|
|
|
|
curscore.CountMiss,
|
|
|
|
))
|
|
|
|
scores = append(scores, curscore)
|
|
|
|
}
|
2017-02-02 12:40:28 +00:00
|
|
|
json(c, 200, scores)
|
2016-05-28 18:24:39 +00:00
|
|
|
}
|