chore: extract the ship into multiple files (#172)

* chore: extract the ship into multiple files

* fix: actual the ship reference link

* fix: revert last commit and replace in ts
This commit is contained in:
CosminPerRam 2023-12-19 20:58:15 +01:00 committed by GitHub
parent 99b0269ec2
commit bdcf64facf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 29 deletions

View file

@ -0,0 +1,8 @@
/// The implementation.
/// Reference: [server queries](https://developer.valvesoftware.com/wiki/Server_queries)
pub mod protocol;
/// All types used by the implementation.
pub mod types;
pub use protocol::*;
pub use types::*;

View file

@ -0,0 +1,23 @@
use crate::games::theship::types::Response;
use crate::protocols::types::TimeoutSettings;
use crate::protocols::valve;
use crate::protocols::valve::Engine;
use crate::GDResult;
use std::net::{IpAddr, SocketAddr};
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<Response> { query_with_timeout(address, port, None) }
pub fn query_with_timeout(
address: &IpAddr,
port: Option<u16>,
timeout_settings: Option<TimeoutSettings>,
) -> GDResult<Response> {
let valve_response = valve::query(
&SocketAddr::new(*address, port.unwrap_or(27015)),
Engine::new(2400),
None,
timeout_settings,
)?;
Response::new_from_valve_response(valve_response)
}

View file

@ -1,17 +1,10 @@
use crate::{
protocols::{
types::{CommonPlayer, CommonResponse, GenericPlayer, TimeoutSettings},
valve::{self, get_optional_extracted_data, Server, ServerPlayer},
GenericResponse,
},
GDErrorKind::PacketBad,
GDResult,
};
use std::net::{IpAddr, SocketAddr};
use crate::protocols::types::{CommonPlayer, CommonResponse, GenericPlayer};
use crate::protocols::valve::{get_optional_extracted_data, Server, ServerPlayer};
use crate::protocols::{valve, GenericResponse};
use crate::GDErrorKind::PacketBad;
use crate::GDResult;
use std::collections::HashMap;
use crate::protocols::valve::Engine;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
@ -127,20 +120,3 @@ impl Response {
})
}
}
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<Response> { query_with_timeout(address, port, None) }
pub fn query_with_timeout(
address: &IpAddr,
port: Option<u16>,
timeout_settings: Option<TimeoutSettings>,
) -> GDResult<Response> {
let valve_response = valve::query(
&SocketAddr::new(*address, port.unwrap_or(27015)),
Engine::new(2400),
None,
timeout_settings,
)?;
Response::new_from_valve_response(valve_response)
}