allow connection errors
This commit is contained in:
parent
6acb821a5a
commit
e53208969e
2
go.mod
2
go.mod
|
@ -3,7 +3,7 @@ module github.com/bedrock-tool/bedrocktool
|
|||
go 1.19
|
||||
|
||||
//replace github.com/sandertv/gophertunnel => ./gophertunnel
|
||||
replace github.com/sandertv/gophertunnel => github.com/olebeck/gophertunnel v1.27.3-2
|
||||
replace github.com/sandertv/gophertunnel => github.com/olebeck/gophertunnel v1.27.3-3
|
||||
|
||||
//replace github.com/df-mc/dragonfly => ./dragonfly
|
||||
replace github.com/df-mc/dragonfly => github.com/olebeck/dragonfly v0.9.2-1
|
||||
|
|
2
go.sum
2
go.sum
|
@ -74,6 +74,8 @@ github.com/olebeck/gophertunnel v1.27.3-1 h1:fexwhP7Pipgj0HohdjElOrPOZURZAGhPUFD
|
|||
github.com/olebeck/gophertunnel v1.27.3-1/go.mod h1:ekREo7U9TPHh86kbuPMaWA93NMyWsfVvP/iNT3XhAb8=
|
||||
github.com/olebeck/gophertunnel v1.27.3-2 h1:hl85ShVJUiIR+mGHfUgEDNVxN4r/XBVzqL8Kphl+Q9k=
|
||||
github.com/olebeck/gophertunnel v1.27.3-2/go.mod h1:ekREo7U9TPHh86kbuPMaWA93NMyWsfVvP/iNT3XhAb8=
|
||||
github.com/olebeck/gophertunnel v1.27.3-3 h1:/zpZ456rihGiWGUPihrZKNEj8pdCDtye2DSLxr7mZdE=
|
||||
github.com/olebeck/gophertunnel v1.27.3-3/go.mod h1:ekREo7U9TPHh86kbuPMaWA93NMyWsfVvP/iNT3XhAb8=
|
||||
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||
github.com/onsi/ginkgo v1.7.0 h1:WSHQ+IS43OoUrWtD1/bbclrwK8TTH5hzp+umCiuxHgs=
|
||||
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||
|
|
|
@ -147,8 +147,12 @@ func (c *SkinCMD) Execute(ctx context.Context, f *flag.FlagSet, _ ...interface{}
|
|||
|
||||
proxy, _ := utils.NewProxy(c.pathCustomUserData)
|
||||
proxy.WithClient = false
|
||||
proxy.ConnectCB = func(proxy *utils.ProxyContext) {
|
||||
proxy.ConnectCB = func(proxy *utils.ProxyContext, err error) bool {
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
logrus.Info(locale.Loc("ctrl_c_to_exit", nil))
|
||||
return true
|
||||
}
|
||||
|
||||
s := NewSkinsSession(proxy, hostname)
|
||||
|
@ -163,11 +167,11 @@ func (c *SkinCMD) Execute(ctx context.Context, f *flag.FlagSet, _ ...interface{}
|
|||
err = proxy.Run(ctx, address)
|
||||
if err != nil {
|
||||
logrus.Error(err)
|
||||
} else {
|
||||
outPathBase := fmt.Sprintf("skins/%s", hostname)
|
||||
os.MkdirAll(outPathBase, 0o755)
|
||||
s.Save(outPathBase)
|
||||
}
|
||||
|
||||
outPathBase := fmt.Sprintf("skins/%s", hostname)
|
||||
os.MkdirAll(outPathBase, 0o755)
|
||||
s.Save(outPathBase)
|
||||
return 0
|
||||
}
|
||||
|
||||
|
|
|
@ -437,7 +437,10 @@ func (w *WorldState) SaveAndReset() {
|
|||
w.Reset()
|
||||
}
|
||||
|
||||
func (w *WorldState) OnConnect(proxy *utils.ProxyContext) {
|
||||
func (w *WorldState) OnConnect(proxy *utils.ProxyContext, err error) bool {
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
w.proxy = proxy
|
||||
gd := w.proxy.Server.GameData()
|
||||
|
||||
|
@ -526,4 +529,6 @@ func (w *WorldState) OnConnect(proxy *utils.ProxyContext) {
|
|||
Description: locale.Loc("void_desc", nil),
|
||||
},
|
||||
})
|
||||
|
||||
return true
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ func (p dummyProto) ConvertFromLatest(pk packet.Packet, _ *minecraft.Conn) []pac
|
|||
type (
|
||||
PacketFunc func(header packet.Header, payload []byte, src, dst net.Addr)
|
||||
PacketCallback func(pk packet.Packet, proxy *ProxyContext, toServer bool, timeReceived time.Time) (packet.Packet, error)
|
||||
ConnectCallback func(proxy *ProxyContext)
|
||||
ConnectCallback func(proxy *ProxyContext, err error) bool
|
||||
IngameCommand struct {
|
||||
Exec func(cmdline []string) bool
|
||||
Cmd protocol.Command
|
||||
|
@ -56,6 +56,7 @@ type ProxyContext struct {
|
|||
commands map[string]IngameCommand
|
||||
AlwaysGetPacks bool
|
||||
WithClient bool
|
||||
IgnoreDisconnect bool
|
||||
CustomClientData *login.ClientData
|
||||
|
||||
// called for every packet
|
||||
|
@ -68,8 +69,9 @@ type ProxyContext struct {
|
|||
|
||||
func NewProxy(pathCustomData string) (*ProxyContext, error) {
|
||||
p := &ProxyContext{
|
||||
commands: make(map[string]IngameCommand),
|
||||
WithClient: true,
|
||||
commands: make(map[string]IngameCommand),
|
||||
WithClient: true,
|
||||
IgnoreDisconnect: false,
|
||||
}
|
||||
if pathCustomData != "" {
|
||||
if err := p.LoadCustomUserData(pathCustomData); err != nil {
|
||||
|
@ -262,7 +264,7 @@ func (p *ProxyContext) Run(ctx context.Context, serverAddress string) (err error
|
|||
},
|
||||
}.Listen("raknet", ":19132")
|
||||
if err != nil {
|
||||
return
|
||||
return err
|
||||
}
|
||||
defer p.Listener.Close()
|
||||
|
||||
|
@ -288,24 +290,32 @@ func (p *ProxyContext) Run(ctx context.Context, serverAddress string) (err error
|
|||
cdp = p.CustomClientData
|
||||
}
|
||||
|
||||
p.Server, err = connectServer(ctx, serverAddress, cdp, p.AlwaysGetPacks, p.PacketFunc)
|
||||
if err != nil {
|
||||
err = fmt.Errorf(locale.Loc("failed_to_connect", locale.Strmap{"Address": serverAddress, "Err": err}))
|
||||
return
|
||||
}
|
||||
// spawn and start the game
|
||||
if err = spawnConn(ctx, p.Client, p.Server); err != nil {
|
||||
err = fmt.Errorf(locale.Loc("failed_to_spawn", locale.Strmap{"Err": err}))
|
||||
return
|
||||
}
|
||||
|
||||
defer p.Server.Close()
|
||||
if p.Listener != nil {
|
||||
defer p.Listener.Disconnect(p.Client, DisconnectReason)
|
||||
}
|
||||
|
||||
p.Server, err = connectServer(ctx, serverAddress, cdp, p.AlwaysGetPacks, p.PacketFunc)
|
||||
if err != nil {
|
||||
if p.ConnectCB != nil {
|
||||
if p.ConnectCB(p, err) {
|
||||
err = nil
|
||||
}
|
||||
}
|
||||
err = fmt.Errorf(locale.Loc("failed_to_connect", locale.Strmap{"Address": serverAddress, "Err": err}))
|
||||
return err
|
||||
}
|
||||
defer p.Server.Close()
|
||||
|
||||
// spawn and start the game
|
||||
if err = spawnConn(ctx, p.Client, p.Server); err != nil {
|
||||
err = fmt.Errorf(locale.Loc("failed_to_spawn", locale.Strmap{"Err": err}))
|
||||
return err
|
||||
}
|
||||
|
||||
if p.ConnectCB != nil {
|
||||
p.ConnectCB(p)
|
||||
if !p.ConnectCB(p, nil) {
|
||||
return errors.New("Cancelled")
|
||||
}
|
||||
}
|
||||
|
||||
wg := sync.WaitGroup{}
|
||||
|
|
|
@ -166,7 +166,7 @@ func createReplayConnection(ctx context.Context, filename string, onConnect Conn
|
|||
})
|
||||
gameStarted = true
|
||||
if onConnect != nil {
|
||||
onConnect(proxy)
|
||||
onConnect(proxy, nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Binary file not shown.
|
@ -74,7 +74,7 @@ func connectServer(ctx context.Context, address string, ClientData *login.Client
|
|||
},
|
||||
}.DialContext(ctx, "raknet", address)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return serverConn, err
|
||||
}
|
||||
|
||||
logrus.Debug(locale.Loc("connected", nil))
|
||||
|
|
Loading…
Reference in New Issue