Skip to content

Commit

Permalink
go.mod: Replaced go.uber.org/atomic with sync/atomic from Go1.19. Bum…
Browse files Browse the repository at this point in the history
…ped minimum Go version to 1.19.
  • Loading branch information
Sandertv committed Aug 26, 2023
1 parent 0b0cc96 commit 92278f9
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 18 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
![telescope gopher](https://raw.githubusercontent.com/Sandertv/gophertunnel/master/gophertunnel_telescope_coloured.png)

## Overview
gophertunnel is composed of several packages that may be of use for creating Minecraft related tools. A brief
overview of all packages may be found [here](https://pkg.go.dev/mod/github.com/sandertv/gophertunnel?tab=packages).
gophertunnel is composed of several packages that may be of use for creating Minecraft related tools. Gophertunnel requires at least Go 1.19.
A brief overview of all packages may be found [here](https://pkg.go.dev/mod/github.com/sandertv/gophertunnel?tab=packages).

## Examples
Examples on how to dial a connection or start a server can be found in the [minecraft package](https://github.com/Sandertv/gophertunnel/tree/master/minecraft).
Expand Down
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/sandertv/gophertunnel

go 1.18
go 1.19

require (
github.com/go-gl/mathgl v1.0.0
Expand All @@ -10,7 +10,6 @@ require (
github.com/muhammadmuzzammil1998/jsonc v1.0.0
github.com/pelletier/go-toml v1.9.4
github.com/sandertv/go-raknet v1.12.0
go.uber.org/atomic v1.9.0
golang.org/x/net v0.7.0
golang.org/x/oauth2 v0.4.0
golang.org/x/text v0.7.0
Expand Down
6 changes: 0 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/df-mc/atomic v1.10.0 h1:0ZuxBKwR/hxcFGorKiHIp+hY7hgY+XBTzhCYD2NqSEg=
github.com/df-mc/atomic v1.10.0/go.mod h1:Gw9rf+rPIbydMjA329Jn4yjd/O2c/qusw3iNp4tFGSc=
github.com/go-gl/mathgl v1.0.0 h1:t9DznWJlXxxjeeKLIdovCOVJQk/GzDEL7h/h+Ro2B68=
Expand All @@ -22,15 +20,11 @@ github.com/muhammadmuzzammil1998/jsonc v1.0.0/go.mod h1:saF2fIVw4banK0H4+/EuqfFL
github.com/pelletier/go-toml v1.9.4 h1:tjENF6MfZAg8e4ZmZTeWaWiT2vXtsoO6+iuOjFhECwM=
github.com/pelletier/go-toml v1.9.4/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sandertv/go-raknet v1.12.0 h1:olUzZlIJyX/pgj/mrsLCZYjKLNDsYiWdvQ4NIm3z0DA=
github.com/sandertv/go-raknet v1.12.0/go.mod h1:Gx+WgZBMQ0V2UoouGoJ8Wj6CDrMBQ4SB2F/ggpl5/+Y=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE=
go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.5.0 h1:U/0M97KRkSFvyD/3FSmdP5W5swImpNgle/EHFhOsQPE=
Expand Down
17 changes: 10 additions & 7 deletions minecraft/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ import (
"github.com/sandertv/gophertunnel/minecraft/protocol/packet"
"github.com/sandertv/gophertunnel/minecraft/resource"
"github.com/sandertv/gophertunnel/minecraft/text"
"go.uber.org/atomic"
"gopkg.in/square/go-jose.v2"
"gopkg.in/square/go-jose.v2/jwt"
"io"
"log"
"net"
"strings"
"sync"
"sync/atomic"
"time"
)

Expand Down Expand Up @@ -137,7 +137,7 @@ type Conn struct {
// to this connection will call this function.
packetFunc func(header packet.Header, payload []byte, src, dst net.Addr)

disconnectMessage atomic.String
disconnectMessage atomic.Pointer[string]

shieldID atomic.Int32

Expand All @@ -164,6 +164,9 @@ func newConn(netConn net.Conn, key *ecdsa.PrivateKey, log *log.Logger, proto Pro
proto: proto,
readerLimits: limits,
}
var s string
conn.disconnectMessage.Store(&s)

if !limits {
// Disable the batch packet limit so that the server can send packets as often as it wants to.
conn.dec.DisableBatchPacketLimit()
Expand Down Expand Up @@ -564,7 +567,7 @@ func (conn *Conn) receive(data []byte) error {
if err != nil {
return err
}
conn.disconnectMessage.Store(pks[0].(*packet.Disconnect).Message)
conn.disconnectMessage.Store(&pks[0].(*packet.Disconnect).Message)
_ = conn.Close()
return nil
}
Expand Down Expand Up @@ -1302,7 +1305,7 @@ func (conn *Conn) handleSetLocalPlayerAsInitialised(pk *packet.SetLocalPlayerAsI
if pk.EntityRuntimeID != conn.gameData.EntityRuntimeID {
return fmt.Errorf("entity runtime ID mismatch: entity runtime ID in StartGame and SetLocalPlayerAsInitialised packets should be equal")
}
if conn.waitingForSpawn.CAS(true, false) {
if conn.waitingForSpawn.CompareAndSwap(true, false) {
close(conn.spawn)
}
return nil
Expand Down Expand Up @@ -1358,8 +1361,8 @@ func (conn *Conn) handlePlayStatus(pk *packet.PlayStatus) error {
// PlayStatus packets have been sent.
func (conn *Conn) tryFinaliseClientConn() {
if conn.waitingForSpawn.Load() && conn.gameDataReceived.Load() {
conn.waitingForSpawn.Toggle()
conn.gameDataReceived.Toggle()
conn.waitingForSpawn.Store(false)
conn.gameDataReceived.Store(false)

close(conn.spawn)
conn.loggedIn = true
Expand Down Expand Up @@ -1407,7 +1410,7 @@ func (conn *Conn) expect(packetIDs ...uint32) {
// closeErr returns an adequate connection closed error for the op passed. If the connection was closed
// through a Disconnect packet, the message is contained.
func (conn *Conn) closeErr(op string) error {
if msg := conn.disconnectMessage.Load(); msg != "" {
if msg := *conn.disconnectMessage.Load(); msg != "" {
return conn.wrap(DisconnectError(msg), op)
}
return conn.wrap(errClosed, op)
Expand Down
2 changes: 1 addition & 1 deletion minecraft/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import (
"github.com/sandertv/gophertunnel/minecraft/protocol"
"github.com/sandertv/gophertunnel/minecraft/protocol/packet"
"github.com/sandertv/gophertunnel/minecraft/resource"
"go.uber.org/atomic"
"log"
"net"
"os"
"sync/atomic"
"time"
)

Expand Down

0 comments on commit 92278f9

Please sign in to comment.