Documentation ¶
Index ¶
- Constants
- Variables
- func NewMcConn(conn net.Conn) mcConn
- func ReadNBytes(r DecodeReader, n int) ([]byte, error)
- func ReadNBytes_ByteReader(r io.ByteReader, n int) ([]byte, error)
- func ReadPacketBytes(r DecodeReader) ([]byte, error)
- func ReadPacketSize_Bytes(bytes []byte) (int, int, error)
- func ReadShot_ByteReader(r io.ByteReader) (int16, error)
- func ReadString_ByteReader(r io.ByteReader) (string, error)
- func ReadVarInt_ByteReader(b io.ByteReader) (int, error)
- func ScanFields(r DecodeReader, fields ...FieldDecoder) error
- type Byte
- type Chat
- type ClientBoundDisconnect
- type ClientBoundResponse
- type DecodeReader
- type DescriptionJSON
- type DifferentStatusResponse
- type Field
- type FieldDecoder
- type FieldEncoder
- type HandshakeState
- type Long
- type McPacket
- type McTypesHandshake
- type Packet
- type PlayerSampleJSON
- type PlayersJSON
- type ResponseJSON
- type ServerBoundHandshake
- func ReadPacket3_Handshake(r *bufio.Reader) (ServerBoundHandshake, error)
- func UnmarshalServerBoundHandshake(packet Packet) (ServerBoundHandshake, error)
- func UnmarshalServerBoundHandshake2(packet Packet) (ServerBoundHandshake, error)
- func UnmarshalServerBoundHandshake_ByteReader(r io.ByteReader) (ServerBoundHandshake, error)
- func (hs ServerBoundHandshake) IsForgeAddress() bool
- func (hs ServerBoundHandshake) IsLoginRequest() bool
- func (hs ServerBoundHandshake) IsRealIPAddress() bool
- func (hs ServerBoundHandshake) IsStatusRequest() bool
- func (pk ServerBoundHandshake) Marshal() Packet
- func (pk ServerBoundHandshake) MarshalPacket() Packet
- func (hs ServerBoundHandshake) ParseServerAddress() string
- func (hs ServerBoundHandshake) State() HandshakeState
- func (hs *ServerBoundHandshake) UpgradeToNewRealIP(clientAddr string, key *ecdsa.PrivateKey) error
- func (hs *ServerBoundHandshake) UpgradeToOldRealIP(clientAddr string)
- func (hs *ServerBoundHandshake) UpgradeToOldRealIP_WithTime(clientAddr string, stamp time.Time)
- type ServerBoundPing
- type ServerBoundRequest
- type ServerLoginStart
- type SimpleStatus
- type String
- type UnsignedShort
- type VarInt
- type VersionJSON
Constants ¶
const ( ServerBoundHandshakePacketID byte = 0x00 HandshakePacketID int = 0x00 StatusState = 1 LoginState = 2 HandshakeStatusState = VarInt(StatusState) HandshakeLoginState = VarInt(LoginState) ForgeSeparator = "\x00" RealIPSeparator = "///" )
const ( ClientBoundResponsePacketID byte = 0x00 ServerBoundRequestPacketID byte = 0x00 ServerBoundPingPacketID byte = 0x01 ClientBoundPongPacketID byte = 0x01 )
const ClientBoundDisconnectPacketID byte = 0x00
const ServerBoundLoginStartPacketID byte = 0x00
Variables ¶
var ( ErrInvalidPacketID = errors.New("invalid packet id") ErrPacketTooBig = errors.New("packet contains too much data") MaxPacketSize = 2097151 )
var (
ErrVarIntSize = errors.New("VarInt is too big")
)
Functions ¶
func ReadNBytes ¶
func ReadNBytes(r DecodeReader, n int) ([]byte, error)
ReadNBytes read N bytes from bytes.Reader
func ReadNBytes_ByteReader ¶
func ReadNBytes_ByteReader(r io.ByteReader, n int) ([]byte, error)
func ReadPacketBytes ¶
func ReadPacketBytes(r DecodeReader) ([]byte, error)
ReadPacketBytes decodes a byte stream and cuts the first Packet as a byte array out
func ReadShot_ByteReader ¶
func ReadShot_ByteReader(r io.ByteReader) (int16, error)
Decode a UnsignedShort
func ReadString_ByteReader ¶
func ReadString_ByteReader(r io.ByteReader) (string, error)
Decode a String
func ReadVarInt_ByteReader ¶
func ReadVarInt_ByteReader(b io.ByteReader) (int, error)
func ScanFields ¶
func ScanFields(r DecodeReader, fields ...FieldDecoder) error
ScanFields decodes a byte stream into fields
Types ¶
type ClientBoundDisconnect ¶
type ClientBoundDisconnect struct {
Reason Chat
}
func UnmarshalClientDisconnect ¶
func UnmarshalClientDisconnect(packet Packet) (ClientBoundDisconnect, error)
func (ClientBoundDisconnect) Marshal ¶
func (pk ClientBoundDisconnect) Marshal() Packet
func (*ClientBoundDisconnect) MarshalPacket ¶
func (pk *ClientBoundDisconnect) MarshalPacket() Packet
type ClientBoundResponse ¶
type ClientBoundResponse struct {
JSONResponse String
}
func UnmarshalClientBoundResponse ¶
func UnmarshalClientBoundResponse(packet Packet) (ClientBoundResponse, error)
func (*ClientBoundResponse) Marshal ¶
func (pk *ClientBoundResponse) Marshal() Packet
type DecodeReader ¶
type DecodeReader interface { io.ByteReader io.Reader }
DecodeReader is both io.Reader and io.ByteReader
type DescriptionJSON ¶
type DescriptionJSON struct {
Text string `json:"text"`
}
type DifferentStatusResponse ¶
type DifferentStatusResponse struct { Version VersionJSON `json:"version"` Description DescriptionJSON `json:"description"` Favicon string `json:"favicon,omitempty"` }
func (*DifferentStatusResponse) Marshal ¶
func (pk *DifferentStatusResponse) Marshal() Packet
type Field ¶
type Field interface { FieldEncoder FieldDecoder }
A Field is both FieldEncoder and FieldDecoder
type FieldDecoder ¶
type FieldDecoder interface {
Decode(r DecodeReader) error
}
A FieldDecoder can Decode from minecraft protocol
type FieldEncoder ¶
type FieldEncoder interface {
Encode() []byte
}
A FieldEncoder can be encode as minecraft protocol used.
type HandshakeState ¶
type HandshakeState byte
const ( UnknownState HandshakeState = iota Status Login )
func RequestState ¶
func RequestState(n byte) HandshakeState
func (HandshakeState) String ¶
func (i HandshakeState) String() string
type McTypesHandshake ¶
type McTypesHandshake struct { ProtocolVersion VarInt ServerAddress String ServerPort UnsignedShort NextState VarInt }
type Packet ¶
Packet is the raw representation of message that is send between the client and the server
func MarshalPacket ¶
func MarshalPacket(ID byte, fields ...FieldEncoder) Packet
MarshalPacket transforms an ID and Fields into a Packet
func ReadPacket ¶
func ReadPacket(r DecodeReader) (Packet, error)
func ReadPacketOld ¶
func ReadPacketOld(r DecodeReader) (Packet, error)
ReadPacketOld decodes and decompresses a byte stream and cuts the first Packet out
func ReadPacket_WithBytes ¶
func ServerBoundRequestPacket ¶
func ServerBoundRequestPacket() Packet
func (Packet) Scan ¶
func (pk Packet) Scan(fields ...FieldDecoder) error
Scan decodes and copies the Packet data into the fields
type PlayerSampleJSON ¶
type PlayersJSON ¶
type PlayersJSON struct { Max int `json:"max"` Online int `json:"online"` Sample []PlayerSampleJSON `json:"sample"` }
type ResponseJSON ¶
type ResponseJSON struct { Version VersionJSON `json:"version"` Players PlayersJSON `json:"players"` Description DescriptionJSON `json:"description"` Favicon string `json:"favicon"` }
type ServerBoundHandshake ¶
type ServerBoundHandshake struct { ProtocolVersion int ServerAddress string ServerPort int16 NextState byte }
func ReadPacket3_Handshake ¶
func ReadPacket3_Handshake(r *bufio.Reader) (ServerBoundHandshake, error)
func UnmarshalServerBoundHandshake ¶
func UnmarshalServerBoundHandshake(packet Packet) (ServerBoundHandshake, error)
func UnmarshalServerBoundHandshake2 ¶
func UnmarshalServerBoundHandshake2(packet Packet) (ServerBoundHandshake, error)
func UnmarshalServerBoundHandshake_ByteReader ¶
func UnmarshalServerBoundHandshake_ByteReader(r io.ByteReader) (ServerBoundHandshake, error)
func (ServerBoundHandshake) IsForgeAddress ¶
func (hs ServerBoundHandshake) IsForgeAddress() bool
func (ServerBoundHandshake) IsLoginRequest ¶
func (hs ServerBoundHandshake) IsLoginRequest() bool
func (ServerBoundHandshake) IsRealIPAddress ¶
func (hs ServerBoundHandshake) IsRealIPAddress() bool
func (ServerBoundHandshake) IsStatusRequest ¶
func (hs ServerBoundHandshake) IsStatusRequest() bool
func (ServerBoundHandshake) Marshal ¶
func (pk ServerBoundHandshake) Marshal() Packet
func (ServerBoundHandshake) MarshalPacket ¶
func (pk ServerBoundHandshake) MarshalPacket() Packet
func (ServerBoundHandshake) ParseServerAddress ¶
func (hs ServerBoundHandshake) ParseServerAddress() string
func (ServerBoundHandshake) State ¶
func (hs ServerBoundHandshake) State() HandshakeState
func (*ServerBoundHandshake) UpgradeToNewRealIP ¶
func (hs *ServerBoundHandshake) UpgradeToNewRealIP(clientAddr string, key *ecdsa.PrivateKey) error
func (*ServerBoundHandshake) UpgradeToOldRealIP ¶
func (hs *ServerBoundHandshake) UpgradeToOldRealIP(clientAddr string)
func (*ServerBoundHandshake) UpgradeToOldRealIP_WithTime ¶
func (hs *ServerBoundHandshake) UpgradeToOldRealIP_WithTime(clientAddr string, stamp time.Time)
type ServerBoundPing ¶
type ServerBoundPing struct {
Time Long
}
func NewServerBoundPing ¶
func NewServerBoundPing() ServerBoundPing
func (ServerBoundPing) Marshal ¶
func (pk ServerBoundPing) Marshal() Packet
type ServerBoundRequest ¶
type ServerBoundRequest struct{}
func (ServerBoundRequest) Marshal ¶
func (pk ServerBoundRequest) Marshal() Packet
func (*ServerBoundRequest) MarshalPacket ¶
func (pk *ServerBoundRequest) MarshalPacket() Packet
type ServerLoginStart ¶
type ServerLoginStart struct {
Name String
}
func UnmarshalServerBoundLoginStart ¶
func UnmarshalServerBoundLoginStart(packet Packet) (ServerLoginStart, error)
func (ServerLoginStart) Marshal ¶
func (pk ServerLoginStart) Marshal() Packet
func (*ServerLoginStart) MarshalPacket ¶
func (pk *ServerLoginStart) MarshalPacket() Packet
type SimpleStatus ¶
type SimpleStatus struct { Name string `json:"name"` Protocol int `json:"protocol"` Description string `json:"text"` Favicon string `json:"favicon,omitempty"` }
func (SimpleStatus) Marshal ¶
func (pk SimpleStatus) Marshal() Packet
func (*SimpleStatus) MarshalPacket ¶
func (pk *SimpleStatus) MarshalPacket() Packet
type String ¶
type String string
String is sequence of Unicode scalar values with a max length of 32767
type UnsignedShort ¶
type UnsignedShort uint16
UnsignedShort is unsigned 16-bit integer
func ReadUnsignedShort ¶
func ReadUnsignedShort(r DecodeReader) (UnsignedShort, error)
Read a UnsignedShort
func (*UnsignedShort) Decode ¶
func (us *UnsignedShort) Decode(r DecodeReader) error
Decode a UnsignedShort
type VarInt ¶
type VarInt int32
VarInt is variable-length data encoding a two's complement signed 32-bit integer