Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pub struct RconConnection {
- pub addr: SocketAddr,
- pub secure: RconSecure,
- pub password: String,
- pub socket: Option<UdpSocket>,
- }
- impl RconConnection {
- pub fn new(addr: SocketAddr, password: String, secure: RconSecure) -> Self {
- Self {
- addr: addr,
- secure: secure,
- password: password,
- socket: None,
- }
- }
- pub fn connect(&mut self) -> Result<(), String> {
- let socket = UdpSocket::bind("0.0.0.0:0").map_err(|e| { format!("Could not bind socket: {}", e)})?;
- socket.connect(self.addr).map_err(|e| { format!("Could not connect: {}", e)})
- }
- pub fn send(&mut self, command: &str) -> std::io::Result<(usize)> {
- let socket = self.socket.as_ref().expect("Can't send anything before connected");
- let packet = RconOutgoingPacket {
- secure: self.secure,
- command: command,
- password: &self.password,
- challenge: None,
- };
- let res = socket.send(packet.prepare().as_slice());
- res
- }
- }
Add Comment
Please, Sign In to add comment