From c822ce93964decec22c21d7e67e498ccfc80d75b Mon Sep 17 00:00:00 2001 From: Giovanni Harting <539@idlegandalf.com> Date: Tue, 1 Feb 2022 02:31:00 +0100 Subject: [PATCH] try parsing match first --- main.go | 15 ++++++++++----- utils/utils.go | 2 +- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/main.go b/main.go index 29bbc77..6760584 100644 --- a/main.go +++ b/main.go @@ -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 } diff --git a/utils/utils.go b/utils/utils.go index 0ce60e9..2d4ab12 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -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)