hopefully actually fix capture
This commit is contained in:
parent
28bfdb09e7
commit
6989421a10
|
@ -20,13 +20,6 @@ import (
|
|||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func cleanup() {
|
||||
logrus.Info("\nCleaning up\n")
|
||||
for i := len(utils.G_cleanup_funcs) - 1; i >= 0; i-- { // go through cleanup functions reversed
|
||||
utils.G_cleanup_funcs[i]()
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
|
@ -111,18 +104,15 @@ func main() {
|
|||
go func() {
|
||||
<-sigs
|
||||
cancel()
|
||||
cleanup()
|
||||
}()
|
||||
|
||||
ret := subcommands.Execute(ctx)
|
||||
cleanup()
|
||||
subcommands.Execute(ctx)
|
||||
|
||||
if utils.G_interactive {
|
||||
logrus.Info("Press Enter to exit.")
|
||||
input := bufio.NewScanner(os.Stdin)
|
||||
input.Scan()
|
||||
}
|
||||
os.Exit(int(ret))
|
||||
}
|
||||
|
||||
type TransCMD struct {
|
||||
|
|
|
@ -8,6 +8,7 @@ import (
|
|||
"io"
|
||||
"net"
|
||||
"os"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/bedrock-tool/bedrocktool/utils"
|
||||
|
@ -21,10 +22,20 @@ func init() {
|
|||
utils.RegisterCommand(&CaptureCMD{})
|
||||
}
|
||||
|
||||
var dump_lock sync.Mutex
|
||||
|
||||
func dump_packet(f io.WriteCloser, toServer bool, payload []byte) {
|
||||
binary.Write(f, binary.LittleEndian, uint32(len(payload)))
|
||||
dump_lock.Lock()
|
||||
defer dump_lock.Unlock()
|
||||
f.Write([]byte{0xAA, 0xAA, 0xAA, 0xAA})
|
||||
packet_size := uint32(len(payload))
|
||||
binary.Write(f, binary.LittleEndian, packet_size)
|
||||
binary.Write(f, binary.LittleEndian, toServer)
|
||||
f.Write(payload)
|
||||
_, err := f.Write(payload)
|
||||
if err != nil {
|
||||
logrus.Error(err)
|
||||
}
|
||||
f.Write([]byte{0xBB, 0xBB, 0xBB, 0xBB})
|
||||
}
|
||||
|
||||
type CaptureCMD struct {
|
||||
|
@ -67,6 +78,7 @@ func (c *CaptureCMD) Execute(ctx context.Context, f *flag.FlagSet, _ ...interfac
|
|||
}
|
||||
|
||||
err = proxy.Run(ctx, address)
|
||||
time.Sleep(2 * time.Second)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
return 1
|
||||
|
|
|
@ -169,6 +169,8 @@ func (c *WorldCMD) Execute(ctx context.Context, f *flag.FlagSet, _ ...interface{
|
|||
return pk, nil
|
||||
}
|
||||
|
||||
defer w.SaveAndReset()
|
||||
|
||||
err = proxy.Run(ctx, server_address)
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
|
@ -496,10 +498,6 @@ func (w *WorldState) OnConnect(proxy *utils.ProxyContext) {
|
|||
|
||||
w.proxy.SendMessage("use /setname <worldname>\nto set the world name")
|
||||
|
||||
utils.G_cleanup_funcs = append(utils.G_cleanup_funcs, func() {
|
||||
w.SaveAndReset()
|
||||
})
|
||||
|
||||
w.ui.Start()
|
||||
go func() { // send map item
|
||||
select {
|
||||
|
|
|
@ -32,6 +32,7 @@ func create_replay_connection(ctx context.Context, log *logrus.Logger, filename
|
|||
|
||||
game_started := false
|
||||
for {
|
||||
var magic uint32 = 0
|
||||
var packet_length uint32 = 0
|
||||
var toServer bool = false
|
||||
|
||||
|
@ -41,6 +42,10 @@ func create_replay_connection(ctx context.Context, log *logrus.Logger, filename
|
|||
return nil
|
||||
}
|
||||
|
||||
binary.Read(f, binary.LittleEndian, &magic)
|
||||
if magic != 0xAAAAAAAA {
|
||||
logrus.Fatal("Wrong Magic")
|
||||
}
|
||||
binary.Read(f, binary.LittleEndian, &packet_length)
|
||||
binary.Read(f, binary.LittleEndian, &toServer)
|
||||
payload := make([]byte, packet_length)
|
||||
|
@ -50,10 +55,16 @@ func create_replay_connection(ctx context.Context, log *logrus.Logger, filename
|
|||
return nil
|
||||
}
|
||||
if n != int(packet_length) {
|
||||
log.Error("Truncated")
|
||||
log.Errorf("Truncated %d", i)
|
||||
return nil
|
||||
}
|
||||
|
||||
var magic2 uint32
|
||||
binary.Read(f, binary.LittleEndian, &magic2)
|
||||
if magic2 != 0xBBBBBBBB {
|
||||
logrus.Fatal("Wrong Magic2")
|
||||
}
|
||||
|
||||
pk_data, err := minecraft.ParseData(payload, proxy.Server)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
@ -34,7 +34,6 @@ var (
|
|||
G_debug bool
|
||||
G_preload_packs bool
|
||||
G_interactive bool
|
||||
G_cleanup_funcs []func() = []func(){}
|
||||
)
|
||||
|
||||
var A string
|
||||
|
|
Loading…
Reference in New Issue