mirror of
https://github.com/tribufu/rust-gamedig
synced 2026-05-18 09:35:50 +00:00
[Protocol] Replace IpAddr with SocketAddr in protocols (#44)
* [Crate] Replace IpAddr with SocketAddr in protocols * [Crate] Remove usage of address.to_string in socket * [Crate] Update CHANGELOG.md
This commit is contained in:
parent
596d15df78
commit
e0830bdae5
70 changed files with 215 additions and 286 deletions
|
|
@ -2,12 +2,11 @@ use crate::bufferer::{Bufferer, Endianess};
|
|||
use crate::socket::{Socket, UdpSocket};
|
||||
use crate::valve_master_server::{Region, SearchFilters};
|
||||
use crate::{GDError, GDResult};
|
||||
use std::net::{IpAddr, Ipv4Addr};
|
||||
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
|
||||
|
||||
/// The default master ip, which is the one for Source.
|
||||
pub const DEFAULT_MASTER_IP: IpAddr = IpAddr::V4(Ipv4Addr::new(208, 64, 201, 194)); // hl2master.steampowered.com
|
||||
/// The default master port.
|
||||
pub const DEFAULT_MASTER_PORT: u16 = 27011;
|
||||
pub const DEFAULT_MASTER_ADDRESS: SocketAddr
|
||||
= SocketAddr::new(IpAddr::V4(Ipv4Addr::new(208, 64, 201, 194)), 27011); // hl2master.steampowered.com
|
||||
|
||||
fn construct_payload(region: Region, filters: &Option<SearchFilters>, last_ip: &str, last_port: u16) -> Vec<u8> {
|
||||
let filters_bytes: Vec<u8> = match filters {
|
||||
|
|
@ -43,8 +42,8 @@ pub struct ValveMasterServer {
|
|||
|
||||
impl ValveMasterServer {
|
||||
/// Construct a new struct.
|
||||
pub fn new(master_ip: &IpAddr, master_port: u16) -> GDResult<Self> {
|
||||
let socket = UdpSocket::new(master_ip, master_port)?;
|
||||
pub fn new(master_address: &SocketAddr) -> GDResult<Self> {
|
||||
let socket = UdpSocket::new(master_address)?;
|
||||
socket.apply_timeout(None)?;
|
||||
|
||||
Ok(Self { socket })
|
||||
|
|
@ -123,7 +122,7 @@ impl ValveMasterServer {
|
|||
/// faster as it results in less packets being sent, received and processed but
|
||||
/// yields less ips.
|
||||
pub fn query_singular(region: Region, search_filters: Option<SearchFilters>) -> GDResult<Vec<(IpAddr, u16)>> {
|
||||
let mut master_server = ValveMasterServer::new(&DEFAULT_MASTER_IP, DEFAULT_MASTER_PORT)?;
|
||||
let mut master_server = ValveMasterServer::new(&DEFAULT_MASTER_ADDRESS)?;
|
||||
|
||||
let mut ips = master_server.query_specific(region, &search_filters, "0.0.0.0", 0)?;
|
||||
|
||||
|
|
@ -138,7 +137,7 @@ pub fn query_singular(region: Region, search_filters: Option<SearchFilters>) ->
|
|||
|
||||
/// Make a complete query.
|
||||
pub fn query(region: Region, search_filters: Option<SearchFilters>) -> GDResult<Vec<(IpAddr, u16)>> {
|
||||
let mut master_server = ValveMasterServer::new(&DEFAULT_MASTER_IP, DEFAULT_MASTER_PORT)?;
|
||||
let mut master_server = ValveMasterServer::new(&DEFAULT_MASTER_ADDRESS)?;
|
||||
|
||||
master_server.query(region, search_filters)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue