diff --git a/.golangci.yml b/.golangci.yml index c208b2c..6e1fcc5 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -39,7 +39,7 @@ linters: - gocritic - gocyclo - godot - - godox + #- godox - goerr113 - gofmt - gofumpt @@ -91,7 +91,7 @@ linters: - typecheck - unconvert - unparam - - unused + #- unused - usestdlibvars #- varnamelen - wastedassign diff --git a/actions.go b/actions.go index f1d8b93..dcbdcd4 100644 --- a/actions.go +++ b/actions.go @@ -4,13 +4,14 @@ import ( "context" "errors" "fmt" - "github.com/leighmacdonald/bd/rules" - "github.com/leighmacdonald/bd/store" - "github.com/leighmacdonald/steamid/v3/steamid" "log/slog" "os" "sort" "time" + + "github.com/leighmacdonald/bd/rules" + "github.com/leighmacdonald/bd/store" + "github.com/leighmacdonald/steamid/v3/steamid" ) // unMark will unmark & remove a player from your local list. This *will not* unmark players from any diff --git a/announce.go b/announce.go index 036bd76..5377fc4 100644 --- a/announce.go +++ b/announce.go @@ -3,10 +3,11 @@ package main import ( "context" "fmt" - "github.com/leighmacdonald/bd/rules" "log/slog" "strings" "time" + + "github.com/leighmacdonald/bd/rules" ) type announceHandler struct { diff --git a/api.go b/api.go index 6a27f00..643a7d5 100644 --- a/api.go +++ b/api.go @@ -5,7 +5,6 @@ import ( "encoding/json" "errors" "fmt" - "github.com/leighmacdonald/bd/store" "log/slog" "net/http" "net/url" @@ -14,6 +13,7 @@ import ( "time" "github.com/leighmacdonald/bd-api/models" + "github.com/leighmacdonald/bd/store" "github.com/leighmacdonald/steamid/v3/steamid" "github.com/leighmacdonald/steamweb/v2" ) @@ -107,12 +107,12 @@ func createLocalDataSource(key string) (*LocalDataSource, error) { return &LocalDataSource{}, nil } -func newDataSource(userSettings userSettings) (DataSource, error) { +func newDataSource(userSettings userSettings) (DataSource, error) { //nolint:ireturn if userSettings.BdAPIEnabled { return createAPIDataSource(userSettings.BdAPIAddress) - } else { - return createLocalDataSource(userSettings.APIKey) } + + return createLocalDataSource(userSettings.APIKey) } // steamIDStringList transforms a steamid.Collection into a comma separated list of SID64 strings. @@ -318,7 +318,9 @@ func (p profileUpdater) applyRemoteData(data updatedRemoteData) { if ban.VACBanned { since := time.Now().AddDate(0, 0, -ban.DaysSinceLastBan) - player.LastVacBanOn.Scan(since) + if err := player.LastVacBanOn.Scan(since); err != nil { + slog.Error("failed to scan last vac ban", errAttr(err)) + } } break diff --git a/discord.go b/discord.go index 9eb95d0..f75f36a 100644 --- a/discord.go +++ b/discord.go @@ -218,9 +218,9 @@ func (d discordState) discordUpdateActivity() error { state := "Offline" // TODO - //if inGame { - // state = "In-Game" - //} + // if inGame { + // state = "In-Game" + // } details := "Idle" if server.ServerName != "" { @@ -246,9 +246,9 @@ func (d discordState) discordUpdateActivity() error { SmallImage: "logo_cd", SmallText: "", Party: party, - //Timestamps: &client.Timestamps{ + // Timestamps: &client.Timestamps{ // Start: &startupTime, - //}, + // }, Buttons: buttons, }); errSetActivity != nil { return errors.Join(errSetActivity, errDiscordActivity) diff --git a/main.go b/main.go index a6b3212..434c25e 100644 --- a/main.go +++ b/main.go @@ -156,18 +156,18 @@ func run() int { slog.String("commit", versionInfo.Commit), slog.String("via", versionInfo.BuiltBy)) - db, dbCloser, errDb := store.CreateDb(settingsMgr.DBPath()) - if errDb != nil { - slog.Error("failed to create database", errAttr(errDb)) + db, dbCloser, errDB := store.CreateDB(settingsMgr.DBPath()) + if errDB != nil { + slog.Error("failed to create database", errAttr(errDB)) return 1 } defer dbCloser() - //fsCache, cacheErr := NewCache(settingsMgr.ConfigRoot(), DurationCacheTimeout) - //if cacheErr != nil { - // slog.Error("Failed to setup cache", errAttr(cacheErr)) - // return 1 - //} + // fsCache, cacheErr := NewCache(settingsMgr.ConfigRoot(), DurationCacheTimeout) + // if cacheErr != nil { + // slog.Error("Failed to setup cache", errAttr(cacheErr)) + // return 1 + // } logChan := make(chan string) @@ -211,11 +211,7 @@ func run() int { slog.Error("failed to create http handlers", errAttr(errRoutes)) } - httpServer, errWeb := newHTTPServer(rootCtx, settings.HTTPListenAddr, mux) - - if errWeb != nil { - slog.Error("Failed to initialize http server", errAttr(errWeb)) - } + httpServer := newHTTPServer(rootCtx, settings.HTTPListenAddr, mux) go testLogFeeder(logChan) diff --git a/platform/linux.go b/platform/linux.go index a41a5d5..cdb4608 100644 --- a/platform/linux.go +++ b/platform/linux.go @@ -5,14 +5,15 @@ package platform import ( "errors" "fmt" - "github.com/leighmacdonald/bd/frontend" - "github.com/mitchellh/go-homedir" - "github.com/mitchellh/go-ps" - "github.com/pkg/browser" "log/slog" "os/exec" "path" "strings" + + "github.com/leighmacdonald/bd/frontend" + "github.com/mitchellh/go-homedir" + "github.com/mitchellh/go-ps" + "github.com/pkg/browser" ) type LinuxPlatform struct { @@ -25,7 +26,7 @@ type LinuxPlatform struct { func New() LinuxPlatform { // We cant really auto-detect this stuff in the same manner as on windows with the registry // so linux users may need to configure this manually if . - var knownInstallLocations = []string{ + knownInstallLocations := []string{ "~/.local/share/Steam", // Standard location "~/.steam/steam/Steam", } @@ -72,13 +73,13 @@ func (l LinuxPlatform) LaunchTF2(steamRoot string, args []string) error { // return errBin //} - //steamBin := path.Join(steamRoot, "steamapps/common/Team Fortress 2/hl2.sh") + // steamBin := path.Join(steamRoot, "steamapps/common/Team Fortress 2/hl2.sh") - //fa := []string{steamBin, "-applaunch", "440"} - //fa := []string{steamBin} - //fa = append(fa, args...) - //slog.Debug(fmt.Sprintf("calling %s %s", steamBin, strings.Join(fa, " "))) - //cmd := exec.Command("/bin/bash", fa...) + // fa := []string{steamBin, "-applaunch", "440"} + // fa := []string{steamBin} + // fa = append(fa, args...) + // slog.Debug(fmt.Sprintf("calling %s %s", steamBin, strings.Join(fa, " "))) + // cmd := exec.Command("/bin/bash", fa...) if errLaunch := cmd.Run(); errLaunch != nil { return errors.Join(errLaunch, ErrLaunchBinary) diff --git a/player.go b/player.go index a1b94fc..9c374cb 100644 --- a/player.go +++ b/player.go @@ -4,12 +4,12 @@ import ( "context" "database/sql" "errors" - "github.com/leighmacdonald/bd/store" "log/slog" "time" "github.com/leighmacdonald/bd-api/models" "github.com/leighmacdonald/bd/rules" + "github.com/leighmacdonald/bd/store" "github.com/leighmacdonald/steamid/v3/steamid" "github.com/leighmacdonald/steamweb/v2" ) diff --git a/process_state.go b/process_state.go index adb04f7..3f8bbc3 100644 --- a/process_state.go +++ b/process_state.go @@ -2,12 +2,13 @@ package main import ( "context" - "github.com/leighmacdonald/bd/addons" - "github.com/leighmacdonald/bd/platform" "log/slog" "os" "sync/atomic" "time" + + "github.com/leighmacdonald/bd/addons" + "github.com/leighmacdonald/bd/platform" ) type processState struct { diff --git a/rcon.go b/rcon.go index 3b94df8..fb4a415 100644 --- a/rcon.go +++ b/rcon.go @@ -4,9 +4,10 @@ import ( "context" "errors" "fmt" - "github.com/leighmacdonald/rcon/rcon" "log/slog" "time" + + "github.com/leighmacdonald/rcon/rcon" ) type rconConnection struct { diff --git a/settings.go b/settings.go index 644e71d..b4ea5b3 100644 --- a/settings.go +++ b/settings.go @@ -163,19 +163,15 @@ func (sm *settingsManager) readDefaultOrCreate() (userSettings, error) { if errRead != nil { if errors.Is(errRead, errConfigNotFound) { slog.Info("Creating default config") - defaultSettings, errNew := newSettings(sm.platform) - if errNew != nil { - return userSettings{}, errNew - } - + defaultSettings := newSettings(sm.platform) if errSave := sm.save(); errSave != nil { return settings, errSave } return defaultSettings, nil - } else { - return userSettings{}, errRead } + + return userSettings{}, errRead } return settings, nil @@ -347,7 +343,7 @@ type userSettings struct { Rcon RCONConfig `yaml:"rcon" json:"rcon"` } -func newSettings(plat platform.Platform) (userSettings, error) { +func newSettings(plat platform.Platform) userSettings { settings := userSettings{ SteamID: "", SteamDir: plat.DefaultSteamRoot(), @@ -458,7 +454,7 @@ func newSettings(plat platform.Platform) (userSettings, error) { Rcon: newRconConfig(false), } - return settings, nil + return settings } func (s *userSettings) AddList(config *ListConfig) error { diff --git a/state.go b/state.go index eb58d94..b5d7212 100644 --- a/state.go +++ b/state.go @@ -5,16 +5,16 @@ import ( "context" "errors" "fmt" - "github.com/leighmacdonald/bd/rules" - "github.com/leighmacdonald/bd/store" - "github.com/leighmacdonald/steamweb/v2" "log/slog" "net" "strings" "sync" "time" + "github.com/leighmacdonald/bd/rules" + "github.com/leighmacdonald/bd/store" "github.com/leighmacdonald/steamid/v3/steamid" + "github.com/leighmacdonald/steamweb/v2" ) var errPlayerNotFound = errors.New("player not found") @@ -74,7 +74,7 @@ func (state *playerState) update(updated Player) { state.Lock() defer state.Unlock() - valid := make([]Player, len(state.activePlayers)) + var valid []Player //nolint:prealloc for _, player := range state.activePlayers { if player.SteamID == updated.SteamID { @@ -146,7 +146,7 @@ func (state *playerState) checkPlayerState(ctx context.Context, db store.Querier if validTeam == player.Team { announcer.announceMatch(ctx, player, matchSteam) - //state.update(*player) + // state.update(*player) } } else if player.Personaname != "" { if matchName := re.MatchName(player.Personaname); matchName != nil && validTeam == player.Team { @@ -154,7 +154,7 @@ func (state *playerState) checkPlayerState(ctx context.Context, db store.Querier if validTeam == player.Team { announcer.announceMatch(ctx, player, matchName) - //state.update(*player) + // state.update(*player) } } } @@ -168,7 +168,6 @@ func (state *playerState) checkPlayerState(ctx context.Context, db store.Querier player.Dirty = false } - } type gameState struct { diff --git a/store/store.go b/store/store.go index 6d67bd3..7c6a586 100644 --- a/store/store.go +++ b/store/store.go @@ -5,10 +5,11 @@ import ( "embed" "errors" "fmt" + "log/slog" + "github.com/golang-migrate/migrate/v4" "github.com/golang-migrate/migrate/v4/database/sqlite" "github.com/golang-migrate/migrate/v4/source/iofs" - "log/slog" ) //go:embed migrations/*.sql @@ -25,13 +26,13 @@ var ( ErrPerformMigration = errors.New("failed to migrate database") ) -func CreateDb(dbPath string) (*Queries, func(), error) { +func CreateDB(dbPath string) (*Queries, func(), error) { dbConn, errDB := Connect(dbPath) if errDB != nil { return nil, nil, errDB } - var closer = func() { + closer := func() { Close(dbConn) } @@ -43,7 +44,7 @@ func CreateDb(dbPath string) (*Queries, func(), error) { } func Connect(dsn string) (*sql.DB, error) { - dsn = dsn + "?cache=shared&mode=rwc" + dsn += "?cache=shared&mode=rwc" database, errOpen := sql.Open("sqlite", dsn) if errOpen != nil { return nil, errors.Join(errOpen, ErrOpenDatabase) diff --git a/testing.go b/testing.go index d303cc3..b0d4abe 100644 --- a/testing.go +++ b/testing.go @@ -3,11 +3,12 @@ package main import ( "context" "fmt" + "math/rand" + "time" + "github.com/leighmacdonald/bd/rules" "github.com/leighmacdonald/steamid/v3/steamid" "github.com/leighmacdonald/steamweb/v2" - "math/rand" - "time" ) type mkPlayerFunc func(ctx context.Context, sid64 steamid.SID64) (Player, error) diff --git a/web.go b/web.go index 73c3210..e52413e 100644 --- a/web.go +++ b/web.go @@ -15,8 +15,8 @@ import ( "github.com/leighmacdonald/steamid/v3/steamid" ) -func newHTTPServer(ctx context.Context, listenAddr string, handler http.Handler) (*http.Server, error) { - httpServer := &http.Server{ +func newHTTPServer(ctx context.Context, listenAddr string, handler http.Handler) *http.Server { + return &http.Server{ Addr: listenAddr, Handler: handler, ReadTimeout: 10 * time.Second, @@ -25,8 +25,6 @@ func newHTTPServer(ctx context.Context, listenAddr string, handler http.Handler) return ctx }, } - - return httpServer, nil } func bind(w http.ResponseWriter, r *http.Request, receiver any) bool {