Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions mcproto/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ func DecodeLoginStart(data interface{}) (*LoginStart, error) {

loginStart.Name, err = ReadString(buffer)
if err != nil {
return nil, errors.Wrap(err, "failed to read username")
return loginStart, errors.Wrap(err, "failed to read username")
}

loginStart.PlayerUuid, err = ReadUuid(buffer)
if err != nil {
return nil, errors.Wrap(err, "failed to read player uuid")
return loginStart, errors.Wrap(err, "failed to read player uuid")
}

return loginStart, nil
Expand Down
6 changes: 4 additions & 2 deletions mcproto/read.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Package mcproto provides functions to read types and decode frames declared
// at https://minecraft.wiki/w/Java_Edition_protocol
package mcproto

import (
Expand Down Expand Up @@ -27,7 +29,7 @@ const MaxFrameLength = 2097151
func ReadPacket(reader *bufio.Reader, addr net.Addr, state State) (*Packet, error) {
logrus.
WithField("client", addr).
Debug("Reading packet")
Trace("Reading packet")

if state == StateHandshaking {
data, err := reader.Peek(1)
Expand Down Expand Up @@ -158,7 +160,7 @@ func ReadUTF16BEString(reader io.Reader, symbolLen uint16) (string, error) {
func ReadFrame(reader io.Reader, addr net.Addr) (*Frame, error) {
logrus.
WithField("client", addr).
Debug("Reading frame")
Trace("Reading frame")

var err error
frame := &Frame{}
Expand Down
27 changes: 18 additions & 9 deletions server/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bufio"
"bytes"
"context"
"errors"
"fmt"
"github.com/google/uuid"
"io"
Expand Down Expand Up @@ -227,7 +228,7 @@ func (c *Connector) HandleConnection(ctx context.Context, frontendConn net.Conn)

logrus.
WithField("client", clientAddr).
Info("Got connection")
Debug("Got connection")
defer logrus.WithField("client", clientAddr).Debug("Closing frontend connection")

// Tee-off the inspected content to a buffer so that we can retransmit it to the backend connection
Expand Down Expand Up @@ -273,14 +274,22 @@ func (c *Connector) HandleConnection(ctx context.Context, frontendConn net.Conn)

var playerInfo *PlayerInfo = nil
if handshake.NextState == mcproto.StateLogin {
playerInfo, err = c.readUserInfo(bufferedReader, clientAddr, handshake.NextState)
playerInfo, err = c.readPlayerInfo(bufferedReader, clientAddr, handshake.NextState)
if err != nil {
logrus.
WithError(err).
WithField("clientAddr", clientAddr).
Error("Failed to read user info")
c.metrics.Errors.With("type", "read").Add(1)
return
if errors.Is(err, io.EOF) {
logrus.
WithError(err).
WithField("clientAddr", clientAddr).
WithField("player", playerInfo).
Warn("Truncated buffer while reading player info")
} else {
logrus.
WithError(err).
WithField("clientAddr", clientAddr).
Error("Failed to read user info")
c.metrics.Errors.With("type", "read").Add(1)
return
}
}
logrus.
WithField("client", clientAddr).
Expand Down Expand Up @@ -319,7 +328,7 @@ func (c *Connector) HandleConnection(ctx context.Context, frontendConn net.Conn)
}
}

func (c *Connector) readUserInfo(bufferedReader *bufio.Reader, clientAddr net.Addr, state mcproto.State) (*PlayerInfo, error) {
func (c *Connector) readPlayerInfo(bufferedReader *bufio.Reader, clientAddr net.Addr, state mcproto.State) (*PlayerInfo, error) {
loginPacket, err := mcproto.ReadPacket(bufferedReader, clientAddr, state)
if err != nil {
return nil, fmt.Errorf("failed to read login packet: %w", err)
Expand Down
Loading