Documentation ¶
Index ¶
- type Conn
- func (conn *Conn) ClientData() login.ClientData
- func (conn *Conn) Close() error
- func (conn *Conn) Flush() error
- func (conn *Conn) IdentityData() login.IdentityData
- func (conn *Conn) LocalAddr() net.Addr
- func (conn *Conn) Read(b []byte) (n int, err error)
- func (conn *Conn) ReadPacket() (pk packet.Packet, err error)
- func (conn *Conn) RemoteAddr() net.Addr
- func (conn *Conn) ResourcePacks() []*resource.Pack
- func (conn *Conn) SetDeadline(t time.Time) error
- func (conn *Conn) SetReadDeadline(t time.Time) error
- func (conn *Conn) SetWriteDeadline(t time.Time) error
- func (conn *Conn) SimulatePacketLoss(lossChance float64)
- func (conn *Conn) Write(b []byte) (n int, err error)
- func (conn *Conn) WritePacket(pk packet.Packet) error
- type Dialer
- type Listener
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Conn ¶
type Conn struct {
// contains filtered or unexported fields
}
Conn represents a Minecraft (Bedrock Edition) connection over a specific net.Conn transport layer. Its methods (Read, Write etc.) are safe to be called from multiple goroutines simultaneously.
func Dial ¶
Dial dials a Minecraft connection to the address passed over the network passed. The network must be "tcp", "tcp4", "tcp6", "unix", "unixpacket" or "raknet". A Conn is returned which may be used to receive packets from and send packets to.
A zero value of a Dialer struct is used to initiate the connection. A custom Dialer may be used to specify additional behaviour.
func (*Conn) ClientData ¶
func (conn *Conn) ClientData() login.ClientData
ClientData returns the client data the client connected with. Note that this client data may be changed during the session, so the data should only be used directly after connection, and should be updated after that by the caller.
func (*Conn) Close ¶
Close closes the Conn and its underlying connection. Before closing, it also calls Flush() so that any packets currently pending are sent out.
func (*Conn) Flush ¶
Flush flushes the packets currently buffered by the connections to the underlying net.Conn, so that they are directly sent.
func (*Conn) IdentityData ¶
func (conn *Conn) IdentityData() login.IdentityData
IdentityData returns the identity data of the connection. It holds the UUID, XUID and username of the connected client.
func (*Conn) Read ¶
Read reads a packet from the connection into the byte slice passed, provided the byte slice is big enough to carry the full packet. It is recommended to use ReadPacket() rather than Read() in cases where reading is done directly.
func (*Conn) ReadPacket ¶
ReadPacket reads a packet from the Conn, depending on the packet ID that is found in front of the packet data. If a read deadline is set, an error is returned if the deadline is reached before any packet is received. The packet received must not be held until the next packet is read using ReadPacket(). If the same type of packet is read, the previous one will be invalidated.
If the packet read was not implemented, a *packet.Unknown is returned, containing the raw payload of the packet read.
func (*Conn) RemoteAddr ¶
RemoteAddr returns the remote address of the underlying connection.
func (*Conn) ResourcePacks ¶
ResourcePacks returns a slice of all resource packs the connection holds. For a Conn obtained using a Listener, this holds all resource packs set to the Listener. For a Conn obtained using Dial, the resource packs include all packs sent by the server connected to.
func (*Conn) SetDeadline ¶
SetDeadline sets the read and write deadline of the connection. It is equivalent to calling SetReadDeadline and SetWriteDeadline at the same time.
func (*Conn) SetReadDeadline ¶
SetReadDeadline sets the read deadline of the Conn to the time passed. The time must be after time.Now(). Passing an empty time.Time to the method (time.Time{}) results in the read deadline being cleared.
func (*Conn) SetWriteDeadline ¶
SetWriteDeadline is a stub function to implement net.Conn. It has no functionality.
func (*Conn) SimulatePacketLoss ¶ added in v0.9.1
SimulatePacketLoss makes the connection simulate packet loss, with a loss chance passed. It will start to discard packets randomly depending on the loss chance, both for sending and for receiving packets. The function panics if a loss change is higher than 1 or lower than 0.
type Dialer ¶
type Dialer struct { // ErrorLog is a log.Logger that errors that occur during packet handling of servers are written to. By // default, ErrorLog is set to one equal to the global logger. ErrorLog *log.Logger // ClientData is the client data used to login to the server with. It includes fields such as the skin, // locale and UUIDs unique to the client. If empty, a default is sent produced using defaultClientData(). ClientData login.ClientData // IdentityData is the identity data used to login to the server with. It includes the username, UUID and // XUID of the player. // The IdentityData object is obtained using Minecraft auth if Email and Password are set. If not, the // object provided here is used, or a default one if left empty. IdentityData login.IdentityData // Email is the email used to login to the XBOX Live account. If empty, no attempt will be made to login, // and an unauthenticated login request will be sent. Email string // Password is the password used to login to the XBOX Live account. If Email is non-empty, a login attempt // will be made using this password. Password string // PacketFunc is called whenever a packet is read from or written to the connection returned when using // Dialer.Dial(). It includes packets that are otherwise covered in the connection sequence, such as the // Login packet. The function is called with the header of the packet and its raw payload, the address // from which the packet originated, and the destination address. PacketFunc func(header packet.Header, payload []byte, src, dst net.Addr) }
Dialer allows specifying specific settings for connection to a Minecraft server. The zero value of Dialer is used for the package level Dial function.
func (Dialer) Dial ¶
Dial dials a Minecraft connection to the address passed over the network passed. The network must be "tcp", "tcp4", "tcp6", "unix", "unixpacket" or "raknet". A Conn is returned which may be used to receive packets from and send packets to. Specific fields in the Dialer specify additional behaviour during the connection, such as authenticating to XBOX Live and custom client data.
type Listener ¶
type Listener struct { // ErrorLog is a log.Logger that errors that occur during packet handling of clients are written to. By // default, ErrorLog is set to one equal to the global logger. ErrorLog *log.Logger // ResourcePacks is a slice of resource packs that the listener may hold. Each client will be asked to // download these resource packs upon joining. ResourcePacks []*resource.Pack // TexturePacksRequired specifies if clients that join must accept the texture pack in order for them to // be able to join the server. If they don't accept, they can only leave the server. TexturePacksRequired bool // contains filtered or unexported fields }
Listener implements a Minecraft listener on top of an unspecific net.Listener. It abstracts away the login sequence of connecting clients and provides the implements the net.Listener interface to provide a consistent API.
func Listen ¶
Listen announces on the local network address. The network must be "tcp", "tcp4", "tcp6", "unix", "unixpacket" or "raknet". A Listener is returned which may be used to accept connections. If the host in the address parameter is empty or a literal unspecified IP address, Listen listens on all available unicast and anycast IP addresses of the local system.
func (*Listener) Accept ¶
Accept accepts a fully connected (on Minecraft layer) connection which is ready to receive and send packets. It is recommended to cast the net.Conn returned to a *minecraft.Conn so that it is possible to use the conn.ReadPacket() and conn.WritePacket() methods.
func (*Listener) HijackPong ¶ added in v0.1.0
HijackPong hijacks the pong response from a server at an address passed. The listener passed will continuously update its pong data by hijacking the pong data of the server at the address. The hijack will last until the listener is shut down. If the address passed could not be resolved, an error is returned. Calling HijackPong means that any current and future pong data set using listener.PongData is overwritten each update.