Skip to content

Commit

Permalink
Merge branch 'LNSSPsd:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
chfwd authored Jan 7, 2023
2 parents e158f28 + b3e6292 commit 2fb34b9
Show file tree
Hide file tree
Showing 71 changed files with 634 additions and 407 deletions.
92 changes: 7 additions & 85 deletions fastbuilder/core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@ import (
"fmt"
"time"
"bufio"
"bytes"
"strings"
"runtime"
"runtime/debug"
"path/filepath"
"encoding/json"
"encoding/binary"
fbtask "phoenixbuilder/fastbuilder/task"
"phoenixbuilder/omega/suggest"
script_bridge "phoenixbuilder/fastbuilder/script_engine/bridge"
Expand Down Expand Up @@ -167,7 +165,7 @@ func InitClient(env *environment.PBEnvironment) {
),
// EnableClientCache: true,
}
cconn, err := dialer.Dial("raknet", "")
cconn, err := dialer.Dial("raknet")

if err != nil {
pterm.Error.Println(err)
Expand Down Expand Up @@ -195,7 +193,7 @@ func InitClient(env *environment.PBEnvironment) {
})
env.UQHolder = uqHolder.NewUQHolder(conn.GameData().EntityRuntimeID)
env.UQHolder.(*uqHolder.UQHolder).UpdateFromConn(conn)
env.UQHolder.(*uqHolder.UQHolder).CurrentTick = uint64(time.Now().Sub(conn.GameData().ConnectTime).Milliseconds()) / 50
env.UQHolder.(*uqHolder.UQHolder).CurrentTick = 0

if args.ShouldEnableOmegaSystem() {
_, cb:=embed.EnableOmegaSystem(env)
Expand All @@ -207,7 +205,7 @@ func InitClient(env *environment.PBEnvironment) {
functionHolder := env.FunctionHolder.(*function.FunctionHolder)
function.InitInternalFunctions(functionHolder)
fbtask.InitTaskStatusDisplay(env)
move.ConnectTime = conn.GameData().ConnectTime
move.ConnectTime = time.Time{}
move.Position = conn.GameData().PlayerPosition
move.Pitch = conn.GameData().Pitch
move.Yaw = conn.GameData().Yaw
Expand Down Expand Up @@ -329,9 +327,11 @@ func EnterWorkerThread(env *environment.PBEnvironment, breaker chan struct{}) {

chunkAssembler := assembler.NewAssembler(assembler.REQUEST_AGGRESSIVE, time.Second*5)
// max 100 chunk request per second
chunkAssembler.CreateRequestScheduler(func(pk *packet.SubChunkRequest) {
/*chunkAssembler.CreateRequestScheduler(func(pk *packet.SubChunkRequest) {
conn.WritePacket(pk)
})
})*/
fmt.Printf("WARNING: TODO: Dump runtime id table, for what chunk loading is currently stubbed.\n")
// Also at mirror/io/assembler/assembler.go:119(currently) search "WIP" plz
// currentChunkConstructor := &world_provider.ChunkConstructor{}
for {
if(breaker!=nil) {
Expand Down Expand Up @@ -379,84 +379,6 @@ func EnterWorkerThread(env *environment.PBEnvironment, breaker chan struct{}) {
// pterm.Info.Println("ClientCacheStatus", p)
// case *packet.ClientCacheBlobStatus:
// pterm.Info.Println("ClientCacheBlobStatus", p)
case *packet.PyRpc:
if args.NoPyRpc() {
break
}
//fmt.Printf("PyRpc!\n")
if strings.Contains(string(p.Content), "GetLoadingTime") {
//fmt.Printf("GetLoadingTime!!\n")
uid := conn.IdentityData().Uid
num := uid&255 ^ (uid&65280)>>8
curTime := time.Now().Unix()
num = curTime&3 ^ (num&7)<<2 ^ (curTime&252)<<3 ^ (num&248)<<8
numcont := make([]byte, 2)
binary.BigEndian.PutUint16(numcont, uint16(num))
conn.WritePacket(&packet.PyRpc{
Content: []byte{0x82, 0xc4, 0x8, 0x5f, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x5f, 0x5f, 0xc4, 0x5, 0x74, 0x75, 0x70, 0x6c, 0x65, 0xc4, 0x5, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x93, 0xc4, 0x12, 0x53, 0x65, 0x74, 0x6c, 0x6f, 0x61, 0x64, 0x4c, 0x6f, 0x61, 0x64, 0x69, 0x6e, 0x67, 0x54, 0x69, 0x6d, 0x65, 0x82, 0xc4, 0x8, 0x5f, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x5f, 0x5f, 0xc4, 0x5, 0x74, 0x75, 0x70, 0x6c, 0x65, 0xc4, 0x5, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x91, 0xcd, numcont[0], numcont[1], 0xc0},
})
// Good job, netease, you wasted 3 days of my idle time
// (-Ruphane)

// See analyze/nemcfix/final.py for its python version
// and see analyze/ for how I did it.
//tellraw(conn, "Welcome to FastBuilder!")
//tellraw(conn, fmt.Sprintf("Operator: %s", env.RespondUser))
//sendCommand("testforblock ~ ~ ~ air", zeroId, conn)
} else if strings.Contains(string(p.Content), "check_server_contain_pet") {
//fmt.Printf("Checkpet!!\n")

// Pet req
/*conn.WritePacket(&packet.PyRpc {
Content: bytes.Join([][]byte{[]byte{0x82,0xc4,0x8,0x5f,0x5f,0x74,0x79,0x70,0x65,0x5f,0x5f,0xc4,0x5,0x74,0x75,0x70,0x6c,0x65,0xc4,0x5,0x76,0x61,0x6c,0x75,0x65,0x93,0xc4,0xb,0x4d,0x6f,0x64,0x45,0x76,0x65,0x6e,0x74,0x43,0x32,0x53,0x82,0xc4,0x8,0x5f,0x5f,0x74,0x79,0x70,0x65,0x5f,0x5f,0xc4,0x5,0x74,0x75,0x70,0x6c,0x65,0xc4,0x5,0x76,0x61,0x6c,0x75,0x65,0x94,0xc4,0x9,0x4d,0x69,0x6e,0x65,0x63,0x72,0x61,0x66,0x74,0xc4,0x3,0x70,0x65,0x74,0xc4,0x12,0x73,0x75,0x6d,0x6d,0x6f,0x6e,0x5f,0x70,0x65,0x74,0x5f,0x72,0x65,0x71,0x75,0x65,0x73,0x74,0x87,0xc4,0x13,0x61,0x6c,0x6c,0x6f,0x77,0x5f,0x73,0x74,0x65,0x70,0x5f,0x6f,0x6e,0x5f,0x62,0x6c,0x6f,0x63,0x6b,0xc2,0xc4,0xb,0x61,0x76,0x6f,0x69,0x64,0x5f,0x6f,0x77,0x6e,0x65,0x72,0xc3,0xc4,0x7,0x73,0x6b,0x69,0x6e,0x5f,0x69,0x64,0xcd,0x27,0x11,0xc4,0x9,0x70,0x6c,0x61,0x79,0x65,0x72,0x5f,0x69,0x64,0xc4},
[]byte{byte(len(runtimeid))},
[]byte(runtimeid),
[]byte{0xc4,0x6,0x70,0x65,0x74,0x5f,0x69,0x64,0x1,0xc4,0xa,0x6d,0x6f,0x64,0x65,0x6c,0x5f,0x6e,0x61,0x6d,0x65,0xc4,0x14,0x74,0x79,0x5f,0x79,0x75,0x61,0x6e,0x73,0x68,0x65,0x6e,0x67,0x68,0x75,0x6c,0x69,0x5f,0x30,0x5f,0x30,0xc4,0x4,0x6e,0x61,0x6d,0x65,0xc4,0xc,0xe6,0x88,0x91,0xe7,0x9a,0x84,0xe4,0xbc,0x99,0xe4,0xbc,0xb4,0xc0},
},[]byte{}),
})*/

} else if strings.Contains(string(p.Content), "summon_pet_response") {
//fmt.Printf("summonpetres\n")
/*conn.WritePacket(&packet.PyRpc {
Content: []byte{0x82,0xc4,0x8,0x5f,0x5f,0x74,0x79,0x70,0x65,0x5f,0x5f,0xc4,0x5,0x74,0x75,0x70,0x6c,0x65,0xc4,0x5,0x76,0x61,0x6c,0x75,0x65,0x93,0xc4,0x19,0x61,0x72,0x65,0x6e,0x61,0x47,0x61,0x6d,0x65,0x50,0x6c,0x61,0x79,0x65,0x72,0x46,0x69,0x6e,0x69,0x73,0x68,0x4c,0x6f,0x61,0x64,0x82,0xc4,0x8,0x5f,0x5f,0x74,0x79,0x70,0x65,0x5f,0x5f,0xc4,0x5,0x74,0x75,0x70,0x6c,0x65,0xc4,0x5,0x76,0x61,0x6c,0x75,0x65,0x90,0xc0},
})
conn.WritePacket(&packet.PyRpc {
Content: bytes.Join([][]byte{[]byte{0x82,0xc4,0x8,0x5f,0x5f,0x74,0x79,0x70,0x65,0x5f,0x5f,0xc4,0x5,0x74,0x75,0x70,0x6c,0x65,0xc4,0x5,0x76,0x61,0x6c,0x75,0x65,0x93,0xc4,0xb,0x4d,0x6f,0x64,0x45,0x76,0x65,0x6e,0x74,0x43,0x32,0x53,0x82,0xc4,0x8,0x5f,0x5f,0x74,0x79,0x70,0x65,0x5f,0x5f,0xc4,0x5,0x74,0x75,0x70,0x6c,0x65,0xc4,0x5,0x76,0x61,0x6c,0x75,0x65,0x94,0xc4,0x9,0x4d,0x69,0x6e,0x65,0x63,0x72,0x61,0x66,0x74,0xc4,0xe,0x76,0x69,0x70,0x45,0x76,0x65,0x6e,0x74,0x53,0x79,0x73,0x74,0x65,0x6d,0xc4,0xc,0x50,0x6c,0x61,0x79,0x65,0x72,0x55,0x69,0x49,0x6e,0x69,0x74,0xc4},
[]byte{byte(len(runtimeid))},
[]byte(runtimeid),
[]byte{0xc0},
},[]byte{}),
})*/
/*conn.WritePacket(&packet.PyRpc {
Content: []byte{0x82,0xc4,0x8,0x5f,0x5f,0x74,0x79,0x70,0x65,0x5f,0x5f,0xc4,0x5,0x74,0x75,0x70,0x6c,0x65,0xc4,0x5,0x76,0x61,0x6c,0x75,0x65,0x93,0xc4,0x1f,0x43,0x6c,0x69,0x65,0x6e,0x74,0x4c,0x6f,0x61,0x64,0x41,0x64,0x64,0x6f,0x6e,0x73,0x46,0x69,0x6e,0x69,0x73,0x68,0x65,0x64,0x46,0x72,0x6f,0x6d,0x47,0x61,0x63,0x82,0xc4,0x8,0x5f,0x5f,0x74,0x79,0x70,0x65,0x5f,0x5f,0xc4,0x5,0x74,0x75,0x70,0x6c,0x65,0xc4,0x5,0x76,0x61,0x6c,0x75,0x65,0x90,0xc0},
})*/
} else if strings.Contains(string(p.Content), "GetStartType") {
// 2021-12-22 10:51~11:55
// Thank netease for wasting my time again ;)
encData := p.Content[68 : len(p.Content)-1]
client := env.FBAuthClient.(*fbauth.Client)
response := client.TransferData(string(encData), fmt.Sprintf("%s", env.Uid))
conn.WritePacket(&packet.PyRpc{
Content: bytes.Join([][]byte{[]byte{0x82, 0xc4, 0x8, 0x5f, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x5f, 0x5f, 0xc4, 0x5, 0x74, 0x75, 0x70, 0x6c, 0x65, 0xc4, 0x5, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x93, 0xc4, 0xc, 0x53, 0x65, 0x74, 0x53, 0x74, 0x61, 0x72, 0x74, 0x54, 0x79, 0x70, 0x65, 0x82, 0xc4, 0x8, 0x5f, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x5f, 0x5f, 0xc4, 0x5, 0x74, 0x75, 0x70, 0x6c, 0x65, 0xc4, 0x5, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x91, 0xc4},
[]byte{byte(len(response))},
[]byte(response),
[]byte{0xc0},
}, []byte{}),
})
} else if strings.Contains(string(p.Content), "GetMCPCheckNum") {
firstArgLenB := p.Content[69:71]
firstArgLen := binary.BigEndian.Uint16(firstArgLenB)
secondArgLen := uint16(p.Content[72+firstArgLen])
secondArg := string(p.Content[73+firstArgLen : 73+firstArgLen+secondArgLen])
valM := utils.GetMD5(fmt.Sprintf("296<6puv?ol%sk", secondArg))
conn.WritePacket(&packet.PyRpc{
Content: bytes.Join([][]byte{[]byte{0x82, 0xc4, 0x8, 0x5f, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x5f, 0x5f, 0xc4, 0x5, 0x74, 0x75, 0x70, 0x6c, 0x65, 0xc4, 0x5, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x93, 0xc4, 0xe, 0x53, 0x65, 0x74, 0x4d, 0x43, 0x50, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x4e, 0x75, 0x6d, 0x82, 0xc4, 0x8, 0x5f, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x5f, 0x5f, 0xc4, 0x5, 0x74, 0x75, 0x70, 0x6c, 0x65, 0xc4, 0x5, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x91, 0xc4, 0x20},
[]byte(valM),
[]byte{0xc0},
}, []byte{}),
})
}
break
case *packet.StructureTemplateDataResponse:
special_tasks.ExportWaiter <- p.StructureTemplate
break
Expand Down
2 changes: 1 addition & 1 deletion fastbuilder/script_engine/packetType.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func init() {
"IDAddVolumeEntity": packet.IDAddVolumeEntity,
"IDRemoveVolumeEntity": packet.IDRemoveVolumeEntity,
// "IDNeteaseJson": packet.IDNeteaseJson,
"IDPyRpc": packet.IDPyRpc,
//"IDPyRpc": packet.IDPyRpc,
}
bridge.PacketNameMap=PacketNameMap
}
7 changes: 3 additions & 4 deletions fastbuilder/uqHolder/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ func (uq *UQHolder) Update(pk packet.Packet) {
// }
//}
// meaning not clear
case *packet.PlayerHotBar:
/*case *packet.PlayerHotBar:
uq.PlayerHotBar = *p
// not supported, plan to support
case *packet.InventoryTransaction:
Expand All @@ -559,8 +559,7 @@ func (uq *UQHolder) Update(pk packet.Packet) {
// no need to support
case *packet.PlayStatus:
// no need to support
case *packet.PyRpc:
//not handled
*/
default:
if !uq.displayUnknownPackets {
break
Expand All @@ -582,7 +581,7 @@ func (uq *UQHolder) Update(pk packet.Packet) {
func (uq *UQHolder) UpdateFromConn(conn *minecraft.Conn) {
gd := conn.GameData()
uq.BotUniqueID = gd.EntityUniqueID
uq.ConnectTime = gd.ConnectTime
uq.ConnectTime = time.Time{} // No longer needed
uq.WorldName = gd.WorldName
uq.WorldGameMode = gd.WorldGameMode
uq.WorldDifficulty = uint32(gd.Difficulty)
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMy
gopkg.in/square/go-jose.v2 v2.6.0 h1:NGk74WTnPKBNUhNzQX7PYcTLUjoq7mzKk2OKbvwk2iI=
gopkg.in/square/go-jose.v2 v2.6.0/go.mod h1:M9dMgbHiYLoDGQrXy7OpJDJWiKiU//h+vD76mk0e1AI=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Expand Down
3 changes: 2 additions & 1 deletion io/commands/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,12 @@ func (sender *CommandSender) Output(content string) error {
}
msg := strings.Replace(content, "schematic", "sc***atic", -1)
msg = strings.Replace(msg, ".", ".", -1)
return sender.SendChat(fmt.Sprintf("§b%s",msg))
// Netease set .bdx, .schematic, .mcacblock, etc as blocked words
// So we should replace half-width points w/ full-width points to avoid being
// blocked
//return SendChat(fmt.Sprintf("§b%s",msg), conn)
return sender.SendSizukanaCommand(TellRawRequest(types.AllPlayers, msg))
//return sender.SendSizukanaCommand(TellRawRequest(types.AllPlayers, msg))
}

func RawTellRawRequest(target types.Target, line string) string {
Expand Down
4 changes: 2 additions & 2 deletions io/special_tasks/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ import (
func CreateExportTask(commandLine string, env *environment.PBEnvironment) *task.Task {
cmdsender := env.CommandSender
// WIP
//cmdsender.Output("Sorry, but compatibility works haven't been done yet, redirected to lexport.")
//return CreateLegacyExportTask(commandLine, env)
cmdsender.Output("Sorry, but compatibility works haven't been done yet, you are being redirected to lexport.")
return CreateLegacyExportTask(commandLine, env)
cfg, err := parsing.Parse(commandLine, configuration.GlobalFullConfig(env).Main())
if err != nil {
cmdsender.Output(fmt.Sprintf("Failed to parse command: %v", err))
Expand Down
10 changes: 6 additions & 4 deletions io/special_tasks/lexport.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@ func CreateLegacyExportTask(commandLine string, env *environment.PBEnvironment)
close(chann)
var dimension float64 = 0
var got interface{}
var testAreaIsLoaded string = "testforblocks ~ -64 ~ ~63 319 ~63 ~ -64 ~"
var testAreaIsLoaded string = "testforblocks ~-31 -64 ~-31 ~31 319 ~31 ~-31 -64 ~-31"
json.Unmarshal([]byte(resp.OutputMessages[0].Parameters[0]), &got)
dimension = got.([]interface{})[0].(map[string]interface{})["dimension"].(float64)
if dimension == 1 {
testAreaIsLoaded = "testforblocks ~-16 0 ~-16 ~63 127 ~63 ~ 0 ~"
testAreaIsLoaded = "testforblocks ~-31 0 ~-31 ~31 127 ~31 ~-31 0 ~-31"
}
if dimension == 2 {
testAreaIsLoaded = "testforblocks ~ 0 ~ ~63 255 ~63 ~ 0 ~"
testAreaIsLoaded = "testforblocks ~-31 0 ~-31 ~31 255 ~31 ~-31 0 ~-31"
}
// 这个前置准备用于后面判断被导出区域是否加载
// 如果尝试请求一个没有被完全加载的区域,那么返回的结构将是只包括空气的结构,但不会报错
Expand All @@ -105,7 +105,7 @@ func CreateLegacyExportTask(commandLine string, env *environment.PBEnvironment)
u_d2, _ := uuid.NewUUID()
wchan := make(chan *packet.CommandOutput)
(*env.CommandSender.GetUUIDMap()).Store(u_d2.String(), wchan)
env.CommandSender.SendWSCommand(fmt.Sprintf("tp %d %d %d", value.BeginX, value.BeginY, value.BeginZ), u_d2)
env.CommandSender.SendWSCommand(fmt.Sprintf("tp %d %d %d", value.BeginX+value.SizeX/2, value.BeginY+value.SizeY/2, value.BeginZ+value.SizeZ/2), u_d2)
<-wchan
close(wchan)
// 传送玩家
Expand All @@ -116,6 +116,7 @@ func CreateLegacyExportTask(commandLine string, env *environment.PBEnvironment)
env.CommandSender.SendWSCommand(testAreaIsLoaded, u_d3)
resp := <-chann
close(chann)
//fmt.Printf("%#v\n",resp)
if resp.OutputMessages[0].Message == "commands.compare.tooManyBlocks" {
break
}
Expand All @@ -136,6 +137,7 @@ func CreateLegacyExportTask(commandLine string, env *environment.PBEnvironment)
Mirror: 0,
Integrity: 100,
Seed: 0,
AllowNonTickingChunks: true,
},
RequestType: packet.StructureTemplateRequestExportFromSave,
})
Expand Down
21 changes: 21 additions & 0 deletions minecraft/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 Sandertv

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
3 changes: 3 additions & 0 deletions minecraft/NOTE
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Codes in this directory are originally from [gophertunnel]
(https://github.com/Sandertv/gophertunnel), which is
licensed under the MIT license, see [LICENSE] for reference.
30 changes: 11 additions & 19 deletions minecraft/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,24 @@ import (
"crypto/sha256"
"encoding/base64"
"fmt"
"io"
"log"
"net"
"github.com/google/uuid"
"github.com/sandertv/go-raknet"
"phoenixbuilder/minecraft/internal"
"phoenixbuilder/minecraft/nbt"
"phoenixbuilder/minecraft/protocol"
"phoenixbuilder/minecraft/protocol/login"
"phoenixbuilder/minecraft/protocol/packet"
"phoenixbuilder/minecraft/resource"
"phoenixbuilder/minecraft/text"
"strings"
"sync"
"time"

"github.com/google/uuid"
"github.com/sandertv/go-raknet"
"go.uber.org/atomic"
"gopkg.in/square/go-jose.v2"
"gopkg.in/square/go-jose.v2/jwt"
"io"
"log"
"net"
"strings"
"sync"
"time"
)

// exemptedResourcePack is a resource pack that is exempted from being downloaded. These packs may be directly
Expand Down Expand Up @@ -111,7 +110,7 @@ type Conn struct {
resourcePacks []*resource.Pack
// biomes is a map of biome definitions that the listener may hold. Each client will be sent these biome
// definitions upon joining.
biomes map[string]interface{}
biomes map[string]any
// texturePacksRequired specifies if clients that join must accept the texture pack in order for them to
// be able to join the server. If they don't accept, they can only leave the server.
texturePacksRequired bool
Expand All @@ -126,9 +125,7 @@ type Conn struct {
disconnectMessage atomic.String

shieldID atomic.Int32

// PhoenixBuilder debug mode, which means this connection is fake
// and nothing will be sended or received from it.

DebugMode bool
}

Expand Down Expand Up @@ -356,10 +353,6 @@ func (conn *Conn) ReadPacket() (pk packet.Packet, err error) {

func (conn *Conn) ReadPacketAndBytes() (pk packet.Packet, data []byte, err error) {
if data, ok := conn.takeDeferredPacket(); ok {
// if data.h.PacketID != 67 {
// fmt.Println(data.h.PacketID)
// }

pk, err := data.decode(conn)
if err != nil {
conn.log.Println(err)
Expand Down Expand Up @@ -1142,7 +1135,6 @@ func (conn *Conn) handleStartGame(pk *packet.StartGame) error {
WorldGameMode: pk.WorldGameMode,
ServerAuthoritativeInventory: pk.ServerAuthoritativeInventory,
Experiments: pk.Experiments,
ConnectTime: time.Now(),
}
for _, item := range pk.Items {
if item.Name == "minecraft:shield" {
Expand Down Expand Up @@ -1254,7 +1246,7 @@ func (conn *Conn) handlePlayStatus(pk *packet.PlayStatus) error {
// handshake packet to the client and enables encryption after that.
func (conn *Conn) enableEncryption(clientPublicKey *ecdsa.PublicKey) error {
signer, _ := jose.NewSigner(jose.SigningKey{Key: conn.privateKey, Algorithm: jose.ES384}, &jose.SignerOptions{
ExtraHeaders: map[jose.HeaderKey]interface{}{"x5u": login.MarshalPublicKey(&conn.privateKey.PublicKey)},
ExtraHeaders: map[jose.HeaderKey]any{"x5u": login.MarshalPublicKey(&conn.privateKey.PublicKey)},
})
// We produce an encoded JWT using the header and payload above, then we send the JWT in a ServerToClient-
// Handshake packet so that the client can initialise encryption.
Expand Down
Loading

0 comments on commit 2fb34b9

Please sign in to comment.