pub struct RconClient { /* private fields */ }
Expand description
A client that has connected to an RCON server.
See the crate-level documentation for an example.
Implementations§
Source§impl RconClient
impl RconClient
Sourcepub fn connect<A: ToSocketAddrs>(server_addr: A) -> Result<RconClient>
pub fn connect<A: ToSocketAddrs>(server_addr: A) -> Result<RconClient>
Construct a RconClient
and connect to a server at the given address.
See the crate-level documentation for an example.
§Errors
This function errors if any I/O errors occur while setting up the connection.
Most notably, if the server is not running or RCON is not enabled,
this method will error with ConnectionRefused
.
Sourcepub fn is_logged_in(&self) -> bool
pub fn is_logged_in(&self) -> bool
Returns whether this client is logged in.
Example:
let client = RconClient::connect("localhost:25575")?;
assert!(!client.is_logged_in());
client.log_in("SuperSecurePassword")?;
assert!(client.is_logged_in());
Sourcepub fn log_in(&self, password: &str) -> Result<(), LogInError>
pub fn log_in(&self, password: &str) -> Result<(), LogInError>
Attempts to log into the server with the given password.
See the crate-level documentation for an example.
§Errors
- If the password is longer than
MAX_OUTGOING_PAYLOAD_LEN
, returnsLogInError::PasswordTooLong
and does not send anything to the server. - If this client is already logged in, returns
LogInError::AlreadyLoggedIn
and does not send anything to the server. - If the given password is successfully sent, and the server responds indicating failure, returns
LogInError::BadPassword
. - If any I/O errors occur, returns
LogInError::IO
with the error. This notably includesConnectionAborted
if the server has closed the connection.
Sourcepub fn send_command(&self, command: &str) -> Result<String, CommandError>
pub fn send_command(&self, command: &str) -> Result<String, CommandError>
Sends the given command to the server and returns its response.
See the crate-level documentation for an example.
Valid commands are dependent on the server; documentation on the commands offered by vanilla Minecraft can be found at https://minecraft.wiki/w/Commands. Servers with mods or plugins may have other commands available.
The return value of this method is the response message from the server. This crate makes no attempt to interpret that response; in particular, this method will never error to indicate that the command failed: a successful return only means that the server recieved this command and responded to it.
§Errors
- If the command is longer than
MAX_OUTGOING_PAYLOAD_LEN
, returnsCommandError::CommandTooLong
and does not send anything to the server. - If this client is not logged in, returns
CommandError::NotLoggedIn
and does not send anything to the server. - If any I/O errors occur, returns
CommandError::IO
with the error. This notably includesConnectionAborted
if the server has closed the connection.