~xenrox/faceit_checker

de7b329043ae972e46c38aa49f654872ba14d145 — Thorben Günther a month ago 0faca94
Remove support for status input

This is no longer supported in CS2.
The status output no longer contains any Steam ID.
3 files changed, 7 insertions(+), 70 deletions(-)

M faceit.go
M steam.go
M templates/faceit.html
M faceit.go => faceit.go +7 -22
@@ 390,14 390,12 @@ func (fc *faceitChecker) faceitHandler(w http.ResponseWriter, r *http.Request) {
	input := r.FormValue("input")
	logger.Debug("Received input",
		slog.Any("input", input))
	status := r.FormValue("status")
	var steamAccountList []steamAccount

	if status == "status" {
		var err error
		steamAccountList, err = fc.parseStatus(input)
	steamLinks := strings.Fields(input)
	for _, steamLink := range steamLinks {
		steamProfile, err := fc.getSteamProfile(r.Context(), steamLink)
		if err != nil {
			logger.Debug("Failed to parse status")
			if err := fc.templates.ExecuteTemplate(w, "error.html", err); err != nil {
				logger.Error("Failed to execute template",
					slog.String("error", err.Error()))


@@ 405,24 403,11 @@ func (fc *faceitChecker) faceitHandler(w http.ResponseWriter, r *http.Request) {
			}
			return
		}
	} else {
		steamLinks := strings.Fields(input)
		for _, steamLink := range steamLinks {
			steamProfile, err := fc.getSteamProfile(r.Context(), steamLink)
			if err != nil {
				if err := fc.templates.ExecuteTemplate(w, "error.html", err); err != nil {
					logger.Error("Failed to execute template",
						slog.String("error", err.Error()))
					http.Error(w, internalError, http.StatusInternalServerError)
				}
				return
			}

			steamAccountList = append(steamAccountList, steamAccount{
				id:   steamProfile.ID64,
				name: steamProfile.Name,
			})
		}
		steamAccountList = append(steamAccountList, steamAccount{
			id:   steamProfile.ID64,
			name: steamProfile.Name,
		})
	}

	r = r.WithContext(context.WithValue(r.Context(), accountsContextKey{}, steamAccountList))

M steam.go => steam.go +0 -45
@@ 1,10 1,7 @@
package main

import (
	"errors"
	"fmt"
	"log/slog"
	"regexp"
	"strconv"
	"strings"
)


@@ 38,45 35,3 @@ func parseSteamID(steamID string) (string, error) {

	return strconv.FormatInt(id64, 10), nil
}

func (fc *faceitChecker) parseStatus(status string) ([]steamAccount, error) {
	lineRegex, err := regexp.Compile(`^#.*"(.*)" (STEAM_[0-9:]*).*$`)
	if err != nil {
		return nil, err
	}

	status = strings.TrimSpace(status)
	i := strings.Index(status, "# userid")
	if i == -1 {
		return nil, errors.New("failed to parse status")
	}
	status = status[i:]
	playerSlice := strings.Split(status, "\n")
	// Remove first and last line
	playerSlice = playerSlice[1 : len(playerSlice)-1]

	// This list could potentially contain less accounts than the playerSlice.
	// It happens for example for bots, which do not have a valid Steam ID.
	var steamAccountList []steamAccount
	for _, player := range playerSlice {
		match := lineRegex.FindStringSubmatch(player)
		if len(match) != 3 {
			continue
		}

		id, err := parseSteamID(match[2])
		if err != nil {
			fc.logger.Error("Failed to parse SteamID",
				slog.String("ID", match[2]),
				slog.String("error", err.Error()))
			continue
		}

		steamAccountList = append(steamAccountList, steamAccount{
			name: match[1],
			id:   id,
		})
	}

	return steamAccountList, nil
}

M templates/faceit.html => templates/faceit.html +0 -3
@@ 9,8 9,6 @@
        <form method="POST">
            <textarea id="input" name="input"></textarea>
            <button type="submit">Submit</button>
            <input type="checkbox" id="status" name="status" value="status" />
            <label for="status">Use status output</label>
        </form>
        You can enter multiple Steam links at once, which have to be separated
        by space.<br />


@@ 20,6 18,5 @@
            <li>https://steamcommunity.com/id/gabelogannewell</li>
            <li>https://steamcommunity.com/profiles/76561197960287930</li>
        </ul>
        As an alternative you can paste the output of the "status" command here.
    </body>
</html>