Struct MSQClient

Source
pub struct MSQClient { /* private fields */ }
Expand description

The primary MSQ client driver (async)

  • Requires feature: async (Turned on by default)
  • Intended to be used with Filter and Region.
  • This uses the tokio asynchronous UDP Socket to achieve an async MSQ client driver.
  • The non-async/blocking version of this: MSQClientBlock

§Quick Start

use msq::{MSQClient, Region, Filter};
use std::io::Result;

#[tokio::main]
async fn main() -> Result<()> {
    let mut client = MSQClient::new().await?;
    client.connect("hl2master.steampowered.com:27011").await?;
    client.max_servers_on_query(256);

    let servers = client
        .query(Region::Europe,  // Restrict query to Europe region
            Filter::new()       // Create a Filter builder
                .appid(240)     // appid of 240 (CS:S)
                .nand()         // Start of NAND special filter
                    .map("de_dust2")     // Map is de_dust2
                    .empty(true)         // Server is empty
                .end()          // End of NAND special filter
                .gametype(&vec!["friendlyfire", "alltalk"])).await?;
    Ok(())
}

Implementations§

Source§

impl MSQClient

Source

pub async fn new() -> Result<MSQClient>

Create a new MSQClient variable and binds the UDP socket to 0.0.0.0:0

Source

pub async fn connect(&mut self, master_server_addr: &str) -> Result<()>

Connect the client to the given master server address/hostname

§Arguments
  • master_server_addr - The master server’s hostname/ip address
§Example
use msq::MSQClient;
use std::io::Result;

#[tokio::main]
async fn main() -> Result<()> {
    let mut client = MSQClient::new().await?;
    client.connect("hl2master.steampowered.com:27011").await?;
    Ok(())
}
Source

pub async fn query_raw( &mut self, region_code: u8, filter_str: &str, ) -> Result<Vec<String>>

Query with raw bytes

§Arguments
  • region_code - Region code in u8 (0x00 - 0x07 / 0xFF)
  • filter_str - Filter in plain string (EX: \\appid\\240\\map\\de_dust2)
Source

pub async fn query( &mut self, region: Region, filter: Filter, ) -> Result<Vec<String>>

Query with specified Region and Filter

Returns a Vec list of IP addresses in strings

§Arguments
  • region - Region enum (Region::USEast - Region::Africa / Region::All)
  • filter - Filter builder (EX: Filter::new().appid(240).map("de_dust2"))
Source

pub async fn single_query( master_server: &str, max_servers: usize, region: Region, filter: Filter, ) -> Result<Vec<String>>

Do a single query in one function

§Arguments
  • master_server - The address of the master server to fetch the query from
  • max_servers - The maximum amount of servers to query
  • region - Region enum (Region::USEast - Region::Africa / Region::All)
  • filter - Filter builder (EX: Filter::new().appid(240).map("de_dust2"))
§Example
use msq::{MSQClient, Region, Filter};
use std::io::Result;

#[tokio::main]
async fn main() -> Result<()> {
    let servers_list = MSQClient::single_query(
            "hl2master.steampowered.com:27011",
            256,
            Region::Europe,
            Filter::new().appid(240)).await?;
    Ok(())
}
Source

pub fn max_servers_on_query(&mut self, max_servers: usize)

Set maximum amount of servers in a given query

§Arguments
  • max_servers - Maximum amount of servers in a query

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.