try parsing match first

This commit is contained in:
2022-02-01 02:31:00 +01:00
parent 26c5e0558c
commit c822ce9396
2 changed files with 11 additions and 6 deletions

15
main.go
View File

@@ -511,6 +511,15 @@ func postPlayerTrack(w http.ResponseWriter, r *http.Request) {
return
}
if shareCode != "" && utils.ShareCodeRegEx.MatchString(shareCode) {
err := demoLoader.LoadDemo(&csgo.Demo{ShareCode: shareCode})
if err != nil {
log.Warningf("[PPT] unable to queue match: %v", err)
w.WriteHeader(http.StatusServiceUnavailable)
return
}
}
_, err = utils.IsAuthCodeValid(tPlayer, conf.Steam.APIKey, shareCode, authCode, rL)
if err != nil {
switch e := err.(type) {
@@ -522,12 +531,8 @@ func postPlayerTrack(w http.ResponseWriter, r *http.Request) {
log.Infof("[PPT] shareCode provided for player %s is invalid: %v", id, e)
w.WriteHeader(http.StatusPreconditionFailed)
return
case *ent.NotFoundError:
log.Infof("[PPT] match not found for player %+v: %+v, %+v", id, authCode, shareCode)
w.WriteHeader(http.StatusBadRequest)
return
default:
log.Infof("[PPT] Temporary Steam-API problem: %v", e)
log.Infof("[PPT] problem with request: %v", e)
w.WriteHeader(http.StatusServiceUnavailable)
return
}

View File

@@ -476,7 +476,7 @@ func IsAuthCodeValid(player *ent.Player, apiKey string, shareCode string, authCo
if shareCode == "" {
tMatch, err = player.QueryMatches().Order(ent.Asc(match.FieldDate)).First(context.Background())
if err != nil {
return false, err
return false, SharecodeNoMatchError{errors.New("sharecode not provided")}
}
_, err := getNextShareCode(tMatch.ShareCode, apiKey, authCode, player.ID, rl)