Skip to content

Commit a7b3983

Browse files
committed
feat: multiprotocol 1.21.124
1 parent 5cd099b commit a7b3983

2 files changed

Lines changed: 45 additions & 1 deletion

File tree

cmd/main.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/df-mc/dragonfly/server/world"
1515
"github.com/didntpot/pregdk"
1616
"github.com/pelletier/go-toml"
17+
"github.com/sandertv/gophertunnel/minecraft"
1718
"github.com/secmc/plugin/plugin/adapters/handlers"
1819
"github.com/secmc/plugin/plugin/adapters/plugin"
1920
pcfg "github.com/secmc/plugin/plugin/config"
@@ -94,6 +95,9 @@ func readConfig(log *slog.Logger) (server.Config, error) {
9495
}
9596
}
9697
cfg, _ := c.Config(log)
97-
listenerFunc(&cfg, c.Network.Address, single(pregdk.Protocol(false)))
98+
listenerFunc(&cfg, c.Network.Address, []minecraft.Protocol{
99+
pregdk.Protocol(false),
100+
basicProtocol{Protocol: 860, Version: "1.21.124"},
101+
})
98102
return cfg, nil
99103
}

cmd/protocol.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package main
2+
3+
import (
4+
"github.com/sandertv/gophertunnel/minecraft"
5+
"github.com/sandertv/gophertunnel/minecraft/protocol"
6+
"github.com/sandertv/gophertunnel/minecraft/protocol/packet"
7+
)
8+
9+
// basicProtocol can be used to support multiple versions in cases of a simple Minecraft protocol
10+
// update where there were minimal changes.
11+
type basicProtocol struct {
12+
Protocol int32
13+
Version string
14+
}
15+
16+
func (b basicProtocol) ID() int32 { return b.Protocol }
17+
func (b basicProtocol) Ver() string { return b.Version }
18+
19+
func (b basicProtocol) Packets(listener bool) packet.Pool {
20+
if listener {
21+
return packet.NewClientPool()
22+
}
23+
return packet.NewServerPool()
24+
}
25+
26+
func (b basicProtocol) NewReader(r minecraft.ByteReader, shieldID int32, enableLimits bool) protocol.IO {
27+
return protocol.NewReader(r, shieldID, enableLimits)
28+
}
29+
30+
func (b basicProtocol) NewWriter(w minecraft.ByteWriter, shieldID int32) protocol.IO {
31+
return protocol.NewWriter(w, shieldID)
32+
}
33+
34+
func (b basicProtocol) ConvertToLatest(pk packet.Packet, _ *minecraft.Conn) []packet.Packet {
35+
return []packet.Packet{pk}
36+
}
37+
38+
func (b basicProtocol) ConvertFromLatest(pk packet.Packet, _ *minecraft.Conn) []packet.Packet {
39+
return []packet.Packet{pk}
40+
}

0 commit comments

Comments
 (0)