fix code format
This commit is contained in:
@ -13,11 +13,11 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"encoding/pem"
|
"encoding/pem"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/Tnze/go-mc/data/packetid"
|
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/Tnze/go-mc/data/packetid"
|
||||||
"github.com/Tnze/go-mc/net/CFB8"
|
"github.com/Tnze/go-mc/net/CFB8"
|
||||||
pk "github.com/Tnze/go-mc/net/packet"
|
pk "github.com/Tnze/go-mc/net/packet"
|
||||||
"github.com/Tnze/go-mc/yggdrasil/user"
|
"github.com/Tnze/go-mc/yggdrasil/user"
|
||||||
@ -40,7 +40,7 @@ func handleEncryptionRequest(c *Client, p pk.Packet) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err := loginAuth(c.Auth, key, er) //向Mojang验证
|
err := loginAuth(c.Auth, key, er) // 向Mojang验证
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("login fail: %v", err)
|
return fmt.Errorf("login fail: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
package save
|
package save
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/Tnze/go-mc/save/region"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/Tnze/go-mc/save/region"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestColumn(t *testing.T) {
|
func TestColumn(t *testing.T) {
|
||||||
@ -36,7 +37,7 @@ func BenchmarkColumn_Load(b *testing.B) {
|
|||||||
|
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
x, z := (i%1024)/32, (i%1024)%32
|
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) {
|
if !r.ExistSector(x, z) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -2,10 +2,11 @@ package server
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
_ "embed"
|
_ "embed"
|
||||||
"github.com/Tnze/go-mc/server/auth"
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
|
|
||||||
"github.com/Tnze/go-mc/net"
|
"github.com/Tnze/go-mc/net"
|
||||||
|
"github.com/Tnze/go-mc/server/auth"
|
||||||
)
|
)
|
||||||
|
|
||||||
type GamePlay interface {
|
type GamePlay interface {
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
package bvh
|
package bvh
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"golang.org/x/exp/constraints"
|
|
||||||
"math"
|
"math"
|
||||||
|
|
||||||
|
"golang.org/x/exp/constraints"
|
||||||
)
|
)
|
||||||
|
|
||||||
type AABB[I constraints.Signed | constraints.Float, V interface {
|
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 {
|
func (aabb AABB[I, V]) WithIn(point V) bool {
|
||||||
return aabb.Lower.Less(point) && aabb.Upper.More(point)
|
return aabb.Lower.Less(point) && aabb.Upper.More(point)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (aabb AABB[I, V]) Touch(other AABB[I, V]) bool {
|
func (aabb AABB[I, V]) Touch(other AABB[I, V]) bool {
|
||||||
return aabb.Lower.Less(other.Upper) && other.Lower.Less(aabb.Upper) &&
|
return aabb.Lower.Less(other.Upper) && other.Lower.Less(aabb.Upper) &&
|
||||||
aabb.Upper.More(other.Lower) && other.Upper.More(aabb.Lower)
|
aabb.Upper.More(other.Lower) && other.Upper.More(aabb.Lower)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (aabb AABB[I, V]) Union(other AABB[I, V]) AABB[I, V] {
|
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)}
|
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 {
|
func (s Sphere[I, V]) WithIn(point V) bool {
|
||||||
return s.Center.Sub(point).Norm() < s.R
|
return s.Center.Sub(point).Norm() < s.R
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s Sphere[I, V]) Touch(other Sphere[I, V]) bool {
|
func (s Sphere[I, V]) Touch(other Sphere[I, V]) bool {
|
||||||
return s.Center.Sub(other.Center).Norm() < s.R+other.R
|
return s.Center.Sub(other.Center).Norm() < s.R+other.R
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s Sphere[I, V]) Union(other Sphere[I, V]) Sphere[I, V] {
|
func (s Sphere[I, V]) Union(other Sphere[I, V]) Sphere[I, V] {
|
||||||
d := other.Center.Sub(s.Center).Norm()
|
d := other.Center.Sub(s.Center).Norm()
|
||||||
r1r2d := (s.R - other.R) / d
|
r1r2d := (s.R - other.R) / d
|
||||||
|
@ -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, 1.5})))
|
||||||
t.Log(find(TouchPoint[Vec2d, AABBVec2d](Vec2d{-1.5, 0})))
|
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{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{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.5, 0.5}, Lower: Vec2d{-2.5, -0.5}})))
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkTree_Insert(b *testing.B) {
|
func BenchmarkTree_Insert(b *testing.B) {
|
||||||
|
@ -4,8 +4,9 @@ import (
|
|||||||
"container/list"
|
"container/list"
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"github.com/Tnze/go-mc/chat"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/Tnze/go-mc/chat"
|
||||||
)
|
)
|
||||||
|
|
||||||
// keepAliveInterval represents the interval when the server sends keep alive
|
// keepAliveInterval represents the interval when the server sends keep alive
|
||||||
|
@ -2,6 +2,7 @@ package server
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/Tnze/go-mc/chat"
|
"github.com/Tnze/go-mc/chat"
|
||||||
"github.com/Tnze/go-mc/data/packetid"
|
"github.com/Tnze/go-mc/data/packetid"
|
||||||
"github.com/Tnze/go-mc/net"
|
"github.com/Tnze/go-mc/net"
|
||||||
@ -51,7 +52,7 @@ type MojangLoginHandler struct {
|
|||||||
|
|
||||||
// AcceptLogin implement LoginHandler for MojangLoginHandler
|
// 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) {
|
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
|
var p pk.Packet
|
||||||
err = conn.ReadPacket(&p)
|
err = conn.ReadPacket(&p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -69,7 +70,7 @@ func (d *MojangLoginHandler) AcceptLogin(conn *net.Conn, protocol int32) (name s
|
|||||||
profileUUID pk.UUID // ignored
|
profileUUID pk.UUID // ignored
|
||||||
)
|
)
|
||||||
err = p.Scan(
|
err = p.Scan(
|
||||||
(*pk.String)(&name), //decode username as pk.String
|
(*pk.String)(&name), // decode username as pk.String
|
||||||
&hasPubKey, pk.Opt{
|
&hasPubKey, pk.Opt{
|
||||||
Has: &hasPubKey,
|
Has: &hasPubKey,
|
||||||
Field: &pubKey,
|
Field: &pubKey,
|
||||||
@ -94,10 +95,10 @@ func (d *MojangLoginHandler) AcceptLogin(conn *net.Conn, protocol int32) (name s
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
//auth
|
// auth
|
||||||
if d.OnlineMode {
|
if d.OnlineMode {
|
||||||
var resp *auth.Resp
|
var resp *auth.Resp
|
||||||
//Auth, Encrypt
|
// Auth, Encrypt
|
||||||
resp, err = auth.Encrypt(conn, name, pubKey.PubKey)
|
resp, err = auth.Encrypt(conn, name, pubKey.PubKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
@ -110,7 +111,7 @@ func (d *MojangLoginHandler) AcceptLogin(conn *net.Conn, protocol int32) (name s
|
|||||||
id = offline.NameToUUID(name)
|
id = offline.NameToUUID(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
//set compression
|
// set compression
|
||||||
if d.Threshold >= 0 {
|
if d.Threshold >= 0 {
|
||||||
err = conn.WritePacket(pk.Marshal(
|
err = conn.WritePacket(pk.Marshal(
|
||||||
packetid.LoginCompression,
|
packetid.LoginCompression,
|
||||||
|
@ -28,14 +28,17 @@ package server
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"log"
|
||||||
|
|
||||||
"github.com/Tnze/go-mc/data/packetid"
|
"github.com/Tnze/go-mc/data/packetid"
|
||||||
"github.com/Tnze/go-mc/net"
|
"github.com/Tnze/go-mc/net"
|
||||||
pk "github.com/Tnze/go-mc/net/packet"
|
pk "github.com/Tnze/go-mc/net/packet"
|
||||||
"log"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const ProtocolName = "1.19.2"
|
const (
|
||||||
const ProtocolVersion = 760
|
ProtocolName = "1.19.2"
|
||||||
|
ProtocolVersion = 760
|
||||||
|
)
|
||||||
|
|
||||||
type Server struct {
|
type Server struct {
|
||||||
*log.Logger
|
*log.Logger
|
||||||
|
Reference in New Issue
Block a user