strom: fix generator for pointer-receiver Encode, use nbt.Tag for named NBT
- Delete raw_capture subcommand (use tcpflow + raw-to-tmcpr instead) - Fix DefaultEncoder to use temp variable for non-addressable value encoding, eliminating manual post-generation patches - Map nbt and optionalNbt types to nbt.Tag (named NBT) instead of nbt.Anon (anonymous NBT) — 1.8 uses named NBT with root tag names
This commit is contained in:
@@ -1,62 +0,0 @@
|
|||||||
package raw_capture
|
|
||||||
|
|
||||||
import (
|
|
||||||
"flag"
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"net"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"github.com/admin-else/strom/mc/client"
|
|
||||||
)
|
|
||||||
|
|
||||||
var Cmd = flag.NewFlagSet("raw-capture", flag.ContinueOnError)
|
|
||||||
|
|
||||||
var TargetAddr = Cmd.String("addr", "127.0.0.1:25565", "address to connect to")
|
|
||||||
var ListenAddr = Cmd.String("listen", "127.0.0.1:25566", "address to listen on")
|
|
||||||
var ClientboundFile = Cmd.String("clientbound-file", "clientbound.tmcpr", "file to write clientbound packets to")
|
|
||||||
var ServerboundFile = Cmd.String("serverbound-file", "serverbound.tmcpr", "file to write serverbound packets to")
|
|
||||||
|
|
||||||
func Handle(c net.Conn, addr string) {
|
|
||||||
sockPuppet, err := net.Dial("tcp", addr)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
io.MultiWriter()
|
|
||||||
go io.Copy(c, sockPuppet)
|
|
||||||
io.Copy(sockPuppet, c)
|
|
||||||
}
|
|
||||||
func Run(args []string) (err error) {
|
|
||||||
err = Cmd.Parse(args)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
clientboundFile, err := os.Create(*ClientboundFile)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("create clientbound file: %w", err)
|
|
||||||
}
|
|
||||||
defer clientboundFile.Close()
|
|
||||||
|
|
||||||
serverboundFile, err := os.Create(*ServerboundFile)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("create serverbound file: %w", err)
|
|
||||||
}
|
|
||||||
defer serverboundFile.Close()
|
|
||||||
|
|
||||||
resolvedAddr, _, _, err := client.DoDNSChecked(nil, *TargetAddr, nil)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
l, err := net.Listen("tcp", *ListenAddr)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
for {
|
|
||||||
c, err := l.Accept()
|
|
||||||
if err != nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
go Handle(c, resolvedAddr)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+1130
-567
File diff suppressed because it is too large
Load Diff
+1050
-527
File diff suppressed because it is too large
Load Diff
+1130
-567
File diff suppressed because it is too large
Load Diff
+306
-155
File diff suppressed because it is too large
Load Diff
+1140
-572
File diff suppressed because it is too large
Load Diff
+1142
-573
File diff suppressed because it is too large
Load Diff
@@ -11,15 +11,16 @@ import (
|
|||||||
"github.com/go-viper/mapstructure/v2"
|
"github.com/go-viper/mapstructure/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func DefaultEncoder(_ *Generator, varToSet ast.Expr, _ any, _ string) (s []ast.Stmt, err error) {
|
func DefaultEncoder(_ *Generator, varToSet ast.Expr, _ any, name string) (s []ast.Stmt, err error) {
|
||||||
|
tmpName := name + "EncTmp"
|
||||||
s = Stmts(
|
s = Stmts(
|
||||||
|
Define121(Ident(tmpName), varToSet),
|
||||||
Assign121(
|
Assign121(
|
||||||
Ident("err"),
|
Ident("err"),
|
||||||
Call(SelectorExprAndStr(varToSet, "Encode"), Ident("w")),
|
Call(SelectorExprAndStr(Ident(tmpName), "Encode"), Ident("w")),
|
||||||
),
|
),
|
||||||
IfErrNil(),
|
IfErrNil(),
|
||||||
)
|
)
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -200,8 +200,8 @@ func (g *Generator) RegisterNatives() {
|
|||||||
"native": VisitDontGenerateType,
|
"native": VisitDontGenerateType,
|
||||||
"anonymousNbt": MakeSelectorVisitor("nbt", "Anon"),
|
"anonymousNbt": MakeSelectorVisitor("nbt", "Anon"),
|
||||||
"anonOptionalNbt": MakeSelectorVisitor("nbt", "Anon"), // I have no idea what the difference is between these two
|
"anonOptionalNbt": MakeSelectorVisitor("nbt", "Anon"), // I have no idea what the difference is between these two
|
||||||
"optionalNbt": MakeSelectorVisitor("nbt", "Anon"),
|
"optionalNbt": MakeSelectorVisitor("nbt", "Tag"),
|
||||||
"nbt": MakeSelectorVisitor("nbt", "Anon"),
|
"nbt": MakeSelectorVisitor("nbt", "Tag"),
|
||||||
"void": VoidType,
|
"void": VoidType,
|
||||||
"bool": MakeIdentVisitor("bool"),
|
"bool": MakeIdentVisitor("bool"),
|
||||||
"u8": MakeIdentVisitor("uint8"),
|
"u8": MakeIdentVisitor("uint8"),
|
||||||
|
|||||||
Reference in New Issue
Block a user