mirror of
https://github.com/tribufu/rust-gamedig
synced 2026-06-01 09:42:41 +00:00
Added Day of Defeat: Source support and renamed The_Ship to TS
This commit is contained in:
parent
aefd8cc43c
commit
a5f9e755ff
7 changed files with 121 additions and 24 deletions
13
GAMES.md
13
GAMES.md
|
|
@ -1,11 +1,12 @@
|
||||||
|
|
||||||
# Supported games:
|
# Supported games:
|
||||||
| ID | Name | Protocol | Notes |
|
| ID | Name | Protocol | Notes |
|
||||||
|----------|----------------------------------|----------------|----------------------------------|
|
|------|----------------------------------|----------------|----------------------------------|
|
||||||
| TF2 | Team Fortress 2 | Valve Protocol | |
|
| TF2 | Team Fortress 2 | Valve Protocol | |
|
||||||
| The_Ship | The Ship | Valve Protocol | |
|
| TS | The Ship | Valve Protocol | |
|
||||||
| CSGO | Counter-Strike: Global Offensive | Valve Protocol | Rules doesnt work on this title. |
|
| CSGO | Counter-Strike: Global Offensive | Valve Protocol | Rules doesnt work on this title. |
|
||||||
| CSS | Counter-Strike: Source | Valve Protocol | |
|
| CSS | Counter-Strike: Source | Valve Protocol | |
|
||||||
|
| DODS | Day of Defeat: Source | Valve Protocol | |
|
||||||
|
|
||||||
## Planned to add support:
|
## Planned to add support:
|
||||||
All Valve titles.
|
All Valve titles.
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
|
|
||||||
use gamedig::games::the_ship;
|
use gamedig::games::dods;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let response = the_ship::query("46.4.48.226", Some(27017));
|
let response = dods::query("88.99.28.151", Some(27055));
|
||||||
match response {
|
match response {
|
||||||
Err(error) => println!("Couldn't query, error: {error}"),
|
Err(error) => println!("Couldn't query, error: {error}"),
|
||||||
Ok(r) => println!("{:?}", r)
|
Ok(r) => println!("{:?}", r)
|
||||||
10
examples/ts.rs
Normal file
10
examples/ts.rs
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
|
||||||
|
use gamedig::games::ts;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let response = ts::query("46.4.48.226", Some(27017));
|
||||||
|
match response {
|
||||||
|
Err(error) => println!("Couldn't query, error: {error}"),
|
||||||
|
Ok(r) => println!("{:?}", r)
|
||||||
|
}
|
||||||
|
}
|
||||||
83
src/games/dods.rs
Normal file
83
src/games/dods.rs
Normal file
|
|
@ -0,0 +1,83 @@
|
||||||
|
use crate::{GDResult, valve};
|
||||||
|
use crate::valve::{ValveProtocol, App, GatheringSettings, Server, ServerRule, ServerPlayer};
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct Player {
|
||||||
|
pub name: String,
|
||||||
|
pub score: u32,
|
||||||
|
pub duration: f32
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Player {
|
||||||
|
fn from_valve_response(player: &ServerPlayer) -> Self {
|
||||||
|
Self {
|
||||||
|
name: player.name.clone(),
|
||||||
|
score: player.score,
|
||||||
|
duration: player.duration
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct Response {
|
||||||
|
pub protocol: u8,
|
||||||
|
pub name: String,
|
||||||
|
pub map: String,
|
||||||
|
pub game: String,
|
||||||
|
pub players: u8,
|
||||||
|
pub players_details: Vec<Player>,
|
||||||
|
pub max_players: u8,
|
||||||
|
pub bots: u8,
|
||||||
|
pub server_type: Server,
|
||||||
|
pub has_password: bool,
|
||||||
|
pub vac_secured: bool,
|
||||||
|
pub version: String,
|
||||||
|
pub port: Option<u16>,
|
||||||
|
pub steam_id: Option<u64>,
|
||||||
|
pub tv_port: Option<u16>,
|
||||||
|
pub tv_name: Option<String>,
|
||||||
|
pub keywords: Option<String>,
|
||||||
|
pub rules: Vec<ServerRule>
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Response {
|
||||||
|
pub fn new_from_valve_response(response: valve::Response) -> Self {
|
||||||
|
let (port, steam_id, tv_port, tv_name, keywords) = match response.info.extra_data {
|
||||||
|
None => (None, None, None, None, None),
|
||||||
|
Some(ed) => (ed.port, ed.steam_id, ed.tv_port, ed.tv_name, ed.keywords)
|
||||||
|
};
|
||||||
|
|
||||||
|
Self {
|
||||||
|
protocol: response.info.protocol,
|
||||||
|
name: response.info.name,
|
||||||
|
map: response.info.map,
|
||||||
|
game: response.info.game,
|
||||||
|
players: response.info.players,
|
||||||
|
players_details: response.players.unwrap().iter().map(|p| Player::from_valve_response(p)).collect(),
|
||||||
|
max_players: response.info.max_players,
|
||||||
|
bots: response.info.bots,
|
||||||
|
server_type: response.info.server_type,
|
||||||
|
has_password: response.info.has_password,
|
||||||
|
vac_secured: response.info.vac_secured,
|
||||||
|
version: response.info.version,
|
||||||
|
port,
|
||||||
|
steam_id,
|
||||||
|
tv_port,
|
||||||
|
tv_name,
|
||||||
|
keywords,
|
||||||
|
rules: response.rules.unwrap()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn query(address: &str, port: Option<u16>) -> GDResult<Response> {
|
||||||
|
let valve_response = ValveProtocol::query(App::DODS, address, match port {
|
||||||
|
None => 27015,
|
||||||
|
Some(port) => port
|
||||||
|
}, GatheringSettings {
|
||||||
|
players: true,
|
||||||
|
rules: true
|
||||||
|
})?;
|
||||||
|
|
||||||
|
Ok(Response::new_from_valve_response(valve_response))
|
||||||
|
}
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
//! Currently supported games.
|
//! Currently supported games.
|
||||||
|
|
||||||
pub mod tf2;
|
pub mod tf2;
|
||||||
pub mod the_ship;
|
pub mod ts;
|
||||||
pub mod csgo;
|
pub mod csgo;
|
||||||
pub mod css;
|
pub mod css;
|
||||||
|
pub mod dods;
|
||||||
|
|
|
||||||
|
|
@ -83,7 +83,7 @@ impl Response {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn query(address: &str, port: Option<u16>) -> GDResult<Response> {
|
pub fn query(address: &str, port: Option<u16>) -> GDResult<Response> {
|
||||||
let valve_response = ValveProtocol::query(App::TheShip, address, match port {
|
let valve_response = ValveProtocol::query(App::TS, address, match port {
|
||||||
None => 27015,
|
None => 27015,
|
||||||
Some(port) => port
|
Some(port) => port
|
||||||
}, GatheringSettings {
|
}, GatheringSettings {
|
||||||
|
|
@ -125,9 +125,10 @@ pub enum Request {
|
||||||
#[derive(PartialEq)]
|
#[derive(PartialEq)]
|
||||||
pub enum App {
|
pub enum App {
|
||||||
CSS = 240,
|
CSS = 240,
|
||||||
|
DODS = 300,
|
||||||
TF2 = 440,
|
TF2 = 440,
|
||||||
CSGO = 730,
|
CSGO = 730,
|
||||||
TheShip = 2400
|
TS = 2400
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryFrom<u16> for App {
|
impl TryFrom<u16> for App {
|
||||||
|
|
@ -136,9 +137,10 @@ impl TryFrom<u16> for App {
|
||||||
fn try_from(value: u16) -> GDResult<Self> {
|
fn try_from(value: u16) -> GDResult<Self> {
|
||||||
match value {
|
match value {
|
||||||
x if x == App::CSS as u16 => Ok(App::CSS),
|
x if x == App::CSS as u16 => Ok(App::CSS),
|
||||||
|
x if x == App::DODS as u16 => Ok(App::DODS),
|
||||||
x if x == App::TF2 as u16 => Ok(App::TF2),
|
x if x == App::TF2 as u16 => Ok(App::TF2),
|
||||||
x if x == App::CSGO as u16 => Ok(App::CSGO),
|
x if x == App::CSGO as u16 => Ok(App::CSGO),
|
||||||
x if x == App::TheShip as u16 => Ok(App::TheShip),
|
x if x == App::TS as u16 => Ok(App::TS),
|
||||||
_ => Err(GDError::UnknownEnumCast),
|
_ => Err(GDError::UnknownEnumCast),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -221,7 +223,7 @@ impl ValveProtocol {
|
||||||
self.send(&challenge_packet)?;
|
self.send(&challenge_packet)?;
|
||||||
|
|
||||||
let mut packet = self.receive(DEFAULT_PACKET_SIZE)?;
|
let mut packet = self.receive(DEFAULT_PACKET_SIZE)?;
|
||||||
if (packet[0] == 0xFE || (packet[0] == 0xFF && packet[4] == 0x45)) && (*app != App::TheShip) { //'E'
|
if (packet[0] == 0xFE || (packet[0] == 0xFF && packet[4] == 0x45)) && (*app != App::TS) { //'E'
|
||||||
self.receive_truncated(&packet)
|
self.receive_truncated(&packet)
|
||||||
} else {
|
} else {
|
||||||
Ok(packet.drain(5..).collect::<Vec<u8>>())
|
Ok(packet.drain(5..).collect::<Vec<u8>>())
|
||||||
|
|
@ -257,7 +259,7 @@ impl ValveProtocol {
|
||||||
},
|
},
|
||||||
has_password: buffer::get_u8(&buf, &mut pos)? == 1,
|
has_password: buffer::get_u8(&buf, &mut pos)? == 1,
|
||||||
vac_secured: buffer::get_u8(&buf, &mut pos)? == 1,
|
vac_secured: buffer::get_u8(&buf, &mut pos)? == 1,
|
||||||
the_ship: match *app == App::TheShip {
|
the_ship: match *app == App::TS {
|
||||||
false => None,
|
false => None,
|
||||||
true => Some(TheShip {
|
true => Some(TheShip {
|
||||||
mode: buffer::get_u8(&buf, &mut pos)?,
|
mode: buffer::get_u8(&buf, &mut pos)?,
|
||||||
|
|
@ -312,11 +314,11 @@ impl ValveProtocol {
|
||||||
name: buffer::get_string(&buf, &mut pos)?,
|
name: buffer::get_string(&buf, &mut pos)?,
|
||||||
score: buffer::get_u32_le(&buf, &mut pos)?,
|
score: buffer::get_u32_le(&buf, &mut pos)?,
|
||||||
duration: buffer::get_f32_le(&buf, &mut pos)?,
|
duration: buffer::get_f32_le(&buf, &mut pos)?,
|
||||||
deaths: match *app == App::TheShip {
|
deaths: match *app == App::TS {
|
||||||
false => None,
|
false => None,
|
||||||
true => Some(buffer::get_u32_le(&buf, &mut pos)?)
|
true => Some(buffer::get_u32_le(&buf, &mut pos)?)
|
||||||
},
|
},
|
||||||
money: match *app == App::TheShip {
|
money: match *app == App::TS {
|
||||||
false => None,
|
false => None,
|
||||||
true => Some(buffer::get_u32_le(&buf, &mut pos)?)
|
true => Some(buffer::get_u32_le(&buf, &mut pos)?)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue