pub struct RconClient { /* private fields */ }Expand description
The basic type to connect to a RCON server and execute commands.
It is certainly not safe to share this in concurrent applications. There should always be only one thread at a time which submits commands, etc.
Implementations§
Source§impl RconClient
impl RconClient
Sourcepub fn exec<T: Into<String>>(&mut self, command: T) -> Result<String>
pub fn exec<T: Into<String>>(&mut self, command: T) -> Result<String>
Submits a command to the open RCON stream. Submit means, that
it sends the package via stream, followed by the [control_packet],
then waits for returning packets until a response packet with a
packet id fitting the [control_packet] packet id is received.
All packets inbetween are considered to be an answer to the provided
RawPacket and their values are combined into one string.
Sourcepub fn open<A: Into<String>, P: Into<String>, C: Into<String>>(
addr: A,
pass: P,
safe_command: Option<C>,
timeout: Option<Duration>,
) -> Result<RconClient>
pub fn open<A: Into<String>, P: Into<String>, C: Into<String>>( addr: A, pass: P, safe_command: Option<C>, timeout: Option<Duration>, ) -> Result<RconClient>
Opens up a connection to an RCON server by connection via TCP/IP and authenticated
with provided pass.
A safe_command can be specified which needs to be a domain-specific RCON command
for which it is guaranteed to receive exactly one packet as an answer, i.e. it needs
to be a command which has an short answer.
If no safe_command is specified, the SERVERDATA_RESPONSE_VALUE trick is used, where
after every command an empty SERVERDATA_RESPONSE_VALUE packet is sent to the server to
trigger a RESPONSE_VALUE packet as a response and test for the end of command response.
(See the section
in this issue there.)
As a last parameter a timeout can be specified to let the function return with an error
after a certain number of seconds while no connection can be established.