format repo with "gofumpt" tool
This commit is contained in:
@ -28,7 +28,7 @@ const verifyTokenLen = 16
|
||||
|
||||
// Encrypt a connection, with authentication
|
||||
func Encrypt(conn *net.Conn, name string, profilePubKey *rsa.PublicKey) (*Resp, error) {
|
||||
//generate keys
|
||||
// generate keys
|
||||
key, err := rsa.GenerateKey(rand.Reader, 1024)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -39,30 +39,30 @@ func Encrypt(conn *net.Conn, name string, profilePubKey *rsa.PublicKey) (*Resp,
|
||||
return nil, err
|
||||
}
|
||||
|
||||
//encryption request
|
||||
// encryption request
|
||||
nonce, err := encryptionRequest(conn, publicKey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
//encryption response
|
||||
// encryption response
|
||||
SharedSecret, err := encryptionResponse(conn, profilePubKey, nonce, key)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
//encryption the connection
|
||||
// encryption the connection
|
||||
block, err := aes.NewCipher(SharedSecret)
|
||||
if err != nil {
|
||||
return nil, errors.New("load aes encryption key fail")
|
||||
}
|
||||
|
||||
conn.SetCipher( //启用加密
|
||||
conn.SetCipher( // 启用加密
|
||||
CFB8.NewCFB8Encrypt(block, SharedSecret),
|
||||
CFB8.NewCFB8Decrypt(block, SharedSecret),
|
||||
)
|
||||
hash := authDigest("", SharedSecret, publicKey)
|
||||
resp, err := authentication(name, hash) //auth
|
||||
resp, err := authentication(name, hash) // auth
|
||||
if err != nil {
|
||||
return nil, errors.New("auth servers down")
|
||||
}
|
||||
@ -136,7 +136,7 @@ func encryptionResponse(conn *net.Conn, profilePubKey *rsa.PublicKey, nonce []by
|
||||
}
|
||||
}
|
||||
|
||||
//confirm to verify token
|
||||
// confirm to verify token
|
||||
SharedSecret, err := rsa.DecryptPKCS1v15(rand.Reader, key, ESharedSecret)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -15,17 +15,17 @@ func TestResp(t *testing.T) {
|
||||
}
|
||||
wantID := uuid.Must(uuid.Parse("853c80ef3c3749fdaa49938b674adae6"))
|
||||
|
||||
//check UUID
|
||||
// check UUID
|
||||
if resp.ID != wantID {
|
||||
t.Errorf("uuid doesn't match: %v, want %s", resp.ID, wantID)
|
||||
}
|
||||
|
||||
//check name
|
||||
// check name
|
||||
if resp.Name != "jeb_" {
|
||||
t.Errorf("name doesn't match: %s, want %s", resp.Name, "jeb_")
|
||||
}
|
||||
|
||||
//check texture
|
||||
// check texture
|
||||
texture, err := resp.Texture()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
@ -10,8 +10,10 @@ import (
|
||||
|
||||
// Packet758 is a packet in protocol 757.
|
||||
// We are using type system to force programmers to update packets.
|
||||
type Packet758 pk.Packet
|
||||
type Packet757 pk.Packet
|
||||
type (
|
||||
Packet758 pk.Packet
|
||||
Packet757 pk.Packet
|
||||
)
|
||||
|
||||
type WritePacketError struct {
|
||||
Err error
|
||||
|
@ -70,8 +70,10 @@ type Node struct {
|
||||
Parser Parser
|
||||
Run HandlerFunc
|
||||
}
|
||||
type Literal Node
|
||||
type Argument Node
|
||||
type (
|
||||
Literal Node
|
||||
Argument Node
|
||||
)
|
||||
|
||||
func (n *Node) parse(cmd string) (left string, value ParsedData, err error) {
|
||||
switch n.kind & 0x03 {
|
||||
|
@ -1,4 +1,6 @@
|
||||
package server
|
||||
|
||||
type Pos struct{ X, Y, Z float64 }
|
||||
type Rot struct{ Yaw, Pitch float32 }
|
||||
type (
|
||||
Pos struct{ X, Y, Z float64 }
|
||||
Rot struct{ Yaw, Pitch float32 }
|
||||
)
|
||||
|
@ -3,6 +3,7 @@ package bvh
|
||||
import (
|
||||
"container/heap"
|
||||
"fmt"
|
||||
|
||||
"golang.org/x/exp/constraints"
|
||||
)
|
||||
|
||||
@ -194,12 +195,14 @@ func TouchBound[B interface{ Touch(B) bool }](other B) func(bound B) bool {
|
||||
}
|
||||
}
|
||||
|
||||
type searchHeap[I constraints.Float, V any] []searchItem[I, V]
|
||||
type searchItem[I constraints.Float, V any] struct {
|
||||
pointer *V
|
||||
parentTo **V
|
||||
inheritedCost I
|
||||
}
|
||||
type (
|
||||
searchHeap[I constraints.Float, V any] []searchItem[I, V]
|
||||
searchItem[I constraints.Float, V any] struct {
|
||||
pointer *V
|
||||
parentTo **V
|
||||
inheritedCost I
|
||||
}
|
||||
)
|
||||
|
||||
func (h searchHeap[I, V]) Len() int { return len(h) }
|
||||
func (h searchHeap[I, V]) Less(i, j int) bool { return h[i].inheritedCost < h[j].inheritedCost }
|
||||
|
@ -1,8 +1,9 @@
|
||||
package bvh
|
||||
|
||||
import (
|
||||
"golang.org/x/exp/constraints"
|
||||
"math"
|
||||
|
||||
"golang.org/x/exp/constraints"
|
||||
)
|
||||
|
||||
type Vec2[I constraints.Signed | constraints.Float] [2]I
|
||||
@ -22,6 +23,7 @@ type Vec3[I constraints.Signed | constraints.Float] [3]I
|
||||
func (v Vec3[I]) Add(other Vec3[I]) Vec3[I] {
|
||||
return Vec3[I]{v[0] + other[0], v[1] + other[1], v[2] + other[2]}
|
||||
}
|
||||
|
||||
func (v Vec3[I]) Sub(other Vec3[I]) Vec3[I] {
|
||||
return Vec3[I]{v[0] - other[0], v[1] - other[1], v[2] - other[2]}
|
||||
}
|
||||
@ -29,6 +31,7 @@ func (v Vec3[I]) Mul(i I) Vec3[I] { return Vec3[I]{v[0] * i, v[1] * i, v[2] * i}
|
||||
func (v Vec3[I]) Max(other Vec3[I]) Vec3[I] {
|
||||
return Vec3[I]{max(v[0], other[0]), max(v[1], other[1]), max(v[2], other[2])}
|
||||
}
|
||||
|
||||
func (v Vec3[I]) Min(other Vec3[I]) Vec3[I] {
|
||||
return Vec3[I]{min(v[0], other[0]), min(v[1], other[1]), min(v[2], other[2])}
|
||||
}
|
||||
|
@ -50,14 +50,14 @@ func (s *Server) acceptListPing(conn *net.Conn) {
|
||||
}
|
||||
|
||||
switch p.ID {
|
||||
case packetid.StatusResponse: //List
|
||||
case packetid.StatusResponse: // List
|
||||
var resp []byte
|
||||
resp, err = s.listResp()
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
err = conn.WritePacket(pk.Marshal(0x00, pk.String(resp)))
|
||||
case packetid.StatusPongResponse: //Ping
|
||||
case packetid.StatusPongResponse: // Ping
|
||||
err = conn.WritePacket(p)
|
||||
}
|
||||
if err != nil {
|
||||
|
Reference in New Issue
Block a user