|
4 | 4 | "bufio" |
5 | 5 | "bytes" |
6 | 6 | "context" |
| 7 | + "errors" |
7 | 8 | "fmt" |
8 | 9 | "github.com/google/uuid" |
9 | 10 | "io" |
@@ -227,7 +228,7 @@ func (c *Connector) HandleConnection(ctx context.Context, frontendConn net.Conn) |
227 | 228 |
|
228 | 229 | logrus. |
229 | 230 | WithField("client", clientAddr). |
230 | | - Info("Got connection") |
| 231 | + Debug("Got connection") |
231 | 232 | defer logrus.WithField("client", clientAddr).Debug("Closing frontend connection") |
232 | 233 |
|
233 | 234 | // Tee-off the inspected content to a buffer so that we can retransmit it to the backend connection |
@@ -273,14 +274,22 @@ func (c *Connector) HandleConnection(ctx context.Context, frontendConn net.Conn) |
273 | 274 |
|
274 | 275 | var playerInfo *PlayerInfo = nil |
275 | 276 | if handshake.NextState == mcproto.StateLogin { |
276 | | - playerInfo, err = c.readUserInfo(bufferedReader, clientAddr, handshake.NextState) |
| 277 | + playerInfo, err = c.readPlayerInfo(bufferedReader, clientAddr, handshake.NextState) |
277 | 278 | if err != nil { |
278 | | - logrus. |
279 | | - WithError(err). |
280 | | - WithField("clientAddr", clientAddr). |
281 | | - Error("Failed to read user info") |
282 | | - c.metrics.Errors.With("type", "read").Add(1) |
283 | | - return |
| 279 | + if errors.Is(err, io.EOF) { |
| 280 | + logrus. |
| 281 | + WithError(err). |
| 282 | + WithField("clientAddr", clientAddr). |
| 283 | + WithField("player", playerInfo). |
| 284 | + Warn("Truncated buffer while reading player info") |
| 285 | + } else { |
| 286 | + logrus. |
| 287 | + WithError(err). |
| 288 | + WithField("clientAddr", clientAddr). |
| 289 | + Error("Failed to read user info") |
| 290 | + c.metrics.Errors.With("type", "read").Add(1) |
| 291 | + return |
| 292 | + } |
284 | 293 | } |
285 | 294 | logrus. |
286 | 295 | WithField("client", clientAddr). |
@@ -319,7 +328,7 @@ func (c *Connector) HandleConnection(ctx context.Context, frontendConn net.Conn) |
319 | 328 | } |
320 | 329 | } |
321 | 330 |
|
322 | | -func (c *Connector) readUserInfo(bufferedReader *bufio.Reader, clientAddr net.Addr, state mcproto.State) (*PlayerInfo, error) { |
| 331 | +func (c *Connector) readPlayerInfo(bufferedReader *bufio.Reader, clientAddr net.Addr, state mcproto.State) (*PlayerInfo, error) { |
323 | 332 | loginPacket, err := mcproto.ReadPacket(bufferedReader, clientAddr, state) |
324 | 333 | if err != nil { |
325 | 334 | return nil, fmt.Errorf("failed to read login packet: %w", err) |
|
0 commit comments