Playtime records from pt_events; sticky top bar, page scroll locked under the drawer
Records: the most bomb plants, defuses, knife, Zeus and headshot kills for the last 7 days, 30 days or all time, and each player's counts, when PlaytimeHistory 0.2.0's pt_events is there. The public site's top bar now sticks the whole way down, Playtime comes after Server, and only the player drawer scrolls while it's open.
This commit is contained in:
parent
6d0fc6e463
commit
7004945d49
9 changed files with 296 additions and 27 deletions
|
|
@ -122,8 +122,13 @@ func viewerZone(r *http.Request) *time.Location {
|
|||
|
||||
// periodSince reads ?period=7d|30d|all; all is nil.
|
||||
func periodSince(r *http.Request, allowAll bool) (string, *time.Time) {
|
||||
return periodParam(r.URL.Query().Get("period"), allowAll)
|
||||
}
|
||||
|
||||
// periodParam turns 7d, 30d or all into when it starts; all is nil. Anything else is 7d.
|
||||
func periodParam(p string, allowAll bool) (string, *time.Time) {
|
||||
now := time.Now()
|
||||
switch p := r.URL.Query().Get("period"); {
|
||||
switch {
|
||||
case p == "30d":
|
||||
t := now.Add(-30 * 24 * time.Hour)
|
||||
return p, &t
|
||||
|
|
@ -167,7 +172,18 @@ func (s *Server) publicPlaytime(w http.ResponseWriter, r *http.Request) {
|
|||
for _, l := range leaders {
|
||||
lv = append(lv, leaderView{Leader: l, Rank: s.rankOf(x, l.SteamID)})
|
||||
}
|
||||
writeJSON(w, http.StatusOK, map[string]any{"overview": o, "period": period, "leaders": lv})
|
||||
resp := map[string]any{"overview": o, "period": period, "leaders": lv}
|
||||
// Records (?records=7d|30d|all) need pt_events, from PlaytimeHistory 0.2.0.
|
||||
if s.pt.HasEvents() {
|
||||
rp, rsince := periodParam(r.URL.Query().Get("records"), true)
|
||||
rec, err := s.pt.Records(ctx, rsince, 5)
|
||||
if err != nil {
|
||||
internal(w, r, err)
|
||||
return
|
||||
}
|
||||
resp["records"], resp["recordsPeriod"] = rec, rp
|
||||
}
|
||||
writeJSON(w, http.StatusOK, resp)
|
||||
}
|
||||
|
||||
type onlineView struct {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue