Skip to content

Commit 194ad5b

Browse files
authored
Update lint action (#103)
* Update lint action * Update build.yml * more
1 parent 8e11edb commit 194ad5b

File tree

6 files changed

+50
-49
lines changed

6 files changed

+50
-49
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ jobs:
1717
cache: false
1818

1919
- name: golangci-lint
20-
uses: golangci/golangci-lint-action@v6
20+
uses: golangci/golangci-lint-action@v7
2121
with:
22-
args: --timeout=10m --enable-all --disable perfsprint,varnamelen,nlreturn,depguard,wsl,nestif,tagliatelle,goerr113,cyclop,lll,funlen,gocritic,gocognit,gocyclo,exhaustivestruct,exhaustruct,maintidx
22+
args: --timeout=10m
2323

2424
- name: Run build script
2525
run: |

internal/gameServer/server.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func (g *GameServer) ManageBuffer() {
106106
}
107107
}
108108
}
109-
time.Sleep(time.Second * 5) //nolint:gomnd,mnd
109+
time.Sleep(time.Second * 5)
110110
}
111111
}
112112

@@ -125,7 +125,7 @@ func (g *GameServer) ManagePlayers() {
125125
playersActive = true
126126
} else {
127127
g.Logger.Info("play disconnected UDP", "player", i, "regID", g.Registrations[i].RegID, "address", g.GameData.PlayerAddresses[i])
128-
g.GameData.Status |= (0x1 << (i + 1)) //nolint:gomnd,mnd
128+
g.GameData.Status |= (0x1 << (i + 1))
129129

130130
g.RegistrationsMutex.Lock() // Registrations can be modified by processTCP
131131
delete(g.Registrations, i)

internal/gameServer/tcp.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ func (g *GameServer) tcpSendFile(tcpData *TCPData, conn *net.TCPConn, withSize b
5454
}
5555
} else {
5656
if withSize {
57-
size := make([]byte, 4) //nolint:gomnd,mnd
58-
binary.BigEndian.PutUint32(size, uint32(len(g.TCPFiles[tcpData.Filename]))) //nolint:gosec
57+
size := make([]byte, 4)
58+
binary.BigEndian.PutUint32(size, uint32(len(g.TCPFiles[tcpData.Filename])))
5959
_, err := conn.Write(size)
6060
if err != nil {
6161
g.Logger.Error(err, "could not write size", "address", conn.RemoteAddr().String())
@@ -123,7 +123,7 @@ func (g *GameServer) tcpSendReg(conn *net.TCPConn) {
123123
}
124124
}
125125
var i byte
126-
registrations := make([]byte, 24) //nolint:gomnd,mnd
126+
registrations := make([]byte, 24)
127127
current := 0
128128
for i = range 4 {
129129
_, ok := g.Registrations[i]
@@ -146,10 +146,10 @@ func (g *GameServer) tcpSendReg(conn *net.TCPConn) {
146146
}
147147

148148
func (g *GameServer) processTCP(conn *net.TCPConn) {
149-
defer conn.Close()
149+
defer conn.Close() //nolint:errcheck
150150

151151
tcpData := &TCPData{Request: RequestNone}
152-
incomingBuffer := make([]byte, 1500) //nolint:gomnd,mnd
152+
incomingBuffer := make([]byte, 1500)
153153
for {
154154
var readDeadline time.Time
155155
if tcpData.Buffer.Len() > 0 {
@@ -197,7 +197,7 @@ func (g *GameServer) processTCP(conn *net.TCPConn) {
197197
}
198198

199199
if tcpData.Request == RequestSendSave && tcpData.Filename != "" && tcpData.Filesize == 0 { // get file size from sender
200-
if tcpData.Buffer.Len() >= 4 { //nolint:gomnd,mnd
200+
if tcpData.Buffer.Len() >= 4 {
201201
filesizeBytes := make([]byte, 4)
202202
_, err = tcpData.Buffer.Read(filesizeBytes)
203203
if err != nil {
@@ -272,14 +272,14 @@ func (g *GameServer) processTCP(conn *net.TCPConn) {
272272
if err != nil {
273273
g.Logger.Error(err, "TCP error", "address", conn.RemoteAddr().String())
274274
}
275-
regIDBytes := make([]byte, 4) //nolint:gomnd,mnd
275+
regIDBytes := make([]byte, 4)
276276
_, err = tcpData.Buffer.Read(regIDBytes)
277277
if err != nil {
278278
g.Logger.Error(err, "TCP error", "address", conn.RemoteAddr().String())
279279
}
280280
regID := binary.BigEndian.Uint32(regIDBytes)
281281

282-
response := make([]byte, 2) //nolint:gomnd,mnd
282+
response := make([]byte, 2)
283283
_, ok := g.Registrations[playerNumber]
284284
if !ok {
285285
if playerNumber > 0 && plugin == 2 { // Only P1 can use mempak
@@ -310,7 +310,7 @@ func (g *GameServer) processTCP(conn *net.TCPConn) {
310310
response[0] = 0
311311
}
312312
}
313-
response[1] = uint8(g.BufferTarget) //nolint:gosec
313+
response[1] = uint8(g.BufferTarget)
314314
_, err = conn.Write(response)
315315
if err != nil {
316316
g.Logger.Error(err, "TCP error", "address", conn.RemoteAddr().String())
@@ -324,7 +324,7 @@ func (g *GameServer) processTCP(conn *net.TCPConn) {
324324
}
325325

326326
if tcpData.Request == RequestDisconnectNotice && tcpData.Buffer.Len() >= 4 { // disconnect notice
327-
regIDBytes := make([]byte, 4) //nolint:gomnd,mnd
327+
regIDBytes := make([]byte, 4)
328328
_, err = tcpData.Buffer.Read(regIDBytes)
329329
if err != nil {
330330
g.Logger.Error(err, "TCP error", "address", conn.RemoteAddr().String())
@@ -339,7 +339,7 @@ func (g *GameServer) processTCP(conn *net.TCPConn) {
339339

340340
g.GameDataMutex.Lock() // any player can modify this, which would be in a different thread
341341
g.GameData.PlayerAlive[i] = false
342-
g.GameData.Status |= (0x1 << (i + 1)) //nolint:gomnd,mnd
342+
g.GameData.Status |= (0x1 << (i + 1))
343343
g.GameDataMutex.Unlock()
344344

345345
g.RegistrationsMutex.Lock() // any player can modify this, which would be in a different thread
@@ -361,7 +361,7 @@ func (g *GameServer) processTCP(conn *net.TCPConn) {
361361
}
362362

363363
if tcpData.Request >= RequestSendCustomStart && tcpData.Request < RequestSendCustomStart+CustomDataOffset && tcpData.Buffer.Len() >= 4 && tcpData.CustomID == 0 { // get custom data (for example, plugin settings)
364-
dataSizeBytes := make([]byte, 4) //nolint:gomnd,mnd
364+
dataSizeBytes := make([]byte, 4)
365365
_, err = tcpData.Buffer.Read(dataSizeBytes)
366366
if err != nil {
367367
g.Logger.Error(err, "TCP error", "address", conn.RemoteAddr().String())
@@ -406,7 +406,7 @@ func (g *GameServer) watchTCP() {
406406
remoteAddr, err := net.ResolveTCPAddr(conn.RemoteAddr().Network(), conn.RemoteAddr().String())
407407
if err != nil {
408408
g.Logger.Error(err, "could not resolve remote IP")
409-
conn.Close()
409+
conn.Close() //nolint:errcheck
410410
continue
411411
}
412412
for _, v := range g.Players {
@@ -416,7 +416,7 @@ func (g *GameServer) watchTCP() {
416416
}
417417
if !validated {
418418
g.Logger.Error(fmt.Errorf("invalid tcp connection"), "bad IP", "IP", conn.RemoteAddr().String())
419-
conn.Close()
419+
conn.Close() //nolint:errcheck
420420
continue
421421
}
422422

internal/gameServer/udp.go

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ const (
5050

5151
// returns true if v is bigger than w (accounting for uint32 wrap around).
5252
func uintLarger(v uint32, w uint32) bool {
53-
return (w - v) > (math.MaxUint32 / 2) //nolint:gomnd,mnd
53+
return (w - v) > (math.MaxUint32 / 2)
5454
}
5555

5656
func (g *GameServer) getPlayerNumberByID(regID uint32) (byte, error) {
@@ -76,7 +76,7 @@ func (g *GameServer) fillInput(playerNumber byte, count uint32) InputData {
7676
}
7777

7878
func (g *GameServer) sendUDPInput(count uint32, addr *net.UDPAddr, playerNumber byte, spectator bool, sendingPlayerNumber byte) uint32 {
79-
buffer := make([]byte, 508) //nolint:gomnd,mnd
79+
buffer := make([]byte, 508)
8080
var countLag uint32
8181
if uintLarger(count, g.GameData.LeadCount) {
8282
if !spectator {
@@ -93,7 +93,7 @@ func (g *GameServer) sendUDPInput(count uint32, addr *net.UDPAddr, playerNumber
9393
}
9494
buffer[1] = playerNumber
9595
buffer[2] = g.GameData.Status
96-
buffer[3] = uint8(countLag) //nolint:gosec
96+
buffer[3] = uint8(countLag)
9797
currentByte := 5
9898
start := count
9999
end := start + g.GameData.BufferSize[sendingPlayerNumber]
@@ -111,7 +111,7 @@ func (g *GameServer) sendUDPInput(count uint32, addr *net.UDPAddr, playerNumber
111111
}
112112

113113
if count > start {
114-
buffer[4] = uint8(count - start) //nolint:gosec // number of counts in packet
114+
buffer[4] = uint8(count - start) // number of counts in packet
115115
_, err := g.UDPListener.WriteToUDP(buffer[0:currentByte], addr)
116116
if err != nil {
117117
g.Logger.Error(err, "could not send input")
@@ -122,7 +122,8 @@ func (g *GameServer) sendUDPInput(count uint32, addr *net.UDPAddr, playerNumber
122122

123123
func (g *GameServer) processUDP(addr *net.UDPAddr, buf []byte) {
124124
playerNumber := buf[1]
125-
if buf[0] == KeyInfoClient {
125+
switch buf[0] {
126+
case KeyInfoClient:
126127
g.GameData.PlayerAddresses[playerNumber] = addr
127128
count := binary.BigEndian.Uint32(buf[2:])
128129

@@ -134,7 +135,7 @@ func (g *GameServer) processUDP(addr *net.UDPAddr, buf []byte) {
134135
g.sendUDPInput(count, g.GameData.PlayerAddresses[i], playerNumber, true, NoRegID)
135136
}
136137
}
137-
} else if buf[0] == PlayerInputRequest {
138+
case PlayerInputRequest:
138139
regID := binary.BigEndian.Uint32(buf[2:])
139140
count := binary.BigEndian.Uint32(buf[6:])
140141
spectator := buf[10]
@@ -154,7 +155,7 @@ func (g *GameServer) processUDP(addr *net.UDPAddr, buf []byte) {
154155
g.GameDataMutex.Unlock()
155156

156157
g.GameData.CountLag[sendingPlayerNumber] = countLag
157-
} else if buf[0] == CP0Info {
158+
case CP0Info:
158159
if g.GameData.Status&StatusDesync == 0 {
159160
viCount := binary.BigEndian.Uint32(buf[1:])
160161
syncValue, ok := g.GameData.SyncValues[viCount]
@@ -173,7 +174,7 @@ func (g *GameServer) processUDP(addr *net.UDPAddr, buf []byte) {
173174

174175
func (g *GameServer) watchUDP() {
175176
for {
176-
buf := make([]byte, 1500) //nolint:gomnd,mnd
177+
buf := make([]byte, 1500)
177178
_, addr, err := g.UDPListener.ReadFromUDP(buf)
178179
if err != nil && !g.isConnClosed(err) {
179180
g.Logger.Error(err, "error from UdpListener")
@@ -201,28 +202,28 @@ func (g *GameServer) createUDPServer() error {
201202
var err error
202203
g.UDPListener, err = net.ListenUDP("udp", &net.UDPAddr{Port: g.Port})
203204
if err != nil {
204-
return err //nolint:wrapcheck
205+
return err
205206
}
206-
if err := ipv4.NewConn(g.UDPListener).SetTOS(CS4 << 2); err != nil { //nolint:gomnd,mnd
207+
if err := ipv4.NewConn(g.UDPListener).SetTOS(CS4 << 2); err != nil {
207208
g.Logger.Error(err, "could not set IPv4 DSCP")
208209
}
209-
if err := ipv6.NewConn(g.UDPListener).SetTrafficClass(CS4 << 2); err != nil { //nolint:gomnd,mnd
210+
if err := ipv6.NewConn(g.UDPListener).SetTrafficClass(CS4 << 2); err != nil {
210211
g.Logger.Error(err, "could not set IPv6 DSCP")
211212
}
212213
g.Logger.Info("Created UDP server", "port", g.Port)
213214

214-
g.GameData.PlayerAddresses = make([]*net.UDPAddr, 4) //nolint:gomnd,mnd
215+
g.GameData.PlayerAddresses = make([]*net.UDPAddr, 4)
215216
g.GameData.BufferSize = []uint32{3, 3, 3, 3}
216217
g.GameData.BufferHealth = []int32{-1, -1, -1, -1}
217-
g.GameData.Inputs = make([]*lru.Cache[uint32, InputData], 4) //nolint:gomnd,mnd
218+
g.GameData.Inputs = make([]*lru.Cache[uint32, InputData], 4)
218219
for i := range 4 {
219220
g.GameData.Inputs[i], _ = lru.New[uint32, InputData](InputDataMax)
220221
}
221-
g.GameData.PendingInput = make([]uint32, 4) //nolint:gomnd,mnd
222-
g.GameData.PendingPlugin = make([]byte, 4) //nolint:gomnd,mnd
222+
g.GameData.PendingInput = make([]uint32, 4)
223+
g.GameData.PendingPlugin = make([]byte, 4)
223224
g.GameData.SyncValues = make(map[uint32][]byte)
224-
g.GameData.PlayerAlive = make([]bool, 4) //nolint:gomnd,mnd
225-
g.GameData.CountLag = make([]uint32, 4) //nolint:gomnd,mnd
225+
g.GameData.PlayerAlive = make([]bool, 4)
226+
g.GameData.CountLag = make([]uint32, 4)
226227

227228
go g.watchUDP()
228229
return nil

internal/lobbyServer/lobby.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ func (s *LobbyServer) updatePlayers(g *gameserver.GameServer) {
132132
return
133133
}
134134
var sendMessage SocketMessage
135-
sendMessage.PlayerNames = make([]string, 4) //nolint:gomnd,mnd
135+
sendMessage.PlayerNames = make([]string, 4)
136136
sendMessage.Type = TypeReplyPlayers
137137
for i, v := range g.Players {
138138
if v.InLobby {
@@ -194,7 +194,7 @@ func (s *LobbyServer) publishDiscord(message string, channel string) {
194194
if err != nil {
195195
s.Logger.Error(err, "could not send request")
196196
} else {
197-
resp.Body.Close()
197+
resp.Body.Close() //nolint:errcheck
198198
}
199199
}
200200

@@ -231,7 +231,7 @@ func (s *LobbyServer) watchGameServer(name string, g *gameserver.GameServer) {
231231
g.PlayersMutex.Unlock()
232232
s.updatePlayers(g)
233233
}
234-
time.Sleep(time.Second * 5) //nolint:gomnd,mnd
234+
time.Sleep(time.Second * 5)
235235
}
236236
}
237237

@@ -250,7 +250,7 @@ func (s *LobbyServer) validateAuth(receivedMessage SocketMessage) bool {
250250

251251
timeDifference := now.Sub(receivedTime)
252252
absTimeDifference := time.Duration(math.Abs(float64(timeDifference)))
253-
maxAllowableDifference := 15 * time.Minute //nolint:gomnd,mnd
253+
maxAllowableDifference := 15 * time.Minute
254254

255255
if absTimeDifference > maxAllowableDifference {
256256
s.Logger.Error(fmt.Errorf("clock skew"), "bad time in auth request", "serverTime", now, "clientTime", receivedTime, "emulator", receivedMessage.Emulator)
@@ -271,7 +271,7 @@ func (s *LobbyServer) validateAuth(receivedMessage SocketMessage) bool {
271271

272272
func (s *LobbyServer) wsHandler(ws *websocket.Conn) {
273273
authenticated := false
274-
defer ws.Close()
274+
defer ws.Close() //nolint:errcheck
275275

276276
// s.Logger.Info("new WS connection", "address", ws.Request().RemoteAddr)
277277

@@ -522,7 +522,7 @@ func (s *LobbyServer) wsHandler(ws *websocket.Conn) {
522522
} else if g.MD5 != receivedMessage.Room.MD5 {
523523
accepted = MismatchVersion
524524
message = "ROM does not match room ROM"
525-
} else if len(g.Players) >= 4 { //nolint:gomnd,mnd
525+
} else if len(g.Players) >= 4 {
526526
accepted = RoomFull
527527
message = "Room is full"
528528
} else if g.Running {
@@ -644,9 +644,9 @@ func (s *LobbyServer) wsHandler(ws *websocket.Conn) {
644644
}
645645
}
646646
if privateNetwork {
647-
g.BufferTarget = 1 //nolint:gomnd
647+
g.BufferTarget = 1
648648
} else {
649-
g.BufferTarget = 2 //nolint:gomnd
649+
g.BufferTarget = 2
650650
}
651651
}
652652

@@ -693,7 +693,7 @@ func (s *LobbyServer) getOutboundIP(dest *net.UDPAddr) (net.IP, error) {
693693
if err != nil {
694694
return nil, fmt.Errorf("error creating udp %s", err.Error())
695695
}
696-
defer conn.Close()
696+
defer conn.Close() //nolint:errcheck
697697
localAddr, ok := conn.LocalAddr().(*net.UDPAddr)
698698
if !ok {
699699
return nil, fmt.Errorf("failed to parse address")
@@ -734,11 +734,11 @@ func (s *LobbyServer) runBroadcastServer(broadcastPort int) {
734734
s.Logger.Error(err, "could not listen for broadcasts")
735735
return
736736
}
737-
defer broadcastServer.Close()
737+
defer broadcastServer.Close() //nolint:errcheck
738738

739739
s.Logger.Info("listening for broadcasts")
740740
for {
741-
buf := make([]byte, 1500) //nolint:gomnd,mnd
741+
buf := make([]byte, 1500)
742742
_, addr, err := broadcastServer.ReadFromUDP(buf)
743743
if err != nil {
744744
s.Logger.Error(err, "error reading broadcast packet")
@@ -763,7 +763,7 @@ func (s *LobbyServer) RunSocketServer(broadcastPort int) error {
763763

764764
s.Logger.Info("server running", "address", listenAddress, "version", getVersion(), "platform", runtime.GOOS, "arch", runtime.GOARCH, "goversion", runtime.Version(), "enable-auth", s.EnableAuth)
765765

766-
err := http.ListenAndServe(listenAddress, nil) //nolint:gosec
766+
err := http.ListenAndServe(listenAddress, nil)
767767
if err != nil {
768768
return fmt.Errorf("error listening on http port %s", err.Error())
769769
}

main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func newZap(logPath string) (*zap.Logger, error) {
2323
if logPath != "" {
2424
cfg.OutputPaths = append(cfg.OutputPaths, logPath)
2525
}
26-
return cfg.Build() //nolint:wrapcheck
26+
return cfg.Build()
2727
}
2828

2929
func main() {
@@ -32,7 +32,7 @@ func main() {
3232
disableBroadcast := flag.Bool("disable-broadcast", false, "Disable LAN broadcast")
3333
logPath := flag.String("log-path", "", "Write logs to this file")
3434
motd := flag.String("motd", "", "MOTD message to display to clients")
35-
maxGames := flag.Int("max-games", 10, "Maximum number of concurrent games") //nolint:gomnd,mnd
35+
maxGames := flag.Int("max-games", 10, "Maximum number of concurrent games")
3636
enableAuth := flag.Bool("enable-auth", false, "Enable client authentication")
3737
flag.Parse()
3838

0 commit comments

Comments
 (0)