class RCON::Client
- RCON::Client
- Reference
- Object
Overview
This class represents a RCON connection.
RCON::Client.open(address, port, password) do |client|
client.command "say Hello from RCON =)"
end
Use as a Server
While this is primarily a client implementation it can also be used as for a server because both ends work in the same manner.
def handle_connection(socket)do
rcon = RCON::Client.new(socket)
packet = rcon.read_
puts "Received packet #{packet}"
# Probably need some authentication logic here
socket.close
end
TCPServer.open(27015) do |server|
while socket = server.accept?
spawn handle_connection(socket)
end
end
Defined in:
client.crConstructors
-
.new(socket : IO, sync_close : Bool = true)
Creates a new client instance wrapping socket.
Class Method Summary
-
.open(address : String, port : Int32, password : String | Nil, & : self -> )
Opens a new connection to the server at address:port and authenticates with password.
-
.open(uri : URI, & : self -> )
Opens a new connection to the server at uri and authenticates.
Instance Method Summary
-
#authenticate(password) : Bool
Sends an auth command to authenticate with password.
-
#close
Sends
#close
command and closes the connection. -
#closed? : Bool
Returns
true
when this client has been closed. -
#command(command : String) : String | Nil
Sends command and returns the server's response.
-
#read : Packet | Nil
Reads a response from the server.
-
#send(command : String | Bytes, cmd_type : Command | Int32 = Command::EXEC_COMMAND) : Int32
Sends command and returns the request id.
-
#send(packet : Packet)
Sends packet and returns the request id.
Constructor Detail
Creates a new client instance wrapping socket.
The socket should usually be a TCPSocket
, but it can really be any
IO
.
Calling .open
is recommended for most use cases. When using this
constructor, authentication needs to be handled explicitly (see
#authenticate
).
Class Method Detail
Opens a new connection to the server at address:port and authenticates with password. Yields the client instance to the block and ensures the connection is closed after returning.
Opens a new connection to the server at uri and authenticates.
URI format: rcon://:password@host:port
Yields the client instance to the block and ensures the connection is closed after returning.
Instance Method Detail
Sends an auth command to authenticate with password.
Return true
if authenticated successfully and false
otherwise.
Raises AuthenticationError
if there was an error in the authentication
process.
Reads a response from the server.
Returns nil
if the connection is closed.
Sends command and returns the request id.