Skip to content

Commit

Permalink
server/conn.go: add Conn method to expose the underlying connection
Browse files Browse the repository at this point in the history
  • Loading branch information
cooldogedev committed Jul 24, 2024
1 parent 737942c commit 1c93b47
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
10 changes: 9 additions & 1 deletion server/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ type Conn struct {
// It is used for reading and writing packets to the underlying connection.
func NewConn(conn io.ReadWriteCloser, addr net.Addr, logger *slog.Logger, token string, clientData login.ClientData, identityData login.IdentityData, pool packet.Pool) *Conn {
c := &Conn{
conn: conn,
conn: conn,
reader: proto.NewReader(conn),
writer: proto.NewWriter(conn),
logger: logger,
Expand Down Expand Up @@ -206,6 +206,14 @@ func (c *Conn) SpawnContext(ctx context.Context) error {
}
}

// Conn returns the underlying connection.
// Direct access to the underlying connection through this method is
// strongly discouraged due to the potential for unpredictable behavior.
// Use this method only when absolutely necessary.
func (c *Conn) Conn() io.ReadWriteCloser {
return c.conn
}

// GameData returns the game data set for the connection by the StartGame packet.
func (c *Conn) GameData() minecraft.GameData {
return c.gameData
Expand Down
1 change: 0 additions & 1 deletion server/packet/connection_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ func (pk *ConnectionRequest) ID() uint32 {
func (pk *ConnectionRequest) Marshal(io protocol.IO) {
io.String(&pk.Addr)
io.String(&pk.Token)

io.ByteSlice(&pk.ClientData)
io.ByteSlice(&pk.IdentityData)
}

0 comments on commit 1c93b47

Please sign in to comment.