Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
oq-x committed Sep 18, 2024
1 parent 4b1cf88 commit 46e025a
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 21 deletions.
20 changes: 15 additions & 5 deletions protocol/net/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import (
var PacketEncodeInterceptor func(c *Conn, pk packet.Encodeable) (stop bool)
var PacketDecodeInterceptor func(c *Conn, pk packet.Decodeable) (stop bool)

var PacketWriteInterceptor func(c *Conn, pk *bytes.Buffer) (stop bool)
var PacketReadInterceptor func(c *Conn, pk *bytes.Reader) (stop bool)
var PacketWriteInterceptor func(c *Conn, pk *bytes.Buffer, headerSize int32) (stop bool)
var PacketReadInterceptor func(c *Conn, pk *bytes.Reader, packetId int32) (stop bool)

const (
clientVeryOldMsg = "Your client is WAYYYYYY too old!!! this server supports MC 1.21"
Expand Down Expand Up @@ -108,10 +108,14 @@ func (conn *Conn) WritePacket(pk packet.Encodeable) error {

w := encoding.NewWriter(packetBuf)
// write the header for the packet

var headerSize int32
if conn.listener.cfg.CompressionThreshold < 0 || !conn.compressionSet {
packetBuf.Write([]byte{0x80, 0x80, 0})
headerSize = 3
} else if conn.compressionSet {
packetBuf.Write([]byte{0x80, 0x80, 0, 0x80, 0x80, 0})
headerSize = 6
}

if err := w.VarInt(pk.ID()); err != nil {
Expand All @@ -122,7 +126,7 @@ func (conn *Conn) WritePacket(pk packet.Encodeable) error {
}

if PacketWriteInterceptor != nil {
if PacketWriteInterceptor(conn, packetBuf) {
if PacketWriteInterceptor(conn, packetBuf, headerSize) {
return nil
}
}
Expand Down Expand Up @@ -232,6 +236,12 @@ func (conn *Conn) ReadPacket() (packet.Decodeable, error) {
packet = data
length = int32(len(data))

if PacketReadInterceptor != nil {
if PacketReadInterceptor(conn, bytes.NewReader(packet), packetId) {
return nil, fmt.Errorf("stopped by interceptor")
}
}

rd = encoding.NewReader(bytes.NewReader(packet), int(length))
} else {
var packetLength int32
Expand Down Expand Up @@ -271,7 +281,7 @@ func (conn *Conn) ReadPacket() (packet.Decodeable, error) {
r := bytes.NewReader(packet)

if PacketReadInterceptor != nil {
if PacketReadInterceptor(conn, r) {
if PacketReadInterceptor(conn, r, packetId) {
return nil, fmt.Errorf("stopped by interceptor")
}
}
Expand Down Expand Up @@ -305,7 +315,7 @@ func (conn *Conn) ReadPacket() (packet.Decodeable, error) {
r := bytes.NewReader(uncompressedPacket)

if PacketReadInterceptor != nil {
if PacketReadInterceptor(conn, r) {
if PacketReadInterceptor(conn, r, packetId) {
return nil, fmt.Errorf("stopped by interceptor")
}
}
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Zeppelin
Highly optimized server implementation written in [Go](https://go.dev) for Minecraft 1.21
Highly optimized server implementation written in [Go](https://go.dev) for Minecraft 1.21.1

[Discord Server](https://discord.gg/T8qEtDWPak)

Expand Down
18 changes: 10 additions & 8 deletions server/command/builder.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package command

import "github.com/zeppelinmc/zeppelin/protocol/net/packet/play"
import (
"github.com/zeppelinmc/zeppelin/protocol/net/packet/play"
)

const (
Bool = iota
Expand Down Expand Up @@ -97,25 +99,25 @@ func NewBoolArgument(name string, nodes ...Node) Node {
}

func NewIntegerArgument(name string, min, max *int32, nodes ...Node) Node {
flags := byte(0)

var m, x int32
flags := int8(0)
var props = make([]any, 1, 3)

if min != nil {
flags &= 0x01
m = *min
props = append(props, *min)
}
if max != nil {
flags &= 0x02
x = *max
props = append(props, *max)
}
props[0] = flags

return Node{
Node: play.Node{
Flags: play.NodeArgument,
Name: name,
ParserId: Integer,
Properties: []any{flags, m, x},
Properties: props,
},
children: nodes,
}
Expand All @@ -126,7 +128,7 @@ func NewStringArgument(name string, typ int, nodes ...Node) Node {
Node: play.Node{
Flags: play.NodeArgument,
Name: name,
ParserId: Integer,
ParserId: String,
Properties: []any{typ},
},
children: nodes,
Expand Down
3 changes: 3 additions & 0 deletions server/command/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ func (mgr *Manager) Call(command string, caller session.Session) {
if len(arguments) > 1 {
ctx.Arguments = arguments[1:]
}
if cmd.Callback == nil {
return
}
cmd.Callback(ctx)
}

Expand Down
14 changes: 7 additions & 7 deletions server/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,13 @@ func (p Plugin) Server() *Server {

func (srv *Server) loadPlugins() {
os.Mkdir("plugins", 0755)
fs.WalkDir(os.DirFS("plugins"), ".", func(path string, e fs.DirEntry, err error) error {
if path == "." || err != nil || e.IsDir() {
return nil
dir, _ := os.ReadDir("plugins")
for _, entry := range dir {
if entry.IsDir() {
continue
}

srv.loadPlugin("plugins/" + path)
return nil
})
srv.loadPlugin("plugins/" + entry.Name())
}
}

func (srv *Server) loadPlugin(name string) {
Expand All @@ -62,4 +61,5 @@ func (srv *Server) loadPlugin(name string) {
plugin.basePluginsPath = "plugins"
plugin.srv = srv
plugin.OnLoad(plugin)
os.Mkdir(plugin.Dir(), 0755)
}

0 comments on commit 46e025a

Please sign in to comment.