Documentation ¶
Overview ¶
Package rcon implements Source RCON Protocol which is described in the documentation: https://developer.valvesoftware.com/wiki/Source_RCON_Protocol.
Index ¶
Constants ¶
const ( PacketPaddingSize int32 = 2 // Size of Packet's padding. PacketHeaderSize int32 = 8 // Size of Packet's header. MinPacketSize = PacketPaddingSize + PacketHeaderSize MaxPacketSize = 4096 + MinPacketSize )
Packet sizes definitions.
const ( // DefaultDialTimeout provides default auth timeout to remote server. DefaultDialTimeout = 5 * time.Second // DefaultDeadline provides default deadline to tcp read/write operations. DefaultDeadline = 5 * time.Second // MaxCommandLen is an artificial restriction, but it will help in case of random // large queries. MaxCommandLen = 1000 // SERVERDATA_AUTH is the first packet sent by the client, // which is used to authenticate the conn with the server. SERVERDATA_AUTH int32 = 3 // SERVERDATA_AUTH_ID is any positive integer, chosen by the client // (will be mirrored back in the server's response). SERVERDATA_AUTH_ID int32 = 0 // SERVERDATA_AUTH_RESPONSE packet is a notification of the conn's current auth // status. When the server receives an auth request, it will respond with an empty // SERVERDATA_RESPONSE_VALUE, followed immediately by a SERVERDATA_AUTH_RESPONSE // indicating whether authentication succeeded or failed. Note that the status // code is returned in the packet id field, so when pairing the response with // the original auth request, you may need to look at the packet id of the // preceding SERVERDATA_RESPONSE_VALUE. // If authentication was successful, the ID assigned by the request. // If auth failed, -1 (0xFF FF FF FF). SERVERDATA_AUTH_RESPONSE int32 = 2 // SERVERDATA_RESPONSE_VALUE packet is the response to a SERVERDATA_EXECCOMMAND // request. The ID assigned by the original request. SERVERDATA_RESPONSE_VALUE int32 = 0 // SERVERDATA_EXECCOMMAND packet type represents a command issued to the server // by a client. The response will vary depending on the command issued. SERVERDATA_EXECCOMMAND int32 = 2 // SERVERDATA_EXECCOMMAND_ID is any positive integer, chosen by the client // (will be mirrored back in the server's response). SERVERDATA_EXECCOMMAND_ID int32 = 0 )
Variables ¶
var ( // ErrAuthNotRCON is returned when got auth response with negative size. ErrAuthNotRCON = errors.New("response from not rcon server") // ErrInvalidAuthResponse is returned when we didn't get an auth packet // back for second read try after discard empty SERVERDATA_RESPONSE_VALUE // from authentication response. ErrInvalidAuthResponse = errors.New("invalid authentication packet type response") // ErrAuthFailed is returned when the package id from authentication // response is -1. ErrAuthFailed = errors.New("authentication failed") // ErrInvalidPacketID is returned when the package id from server response // was not mirrored back from request. ErrInvalidPacketID = errors.New("response for another request") // ErrInvalidPacketPadding is returned when the bytes after type field from // response is not equal to null-terminated ASCII strings. ErrInvalidPacketPadding = errors.New("invalid response padding") // ErrResponseTooSmall is returned when the server response is smaller // than 10 bytes. ErrResponseTooSmall = errors.New("response too small") // ErrCommandTooLong is returned when executed command length is bigger // than MaxCommandLen characters. ErrCommandTooLong = errors.New("command too long") // ErrCommandEmpty is returned when executed command length equal 0. ErrCommandEmpty = errors.New("command too small") // ErrMultiErrorOccurred is returned when close connection failed with // error after auth failed. ErrMultiErrorOccurred = errors.New("an error occurred while handling another error") )
var DefaultSettings = Settings{ // contains filtered or unexported fields }
DefaultSettings provides default deadline settings to Conn.
Functions ¶
This section is empty.
Types ¶
type Conn ¶
type Conn struct {
// contains filtered or unexported fields
}
Conn is source RCON generic stream-oriented network connection.
func (*Conn) Execute ¶
Execute sends command type and it string to execute to the remote server, creating a packet with a SERVERDATA_EXECCOMMAND_ID for the server to mirror, and compiling its payload bytes in the appropriate order. The response body is decompiled from bytes into a string for return.
func (*Conn) RemoteAddr ¶
RemoteAddr returns the remote network address.
type Option ¶ added in v1.2.0
type Option func(s *Settings)
Option allows to inject settings to Settings.
func SetDeadline ¶ added in v1.2.0
SetDeadline injects read/write Timeout to Settings.
func SetDialTimeout ¶ added in v1.2.0
SetDialTimeout injects dial Timeout to Settings.
type Packet ¶
type Packet struct { // The packet size field is a 32-bit little endian integer, representing // the length of the request in bytes. Note that the packet size field // itself is not included when determining the size of the packet, // so the value of this field is always 4 less than the packet's actual // length. The minimum possible value for packet size is 10. // The maximum possible value of packet size is 4096. // If the response is too large to fit into one packet, it will be split // and sent as multiple packets. Size int32 // The packet id field is a 32-bit little endian integer chosen by the // client for each request. It may be set to any positive integer. // When the RemoteServer responds to the request, the response packet // will have the same packet id as the original request (unless it is // a failed SERVERDATA_AUTH_RESPONSE packet). // It need not be unique, but if a unique packet id is assigned, // it can be used to match incoming responses to their corresponding requests. ID int32 // The packet type field is a 32-bit little endian integer, which indicates // the purpose of the packet. Its value will always be either 0, 2, or 3, // depending on which of the following request/response types the packet // represents: // SERVERDATA_AUTH = 3, // SERVERDATA_AUTH_RESPONSE = 2, // SERVERDATA_EXECCOMMAND = 2, // SERVERDATA_RESPONSE_VALUE = 0. Type int32 // contains filtered or unexported fields }
Packet is a rcon packet. Both requests and responses are sent as TCP packets. Their payload follows the following basic structure.
func NewPacket ¶
NewPacket creates and initializes a new Packet using packetType, packetID and body as its initial contents. NewPacket is intended to calculate packet size from body length and 10 bytes for rcon headers and termination strings.