Skip to content

Commit 94674ca

Browse files
oq-xaimjel
andcommitted
start inventory handling
compression bug fix(@bn4t) Co-authored-by: Angel <aimjel@users.noreply.github.com>
1 parent b6af2e5 commit 94674ca

File tree

33 files changed

+786
-137
lines changed

33 files changed

+786
-137
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@ server-icon.png
2525
/server/session/a_test.go
2626
/qnbt2
2727
/qnbt2test.go
28-
/main
28+
/main
29+
/qnbt

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ require (
1515

1616
require github.com/oq-x/unsafe2 v0.0.0-20240901191313-2b7bec1d9e3b
1717

18+
require github.com/grailbio/base v0.0.11 // indirect
19+
1820
require (
1921
github.com/4kills/go-zlib v1.2.0
2022
github.com/aimjel/minecraft v0.0.0-20240907220502-e1fe5798908b

go.sum

Lines changed: 312 additions & 0 deletions
Large diffs are not rendered by default.

main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
_ "embed"
45
"fmt"
56
"math/rand"
67
"net/http"

protocol/nbt/qnbt/native/be.go

Lines changed: 0 additions & 5 deletions
This file was deleted.

protocol/nbt/qnbt/native/le.go

Lines changed: 0 additions & 5 deletions
This file was deleted.

protocol/nbt/qnbt/native/n.go

Lines changed: 0 additions & 13 deletions
This file was deleted.

protocol/net/conn.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,7 @@ var pkcppool = sync.Pool{
9292
},
9393
}
9494

95-
func (conn *Conn) WritePacket(pk packet.Encodeable) error {
96-
if conn.encrypted {
97-
conn.write_mu.Lock()
98-
defer conn.write_mu.Unlock()
99-
} //no lock seems to work fine without encryption (?)
95+
func (conn *Conn) wpk(pk packet.Encodeable) error {
10096
if PacketEncodeInterceptor != nil {
10197
if PacketEncodeInterceptor(conn, pk) {
10298
return nil
@@ -142,7 +138,7 @@ func (conn *Conn) WritePacket(pk packet.Encodeable) error {
142138
return err
143139
} else { // yes compression
144140
if conn.listener.cfg.CompressionThreshold > int32(packetBuf.Len())-6 { // packet is too small to be compressed
145-
i := encoding.PutVarInt(packetBuf.Bytes()[:3], int32(packetBuf.Len()-6))
141+
i := encoding.PutVarInt(packetBuf.Bytes()[:3], int32(packetBuf.Len()-3))
146142
if i != 2 {
147143
packetBuf.Bytes()[i] |= 0x80
148144
}
@@ -176,6 +172,14 @@ func (conn *Conn) WritePacket(pk packet.Encodeable) error {
176172
}
177173
}
178174

175+
func (conn *Conn) WritePacket(pk packet.Encodeable) error {
176+
if conn.encrypted {
177+
conn.write_mu.Lock()
178+
defer conn.write_mu.Unlock()
179+
} //no lock seems to work fine without encryption (?)
180+
return conn.wpk(pk)
181+
}
182+
179183
// 1MiB
180184
var MaxCompressedPacketSize = 1024 * 1024
181185

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package play
2+
3+
import (
4+
"github.com/zeppelinmc/zeppelin/protocol/net/io/encoding"
5+
"github.com/zeppelinmc/zeppelin/protocol/net/slot"
6+
)
7+
8+
// serverbound
9+
const PacketIdClickContainer = 0x0E
10+
11+
type ClickContainer struct {
12+
WindowId byte
13+
State int32
14+
Slot int16
15+
Button int8
16+
Mode int32
17+
ChangedSlots []ChangedSlot
18+
CarriedItem slot.Slot
19+
}
20+
21+
type ChangedSlot struct {
22+
slot.Slot
23+
Num int16
24+
}
25+
26+
func (ClickContainer) ID() int32 {
27+
return PacketIdClickContainer
28+
}
29+
30+
func (c *ClickContainer) Decode(r encoding.Reader) error {
31+
if err := r.Ubyte(&c.WindowId); err != nil {
32+
return err
33+
}
34+
if _, err := r.VarInt(&c.State); err != nil {
35+
return err
36+
}
37+
if err := r.Short(&c.Slot); err != nil {
38+
return err
39+
}
40+
if err := r.Byte(&c.Button); err != nil {
41+
return err
42+
}
43+
if _, err := r.VarInt(&c.Mode); err != nil {
44+
return err
45+
}
46+
var len int32
47+
if _, err := r.VarInt(&len); err != nil {
48+
return err
49+
}
50+
c.ChangedSlots = make([]ChangedSlot, len)
51+
52+
for i := int32(0); i < len; i++ {
53+
if err := r.Short(&c.ChangedSlots[i].Num); err != nil {
54+
return err
55+
}
56+
if err := c.ChangedSlots[i].Decode(r); err != nil {
57+
return err
58+
}
59+
}
60+
61+
return c.CarriedItem.Decode(r)
62+
}

protocol/net/pool.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ var ServerboundPool = map[int32]map[int32]func() packet.Decodeable{
4040
0x08: func() packet.Decodeable { return &play.ChunkBatchReceived{} },
4141
0x07: func() packet.Decodeable { return &play.PlayerSession{} },
4242
0x0A: func() packet.Decodeable { return &play.ClientInformation{} },
43+
0x0E: func() packet.Decodeable { return &play.ClickContainer{} },
4344
0x0F: func() packet.Decodeable { return &play.CloseContainer{} },
4445
0x12: func() packet.Decodeable { return &play.ServerboundPluginMessage{} },
4546
0x16: func() packet.Decodeable { return &play.Interact{} },

0 commit comments

Comments
 (0)