mirror of
https://github.com/tribufu/rust-gamedig
synced 2026-06-01 09:42:41 +00:00
The ship support
This commit is contained in:
parent
5cf5615265
commit
401d499d61
3 changed files with 19 additions and 9 deletions
10
examples/the_ship.rs
Normal file
10
examples/the_ship.rs
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
|
||||||
|
use gamedig::TheShip;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let response = TheShip::query("46.4.48.226", Some(27017));
|
||||||
|
match response {
|
||||||
|
Err(error) => println!("Couldn't query, error: {error}"),
|
||||||
|
Ok(r) => println!("{:?}", r)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -9,8 +9,8 @@ impl TheShip {
|
||||||
None => 27015,
|
None => 27015,
|
||||||
Some(port) => port
|
Some(port) => port
|
||||||
}, GatheringSettings {
|
}, GatheringSettings {
|
||||||
players: false,
|
players: true,
|
||||||
rules: false
|
rules: true
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -152,7 +152,7 @@ impl ValveProtocol {
|
||||||
Ok(final_packet)
|
Ok(final_packet)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_request_data(&self, kind: Request) -> Result<Vec<u8>, GDError> {
|
pub fn get_request_data(&self, app: &App, kind: Request) -> Result<Vec<u8>, GDError> {
|
||||||
let info_initial_packet = vec![0xFF, 0xFF, 0xFF, 0xFF, 0x54, 0x53, 0x6F, 0x75, 0x72, 0x63, 0x65, 0x20, 0x45, 0x6E, 0x67, 0x69, 0x6E, 0x65, 0x20, 0x51, 0x75, 0x65, 0x72, 0x79, 0x00];
|
let info_initial_packet = vec![0xFF, 0xFF, 0xFF, 0xFF, 0x54, 0x53, 0x6F, 0x75, 0x72, 0x63, 0x65, 0x20, 0x45, 0x6E, 0x67, 0x69, 0x6E, 0x65, 0x20, 0x51, 0x75, 0x65, 0x72, 0x79, 0x00];
|
||||||
let players_initial_packet = vec![0xFF, 0xFF, 0xFF, 0xFF, 0x55, 0xFF, 0xFF, 0xFF, 0xFF];
|
let players_initial_packet = vec![0xFF, 0xFF, 0xFF, 0xFF, 0x55, 0xFF, 0xFF, 0xFF, 0xFF];
|
||||||
let rules_initial_packet = vec![0xFF, 0xFF, 0xFF, 0xFF, 0x56, 0xFF, 0xFF, 0xFF, 0xFF];
|
let rules_initial_packet = vec![0xFF, 0xFF, 0xFF, 0xFF, 0x56, 0xFF, 0xFF, 0xFF, 0xFF];
|
||||||
|
|
@ -184,7 +184,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) { //'E'
|
if (packet[0] == 0xFE || (packet[0] == 0xFF && packet[4] == 0x45)) && (*app != App::TheShip) { //'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>>())
|
||||||
|
|
@ -192,7 +192,7 @@ impl ValveProtocol {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_server_info(&self, app: &App) -> Result<ServerInfo, GDError> {
|
fn get_server_info(&self, app: &App) -> Result<ServerInfo, GDError> {
|
||||||
let buf = self.get_request_data(Request::INFO)?;
|
let buf = self.get_request_data(app, Request::INFO)?;
|
||||||
let mut pos = 0;
|
let mut pos = 0;
|
||||||
|
|
||||||
Ok(ServerInfo {
|
Ok(ServerInfo {
|
||||||
|
|
@ -259,7 +259,7 @@ impl ValveProtocol {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_server_players(&self, app: &App) -> Result<ServerPlayers, GDError> {
|
fn get_server_players(&self, app: &App) -> Result<ServerPlayers, GDError> {
|
||||||
let buf = self.get_request_data(Request::PLAYERS)?;
|
let buf = self.get_request_data(app, Request::PLAYERS)?;
|
||||||
let mut pos = 0;
|
let mut pos = 0;
|
||||||
|
|
||||||
let count = buffer::get_u8(&buf, &mut pos)?;
|
let count = buffer::get_u8(&buf, &mut pos)?;
|
||||||
|
|
@ -288,8 +288,8 @@ impl ValveProtocol {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_server_rules(&self) -> Result<ServerRules, GDError> {
|
fn get_server_rules(&self, app: &App) -> Result<ServerRules, GDError> {
|
||||||
let buf = self.get_request_data(Request::RULES)?;
|
let buf = self.get_request_data(app, Request::RULES)?;
|
||||||
let mut pos = 0;
|
let mut pos = 0;
|
||||||
|
|
||||||
let count = buffer::get_u16_le(&buf, &mut pos)?;
|
let count = buffer::get_u16_le(&buf, &mut pos)?;
|
||||||
|
|
@ -321,7 +321,7 @@ impl ValveProtocol {
|
||||||
},
|
},
|
||||||
rules: match gather.rules {
|
rules: match gather.rules {
|
||||||
false => None,
|
false => None,
|
||||||
true => Some(client.get_server_rules()?)
|
true => Some(client.get_server_rules(&app)?)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue