RconClient

Struct RconClient 

Source
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

Source

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.

Source

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.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.