-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmc_conn.go
58 lines (49 loc) · 964 Bytes
/
mc_conn.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package main
import (
"bufio"
"io"
"net"
)
// minecraft connection that assists in writing/reading minecraft data types
type Reader interface {
io.ByteReader
io.Reader
}
type Writer interface {
io.Writer
}
type Conn struct {
Conn net.Conn
Reader
io.Writer
}
func NewConn(conn net.Conn) *Conn {
return &Conn{
Conn: conn,
Reader: bufio.NewReader(conn),
Writer: conn,
}
}
func (c *Conn) ReadVarInt() int {
return readVarInt(c)
}
func (c *Conn) WriteVarInt(n int) (int, error) {
return writeVarInt(n, c)
}
func (c *Conn) WriteVarShort(n uint16) (int, error) {
return writeVarShort(n, c)
}
func (c *Conn) WriteString(s string) (int, error) {
return writeString(s, c)
}
func (c *Conn) ReadString() string {
return readString(c)
}
func (c *Conn) WritePacket(packetID byte, data []byte) (int, error) {
c.WriteVarInt(len(data) + 1)
c.Write([]byte{packetID})
return c.Write(data)
}
func (c *Conn) Close() error {
return c.Conn.Close()
}