Skip to content

Commit

Permalink
feat: bump go to 1.21 (#13)
Browse files Browse the repository at this point in the history
* feat: bump go to 1.21

* feat: upgrade deps

* test: fix flaky prober test
  • Loading branch information
sergeii authored Aug 15, 2023
1 parent 01f01a9 commit d8ff485
Show file tree
Hide file tree
Showing 21 changed files with 148 additions and 94 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ name: ci

on: [push]

env:
GOEXPERIMENT: loopvar

jobs:
meta:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -48,7 +51,8 @@ jobs:
- name: Run golangci
uses: golangci/golangci-lint-action@v3
with:
version: v1.51.2
version: v1.54.1
install-mode: "goinstall"

smoke-binary:
runs-on: ubuntu-latest
Expand Down
2 changes: 2 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ linters:
- maintidx
- misspell
- dupword
- depguard
- structcheck
linters-settings:
cyclop:
max-complexity: 10
Expand Down
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0
rev: v4.4.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/dnephin/pre-commit-golang
rev: v0.4.0
rev: v0.5.1
hooks:
- id: go-fmt
- id: go-imports
Expand Down
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.20-alpine AS build
FROM golang:1.21-alpine AS build

ARG build_commit_sha="-"
ARG build_version="-"
Expand All @@ -7,6 +7,7 @@ ARG build_time="-"
ENV CGO_ENABLED=0
ENV GOOS=linux
ENV GOARCH=amd64
ENV GOEXPERIMENT=loopvar
ENV PATH=/go/bin/linux_amd64:$PATH

ARG _pkg="github.com/sergeii/swat4master/cmd/swat4master"
Expand Down
66 changes: 50 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# SWAT4 Master Server

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![GitHub go.mod Go version of a Go module](https://img.shields.io/github/go-mod/go-version/sergeii/swat4master.svg)](https://tip.golang.org/doc/go1.20)
[![ci](https://github.com/sergeii/swat4master/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/sergeii/swat4master/actions/workflows/ci.yml)
[![codecov](https://codecov.io/gh/sergeii/swat4master/branch/main/graph/badge.svg?token=ZYQ1x62kR3)](https://codecov.io/gh/sergeii/swat4master)
[![Go Report Card](https://goreportcard.com/badge/github.com/sergeii/swat4master)](https://goreportcard.com/report/github.com/sergeii/swat4master)
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/007d7e28f8ba4f63a56dc1bd095bb2b2)](https://www.codacy.com/gh/sergeii/swat4master/dashboard?utm_source=github.com&utm_medium=referral&utm_content=sergeii/swat4master&utm_campaign=Badge_Grade)
[![Uptime](https://img.shields.io/uptimerobot/ratio/m791541581-aa817e2819dfd400d3cf3bd9)](https://updown.io/p/h6vfe)
[![License: MIT][mit-img]][mit]
[![GitHub go.mod Go version of a Go module][go-version-img]][go-version]
[![ci][ci-img]][ci]
[![codecov][codecov-img]][codecov]
[![Go Report Card][go-report-img]][go-report]
[![Codacy Badge][codacy-img]][codacy]
[![Uptime][uptime-img]][uptime]

## Description
This project implements the GameSpy master server protocol
Expand All @@ -15,27 +15,27 @@ Namely, it accepts heartbeat requests from game servers
and allows players to browse these servers from the in-game server list.

Backed by this project and widely accepted in the community,
the master server is available for use by players and server owners either with [a patch](https://github.com/sergeii/swat-patches/tree/master/swat4stats-masterserver) or
with a [hosts](https://www.howtogeek.com/howto/27350/beginner-geek-how-to-edit-your-hosts-file/) file adjustment:
the master server is available for use by players and server owners either with [a patch][master-server-patch] or
with a [hosts][fix-hosts-tutorial] file adjustment:
```
116.202.1.82 swat4.available.gamespy.com
116.202.1.82 swat4.master.gamespy.com
116.202.1.82 swat4.ms15.gamespy.com
```

## Background
GameSpy shut down its services in 2014, rendering multiplayer for [a good share of games](https://www.reddit.com/r/Games/comments/22fz75/list_of_games_affected_by_gamespy_shutdown/) unusable.
For SWAT4, however, [it happened a year earlier](https://www.pcgamer.com/gamespy-shuts-down-multiplayer-support-for-swat-4-neverwinter-nights-and-other-classics/).
GameSpy shut down its services in 2014, rendering multiplayer for [a good share of games][gamespy-shutdown-global] unusable.
For SWAT4, however, [it happened a year earlier][gamespy-shutdown-swat4].

In 2013, I launched [swat4stats.com](https://swat4stats.com/) [[GitHub](https://github.com/sergeii/swat4stats.com)],
In 2013, I launched [swat4stats.com](https://swat4stats.com/) [[GitHub][swat4stats-github]]],
a player statistics tracking service for SWAT4. The core feature set in [swat4stats.com](https://swat4stats.com/)
has always been about statistics and numbers. However, one of its extra features, the live server browser,
has quickly become the most popular part of the service thanks to the GameSpy shutdown.

<img src="https://user-images.githubusercontent.com/4739840/164216907-1d69d6d5-558c-4c96-9533-7e616911f8e7.png" alt="drawing" width="600" />


A couple of years later, with the help of the SWAT4 community and research articles published by [Luigi Auriemma](http://aluigi.altervista.org/papers.htm#distrust),
A couple of years later, with the help of the SWAT4 community and research articles published by [Luigi Auriemma][luigi-auriemma],
I was able to reverse engineer the protocols used by the game, and then reimplement the master server functionality,
returning servers back to the in-game server browser:

Expand All @@ -46,12 +46,46 @@ If for any reason you wish to run your own instance of this service you can do i
```
docker run --rm ghcr.io/sergeii/swat4master:latest
```
For other tags see [container registry](https://github.com/sergeii/swat4master/pkgs/container/swat4master/versions).
For other tags see [container registry][packages].

Alternatively you can download and run a server binary suitable for your platform from one of the [releases](https://github.com/sergeii/swat4master/releases).
Alternatively you can download and run a server binary suitable for your platform from one of the [releases][releases].

## Building from source
To build the project from source you need Go 1.20+
To build the project from source you need Go 1.21+
```
go build -o swat4master cmd/swat4master/main.go
```

---
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.

[mit-img]: https://img.shields.io/badge/License-MIT-yellow.svg
[mit]: https://opensource.org/licenses/MIT

[go-version-img]: https://img.shields.io/github/go-mod/go-version/sergeii/swat4master.svg
[go-version]: https://tip.golang.org/doc/go1.21

[ci-img]: https://github.com/sergeii/swat4master/actions/workflows/ci.yml/badge.svg?branch=main
[ci]: https://github.com/sergeii/swat4master/actions/workflows/ci.yml

[codecov-img]: https://codecov.io/gh/sergeii/swat4master/branch/main/graph/badge.svg?token=ZYQ1x62kR3
[codecov]: https://codecov.io/gh/sergeii/swat4master

[go-report-img]: https://goreportcard.com/badge/github.com/sergeii/swat4master
[go-report]: https://goreportcard.com/report/github.com/sergeii/swat4master

[codacy-img]: https://app.codacy.com/project/badge/Grade/007d7e28f8ba4f63a56dc1bd095bb2b2
[codacy]: https://www.codacy.com/gh/sergeii/swat4master/dashboard

[uptime-img]: https://img.shields.io/uptimerobot/ratio/m791541581-aa817e2819dfd400d3cf3bd9
[uptime]: https://status.master.swat4stats.com

[packages]: https://github.com/sergeii/swat4master/pkgs/container/swat4master/versions
[releases]: https://github.com/sergeii/swat4master/releases

[swat4stats-github]: https://github.com/sergeii/swat4stats
[fix-hosts-tutorial]: https://www.howtogeek.com/27350/beginner-geek-how-to-edit-your-hosts-file/
[master-server-patch]: https://github.com/sergeii/swat-patches/tree/master/swat4stats-masterserver
[gamespy-shutdown-global]: https://www.reddit.com/r/Games/comments/22fz75/list_of_games_affected_by_gamespy_shutdown/
[gamespy-shutdown-swat4]: https://www.pcgamer.com/gamespy-shuts-down-multiplayer-support-for-swat-4-neverwinter-nights-and-other-classics/
[luigi-auriemma]: http://aluigi.altervista.org/papers.htm#distrust
5 changes: 0 additions & 5 deletions cmd/swat4master/modules/browser/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import (
"context"
"fmt"
"net"

"github.com/sergeii/swat4master/pkg/logutils"
)

func (h *Handler) Handle(ctx context.Context, conn *net.TCPConn) {
Expand All @@ -23,9 +21,6 @@ func (h *Handler) Handle(ctx context.Context, conn *net.TCPConn) {
h.logger.Debug().
Int("len", len(req)).Stringer("src", conn.RemoteAddr()).
Msg("Received server browser request")
if e := h.logger.Debug(); e.Enabled() {
logutils.Hexdump(req) // nolint: errcheck
}

h.metrics.BrowserReceived.Add(float64(len(req)))

Expand Down
7 changes: 4 additions & 3 deletions cmd/swat4master/modules/prober/prober.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package prober

import (
"context"
"time"

"github.com/benbjohnson/clock"
"github.com/rs/zerolog"
Expand Down Expand Up @@ -38,11 +37,12 @@ func Run(
stop chan struct{},
stopped chan struct{},
logger *zerolog.Logger,
clock clock.Clock,
queue *probe.Service,
wg *WorkerGroup,
cfg config.Config,
) {
ticker := time.NewTicker(cfg.ProbePollSchedule)
ticker := clock.Ticker(cfg.ProbePollSchedule)
defer ticker.Stop()

ctx, cancel := context.WithCancel(context.Background())
Expand Down Expand Up @@ -79,6 +79,7 @@ type Params struct {
func NewProber(
lc fx.Lifecycle,
cfg config.Config,
clock clock.Clock,
queue *probe.Service,
wg *WorkerGroup,
logger *zerolog.Logger,
Expand All @@ -89,7 +90,7 @@ func NewProber(

lc.Append(fx.Hook{
OnStart: func(context.Context) error {
go Run(stop, stopped, logger, queue, wg, cfg) // nolint: contextcheck
go Run(stop, stopped, logger, clock, queue, wg, cfg) // nolint: contextcheck
return nil
},
OnStop: func(context.Context) error {
Expand Down
6 changes: 3 additions & 3 deletions cmd/swat4master/modules/prober/prober_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func TestProber_Run(t *testing.T) {
DiscoveryRevivalScope: time.Second,
DiscoveryRevivalPorts: []int{1},
ProbeConcurrency: 5,
ProbePollSchedule: time.Millisecond,
ProbePollSchedule: time.Millisecond * 50, // speed up the test
ProbeRetries: 2,
ProbeTimeout: time.Millisecond * 100,
}
Expand All @@ -168,8 +168,8 @@ func TestProber_Run(t *testing.T) {
}()
runtime.Gosched()

for i := 0; i < 10; i++ {
clockMock.Add(time.Millisecond * 100)
for i := 0; i < 100; i++ {
clockMock.Add(time.Millisecond * 10)
}

updatedSvr1, _ := repos.Servers.Get(ctx, svr1.GetAddr())
Expand Down
10 changes: 1 addition & 9 deletions cmd/swat4master/modules/reporter/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@ import (
"go.uber.org/fx"

"github.com/sergeii/swat4master/cmd/swat4master/config"
"github.com/sergeii/swat4master/internal/services/monitoring"
"github.com/sergeii/swat4master/pkg/logutils"

"github.com/sergeii/swat4master/internal/services/master/reporting"
"github.com/sergeii/swat4master/internal/services/monitoring"
udp "github.com/sergeii/swat4master/pkg/udp/server"
)

Expand Down Expand Up @@ -46,9 +44,6 @@ func (h *Handler) Handle(
h.logger.Debug().
Str("type", fmt.Sprintf("0x%02x", req[0])).Stringer("src", addr).Int("len", len(req)).
Msg("Received request")
if e := h.logger.Debug(); e.Enabled() {
logutils.Hexdump(req) // nolint: errcheck
}

h.metrics.ReporterReceived.Add(float64(len(req)))

Expand All @@ -66,9 +61,6 @@ func (h *Handler) Handle(
h.logger.Debug().
Stringer("dst", addr).Int("len", len(resp)).
Msg("Sending response")
if e := h.logger.Debug(); e.Enabled() {
logutils.Hexdump(resp) // nolint: errcheck
}
if _, err := conn.WriteToUDP(resp, addr); err != nil {
h.logger.Error().
Err(err).Stringer("dst", addr).Int("len", len(resp)).
Expand Down
30 changes: 16 additions & 14 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
module github.com/sergeii/swat4master

go 1.20
go 1.21

require (
github.com/benbjohnson/clock v1.3.4
github.com/gin-gonic/gin v1.9.0
github.com/go-playground/validator/v10 v10.13.0
github.com/benbjohnson/clock v1.3.5
github.com/gin-gonic/gin v1.9.1
github.com/go-playground/validator/v10 v10.15.0
github.com/gosimple/slug v1.13.1
github.com/prometheus/client_golang v1.15.1
github.com/prometheus/client_golang v1.16.0
github.com/prometheus/client_model v0.4.0
github.com/prometheus/common v0.43.0
github.com/rs/zerolog v1.29.1
github.com/stretchr/testify v1.8.2
github.com/prometheus/common v0.44.0
github.com/rs/zerolog v1.30.0
github.com/stretchr/testify v1.8.4
github.com/swaggo/files v1.0.1
github.com/swaggo/gin-swagger v1.6.0
github.com/swaggo/swag v1.16.1
go.uber.org/fx v1.19.3
golang.org/x/text v0.9.0
go.uber.org/fx v1.20.0
golang.org/x/text v0.12.0
)

require (
github.com/KyleBanks/depth v1.2.1 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bytedance/sonic v1.8.8 // indirect
github.com/bytedance/sonic v1.9.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
Expand All @@ -42,13 +43,14 @@ require (
github.com/leodido/go-urn v1.2.4 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.18 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pelletier/go-toml/v2 v2.0.7 // indirect
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/procfs v0.9.0 // indirect
github.com/prometheus/procfs v0.10.1 // indirect
github.com/stretchr/objx v0.5.0 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.11 // indirect
go.uber.org/atomic v1.11.0 // indirect
Expand Down
Loading

0 comments on commit d8ff485

Please sign in to comment.