Documentation ¶
Index ¶
- type Client
- func (mc *Client) CloseConnection() error
- func (mc *Client) Connect(host string) 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() (*packets.MinecraftPacket, 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 SerializablePacket
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶ added in v0.1.1
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 ¶ added in v0.2.0
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 ¶ added in v0.2.0
CloseConnection closes the underlying connection making further comunication impossible
func (*Client) Connect ¶ added in v0.1.1
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 ¶ added in v0.2.0
func (*Client) Initialize ¶ added in v0.1.1
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 ¶ added in v0.3.1
func (*Client) ReceivePacket ¶ added in v0.1.1
func (mc *Client) ReceivePacket() (*packets.MinecraftPacket, error)
ReceivePacket receives and deserializes a packet from the connection, uncompressing it if necessary
func (*Client) ReceiveRawPacket ¶ added in v0.3.1
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 ¶ added in v0.1.1
func (mc *Client) WritePacket(packet SerializablePacket) error
WritePacket calls SerializeData and then calls WriteRawPacket
func (*Client) WriteRawPacket ¶ added in v0.1.1
func (mc *Client) WriteRawPacket(rawPacket *packets.MinecraftRawPacket) error
WriteRawPacket takes a rawpacket as input and serializes it in the connection
type LoginDisconnectError ¶ added in v0.2.3
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 ¶ added in v0.2.3
func (disconnectError *LoginDisconnectError) Error() string
type SerializablePacket ¶ added in v0.2.0
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