Documentation
¶
Index ¶
- type Client
- func (mc *Client) CloseConnection() error
- func (mc *Client) Connect(host string) error
- func (mc *Client) FromConnection(conn net.Conn) error
- func (client *Client) GetRemoteAddress() net.TCPAddr
- func (mc *Client) Initialize(host string, port uint16, protocolVersion int32, username string) error
- func (client *Client) IsCompressionEnabled() bool
- func (mc *Client) ReceivePacket() (*PacketReceipt, error)
- func (mc *Client) ReceiveRawPacket() (*packets.MinecraftRawPacket, error)
- func (mc *Client) WritePacket(packet SerializablePacket) error
- func (mc *Client) WriteRawPacket(rawPacket *packets.MinecraftRawPacket) error
- type LoginDisconnectError
- type PacketReceipt
- type SerializablePacket
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// Determines whenever a packet should be compressed or not
// if negative, the library will serialize packets using the Uncompressed Format (wiki.vg)
//
// automatically set by the Client.Initialize method, so if you are using this method
// to open up the connection between the server and the client you must not modify it
CompressionTreshold int32
// contains filtered or unexported fields
}
func FromListener ¶
func FromListener(ln *net.TCPListener) (client *Client, err error)
FromListener accepts the connection from a net.Listener and uses it as the underlying connection for packet comunication between the server and the client
func (*Client) CloseConnection ¶
CloseConnection closes the underlying connection making further comunication impossible
func (*Client) Connect ¶
Connect initializes the connection to the server.
host must have the format of "host:port" as a port has to be specified in order to open a connection. 25565 is not taken for granted
func (*Client) GetRemoteAddress ¶
func (*Client) Initialize ¶
func (mc *Client) Initialize(host string, port uint16, protocolVersion int32, username string) error
Initializes the connection to the server by sending the handshake packet and the login packet
host is the server fqdn or ip address of the server, port is the uint16 port where the server is listening on
username is the in-game username the client will send to the server during handshaking. Might differ from the actual in-game username as the server sends a confirmation of it after the login state.
func (*Client) IsCompressionEnabled ¶
func (*Client) ReceivePacket ¶
func (mc *Client) ReceivePacket() (*PacketReceipt, error)
ReceivePacket receives and deserializes a packet from the connection, uncompressing it if necessary
func (*Client) ReceiveRawPacket ¶
func (mc *Client) ReceiveRawPacket() (*packets.MinecraftRawPacket, error)
ReceiveRawPacket reads a raw packet from the connection but doesn't deserialize neither uncompress it
func (*Client) WritePacket ¶
func (mc *Client) WritePacket(packet SerializablePacket) error
WritePacket calls SerializeData and then calls WriteRawPacket
func (*Client) WriteRawPacket ¶
func (mc *Client) WriteRawPacket(rawPacket *packets.MinecraftRawPacket) error
WriteRawPacket takes a rawpacket as input and serializes it in the connection
type LoginDisconnectError ¶
type LoginDisconnectError struct {
// Reason is the json encoded Reason for which the client has been
// disconnected from the server
Reason string
}
LoginDisconnectError rapresents the disconnection of the client during the login state, during the initialization process
func (*LoginDisconnectError) Error ¶
func (disconnectError *LoginDisconnectError) Error() string
type PacketReceipt ¶ added in v1.0.2
type PacketReceipt struct {
Packet *packets.MinecraftPacket
RawPacket *packets.MinecraftRawPacket
}
type SerializablePacket ¶
type SerializablePacket interface {
// SerializeData takes an interface pointer as input and serializes all the fields in the
// data buffer. It can and will return an error in case of invalid data
SerializeData(inter interface{}) error
SerializeCompressed(writer io.Writer, compressionTreshold int) error
SerializeUncompressed(writer io.Writer) error
}
SerializablePacket defines the standard methods that a struct should have in order to be serializable by the library
You can actually create your own methods as long as they respect this standard