这是indexloc提供的服务,不要输入任何密码
Skip to content
Closed
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
11 changes: 11 additions & 0 deletions minecraft/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,17 @@ func (conn *Conn) Context() context.Context {
return conn.ctx
}

// Disconnect disconnects the connection by first sending a disconnect packet with the message passed, and
// closing the connection after. If the message passed is empty, the client will be immediately sent to the
// server list instead of a disconnect screen.
func (conn *Conn) Disconnect(message string) error {
_ = conn.WritePacket(&packet.Disconnect{
HideDisconnectionScreen: message == "",
Message: message,
})
Comment on lines +584 to +587
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sends a Disconnect packet to the server if it is a client connection. That is not a logical change.

return conn.close(conn.closeErr(message))
}

// takeDeferredPacket locks the deferred packets lock and takes the next packet from the list of deferred
// packets. If none was found, it returns false, and if one was found, the data and true is returned.
func (conn *Conn) takeDeferredPacket() (*packetData, bool) {
Expand Down
17 changes: 7 additions & 10 deletions minecraft/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,19 @@ import (
"crypto/rand"
"errors"
"fmt"
"github.com/sandertv/gophertunnel/minecraft/internal"
"github.com/sandertv/gophertunnel/minecraft/protocol"
"github.com/sandertv/gophertunnel/minecraft/protocol/login"
"github.com/sandertv/gophertunnel/minecraft/protocol/packet"
"github.com/sandertv/gophertunnel/minecraft/resource"
"log/slog"
"math"
"net"
"slices"
"sync"
"sync/atomic"
"time"

"github.com/sandertv/gophertunnel/minecraft/internal"
"github.com/sandertv/gophertunnel/minecraft/protocol"
"github.com/sandertv/gophertunnel/minecraft/protocol/login"
"github.com/sandertv/gophertunnel/minecraft/protocol/packet"
"github.com/sandertv/gophertunnel/minecraft/resource"
)

// ListenConfig holds settings that may be edited to change behaviour of a Listener.
Expand Down Expand Up @@ -187,11 +188,7 @@ func (listener *Listener) Accept() (net.Conn, error) {
// closing the connection after. If the message passed is empty, the client will be immediately sent to the
// server list instead of a disconnect screen.
func (listener *Listener) Disconnect(conn *Conn, message string) error {
_ = conn.WritePacket(&packet.Disconnect{
HideDisconnectionScreen: message == "",
Message: message,
})
return conn.close(conn.closeErr(message))
return conn.Disconnect(message)
}

// AddResourcePack adds a new resource pack to the listener's resource packs.
Expand Down