switched to steam-api for player profile information

This commit is contained in:
2021-10-16 01:33:57 +02:00
parent 3787c59b9e
commit af2523a78a
12 changed files with 388 additions and 116 deletions

62
main.go
View File

@@ -16,6 +16,7 @@ import (
"github.com/go-redis/redis/v8"
"github.com/gorilla/handlers"
"github.com/gorilla/mux"
_ "github.com/lib/pq"
_ "github.com/mattn/go-sqlite3"
log "github.com/sirupsen/logrus"
"github.com/wercker/journalhook"
@@ -45,43 +46,6 @@ var (
journalLogFlag = flag.Bool("journal", false, "Log to systemd journal instead of stdout")
)
type PlayerResponse struct {
SteamID64 uint64 `json:"steamid64,string"`
Name string `json:"name"`
Avatar string `json:"avatar"`
VAC bool `json:"vac"`
VACDate time.Time `json:"vac_date,omitempty"`
Tracked bool `json:"tracked"`
VanityURL string `json:"vanity_url,omitempty"`
MatchStats utils.MatchStats `json:"match_stats,omitempty"`
Matches []*MatchResponse `json:"matches,omitempty"`
}
type EqResponse struct {
Victim uint64 `json:"victim"`
Type int `json:"type"`
HitGroup int `json:"hit_group"`
Dmg uint `json:"dmg"`
}
type WeaponResponse struct {
Player *PlayerResponse `json:"player"`
Eq []*EqResponse `json:"eq,omitempty"`
}
type MatchResponse struct {
MatchId uint64 `json:"match_id,string"`
ShareCode string `json:"share_code,omitempty"`
Map string `json:"map"`
Date time.Time `json:"date"`
Score [2]int `json:"score"`
Duration int `json:"duration"`
MatchResult int `json:"match_result"`
MaxRounds int `json:"max_rounds,omitempty"`
Parsed bool `json:"parsed"`
Stats interface{} `json:"stats,omitempty"`
}
func housekeeping() {
for {
if !firstHK {
@@ -100,9 +64,7 @@ func housekeeping() {
continue
}
for _, tPlayer := range tPlayerNeedSteamUpdate {
_, err = utils.UpdatePlayerFromSteam(tPlayer, conf.Steam.APIKey, db.Lock, rL)
}
_, err = utils.UpdatePlayerFromSteam(tPlayerNeedSteamUpdate, db.Client, conf.Steam.APIKey, db.Lock, rL)
// getting new sharecodes
if !demoLoader.GCReady {
@@ -171,14 +133,14 @@ func getPlayer(w http.ResponseWriter, r *http.Request) {
return
}
response := PlayerResponse{
response := utils.PlayerResponse{
SteamID64: tPlayer.ID,
Name: tPlayer.Name,
Avatar: tPlayer.AvatarURL,
VAC: tPlayer.Vac,
VanityURL: tPlayer.VanityURLReal,
Tracked: tPlayer.AuthCode != "",
Matches: []*MatchResponse{},
Matches: []*utils.MatchResponse{},
}
if !tPlayer.VacDate.IsZero() {
@@ -232,7 +194,7 @@ func getPlayer(w http.ResponseWriter, r *http.Request) {
}
for _, iMatch := range tMatches {
mResponse := &MatchResponse{
mResponse := &utils.MatchResponse{
MatchId: iMatch.ID,
Map: iMatch.Map,
Date: iMatch.Date,
@@ -386,7 +348,7 @@ func getMatchWeapons(w http.ResponseWriter, r *http.Request) {
return
}
mResponse := make([]*WeaponResponse, 0)
mResponse := make([]*utils.WeaponResponse, 0)
db.Lock.RLock()
tStats, err := db.Client.Stats.Query().Where(stats.HasMatchesWith(match.ID(matchId))).All(context.Background())
@@ -406,12 +368,12 @@ func getMatchWeapons(w http.ResponseWriter, r *http.Request) {
continue
}
mWr := &WeaponResponse{
Player: &PlayerResponse{SteamID64: stat.PlayerStats},
mWr := &utils.WeaponResponse{
Player: &utils.PlayerResponse{SteamID64: stat.PlayerStats},
}
for _, wr := range mWs {
mWr.Eq = append(mWr.Eq, &EqResponse{
mWr.Eq = append(mWr.Eq, &utils.EqResponse{
Victim: wr.Victim,
Type: wr.EqType,
HitGroup: wr.HitGroup,
@@ -453,7 +415,7 @@ func getMatch(w http.ResponseWriter, r *http.Request) {
return
}
mResponse := &MatchResponse{
mResponse := &utils.MatchResponse{
MatchId: tMatch.ID,
ShareCode: tMatch.ShareCode,
Map: tMatch.Map,
@@ -479,7 +441,7 @@ func getMatch(w http.ResponseWriter, r *http.Request) {
for _, iStats := range tStats {
sResponse := &utils.StatsResponse{
Player: PlayerResponse{
Player: utils.PlayerResponse{
SteamID64: iStats.Edges.Players.ID,
Name: iStats.Edges.Players.Name,
Avatar: iStats.Edges.Players.AvatarURL,
@@ -545,7 +507,7 @@ func getMatch(w http.ResponseWriter, r *http.Request) {
if !iStats.Edges.Players.VacDate.IsZero() {
switch s := sResponse.Player.(type) {
case PlayerResponse:
case utils.PlayerResponse:
s.VACDate = iStats.Edges.Players.VacDate
}
}