Minecraft v0.1.0 Minecraft.Connection View Source

Maintains the state of a client’s connection, and provides utilities for sending and receiving data. It is designed to be chained in a fashion similar to Plug.

Link to this section Summary

Types

The possible states a client/server can be in

t()

Allowed ranch transport types

Functions

Closes the Connection

Continues receiving messages from the client

Initializes a Connection

Stores data received from the client in this Connection

Puts the Connection into the given error state

Sets the protocol for the Connection

Replaces the Connection’s underlying socket

Updates the Connection state

Pops a packet from the Connection

Sends a response to the client

Link to this section Types

Link to this type state() View Source
state() :: :handshake | :status | :login | :play

The possible states a client/server can be in.

Link to this type t() View Source
t() :: %Minecraft.Connection{
  client_ip: String.t(),
  current_state: state(),
  data: binary() | nil,
  error: any(),
  protocol_version: integer() | nil,
  socket: port() | nil,
  transport: transport() | nil
}
Link to this type transport() View Source
transport() :: :ranch_tcp

Allowed ranch transport types.

Link to this section Functions

Link to this function close(conn) View Source
close(t()) :: t()

Closes the Connection.

Link to this function continue(conn) View Source
continue(t()) :: t()

Continues receiving messages from the client.

To prevent a client from flooding our process mailbox, we only receive one message at a time, and explicitly continue to receive messages once we finish processing the ones we have.

Link to this function init(socket, transport) View Source
init(port(), transport()) :: t()

Initializes a Connection.

Link to this function put_data(conn, data) View Source
put_data(t(), binary()) :: t()

Stores data received from the client in this Connection.

Link to this function put_error(conn, error) View Source
put_error(t(), any()) :: t()

Puts the Connection into the given error state.

Link to this function put_protocol(conn, protocol_version) View Source
put_protocol(t(), integer()) :: t()

Sets the protocol for the Connection.

Link to this function put_socket(conn, socket) View Source
put_socket(t(), port()) :: t()

Replaces the Connection’s underlying socket.

Link to this function put_state(conn, state) View Source
put_state(t(), state()) :: t()

Updates the Connection state.

Link to this function read_packet(conn) View Source
read_packet(t()) :: {:ok, struct(), t()} | {:error, t()}

Pops a packet from the Connection.

Link to this function send_response(conn, response) View Source
send_response(t(), struct()) :: t()

Sends a response to the client.