Struct BERemoteConsole

Source
pub struct BERemoteConsole { /* private fields */ }

Implementations§

Source§

impl BERemoteConsole

Source

pub fn new(udp_socket: UdpSocketConnection) -> BERemoteConsole

Create new BERemoteConsole including a UDP socket

Examples found in repository?
examples/listen_to_socket.rs (line 20)
11fn main() {
12    let ip = "127.0.0.1".to_string();
13    let port = 2306;
14    let password = "password".to_string();
15    let udp_socket =
16        UdpSocket::bind((Ipv4Addr::UNSPECIFIED, 0)).expect("Unable to bind an IP address");
17    udp_socket.connect(ip.to_string() + ":" + &port.to_string());
18
19    let be_remote_console: Arc<BERemoteConsole> =
20        Arc::new(BERemoteConsole::new(UdpSocketConnection::new(udp_socket)));
21
22    be_remote_console.authenticate(password);
23
24    let keep_alive_socket = be_remote_console.clone();
25
26    thread::spawn(move || loop {
27        sleep(Duration::from_secs(35)); // BE recommends sending a keep alive packet before 45 seconds.
28        keep_alive_socket.keep_alive();
29    });
30
31    thread::spawn(move || loop {
32        sleep(Duration::from_millis(50)); // Reduce CPU workload
33        let response = be_remote_console
34            .receive_data()
35            .expect("Failed to receive socket data");
36
37        if response.is_empty() {
38            continue;
39        }
40
41        // println!("{:#04X?}", response);
42
43        match response[1] {
44            0x00 => {
45                if response[2] == 0x01 {
46                    println!("Authentication accepted");
47                } else {
48                    println!("Password does not match with BattlEye config file");
49                }
50            }
51            0x01 => {
52                if response[2] == 0x00 {
53                    println!(
54                        "{}",
55                        String::from_utf8(response[3..response.len()].to_owned()).unwrap()
56                    );
57                }
58            }
59            0x02 => {
60                println!(
61                    "{}",
62                    String::from_utf8(response[3..response.len()].to_owned()).unwrap()
63                );
64            }
65            _ => {
66                println!("Unknown packet identifier");
67            }
68        }
69    })
70    .join();
71}
More examples
Hide additional examples
examples/read_write_to_socket.rs (line 21)
12fn main() {
13    let ip = "127.0.0.1".to_string();
14    let port = 2306;
15    let password = "password".to_string();
16    let udp_socket =
17        UdpSocket::bind((Ipv4Addr::UNSPECIFIED, 0)).expect("Unable to bind an IP address");
18    udp_socket.connect(ip.to_string() + ":" + &port.to_string());
19
20    let be_remote_console: Arc<BERemoteConsole> =
21        Arc::new(BERemoteConsole::new(UdpSocketConnection::new(udp_socket)));
22
23    be_remote_console.authenticate(password);
24
25    let socket_commands = be_remote_console.clone();
26    let socket_keep_alive = be_remote_console.clone();
27
28    thread::spawn(move || loop {
29        sleep(Duration::from_secs(35));
30        socket_keep_alive.keep_alive();
31    });
32
33    // Thread for terminal input
34    thread::spawn(move || loop {
35        let mut input_string = String::new();
36        stdin()
37            .read_line(&mut input_string)
38            .expect("Did not enter a correct string");
39        socket_commands.send_command(input_string.trim());
40    });
41
42    thread::spawn(move || loop {
43        let response = be_remote_console
44            .receive_data()
45            .expect("Failed to receive socket data");
46
47        if response.is_empty() {
48            continue;
49        }
50
51        // println!("{:#04X?}", response);
52
53        match response[1] {
54            0x00 => {
55                if response[2] == 0x01 {
56                    println!("Authentication accepted.");
57                } else {
58                    println!("Password does not match with BattlEye config file.");
59                }
60            }
61            0x01 => {
62                if response[2] == 0x00 && response.len() > 3 {
63                    println!(
64                        "{}",
65                        String::from_utf8(response[3..response.len()].to_owned()).unwrap()
66                    );
67                }
68            }
69            0x02 => {
70                println!(
71                    "{}",
72                    String::from_utf8(response[3..response.len()].to_owned()).unwrap()
73                );
74            }
75            _ => {
76                println!("Unknown packet identifier.");
77            }
78        }
79    })
80    .join();
81}
Source

pub fn authenticate(&self, password: String) -> Result<usize>

Authenticate to BattlEye remote console server. Result will only throw an error if there is no established connection to the server. Incorrect authentication results an expected value and therefore will not raise an error.

Examples found in repository?
examples/listen_to_socket.rs (line 22)
11fn main() {
12    let ip = "127.0.0.1".to_string();
13    let port = 2306;
14    let password = "password".to_string();
15    let udp_socket =
16        UdpSocket::bind((Ipv4Addr::UNSPECIFIED, 0)).expect("Unable to bind an IP address");
17    udp_socket.connect(ip.to_string() + ":" + &port.to_string());
18
19    let be_remote_console: Arc<BERemoteConsole> =
20        Arc::new(BERemoteConsole::new(UdpSocketConnection::new(udp_socket)));
21
22    be_remote_console.authenticate(password);
23
24    let keep_alive_socket = be_remote_console.clone();
25
26    thread::spawn(move || loop {
27        sleep(Duration::from_secs(35)); // BE recommends sending a keep alive packet before 45 seconds.
28        keep_alive_socket.keep_alive();
29    });
30
31    thread::spawn(move || loop {
32        sleep(Duration::from_millis(50)); // Reduce CPU workload
33        let response = be_remote_console
34            .receive_data()
35            .expect("Failed to receive socket data");
36
37        if response.is_empty() {
38            continue;
39        }
40
41        // println!("{:#04X?}", response);
42
43        match response[1] {
44            0x00 => {
45                if response[2] == 0x01 {
46                    println!("Authentication accepted");
47                } else {
48                    println!("Password does not match with BattlEye config file");
49                }
50            }
51            0x01 => {
52                if response[2] == 0x00 {
53                    println!(
54                        "{}",
55                        String::from_utf8(response[3..response.len()].to_owned()).unwrap()
56                    );
57                }
58            }
59            0x02 => {
60                println!(
61                    "{}",
62                    String::from_utf8(response[3..response.len()].to_owned()).unwrap()
63                );
64            }
65            _ => {
66                println!("Unknown packet identifier");
67            }
68        }
69    })
70    .join();
71}
More examples
Hide additional examples
examples/read_write_to_socket.rs (line 23)
12fn main() {
13    let ip = "127.0.0.1".to_string();
14    let port = 2306;
15    let password = "password".to_string();
16    let udp_socket =
17        UdpSocket::bind((Ipv4Addr::UNSPECIFIED, 0)).expect("Unable to bind an IP address");
18    udp_socket.connect(ip.to_string() + ":" + &port.to_string());
19
20    let be_remote_console: Arc<BERemoteConsole> =
21        Arc::new(BERemoteConsole::new(UdpSocketConnection::new(udp_socket)));
22
23    be_remote_console.authenticate(password);
24
25    let socket_commands = be_remote_console.clone();
26    let socket_keep_alive = be_remote_console.clone();
27
28    thread::spawn(move || loop {
29        sleep(Duration::from_secs(35));
30        socket_keep_alive.keep_alive();
31    });
32
33    // Thread for terminal input
34    thread::spawn(move || loop {
35        let mut input_string = String::new();
36        stdin()
37            .read_line(&mut input_string)
38            .expect("Did not enter a correct string");
39        socket_commands.send_command(input_string.trim());
40    });
41
42    thread::spawn(move || loop {
43        let response = be_remote_console
44            .receive_data()
45            .expect("Failed to receive socket data");
46
47        if response.is_empty() {
48            continue;
49        }
50
51        // println!("{:#04X?}", response);
52
53        match response[1] {
54            0x00 => {
55                if response[2] == 0x01 {
56                    println!("Authentication accepted.");
57                } else {
58                    println!("Password does not match with BattlEye config file.");
59                }
60            }
61            0x01 => {
62                if response[2] == 0x00 && response.len() > 3 {
63                    println!(
64                        "{}",
65                        String::from_utf8(response[3..response.len()].to_owned()).unwrap()
66                    );
67                }
68            }
69            0x02 => {
70                println!(
71                    "{}",
72                    String::from_utf8(response[3..response.len()].to_owned()).unwrap()
73                );
74            }
75            _ => {
76                println!("Unknown packet identifier.");
77            }
78        }
79    })
80    .join();
81}
Source

pub fn receive_data(&self) -> Result<Vec<u8>, Error>

Listen to socket and if and only if there is a response from the server, then the validation can start. Unused bytes gets truncated from buffer.

After server response validation, gets validation has completed,

This method relies on an established connection from socket. If the socket is not connected or lost connection to host, it will fail.

This method ignores ErrorKind::WouldBlock and therefore an empty Vec gets returned.

Examples found in repository?
examples/listen_to_socket.rs (line 34)
11fn main() {
12    let ip = "127.0.0.1".to_string();
13    let port = 2306;
14    let password = "password".to_string();
15    let udp_socket =
16        UdpSocket::bind((Ipv4Addr::UNSPECIFIED, 0)).expect("Unable to bind an IP address");
17    udp_socket.connect(ip.to_string() + ":" + &port.to_string());
18
19    let be_remote_console: Arc<BERemoteConsole> =
20        Arc::new(BERemoteConsole::new(UdpSocketConnection::new(udp_socket)));
21
22    be_remote_console.authenticate(password);
23
24    let keep_alive_socket = be_remote_console.clone();
25
26    thread::spawn(move || loop {
27        sleep(Duration::from_secs(35)); // BE recommends sending a keep alive packet before 45 seconds.
28        keep_alive_socket.keep_alive();
29    });
30
31    thread::spawn(move || loop {
32        sleep(Duration::from_millis(50)); // Reduce CPU workload
33        let response = be_remote_console
34            .receive_data()
35            .expect("Failed to receive socket data");
36
37        if response.is_empty() {
38            continue;
39        }
40
41        // println!("{:#04X?}", response);
42
43        match response[1] {
44            0x00 => {
45                if response[2] == 0x01 {
46                    println!("Authentication accepted");
47                } else {
48                    println!("Password does not match with BattlEye config file");
49                }
50            }
51            0x01 => {
52                if response[2] == 0x00 {
53                    println!(
54                        "{}",
55                        String::from_utf8(response[3..response.len()].to_owned()).unwrap()
56                    );
57                }
58            }
59            0x02 => {
60                println!(
61                    "{}",
62                    String::from_utf8(response[3..response.len()].to_owned()).unwrap()
63                );
64            }
65            _ => {
66                println!("Unknown packet identifier");
67            }
68        }
69    })
70    .join();
71}
More examples
Hide additional examples
examples/read_write_to_socket.rs (line 44)
12fn main() {
13    let ip = "127.0.0.1".to_string();
14    let port = 2306;
15    let password = "password".to_string();
16    let udp_socket =
17        UdpSocket::bind((Ipv4Addr::UNSPECIFIED, 0)).expect("Unable to bind an IP address");
18    udp_socket.connect(ip.to_string() + ":" + &port.to_string());
19
20    let be_remote_console: Arc<BERemoteConsole> =
21        Arc::new(BERemoteConsole::new(UdpSocketConnection::new(udp_socket)));
22
23    be_remote_console.authenticate(password);
24
25    let socket_commands = be_remote_console.clone();
26    let socket_keep_alive = be_remote_console.clone();
27
28    thread::spawn(move || loop {
29        sleep(Duration::from_secs(35));
30        socket_keep_alive.keep_alive();
31    });
32
33    // Thread for terminal input
34    thread::spawn(move || loop {
35        let mut input_string = String::new();
36        stdin()
37            .read_line(&mut input_string)
38            .expect("Did not enter a correct string");
39        socket_commands.send_command(input_string.trim());
40    });
41
42    thread::spawn(move || loop {
43        let response = be_remote_console
44            .receive_data()
45            .expect("Failed to receive socket data");
46
47        if response.is_empty() {
48            continue;
49        }
50
51        // println!("{:#04X?}", response);
52
53        match response[1] {
54            0x00 => {
55                if response[2] == 0x01 {
56                    println!("Authentication accepted.");
57                } else {
58                    println!("Password does not match with BattlEye config file.");
59                }
60            }
61            0x01 => {
62                if response[2] == 0x00 && response.len() > 3 {
63                    println!(
64                        "{}",
65                        String::from_utf8(response[3..response.len()].to_owned()).unwrap()
66                    );
67                }
68            }
69            0x02 => {
70                println!(
71                    "{}",
72                    String::from_utf8(response[3..response.len()].to_owned()).unwrap()
73                );
74            }
75            _ => {
76                println!("Unknown packet identifier.");
77            }
78        }
79    })
80    .join();
81}
Source

pub fn send_command(&self, command: &str) -> Result<usize>

Dispatch a command to server. Command gets composed to make it identifiable to BattlEye.

This method relies on an established connection from socket. If the socket is not connected or lost connection to host, it will fail.

Examples found in repository?
examples/read_write_to_socket.rs (line 39)
12fn main() {
13    let ip = "127.0.0.1".to_string();
14    let port = 2306;
15    let password = "password".to_string();
16    let udp_socket =
17        UdpSocket::bind((Ipv4Addr::UNSPECIFIED, 0)).expect("Unable to bind an IP address");
18    udp_socket.connect(ip.to_string() + ":" + &port.to_string());
19
20    let be_remote_console: Arc<BERemoteConsole> =
21        Arc::new(BERemoteConsole::new(UdpSocketConnection::new(udp_socket)));
22
23    be_remote_console.authenticate(password);
24
25    let socket_commands = be_remote_console.clone();
26    let socket_keep_alive = be_remote_console.clone();
27
28    thread::spawn(move || loop {
29        sleep(Duration::from_secs(35));
30        socket_keep_alive.keep_alive();
31    });
32
33    // Thread for terminal input
34    thread::spawn(move || loop {
35        let mut input_string = String::new();
36        stdin()
37            .read_line(&mut input_string)
38            .expect("Did not enter a correct string");
39        socket_commands.send_command(input_string.trim());
40    });
41
42    thread::spawn(move || loop {
43        let response = be_remote_console
44            .receive_data()
45            .expect("Failed to receive socket data");
46
47        if response.is_empty() {
48            continue;
49        }
50
51        // println!("{:#04X?}", response);
52
53        match response[1] {
54            0x00 => {
55                if response[2] == 0x01 {
56                    println!("Authentication accepted.");
57                } else {
58                    println!("Password does not match with BattlEye config file.");
59                }
60            }
61            0x01 => {
62                if response[2] == 0x00 && response.len() > 3 {
63                    println!(
64                        "{}",
65                        String::from_utf8(response[3..response.len()].to_owned()).unwrap()
66                    );
67                }
68            }
69            0x02 => {
70                println!(
71                    "{}",
72                    String::from_utf8(response[3..response.len()].to_owned()).unwrap()
73                );
74            }
75            _ => {
76                println!("Unknown packet identifier.");
77            }
78        }
79    })
80    .join();
81}
Source

pub fn keep_alive(&self) -> Result<usize>

Send keep alive packet to BattlEye remote console server. This will ensure the server to keep you subscribed.

This method relies on an established connection from socket. If the socket is not connected or lost connection to host, it will fail.

Examples found in repository?
examples/listen_to_socket.rs (line 28)
11fn main() {
12    let ip = "127.0.0.1".to_string();
13    let port = 2306;
14    let password = "password".to_string();
15    let udp_socket =
16        UdpSocket::bind((Ipv4Addr::UNSPECIFIED, 0)).expect("Unable to bind an IP address");
17    udp_socket.connect(ip.to_string() + ":" + &port.to_string());
18
19    let be_remote_console: Arc<BERemoteConsole> =
20        Arc::new(BERemoteConsole::new(UdpSocketConnection::new(udp_socket)));
21
22    be_remote_console.authenticate(password);
23
24    let keep_alive_socket = be_remote_console.clone();
25
26    thread::spawn(move || loop {
27        sleep(Duration::from_secs(35)); // BE recommends sending a keep alive packet before 45 seconds.
28        keep_alive_socket.keep_alive();
29    });
30
31    thread::spawn(move || loop {
32        sleep(Duration::from_millis(50)); // Reduce CPU workload
33        let response = be_remote_console
34            .receive_data()
35            .expect("Failed to receive socket data");
36
37        if response.is_empty() {
38            continue;
39        }
40
41        // println!("{:#04X?}", response);
42
43        match response[1] {
44            0x00 => {
45                if response[2] == 0x01 {
46                    println!("Authentication accepted");
47                } else {
48                    println!("Password does not match with BattlEye config file");
49                }
50            }
51            0x01 => {
52                if response[2] == 0x00 {
53                    println!(
54                        "{}",
55                        String::from_utf8(response[3..response.len()].to_owned()).unwrap()
56                    );
57                }
58            }
59            0x02 => {
60                println!(
61                    "{}",
62                    String::from_utf8(response[3..response.len()].to_owned()).unwrap()
63                );
64            }
65            _ => {
66                println!("Unknown packet identifier");
67            }
68        }
69    })
70    .join();
71}
More examples
Hide additional examples
examples/read_write_to_socket.rs (line 30)
12fn main() {
13    let ip = "127.0.0.1".to_string();
14    let port = 2306;
15    let password = "password".to_string();
16    let udp_socket =
17        UdpSocket::bind((Ipv4Addr::UNSPECIFIED, 0)).expect("Unable to bind an IP address");
18    udp_socket.connect(ip.to_string() + ":" + &port.to_string());
19
20    let be_remote_console: Arc<BERemoteConsole> =
21        Arc::new(BERemoteConsole::new(UdpSocketConnection::new(udp_socket)));
22
23    be_remote_console.authenticate(password);
24
25    let socket_commands = be_remote_console.clone();
26    let socket_keep_alive = be_remote_console.clone();
27
28    thread::spawn(move || loop {
29        sleep(Duration::from_secs(35));
30        socket_keep_alive.keep_alive();
31    });
32
33    // Thread for terminal input
34    thread::spawn(move || loop {
35        let mut input_string = String::new();
36        stdin()
37            .read_line(&mut input_string)
38            .expect("Did not enter a correct string");
39        socket_commands.send_command(input_string.trim());
40    });
41
42    thread::spawn(move || loop {
43        let response = be_remote_console
44            .receive_data()
45            .expect("Failed to receive socket data");
46
47        if response.is_empty() {
48            continue;
49        }
50
51        // println!("{:#04X?}", response);
52
53        match response[1] {
54            0x00 => {
55                if response[2] == 0x01 {
56                    println!("Authentication accepted.");
57                } else {
58                    println!("Password does not match with BattlEye config file.");
59                }
60            }
61            0x01 => {
62                if response[2] == 0x00 && response.len() > 3 {
63                    println!(
64                        "{}",
65                        String::from_utf8(response[3..response.len()].to_owned()).unwrap()
66                    );
67                }
68            }
69            0x02 => {
70                println!(
71                    "{}",
72                    String::from_utf8(response[3..response.len()].to_owned()).unwrap()
73                );
74            }
75            _ => {
76                println!("Unknown packet identifier.");
77            }
78        }
79    })
80    .join();
81}

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.