blob: 0e15d3436f45ffc4b7723b8ab39422986b3d860c (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
package main
import (
"encoding/json"
"fmt"
"strconv"
)
type Record struct {
MapID int `json:"id"`
MapName string `json:"name"`
MapMode int `json:"mode"`
MapWR int `json:"wr"`
MapLimit *int `json:"limit"`
}
type Leaderboard struct {
Entries LeaderboardEntries `xml:"entries"`
}
func (l *Leaderboard) needsAnotherPage(record *Record) bool {
if l.Entries.Entry[len(l.Entries.Entry)-1].Score == record.MapWR {
return true
} else if record.MapLimit != nil && l.Entries.Entry[len(l.Entries.Entry)-1].Score <= *record.MapLimit {
return true
}
return false
}
type LeaderboardEntries struct {
Entry []LeaderboardEntry `xml:"entry"`
}
type SteamID int64
func (m SteamID) MarshalJSON() ([]byte, error) {
return json.Marshal(strconv.FormatInt(int64(m), 10))
}
func (id *SteamID) UnmarshalJSON(data []byte) error {
var s string
if err := json.Unmarshal(data, &s); err == nil {
n, err := strconv.ParseInt(s, 10, 64)
if err != nil {
return err
}
*id = SteamID(n)
return nil
}
return fmt.Errorf("invalid type for SteamID: %s", data)
}
type LeaderboardEntry struct {
SteamID SteamID `xml:"steamid"`
Score int `xml:"score"`
}
type Player struct {
Username string `json:"user_name"`
AvatarLink string `json:"avatar_link"`
SteamID SteamID `json:"steam_id"`
Entries []PlayerEntry `json:"-"`
SpScoreCount int `json:"sp_score"`
MpScoreCount int `json:"mp_score"`
OverallScoreCount int `json:"overall_score"`
SpRank int `json:"sp_rank"`
MpRank int `json:"mp_rank"`
OverallRank int `json:"overall_rank"`
SpIterations int `json:"-"`
MpIterations int `json:"-"`
}
type PlayerEntry struct {
MapID int
MapScore int
}
|