diff --git a/bot/login.go b/bot/login.go index 3e51a0e..5dd67fa 100644 --- a/bot/login.go +++ b/bot/login.go @@ -13,11 +13,11 @@ import ( "encoding/json" "encoding/pem" "fmt" - "github.com/Tnze/go-mc/data/packetid" "io" "net/http" "strings" + "github.com/Tnze/go-mc/data/packetid" "github.com/Tnze/go-mc/net/CFB8" pk "github.com/Tnze/go-mc/net/packet" "github.com/Tnze/go-mc/yggdrasil/user" @@ -40,7 +40,7 @@ func handleEncryptionRequest(c *Client, p pk.Packet) error { return err } - err := loginAuth(c.Auth, key, er) //向Mojang验证 + err := loginAuth(c.Auth, key, er) // 向Mojang验证 if err != nil { return fmt.Errorf("login fail: %v", err) } diff --git a/save/chunk_test.go b/save/chunk_test.go index 19403e5..e85703f 100644 --- a/save/chunk_test.go +++ b/save/chunk_test.go @@ -1,8 +1,9 @@ package save import ( - "github.com/Tnze/go-mc/save/region" "testing" + + "github.com/Tnze/go-mc/save/region" ) func TestColumn(t *testing.T) { @@ -36,7 +37,7 @@ func BenchmarkColumn_Load(b *testing.B) { for i := 0; i < b.N; i++ { x, z := (i%1024)/32, (i%1024)%32 - //x, z := rand.Intn(32), rand.Intn(32) + // x, z := rand.Intn(32), rand.Intn(32) if !r.ExistSector(x, z) { continue } diff --git a/server/gameplay.go b/server/gameplay.go index cd89e80..82aa060 100644 --- a/server/gameplay.go +++ b/server/gameplay.go @@ -2,10 +2,11 @@ package server import ( _ "embed" - "github.com/Tnze/go-mc/server/auth" + "github.com/google/uuid" "github.com/Tnze/go-mc/net" + "github.com/Tnze/go-mc/server/auth" ) type GamePlay interface { diff --git a/server/internal/bvh/bound.go b/server/internal/bvh/bound.go index ce9758a..6b480cb 100644 --- a/server/internal/bvh/bound.go +++ b/server/internal/bvh/bound.go @@ -1,8 +1,9 @@ package bvh import ( - "golang.org/x/exp/constraints" "math" + + "golang.org/x/exp/constraints" ) type AABB[I constraints.Signed | constraints.Float, V interface { @@ -18,10 +19,12 @@ type AABB[I constraints.Signed | constraints.Float, V interface { func (aabb AABB[I, V]) WithIn(point V) bool { return aabb.Lower.Less(point) && aabb.Upper.More(point) } + func (aabb AABB[I, V]) Touch(other AABB[I, V]) bool { return aabb.Lower.Less(other.Upper) && other.Lower.Less(aabb.Upper) && aabb.Upper.More(other.Lower) && other.Upper.More(aabb.Lower) } + func (aabb AABB[I, V]) Union(other AABB[I, V]) AABB[I, V] { return AABB[I, V]{Upper: aabb.Upper.Max(other.Upper), Lower: aabb.Lower.Min(other.Lower)} } @@ -45,9 +48,11 @@ type Sphere[I constraints.Float, V interface { func (s Sphere[I, V]) WithIn(point V) bool { return s.Center.Sub(point).Norm() < s.R } + func (s Sphere[I, V]) Touch(other Sphere[I, V]) bool { return s.Center.Sub(other.Center).Norm() < s.R+other.R } + func (s Sphere[I, V]) Union(other Sphere[I, V]) Sphere[I, V] { d := other.Center.Sub(s.Center).Norm() r1r2d := (s.R - other.R) / d diff --git a/server/internal/bvh/bvh_test.go b/server/internal/bvh/bvh_test.go index 6103fc2..2c40bac 100644 --- a/server/internal/bvh/bvh_test.go +++ b/server/internal/bvh/bvh_test.go @@ -58,9 +58,9 @@ func TestTree2_Find_vec(t *testing.T) { t.Log(find(TouchPoint[Vec2d, AABBVec2d](Vec2d{1.5, 1.5}))) t.Log(find(TouchPoint[Vec2d, AABBVec2d](Vec2d{-1.5, 0}))) - t.Log(find(TouchBound[AABBVec2d](AABBVec2d{Upper: Vec2d{1, 1}, Lower: Vec2d{-1, -1}}))) - t.Log(find(TouchBound[AABBVec2d](AABBVec2d{Upper: Vec2d{1, 1}, Lower: Vec2d{1.5, 1.5}}))) - t.Log(find(TouchBound[AABBVec2d](AABBVec2d{Upper: Vec2d{-1.5, 0.5}, Lower: Vec2d{-2.5, -0.5}}))) + t.Log(find(TouchBound(AABBVec2d{Upper: Vec2d{1, 1}, Lower: Vec2d{-1, -1}}))) + t.Log(find(TouchBound(AABBVec2d{Upper: Vec2d{1, 1}, Lower: Vec2d{1.5, 1.5}}))) + t.Log(find(TouchBound(AABBVec2d{Upper: Vec2d{-1.5, 0.5}, Lower: Vec2d{-2.5, -0.5}}))) } func BenchmarkTree_Insert(b *testing.B) { diff --git a/server/keepalive.go b/server/keepalive.go index 42ff727..2837476 100644 --- a/server/keepalive.go +++ b/server/keepalive.go @@ -4,8 +4,9 @@ import ( "container/list" "context" "errors" - "github.com/Tnze/go-mc/chat" "time" + + "github.com/Tnze/go-mc/chat" ) // keepAliveInterval represents the interval when the server sends keep alive diff --git a/server/login.go b/server/login.go index d79d4b6..db4a9bb 100644 --- a/server/login.go +++ b/server/login.go @@ -2,6 +2,7 @@ package server import ( "fmt" + "github.com/Tnze/go-mc/chat" "github.com/Tnze/go-mc/data/packetid" "github.com/Tnze/go-mc/net" @@ -51,7 +52,7 @@ type MojangLoginHandler struct { // AcceptLogin implement LoginHandler for MojangLoginHandler func (d *MojangLoginHandler) AcceptLogin(conn *net.Conn, protocol int32) (name string, id uuid.UUID, profilePubKey *auth.PublicKey, properties []auth.Property, err error) { - //login start + // login start var p pk.Packet err = conn.ReadPacket(&p) if err != nil { @@ -69,7 +70,7 @@ func (d *MojangLoginHandler) AcceptLogin(conn *net.Conn, protocol int32) (name s profileUUID pk.UUID // ignored ) err = p.Scan( - (*pk.String)(&name), //decode username as pk.String + (*pk.String)(&name), // decode username as pk.String &hasPubKey, pk.Opt{ Has: &hasPubKey, Field: &pubKey, @@ -94,10 +95,10 @@ func (d *MojangLoginHandler) AcceptLogin(conn *net.Conn, protocol int32) (name s return } - //auth + // auth if d.OnlineMode { var resp *auth.Resp - //Auth, Encrypt + // Auth, Encrypt resp, err = auth.Encrypt(conn, name, pubKey.PubKey) if err != nil { return @@ -110,7 +111,7 @@ func (d *MojangLoginHandler) AcceptLogin(conn *net.Conn, protocol int32) (name s id = offline.NameToUUID(name) } - //set compression + // set compression if d.Threshold >= 0 { err = conn.WritePacket(pk.Marshal( packetid.LoginCompression, diff --git a/server/server.go b/server/server.go index 3836caf..8a2d23c 100644 --- a/server/server.go +++ b/server/server.go @@ -28,14 +28,17 @@ package server import ( "errors" + "log" + "github.com/Tnze/go-mc/data/packetid" "github.com/Tnze/go-mc/net" pk "github.com/Tnze/go-mc/net/packet" - "log" ) -const ProtocolName = "1.19.2" -const ProtocolVersion = 760 +const ( + ProtocolName = "1.19.2" + ProtocolVersion = 760 +) type Server struct { *log.Logger