format a bit
This commit is contained in:
parent
29417b600c
commit
88589933ea
3
go.mod
3
go.mod
|
@ -6,7 +6,7 @@ go 1.20
|
||||||
replace github.com/sandertv/gophertunnel => github.com/olebeck/gophertunnel v1.28.1-1
|
replace github.com/sandertv/gophertunnel => github.com/olebeck/gophertunnel v1.28.1-1
|
||||||
|
|
||||||
//replace github.com/df-mc/dragonfly => ./dragonfly
|
//replace github.com/df-mc/dragonfly => ./dragonfly
|
||||||
replace github.com/df-mc/dragonfly => github.com/olebeck/dragonfly v0.9.4-4
|
replace github.com/df-mc/dragonfly => github.com/olebeck/dragonfly v0.9.4-5
|
||||||
|
|
||||||
//replace gioui.org => ./gio
|
//replace gioui.org => ./gio
|
||||||
replace gioui.org => github.com/olebeck/gio v0.0.0-20230321105529-d424f1a59af9
|
replace gioui.org => github.com/olebeck/gio v0.0.0-20230321105529-d424f1a59af9
|
||||||
|
@ -61,6 +61,7 @@ require (
|
||||||
github.com/mattn/go-isatty v0.0.17 // indirect
|
github.com/mattn/go-isatty v0.0.17 // indirect
|
||||||
github.com/muhammadmuzzammil1998/jsonc v1.0.0 // indirect
|
github.com/muhammadmuzzammil1998/jsonc v1.0.0 // indirect
|
||||||
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
|
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
|
||||||
|
github.com/repeale/fp-go v0.11.1 // indirect
|
||||||
github.com/tklauser/go-sysconf v0.3.11 // indirect
|
github.com/tklauser/go-sysconf v0.3.11 // indirect
|
||||||
github.com/tklauser/numcpus v0.6.0 // indirect
|
github.com/tklauser/numcpus v0.6.0 // indirect
|
||||||
github.com/yusufpapurcu/wmi v1.2.2 // indirect
|
github.com/yusufpapurcu/wmi v1.2.2 // indirect
|
||||||
|
|
11
go.sum
11
go.sum
|
@ -10,6 +10,8 @@ git.wow.st/gmp/jni v0.0.0-20210610011705-34026c7e22d0 h1:bGG/g4ypjrCJoSvFrP5hafr
|
||||||
git.wow.st/gmp/jni v0.0.0-20210610011705-34026c7e22d0/go.mod h1:+axXBRUTIDlCeE73IKeD/os7LoEnTKdkp8/gQOFjqyo=
|
git.wow.st/gmp/jni v0.0.0-20210610011705-34026c7e22d0/go.mod h1:+axXBRUTIDlCeE73IKeD/os7LoEnTKdkp8/gQOFjqyo=
|
||||||
github.com/BurntSushi/toml v1.0.0 h1:dtDWrepsVPfW9H/4y7dDgFc2MBUSeJhlaDtK13CxFlU=
|
github.com/BurntSushi/toml v1.0.0 h1:dtDWrepsVPfW9H/4y7dDgFc2MBUSeJhlaDtK13CxFlU=
|
||||||
github.com/BurntSushi/toml v1.0.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
|
github.com/BurntSushi/toml v1.0.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
|
||||||
|
github.com/TeaEntityLab/fpGo/v2 v2.3.2 h1:qlGjFzXukp9IgVQl32cz4PosbiFEnwXa2EpDbwddHS8=
|
||||||
|
github.com/TeaEntityLab/fpGo/v2 v2.3.2/go.mod h1:b06fRNLSnNiUwfSskBC3f3cocA4mAC2iySdtaP/T9uA=
|
||||||
github.com/benoitkugler/pstokenizer v1.0.0/go.mod h1:l1G2Voirz0q/jj0TQfabNxVsa8HZXh/VMxFSRALWTiE=
|
github.com/benoitkugler/pstokenizer v1.0.0/go.mod h1:l1G2Voirz0q/jj0TQfabNxVsa8HZXh/VMxFSRALWTiE=
|
||||||
github.com/benoitkugler/textlayout v0.3.0 h1:2ehWXEkgb6RUokTjXh1LzdGwG4dRP6X3dqhYYDYhUVk=
|
github.com/benoitkugler/textlayout v0.3.0 h1:2ehWXEkgb6RUokTjXh1LzdGwG4dRP6X3dqhYYDYhUVk=
|
||||||
github.com/benoitkugler/textlayout v0.3.0/go.mod h1:o+1hFV+JSHBC9qNLIuwVoLedERU7sBPgEFcuSgfvi/w=
|
github.com/benoitkugler/textlayout v0.3.0/go.mod h1:o+1hFV+JSHBC9qNLIuwVoLedERU7sBPgEFcuSgfvi/w=
|
||||||
|
@ -83,10 +85,8 @@ github.com/muhammadmuzzammil1998/jsonc v1.0.0 h1:8o5gBQn4ZA3NBA9DlTujCj2a4w0tqWr
|
||||||
github.com/muhammadmuzzammil1998/jsonc v1.0.0/go.mod h1:saF2fIVw4banK0H4+/EuqfFLpRnoy5S+ECwTOCcRcSU=
|
github.com/muhammadmuzzammil1998/jsonc v1.0.0/go.mod h1:saF2fIVw4banK0H4+/EuqfFLpRnoy5S+ECwTOCcRcSU=
|
||||||
github.com/nicksnyder/go-i18n/v2 v2.2.1 h1:aOzRCdwsJuoExfZhoiXHy4bjruwCMdt5otbYojM/PaA=
|
github.com/nicksnyder/go-i18n/v2 v2.2.1 h1:aOzRCdwsJuoExfZhoiXHy4bjruwCMdt5otbYojM/PaA=
|
||||||
github.com/nicksnyder/go-i18n/v2 v2.2.1/go.mod h1:fF2++lPHlo+/kPaj3nB0uxtPwzlPm+BlgwGX7MkeGj0=
|
github.com/nicksnyder/go-i18n/v2 v2.2.1/go.mod h1:fF2++lPHlo+/kPaj3nB0uxtPwzlPm+BlgwGX7MkeGj0=
|
||||||
github.com/olebeck/dragonfly v0.9.4-3 h1:zG6f7zBCM9HWx6eQ/O5VKUBxU6bjln+nDlfCF0vNZ/A=
|
github.com/olebeck/dragonfly v0.9.4-5 h1:ixVX0Fe3wX8FryJiKC5gFVS4KDrKtd1dXJoBkzWhd1c=
|
||||||
github.com/olebeck/dragonfly v0.9.4-3/go.mod h1:k8OQvjmfj+JbrwQf1qHfMETlFHOp0WJLjILN+QVqh+c=
|
github.com/olebeck/dragonfly v0.9.4-5/go.mod h1:k8OQvjmfj+JbrwQf1qHfMETlFHOp0WJLjILN+QVqh+c=
|
||||||
github.com/olebeck/dragonfly v0.9.4-4 h1:qe2pEasLpGdbOvz6DYE56AlxMCyidj60/i0ZbfdD+no=
|
|
||||||
github.com/olebeck/dragonfly v0.9.4-4/go.mod h1:k8OQvjmfj+JbrwQf1qHfMETlFHOp0WJLjILN+QVqh+c=
|
|
||||||
github.com/olebeck/gio v0.0.0-20230321105529-d424f1a59af9 h1:TqDsMHwjW5ZYfh+RE8ussT62m0qXqo+QjzSXb7BCVA4=
|
github.com/olebeck/gio v0.0.0-20230321105529-d424f1a59af9 h1:TqDsMHwjW5ZYfh+RE8ussT62m0qXqo+QjzSXb7BCVA4=
|
||||||
github.com/olebeck/gio v0.0.0-20230321105529-d424f1a59af9/go.mod h1:+W1Kpf96YcfissZocFqIp6O42FDTuphkObbEybp+Ffc=
|
github.com/olebeck/gio v0.0.0-20230321105529-d424f1a59af9/go.mod h1:+W1Kpf96YcfissZocFqIp6O42FDTuphkObbEybp+Ffc=
|
||||||
github.com/olebeck/gophertunnel v1.28.1-1 h1:bw2jeMz94YHF5qQYhq1Yq/6fALkklGu7k26YbPI4DSs=
|
github.com/olebeck/gophertunnel v1.28.1-1 h1:bw2jeMz94YHF5qQYhq1Yq/6fALkklGu7k26YbPI4DSs=
|
||||||
|
@ -100,6 +100,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c h1:ncq/mPwQF4JjgDlrVEn3C11VoGHZN7m8qihwgMEtzYw=
|
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c h1:ncq/mPwQF4JjgDlrVEn3C11VoGHZN7m8qihwgMEtzYw=
|
||||||
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE=
|
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE=
|
||||||
|
github.com/repeale/fp-go v0.11.1 h1:Q/e+gNyyHaxKAyfdbBqvip3DxhVWH453R+kthvSr9Mk=
|
||||||
|
github.com/repeale/fp-go v0.11.1/go.mod h1:4KrwQJB1VRY+06CA+jTc4baZetr6o2PeuqnKr5ybQUc=
|
||||||
github.com/sanbornm/go-selfupdate v0.0.0-20210106163404-c9b625feac49 h1:LuxslTBxJrrNeKfqoywIERWWhH43TgiVAiPEVlhgNBA=
|
github.com/sanbornm/go-selfupdate v0.0.0-20210106163404-c9b625feac49 h1:LuxslTBxJrrNeKfqoywIERWWhH43TgiVAiPEVlhgNBA=
|
||||||
github.com/sanbornm/go-selfupdate v0.0.0-20210106163404-c9b625feac49/go.mod h1:fY313ZGG810aWruFYcyq3coFpHDrWJVoMfSRI81y1r4=
|
github.com/sanbornm/go-selfupdate v0.0.0-20210106163404-c9b625feac49/go.mod h1:fY313ZGG810aWruFYcyq3coFpHDrWJVoMfSRI81y1r4=
|
||||||
github.com/sandertv/go-raknet v1.12.0 h1:olUzZlIJyX/pgj/mrsLCZYjKLNDsYiWdvQ4NIm3z0DA=
|
github.com/sandertv/go-raknet v1.12.0 h1:olUzZlIJyX/pgj/mrsLCZYjKLNDsYiWdvQ4NIm3z0DA=
|
||||||
|
@ -198,6 +200,7 @@ google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175
|
||||||
google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
|
google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
|
||||||
gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4=
|
gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4=
|
||||||
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
|
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
|
||||||
gopkg.in/inconshreveable/go-update.v0 v0.0.0-20150814200126-d8b0b1d421aa h1:drvf2JoUL1fz3ttkGNkw+rf3kZa2//7XkYGpSO4NHNA=
|
gopkg.in/inconshreveable/go-update.v0 v0.0.0-20150814200126-d8b0b1d421aa h1:drvf2JoUL1fz3ttkGNkw+rf3kZa2//7XkYGpSO4NHNA=
|
||||||
|
|
|
@ -54,11 +54,6 @@ func (c *BlindProxyCMD) Execute(ctx context.Context, ui utils.UI) error {
|
||||||
listener.ID(), "Creative", 1, listener.Addr().(*net.UDPAddr).Port, listener.Addr().(*net.UDPAddr).Port,
|
listener.ID(), "Creative", 1, listener.Addr().(*net.UDPAddr).Port, listener.Addr().(*net.UDPAddr).Port,
|
||||||
)))
|
)))
|
||||||
|
|
||||||
go func() {
|
|
||||||
<-ctx.Done()
|
|
||||||
listener.Close()
|
|
||||||
}()
|
|
||||||
|
|
||||||
clientConn, err := listener.Accept()
|
clientConn, err := listener.Accept()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"flag"
|
"flag"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
|
@ -15,7 +16,6 @@ import (
|
||||||
"github.com/bedrock-tool/bedrocktool/utils"
|
"github.com/bedrock-tool/bedrocktool/utils"
|
||||||
|
|
||||||
"github.com/sandertv/gophertunnel/minecraft/protocol/packet"
|
"github.com/sandertv/gophertunnel/minecraft/protocol/packet"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
@ -32,13 +32,7 @@ func dumpPacket(f io.WriteCloser, toServer bool, payload []byte) {
|
||||||
binary.Write(f, binary.LittleEndian, packetSize)
|
binary.Write(f, binary.LittleEndian, packetSize)
|
||||||
binary.Write(f, binary.LittleEndian, toServer)
|
binary.Write(f, binary.LittleEndian, toServer)
|
||||||
binary.Write(f, binary.LittleEndian, time.Now().UnixMilli())
|
binary.Write(f, binary.LittleEndian, time.Now().UnixMilli())
|
||||||
n, err := f.Write(payload)
|
f.Write(payload)
|
||||||
if err != nil {
|
|
||||||
logrus.Error(err)
|
|
||||||
}
|
|
||||||
if n < int(packetSize) {
|
|
||||||
f.Write(make([]byte, int(packetSize)-n))
|
|
||||||
}
|
|
||||||
f.Write([]byte{0xBB, 0xBB, 0xBB, 0xBB})
|
f.Write([]byte{0xBB, 0xBB, 0xBB, 0xBB})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,7 +53,7 @@ func (c *CaptureCMD) Execute(ctx context.Context, ui utils.UI) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
os.Mkdir("captures", 0o775)
|
os.Mkdir("captures", 0o775)
|
||||||
fio, err := os.Create("captures/" + hostname + "-" + time.Now().Format("2006-01-02_15-04-05") + ".pcap2")
|
fio, err := os.Create(fmt.Sprintf("captures/%s-%s.pcap2", hostname, time.Now().Format("2006-01-02_15-04-05")))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -68,7 +62,7 @@ func (c *CaptureCMD) Execute(ctx context.Context, ui utils.UI) error {
|
||||||
|
|
||||||
proxy, err := utils.NewProxy()
|
proxy, err := utils.NewProxy()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Fatal(err)
|
return err
|
||||||
}
|
}
|
||||||
proxy.PacketFunc = func(header packet.Header, payload []byte, src, dst net.Addr) {
|
proxy.PacketFunc = func(header packet.Header, payload []byte, src, dst net.Addr) {
|
||||||
IsfromClient := src.String() == proxy.Client.LocalAddr().String()
|
IsfromClient := src.String() == proxy.Client.LocalAddr().String()
|
||||||
|
@ -79,10 +73,5 @@ func (c *CaptureCMD) Execute(ctx context.Context, ui utils.UI) error {
|
||||||
dumpPacket(fio, IsfromClient, buf.Bytes())
|
dumpPacket(fio, IsfromClient, buf.Bytes())
|
||||||
}
|
}
|
||||||
|
|
||||||
err = proxy.Run(ctx, address)
|
return proxy.Run(ctx, address)
|
||||||
time.Sleep(2 * time.Second)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,8 +59,7 @@ func (c *ChatLogCMD) Execute(ctx context.Context, ui utils.UI) error {
|
||||||
return pk, nil
|
return pk, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
err = proxy.Run(ctx, address)
|
return proxy.Run(ctx, address)
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
Binary file not shown.
|
@ -149,13 +149,13 @@ func (c *SkinCMD) Execute(ctx context.Context, ui utils.UI) error {
|
||||||
proxy, _ := utils.NewProxy()
|
proxy, _ := utils.NewProxy()
|
||||||
proxy.WithClient = !c.NoProxy
|
proxy.WithClient = !c.NoProxy
|
||||||
proxy.OnClientConnect = func(hasClient bool) {
|
proxy.OnClientConnect = func(hasClient bool) {
|
||||||
ui.Message(messages.SetUIState, messages.UIStateConnecting)
|
ui.Message(messages.SetUIState(messages.UIStateConnecting))
|
||||||
}
|
}
|
||||||
proxy.ConnectCB = func(err error) bool {
|
proxy.ConnectCB = func(err error) bool {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
ui.Message(messages.SetUIState, messages.UIStateMain)
|
ui.Message(messages.SetUIState(messages.UIStateMain))
|
||||||
logrus.Info(locale.Loc("ctrl_c_to_exit", nil))
|
logrus.Info(locale.Loc("ctrl_c_to_exit", nil))
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -168,7 +168,7 @@ func (c *SkinCMD) Execute(ctx context.Context, ui utils.UI) error {
|
||||||
proxy.PacketCB = func(pk packet.Packet, toServer bool, _ time.Time) (packet.Packet, error) {
|
proxy.PacketCB = func(pk packet.Packet, toServer bool, _ time.Time) (packet.Packet, error) {
|
||||||
if !toServer {
|
if !toServer {
|
||||||
for _, s := range s.ProcessPacket(pk) {
|
for _, s := range s.ProcessPacket(pk) {
|
||||||
ui.Message(messages.NewSkin, messages.NewSkinPayload{
|
ui.Message(messages.NewSkin{
|
||||||
PlayerName: s.PlayerName,
|
PlayerName: s.PlayerName,
|
||||||
Skin: s.Skin,
|
Skin: s.Skin,
|
||||||
})
|
})
|
||||||
|
@ -178,9 +178,9 @@ func (c *SkinCMD) Execute(ctx context.Context, ui utils.UI) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if proxy.WithClient {
|
if proxy.WithClient {
|
||||||
ui.Message(messages.SetUIState, messages.UIStateConnect)
|
ui.Message(messages.SetUIState(messages.UIStateConnect))
|
||||||
} else {
|
} else {
|
||||||
ui.Message(messages.SetUIState, messages.UIStateConnecting)
|
ui.Message(messages.SetUIState(messages.UIStateConnecting))
|
||||||
}
|
}
|
||||||
err = proxy.Run(ctx, address)
|
err = proxy.Run(ctx, address)
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"github.com/bedrock-tool/bedrocktool/locale"
|
"github.com/bedrock-tool/bedrocktool/locale"
|
||||||
"github.com/df-mc/dragonfly/server/world"
|
"github.com/df-mc/dragonfly/server/world"
|
||||||
"github.com/df-mc/dragonfly/server/world/chunk"
|
"github.com/df-mc/dragonfly/server/world/chunk"
|
||||||
|
"github.com/repeale/fp-go"
|
||||||
"github.com/sandertv/gophertunnel/minecraft/protocol"
|
"github.com/sandertv/gophertunnel/minecraft/protocol"
|
||||||
"github.com/sandertv/gophertunnel/minecraft/protocol/packet"
|
"github.com/sandertv/gophertunnel/minecraft/protocol/packet"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
|
@ -76,13 +77,9 @@ func (w *worldsServer) processLevelChunk(pk *packet.LevelChunk) {
|
||||||
})
|
})
|
||||||
default:
|
default:
|
||||||
// legacy
|
// legacy
|
||||||
empty := true
|
empty := fp.Every(func(sub *chunk.SubChunk) bool {
|
||||||
for _, sub := range ch.Sub() {
|
return sub.Empty()
|
||||||
if !sub.Empty() {
|
})(ch.Sub())
|
||||||
empty = false
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !empty {
|
if !empty {
|
||||||
w.mapUI.SetChunk(pk.Position, ch, true)
|
w.mapUI.SetChunk(pk.Position, ch, true)
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,37 +29,43 @@ func blockColorAt(c *chunk.Chunk, x uint8, y int16, z uint8) (blockColor color.R
|
||||||
|
|
||||||
blockColor = color.RGBA{255, 0, 255, 255}
|
blockColor = color.RGBA{255, 0, 255, 255}
|
||||||
b, found := world.BlockByRuntimeID(rid)
|
b, found := world.BlockByRuntimeID(rid)
|
||||||
if found {
|
if !found {
|
||||||
if _, isWater := b.(block.Water); isWater {
|
|
||||||
// get the first non water block at the position
|
|
||||||
heightBlock := c.HeightMap().At(x, z)
|
|
||||||
depth := y - heightBlock
|
|
||||||
if depth > 0 {
|
|
||||||
blockColor = blockColorAt(c, x, heightBlock, z)
|
|
||||||
}
|
|
||||||
|
|
||||||
// blend that blocks color with water depending on depth
|
|
||||||
waterColor := (&block.Water{}).Color()
|
|
||||||
waterColor.A = uint8(utils.Clamp(int(150+depth*7), 255))
|
|
||||||
blockColor = utils.BlendColors(blockColor, waterColor)
|
|
||||||
blockColor.R -= uint8(depth * 2)
|
|
||||||
blockColor.G -= uint8(depth * 2)
|
|
||||||
blockColor.B -= uint8(depth * 2)
|
|
||||||
return blockColor
|
|
||||||
} else {
|
|
||||||
col := b.Color()
|
|
||||||
if col.A != 255 {
|
|
||||||
col = utils.BlendColors(blockColorAt(c, x, y-1, z), col)
|
|
||||||
}
|
|
||||||
return col
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
/*
|
|
||||||
name, nbt := b.EncodeBlock()
|
|
||||||
fmt.Printf("unknown color %d %s %s %s\n", rid, reflect.TypeOf(b), name, nbt)
|
|
||||||
*/
|
|
||||||
return blockColor
|
return blockColor
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if _, isWater := b.(block.Water); isWater {
|
||||||
|
waterColor := block.Water{}.Color()
|
||||||
|
|
||||||
|
// get the first non water block at the position
|
||||||
|
heightBlock := c.HeightMap().At(x, z)
|
||||||
|
depth := y - heightBlock
|
||||||
|
if depth > 0 {
|
||||||
|
blockColor = blockColorAt(c, x, heightBlock, z)
|
||||||
|
}
|
||||||
|
|
||||||
|
// blend that blocks color with water depending on depth
|
||||||
|
waterColor.A = uint8(utils.Clamp(int(150+depth*7), 255))
|
||||||
|
blockColor = utils.BlendColors(blockColor, waterColor)
|
||||||
|
blockColor.R -= uint8(depth * 2)
|
||||||
|
blockColor.G -= uint8(depth * 2)
|
||||||
|
blockColor.B -= uint8(depth * 2)
|
||||||
|
return blockColor
|
||||||
|
} else {
|
||||||
|
col := b.Color()
|
||||||
|
if col.A != 255 {
|
||||||
|
col = utils.BlendColors(blockColorAt(c, x, y-1, z), col)
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
a := color.RGBA{255, 0, 255, 255}
|
||||||
|
if col == a {
|
||||||
|
name, nbt := b.EncodeBlock()
|
||||||
|
fmt.Printf("unknown color %d %s %s %s\n", rid, reflect.TypeOf(b), name, nbt)
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
return col
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func chunkGetColorAt(c *chunk.Chunk, x uint8, y int16, z uint8) color.RGBA {
|
func chunkGetColorAt(c *chunk.Chunk, x uint8, y int16, z uint8) color.RGBA {
|
||||||
|
|
|
@ -95,7 +95,7 @@ func NewMapUI(w *worldsServer) *MapUI {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MapUI) Start() {
|
func (m *MapUI) Start() {
|
||||||
r := m.w.gui.Message("can_show_images", nil)
|
r := m.w.gui.Message(messages.CanShowImages{})
|
||||||
if r.Ok {
|
if r.Ok {
|
||||||
m.showOnGui = true
|
m.showOnGui = true
|
||||||
}
|
}
|
||||||
|
@ -182,7 +182,7 @@ func (m *MapUI) SchedRedraw() {
|
||||||
// Redraw draws chunk images to the map image
|
// Redraw draws chunk images to the map image
|
||||||
func (m *MapUI) Redraw() {
|
func (m *MapUI) Redraw() {
|
||||||
m.l.Lock()
|
m.l.Lock()
|
||||||
updatedChunks := []protocol.ChunkPos{}
|
updatedChunks := make([]protocol.ChunkPos, 0, m.renderQueue.Length())
|
||||||
for {
|
for {
|
||||||
r, ok := m.renderQueue.Dequeue().(*RenderElem)
|
r, ok := m.renderQueue.Dequeue().(*RenderElem)
|
||||||
if !ok {
|
if !ok {
|
||||||
|
@ -225,7 +225,7 @@ func (m *MapUI) Redraw() {
|
||||||
}
|
}
|
||||||
if m.showOnGui {
|
if m.showOnGui {
|
||||||
min, max := m.GetBounds()
|
min, max := m.GetBounds()
|
||||||
m.w.gui.Message(messages.UpdateMap, messages.UpdateMapPayload{
|
m.w.gui.Message(messages.UpdateMap{
|
||||||
ChunkCount: len(m.renderedChunks),
|
ChunkCount: len(m.renderedChunks),
|
||||||
Rotation: m.w.serverState.PlayerPos.Yaw,
|
Rotation: m.w.serverState.PlayerPos.Yaw,
|
||||||
UpdatedTiles: updatedChunks,
|
UpdatedTiles: updatedChunks,
|
||||||
|
|
|
@ -25,6 +25,7 @@ import (
|
||||||
"github.com/df-mc/dragonfly/server/world/mcdb"
|
"github.com/df-mc/dragonfly/server/world/mcdb"
|
||||||
"github.com/df-mc/goleveldb/leveldb/opt"
|
"github.com/df-mc/goleveldb/leveldb/opt"
|
||||||
"github.com/go-gl/mathgl/mgl32"
|
"github.com/go-gl/mathgl/mgl32"
|
||||||
|
"github.com/repeale/fp-go"
|
||||||
"github.com/sandertv/gophertunnel/minecraft"
|
"github.com/sandertv/gophertunnel/minecraft"
|
||||||
"github.com/sandertv/gophertunnel/minecraft/protocol"
|
"github.com/sandertv/gophertunnel/minecraft/protocol"
|
||||||
"github.com/sandertv/gophertunnel/minecraft/protocol/packet"
|
"github.com/sandertv/gophertunnel/minecraft/protocol/packet"
|
||||||
|
@ -104,8 +105,8 @@ func NewWorldsServer(ctx context.Context, proxy *utils.ProxyContext, ServerName
|
||||||
w.mapUI = NewMapUI(w)
|
w.mapUI = NewMapUI(w)
|
||||||
w.Reset(w.CurrentName())
|
w.Reset(w.CurrentName())
|
||||||
|
|
||||||
w.gui.Message(messages.Init, messages.InitPayload{
|
w.gui.Message(messages.Init{
|
||||||
Handler: w.uiMessage,
|
Handler: nil,
|
||||||
})
|
})
|
||||||
|
|
||||||
return w
|
return w
|
||||||
|
@ -173,7 +174,7 @@ func (c *WorldCMD) Execute(ctx context.Context, ui utils.UI) error {
|
||||||
}
|
}
|
||||||
proxy.ConnectCB = w.OnConnect
|
proxy.ConnectCB = w.OnConnect
|
||||||
proxy.OnClientConnect = func(hasClient bool) {
|
proxy.OnClientConnect = func(hasClient bool) {
|
||||||
w.gui.Message(messages.SetUIState, messages.UIStateConnecting)
|
w.gui.Message(messages.SetUIState(messages.UIStateConnecting))
|
||||||
}
|
}
|
||||||
proxy.PacketCB = func(pk packet.Packet, toServer bool, _ time.Time) (packet.Packet, error) {
|
proxy.PacketCB = func(pk packet.Packet, toServer bool, _ time.Time) (packet.Packet, error) {
|
||||||
forward := true
|
forward := true
|
||||||
|
@ -200,32 +201,16 @@ func (c *WorldCMD) Execute(ctx context.Context, ui utils.UI) error {
|
||||||
return pk, nil
|
return pk, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
w.gui.Message(messages.SetUIState, messages.UIStateConnect)
|
w.gui.Message(messages.SetUIState(messages.UIStateConnect))
|
||||||
err = w.proxy.Run(ctx, serverAddress)
|
err = w.proxy.Run(ctx, serverAddress)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
w.SaveAndReset()
|
w.SaveAndReset()
|
||||||
ui.Message(messages.SetUIState, messages.UIStateFinished)
|
ui.Message(messages.SetUIState(messages.UIStateFinished))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *worldsServer) uiMessage(name string, data interface{}) messages.MessageResponse {
|
|
||||||
r := messages.MessageResponse{
|
|
||||||
Ok: false,
|
|
||||||
Data: nil,
|
|
||||||
}
|
|
||||||
switch name {
|
|
||||||
case messages.SetVoidGen:
|
|
||||||
set_void_gen := data.(messages.SetVoidGenPayload)
|
|
||||||
r.Ok = w.setVoidGen(set_void_gen.Value, true)
|
|
||||||
case messages.SetWorldName:
|
|
||||||
set_world_name := data.(messages.SetWorldNamePayload)
|
|
||||||
r.Ok = w.setWorldName(set_world_name.WorldName, true)
|
|
||||||
}
|
|
||||||
return r
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w *worldsServer) SetPlayerPos(Position mgl32.Vec3, Pitch, Yaw, HeadYaw float32) {
|
func (w *worldsServer) SetPlayerPos(Position mgl32.Vec3, Pitch, Yaw, HeadYaw float32) {
|
||||||
last := w.serverState.PlayerPos
|
last := w.serverState.PlayerPos
|
||||||
current := TPlayerPos{
|
current := TPlayerPos{
|
||||||
|
@ -243,16 +228,14 @@ func (w *worldsServer) SetPlayerPos(Position mgl32.Vec3, Pitch, Yaw, HeadYaw flo
|
||||||
|
|
||||||
func (w *worldsServer) setVoidGen(val bool, fromUI bool) bool {
|
func (w *worldsServer) setVoidGen(val bool, fromUI bool) bool {
|
||||||
w.settings.voidGen = val
|
w.settings.voidGen = val
|
||||||
var s string
|
var s = locale.Loc("void_generator_false", nil)
|
||||||
if w.settings.voidGen {
|
if w.settings.voidGen {
|
||||||
s = locale.Loc("void_generator_true", nil)
|
s = locale.Loc("void_generator_true", nil)
|
||||||
} else {
|
|
||||||
s = locale.Loc("void_generator_false", nil)
|
|
||||||
}
|
}
|
||||||
w.proxy.SendMessage(s)
|
w.proxy.SendMessage(s)
|
||||||
|
|
||||||
if !fromUI {
|
if !fromUI {
|
||||||
w.gui.Message(messages.SetVoidGen, messages.SetVoidGenPayload{
|
w.gui.Message(messages.SetVoidGen{
|
||||||
Value: w.settings.voidGen,
|
Value: w.settings.voidGen,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -265,7 +248,7 @@ func (w *worldsServer) setWorldName(val string, fromUI bool) bool {
|
||||||
w.proxy.SendMessage(locale.Loc("worldname_set", locale.Strmap{"Name": w.worldState.Name}))
|
w.proxy.SendMessage(locale.Loc("worldname_set", locale.Strmap{"Name": w.worldState.Name}))
|
||||||
|
|
||||||
if !fromUI {
|
if !fromUI {
|
||||||
w.gui.Message(messages.SetWorldName, messages.SetWorldNamePayload{
|
w.gui.Message(messages.SetWorldName{
|
||||||
WorldName: w.worldState.Name,
|
WorldName: w.worldState.Name,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -301,25 +284,22 @@ func (w *worldsServer) SaveAndReset() {
|
||||||
for cp := range w.worldState.chunks {
|
for cp := range w.worldState.chunks {
|
||||||
keys = append(keys, cp)
|
keys = append(keys, cp)
|
||||||
}
|
}
|
||||||
for _, cp := range keys {
|
|
||||||
has_any := false
|
for _, cp := range fp.Filter(func(cp protocol.ChunkPos) bool {
|
||||||
for _, sc := range w.worldState.chunks[cp].Sub() {
|
return fp.Some(func(sc *chunk.SubChunk) bool {
|
||||||
has_any = !sc.Empty()
|
return !sc.Empty()
|
||||||
if has_any {
|
})(w.worldState.chunks[cp].Sub())
|
||||||
break
|
})(keys) {
|
||||||
}
|
delete(w.worldState.chunks, cp)
|
||||||
}
|
|
||||||
if !has_any {
|
|
||||||
delete(w.worldState.chunks, cp)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(w.worldState.chunks) == 0 {
|
if len(w.worldState.chunks) == 0 {
|
||||||
w.Reset(w.CurrentName())
|
w.Reset(w.CurrentName())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
logrus.Infof(locale.Loc("saving_world", locale.Strmap{"Name": w.worldState.Name, "Count": len(w.worldState.chunks)}))
|
logrus.Infof(locale.Loc("saving_world", locale.Strmap{"Name": w.worldState.Name, "Count": len(w.worldState.chunks)}))
|
||||||
w.gui.Message(messages.SavingWorld, messages.SavingWorldPayload{
|
w.gui.Message(messages.SavingWorld{
|
||||||
Name: w.worldState.Name,
|
Name: w.worldState.Name,
|
||||||
Chunks: len(w.worldState.chunks),
|
Chunks: len(w.worldState.chunks),
|
||||||
})
|
})
|
||||||
|
@ -558,11 +538,11 @@ func (w *worldsServer) SaveAndReset() {
|
||||||
logrus.Info(locale.Loc("saved", locale.Strmap{"Name": filename}))
|
logrus.Info(locale.Loc("saved", locale.Strmap{"Name": filename}))
|
||||||
//os.RemoveAll(folder)
|
//os.RemoveAll(folder)
|
||||||
w.Reset(w.CurrentName())
|
w.Reset(w.CurrentName())
|
||||||
w.gui.Message(messages.SetUIState, messages.UIStateMain)
|
w.gui.Message(messages.SetUIState(messages.UIStateMain))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *worldsServer) OnConnect(err error) bool {
|
func (w *worldsServer) OnConnect(err error) bool {
|
||||||
w.gui.Message(messages.SetUIState, messages.UIStateMain)
|
w.gui.Message(messages.SetUIState(messages.UIStateMain))
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false
|
return false
|
||||||
|
|
|
@ -114,8 +114,8 @@ func (g *GUI) run(w *app.Window) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *GUI) Message(name string, data interface{}) messages.MessageResponse {
|
func (g *GUI) Message(data interface{}) messages.MessageResponse {
|
||||||
r := g.router.Handler(name, data)
|
r := g.router.Handler(data)
|
||||||
if r.Ok || r.Data != nil {
|
if r.Ok || r.Data != nil {
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
@ -125,8 +125,8 @@ func (g *GUI) Message(name string, data interface{}) messages.MessageResponse {
|
||||||
Data: nil,
|
Data: nil,
|
||||||
}
|
}
|
||||||
|
|
||||||
switch name {
|
switch data.(type) {
|
||||||
case "can_show_images":
|
case messages.CanShowImages:
|
||||||
r.Ok = true
|
r.Ok = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ import (
|
||||||
"github.com/bedrock-tool/bedrocktool/ui/messages"
|
"github.com/bedrock-tool/bedrocktool/ui/messages"
|
||||||
)
|
)
|
||||||
|
|
||||||
type HandlerFunc = func(name string, data interface{}) messages.MessageResponse
|
type HandlerFunc = func(data interface{}) messages.MessageResponse
|
||||||
|
|
||||||
type Page interface {
|
type Page interface {
|
||||||
Actions() []component.AppBarAction
|
Actions() []component.AppBarAction
|
||||||
|
@ -133,10 +133,10 @@ func (r *Router) Layout(gtx layout.Context, th *material.Theme) layout.Dimension
|
||||||
return layout.Dimensions{Size: gtx.Constraints.Max}
|
return layout.Dimensions{Size: gtx.Constraints.Max}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Router) Handler(name string, data interface{}) messages.MessageResponse {
|
func (r *Router) Handler(data interface{}) messages.MessageResponse {
|
||||||
page, ok := r.pages[r.current]
|
page, ok := r.pages[r.current]
|
||||||
if ok {
|
if ok {
|
||||||
return page.Handler()(name, data)
|
return page.Handler()(data)
|
||||||
}
|
}
|
||||||
return messages.MessageResponse{}
|
return messages.MessageResponse{}
|
||||||
}
|
}
|
||||||
|
|
|
@ -176,7 +176,7 @@ func (p *Page) Layout(gtx C, th *material.Theme) D {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Page) Handler() pages.HandlerFunc {
|
func (p *Page) Handler() pages.HandlerFunc {
|
||||||
return func(name string, data interface{}) messages.MessageResponse {
|
return func(data interface{}) messages.MessageResponse {
|
||||||
return messages.MessageResponse{
|
return messages.MessageResponse{
|
||||||
Ok: false,
|
Ok: false,
|
||||||
Data: nil,
|
Data: nil,
|
||||||
|
|
|
@ -24,7 +24,7 @@ type Page struct {
|
||||||
State messages.UIState
|
State messages.UIState
|
||||||
SkinsList widget.List
|
SkinsList widget.List
|
||||||
l sync.Mutex
|
l sync.Mutex
|
||||||
Skins []messages.NewSkinPayload
|
Skins []messages.NewSkin
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(router *pages.Router) *Page {
|
func New(router *pages.Router) *Page {
|
||||||
|
@ -96,28 +96,20 @@ func (p *Page) Layout(gtx C, th *material.Theme) D {
|
||||||
return layout.Flex{}.Layout(gtx)
|
return layout.Flex{}.Layout(gtx)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Page) handler(name string, data interface{}) messages.MessageResponse {
|
func (p *Page) handler(data interface{}) messages.MessageResponse {
|
||||||
r := messages.MessageResponse{
|
r := messages.MessageResponse{
|
||||||
Ok: false,
|
Ok: false,
|
||||||
Data: nil,
|
Data: nil,
|
||||||
}
|
}
|
||||||
|
|
||||||
switch name {
|
switch m := data.(type) {
|
||||||
case messages.SetUIState:
|
case messages.SetUIState:
|
||||||
state := data.(messages.UIState)
|
p.State = m
|
||||||
p.State = state
|
|
||||||
p.Router.Invalidate()
|
p.Router.Invalidate()
|
||||||
r.Ok = true
|
r.Ok = true
|
||||||
|
|
||||||
case messages.Init:
|
|
||||||
init := data.(messages.InitPayload)
|
|
||||||
_ = init
|
|
||||||
r.Ok = true
|
|
||||||
|
|
||||||
case messages.NewSkin:
|
case messages.NewSkin:
|
||||||
p.l.Lock()
|
p.l.Lock()
|
||||||
new_skin := data.(messages.NewSkinPayload)
|
p.Skins = append(p.Skins, m)
|
||||||
p.Skins = append(p.Skins, new_skin)
|
|
||||||
p.l.Unlock()
|
p.l.Unlock()
|
||||||
p.Router.Invalidate()
|
p.Router.Invalidate()
|
||||||
r.Ok = true
|
r.Ok = true
|
||||||
|
|
|
@ -90,7 +90,7 @@ func drawTile(img *image.RGBA, min, pos protocol.ChunkPos, tile *image.RGBA) {
|
||||||
), tile, image.Point{}, draw.Src)
|
), tile, image.Point{}, draw.Src)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Map) Update(u *messages.UpdateMapPayload) {
|
func (m *Map) Update(u *messages.UpdateMap) {
|
||||||
if m.MapImage == nil {
|
if m.MapImage == nil {
|
||||||
m.scaleFactor = 1
|
m.scaleFactor = 1
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ type Page struct {
|
||||||
worldName string
|
worldName string
|
||||||
|
|
||||||
worldsList widget.List
|
worldsList widget.List
|
||||||
worlds []messages.SavingWorldPayload
|
worlds []messages.SavingWorld
|
||||||
l sync.Mutex
|
l sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,47 +115,33 @@ func (p *Page) Layout(gtx C, th *material.Theme) D {
|
||||||
return layout.Dimensions{}
|
return layout.Dimensions{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *Page) handler(name string, data interface{}) messages.MessageResponse {
|
func (u *Page) handler(data interface{}) messages.MessageResponse {
|
||||||
r := messages.MessageResponse{
|
r := messages.MessageResponse{
|
||||||
Ok: false,
|
Ok: false,
|
||||||
Data: nil,
|
Data: nil,
|
||||||
}
|
}
|
||||||
|
|
||||||
switch name {
|
switch m := data.(type) {
|
||||||
case messages.SetUIState:
|
case messages.SetUIState:
|
||||||
state := data.(messages.UIState)
|
u.State = m
|
||||||
u.State = state
|
|
||||||
u.Router.Invalidate()
|
u.Router.Invalidate()
|
||||||
r.Ok = true
|
r.Ok = true
|
||||||
|
|
||||||
case messages.Init:
|
|
||||||
init := data.(messages.InitPayload)
|
|
||||||
_ = init
|
|
||||||
r.Ok = true
|
|
||||||
|
|
||||||
case messages.UpdateMap:
|
case messages.UpdateMap:
|
||||||
update_map := data.(messages.UpdateMapPayload)
|
u.chunkCount = m.ChunkCount
|
||||||
u.chunkCount = update_map.ChunkCount
|
u.worldMap.Update(&m)
|
||||||
u.worldMap.Update(&update_map)
|
|
||||||
u.Router.Invalidate()
|
u.Router.Invalidate()
|
||||||
r.Ok = true
|
r.Ok = true
|
||||||
|
|
||||||
case messages.SetVoidGen:
|
case messages.SetVoidGen:
|
||||||
set_void_gen := data.(messages.SetVoidGenPayload)
|
u.voidGen = m.Value
|
||||||
u.voidGen = set_void_gen.Value
|
|
||||||
u.Router.Invalidate()
|
u.Router.Invalidate()
|
||||||
r.Ok = true
|
r.Ok = true
|
||||||
|
|
||||||
case messages.SetWorldName:
|
case messages.SetWorldName:
|
||||||
set_world_name := data.(messages.SetWorldNamePayload)
|
u.worldName = m.WorldName
|
||||||
u.worldName = set_world_name.WorldName
|
|
||||||
u.Router.Invalidate()
|
u.Router.Invalidate()
|
||||||
r.Ok = true
|
r.Ok = true
|
||||||
|
|
||||||
case messages.SavingWorld:
|
case messages.SavingWorld:
|
||||||
u.l.Lock()
|
u.l.Lock()
|
||||||
saving_world := data.(messages.SavingWorldPayload)
|
u.worlds = append(u.worlds, m)
|
||||||
u.worlds = append(u.worlds, saving_world)
|
|
||||||
u.l.Unlock()
|
u.l.Unlock()
|
||||||
u.Router.Invalidate()
|
u.Router.Invalidate()
|
||||||
r.Ok = true
|
r.Ok = true
|
||||||
|
|
|
@ -8,4 +8,4 @@ import (
|
||||||
type C = layout.Context
|
type C = layout.Context
|
||||||
type D = layout.Dimensions
|
type D = layout.Dimensions
|
||||||
|
|
||||||
type HandlerFunc = func(name string, data interface{}) messages.MessageResponse
|
type HandlerFunc = func(data interface{}) messages.MessageResponse
|
||||||
|
|
|
@ -11,7 +11,7 @@ type MessageResponse struct {
|
||||||
Data interface{}
|
Data interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
type UIState = int
|
type UIState int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
UIStateConnect = iota
|
UIStateConnect = iota
|
||||||
|
@ -24,39 +24,29 @@ type HandlerFunc = func(name string, data interface{}) MessageResponse
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
||||||
const SetUIState = "set_ui_state"
|
type SetUIState = UIState
|
||||||
|
|
||||||
type SetUIStatePayload = UIState
|
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
||||||
const SetVoidGen = "set_void_gen"
|
type SetVoidGen struct {
|
||||||
|
|
||||||
type SetVoidGenPayload struct {
|
|
||||||
Value bool
|
Value bool
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
||||||
const SetWorldName = "set_world_name"
|
type SetWorldName struct {
|
||||||
|
|
||||||
type SetWorldNamePayload struct {
|
|
||||||
WorldName string
|
WorldName string
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
||||||
var Init = "init"
|
type Init struct {
|
||||||
|
|
||||||
type InitPayload struct {
|
|
||||||
Handler HandlerFunc
|
Handler HandlerFunc
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
||||||
var UpdateMap = "update_map"
|
type UpdateMap struct {
|
||||||
|
|
||||||
type UpdateMapPayload struct {
|
|
||||||
ChunkCount int
|
ChunkCount int
|
||||||
Rotation float32
|
Rotation float32
|
||||||
UpdatedTiles []protocol.ChunkPos
|
UpdatedTiles []protocol.ChunkPos
|
||||||
|
@ -67,16 +57,14 @@ type UpdateMapPayload struct {
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
||||||
var NewSkin = "new_skin"
|
type NewSkin struct {
|
||||||
|
|
||||||
type NewSkinPayload struct {
|
|
||||||
PlayerName string
|
PlayerName string
|
||||||
Skin *protocol.Skin
|
Skin *protocol.Skin
|
||||||
}
|
}
|
||||||
|
|
||||||
var SavingWorld = "saving_world"
|
type SavingWorld struct {
|
||||||
|
|
||||||
type SavingWorldPayload struct {
|
|
||||||
Name string
|
Name string
|
||||||
Chunks int
|
Chunks int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type CanShowImages struct{}
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/bedrock-tool/bedrocktool/utils"
|
"github.com/bedrock-tool/bedrocktool/utils"
|
||||||
|
"github.com/repeale/fp-go"
|
||||||
"github.com/sandertv/gophertunnel/minecraft/resource"
|
"github.com/sandertv/gophertunnel/minecraft/resource"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
@ -73,22 +74,16 @@ func (bp *BehaviourPack) CheckAddLink(pack utils.Pack) {
|
||||||
|
|
||||||
hasEntitiesFolder := false
|
hasEntitiesFolder := false
|
||||||
if bp.HasEntities() {
|
if bp.HasEntities() {
|
||||||
for _, f := range z.File {
|
hasEntitiesFolder = fp.Some(func(f *zip.File) bool {
|
||||||
if f.Name == "entity" && f.FileInfo().IsDir() {
|
return f.Name == "entity" && f.FileInfo().IsDir()
|
||||||
hasEntitiesFolder = true
|
})(z.File)
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
hasItemsFolder := false
|
hasItemsFolder := false
|
||||||
if bp.HasItems() {
|
if bp.HasItems() {
|
||||||
for _, f := range z.File {
|
hasItemsFolder = fp.Some(func(f *zip.File) bool {
|
||||||
if f.Name == "items" && f.FileInfo().IsDir() {
|
return f.Name == "items" && f.FileInfo().IsDir()
|
||||||
hasItemsFolder = true
|
})(z.File)
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// has no assets needed
|
// has no assets needed
|
||||||
|
@ -139,7 +134,7 @@ func (bp *BehaviourPack) Save(fpath string) error {
|
||||||
return e.Encode(thing)
|
return e.Encode(thing)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(bp.blocks) > 0 { // blocks
|
if bp.HasBlocks() { // blocks
|
||||||
blocks_dir := path.Join(fpath, "blocks")
|
blocks_dir := path.Join(fpath, "blocks")
|
||||||
os.Mkdir(blocks_dir, 0o755)
|
os.Mkdir(blocks_dir, 0o755)
|
||||||
for _, be := range bp.blocks {
|
for _, be := range bp.blocks {
|
||||||
|
@ -149,7 +144,7 @@ func (bp *BehaviourPack) Save(fpath string) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(bp.items) > 0 { // items
|
if bp.HasItems() { // items
|
||||||
items_dir := path.Join(fpath, "items")
|
items_dir := path.Join(fpath, "items")
|
||||||
os.Mkdir(items_dir, 0o755)
|
os.Mkdir(items_dir, 0o755)
|
||||||
for _, ib := range bp.items {
|
for _, ib := range bp.items {
|
||||||
|
@ -159,7 +154,7 @@ func (bp *BehaviourPack) Save(fpath string) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(bp.entities) > 0 { // items
|
if bp.HasEntities() { // entities
|
||||||
items_dir := path.Join(fpath, "entities")
|
items_dir := path.Join(fpath, "entities")
|
||||||
os.Mkdir(items_dir, 0o755)
|
os.Mkdir(items_dir, 0o755)
|
||||||
for _, eb := range bp.entities {
|
for _, eb := range bp.entities {
|
||||||
|
|
|
@ -17,7 +17,7 @@ import (
|
||||||
type UI interface {
|
type UI interface {
|
||||||
Init() bool
|
Init() bool
|
||||||
Start(context.Context, context.CancelFunc) error
|
Start(context.Context, context.CancelFunc) error
|
||||||
Message(name string, data interface{}) messages.MessageResponse
|
Message(data interface{}) messages.MessageResponse
|
||||||
ServerInput(context.Context, string) (string, string, error)
|
ServerInput(context.Context, string) (string, string, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ type BaseUI struct {
|
||||||
UI
|
UI
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *BaseUI) Message(name string, data interface{}) messages.MessageResponse {
|
func (u *BaseUI) Message(data interface{}) messages.MessageResponse {
|
||||||
return messages.MessageResponse{
|
return messages.MessageResponse{
|
||||||
Ok: false,
|
Ok: false,
|
||||||
Data: nil,
|
Data: nil,
|
||||||
|
|
17
utils/net.go
17
utils/net.go
|
@ -1,8 +1,12 @@
|
||||||
package utils
|
package utils
|
||||||
|
|
||||||
import "net"
|
import (
|
||||||
|
"net"
|
||||||
|
|
||||||
var PrivateIPNetworks = []net.IPNet{
|
"github.com/repeale/fp-go"
|
||||||
|
)
|
||||||
|
|
||||||
|
var privateIPNetworks = []net.IPNet{
|
||||||
{
|
{
|
||||||
IP: net.ParseIP("10.0.0.0"),
|
IP: net.ParseIP("10.0.0.0"),
|
||||||
Mask: net.CIDRMask(8, 32),
|
Mask: net.CIDRMask(8, 32),
|
||||||
|
@ -19,12 +23,9 @@ var PrivateIPNetworks = []net.IPNet{
|
||||||
|
|
||||||
// IPPrivate checks if ip is private
|
// IPPrivate checks if ip is private
|
||||||
func IPPrivate(ip net.IP) bool {
|
func IPPrivate(ip net.IP) bool {
|
||||||
for _, ipNet := range PrivateIPNetworks {
|
return fp.Some(func(ipNet net.IPNet) bool {
|
||||||
if ipNet.Contains(ip) {
|
return ipNet.Contains(ip)
|
||||||
return true
|
})(privateIPNetworks)
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetLocalIP returns the non loopback local IP of the host
|
// GetLocalIP returns the non loopback local IP of the host
|
||||||
|
|
|
@ -120,30 +120,6 @@ func spawnConn(ctx context.Context, clientConn *minecraft.Conn, serverConn *mine
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// get longest line length
|
|
||||||
func maxLen(lines []string) int {
|
|
||||||
o := 0
|
|
||||||
for _, line := range lines {
|
|
||||||
if o < len(line) {
|
|
||||||
o = len(line)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return o
|
|
||||||
}
|
|
||||||
|
|
||||||
// MarginLines makes text centered
|
|
||||||
func MarginLines(lines []string) string {
|
|
||||||
ret := ""
|
|
||||||
max := maxLen(lines)
|
|
||||||
for _, line := range lines {
|
|
||||||
if len(line) != max {
|
|
||||||
ret += strings.Repeat(" ", max/2-len(line)/4)
|
|
||||||
}
|
|
||||||
ret += line + "\n"
|
|
||||||
}
|
|
||||||
return ret
|
|
||||||
}
|
|
||||||
|
|
||||||
// SplitExt splits path to filename and extension
|
// SplitExt splits path to filename and extension
|
||||||
func SplitExt(filename string) (name, ext string) {
|
func SplitExt(filename string) (name, ext string) {
|
||||||
name, ext = path.Base(filename), path.Ext(filename)
|
name, ext = path.Base(filename), path.Ext(filename)
|
||||||
|
|
Loading…
Reference in New Issue