Modified public presentation files

This commit is contained in:
CosminPerRam 2022-10-16 03:23:18 +03:00
parent c9eb725a51
commit 73c8ade3a2
7 changed files with 77 additions and 27 deletions

View file

@ -2,13 +2,16 @@
name = "gamedig"
version = "0.0.0"
edition = "2021"
authors = ["CosminPerRam [cosmin.p@live.com]", "mmorrisontx [https://github.com/mmorrisontx]"]
authors = ["CosminPerRam [cosmin.p@live.com]", "node-GameDig [https://github.com/gamedig/node-gamedig]"]
license-file = "LICENSE.md"
description = "Check out servers with this."
homepage = "https://github.com/CosminPerRam/rust-gamedig"
documentation = "https://github.com/CosminPerRam/rust-gamedig"
documentation = "https://docs.rs/gamedig/latest/gamedig/"
repository = "https://github.com/CosminPerRam/rust-gamedig"
readme = "README.md"
keywords = ["server", "valve", "games", "checker", "status"]
[package.metadata]
msrv = "1.58.1"
[dependencies]

7
GAMES.md Normal file
View file

@ -0,0 +1,7 @@
# Supported games:
| Type ID | Name | Notes |
|---------|-----------------|-------|
| TF2 | Team Fortress 2 | |
# Planned to add support:
All Valve titles.

View file

@ -1 +1,31 @@
# rust-gamedig
# rust-gamedig
rust-GameDig is a game server/services query library, capable of querying the status of many games/services, this library brings what [node-GameDig](https://github.com/gamedig/node-gamedig) does, to pure Rust!
MSRV is `1.58.1` and the code is cross-platform.
# Example
Basic usage of the library is:
```rust
use gamedig::TF2;
fn main() {
let response = TF2::query("91.216.250.10", None);
//query your favorite game/protocol/service, some might come with different parameters
//here its just the IP and the port (if None, its gonna be the default from the protocol)
match response {
Err(error) => println!("Couldn't query, error: {error}"),
Ok(r) => println!("{:?}", r)
}
}
```
To see more examples, see the [examples](examples) folder.
# Documentation
The documentation is available at [docs.rs](https://docs.rs/gamedig/latest/gamedig/).
# Games List
To see the supported games, see [GAMES](GAMES.md).
# Contributing
If you want see your favorite game/service being supported here, open an issue (or do a pull request if you want to implement it yourself)!

View file

@ -4,7 +4,7 @@ use gamedig::TF2;
fn main() {
let response = TF2::query("91.216.250.10", None);
match response {
Err(error) => println!("Couldn't query, error: {}", error),
Err(error) => println!("Couldn't query, error: {error}"),
Ok(r) => println!("{:?}", r)
}
}

View file

@ -62,7 +62,7 @@ pub struct ValveProtocol {
complete_address: String
}
static default_packet_size: usize = 256;
static DEFAULT_PACKET_SIZE: usize = 256;
impl ValveProtocol {
fn new(address: &str, port: u16) -> Self {
@ -95,11 +95,7 @@ impl ValveProtocol {
}
}
pub fn receive(&self) -> Vec<u8> {
self.receive_with_size(64)
}
pub fn receive_with_size(&self, buffer_size: usize) -> Vec<u8> {
pub fn receive(&self, buffer_size: usize) -> Vec<u8> {
let mut buffer: Vec<u8> = vec![0; buffer_size];
let (amt, _) = self.socket.recv_from(&mut buffer.as_mut_slice()).unwrap();
buffer[..amt].to_vec()
@ -111,11 +107,11 @@ impl ValveProtocol {
let client = ValveProtocol::new(address, port);
client.do_request(Request::A2sInfo(None), None);
let mut buf = client.receive_with_size(default_packet_size);
let mut buf = client.receive(DEFAULT_PACKET_SIZE);
if buf[4] == 0x41 {
client.do_request(Request::A2sInfo(Some([buf[5], buf[6], buf[7], buf[8]])), None);
buf = client.receive_with_size(default_packet_size);
buf = client.receive(DEFAULT_PACKET_SIZE);
}
println!("{:x?}", &buf);

View file

@ -26,3 +26,32 @@ pub fn combine_eight_u8(a: u8, b: u8, c: u8, d: u8, e: u8, f: u8, g: u8, h: u8)
pub fn get_u64_from_buf(buf: &[u8]) -> u64 {
combine_eight_u8(buf[7], buf[6], buf[5], buf[4], buf[3], buf[2], buf[1], buf[0])
}
#[cfg(test)]
mod utils {
use super::*;
#[test]
fn concat_u8_test() {
let a: [u8; 2] = [1, 2];
let b: [u8; 2] = [3, 4];
let combined = concat_u8(&a, &b);
assert_eq!(a[0], combined[0]);
assert_eq!(a[1], combined[1]);
assert_eq!(b[0], combined[2]);
assert_eq!(b[1], combined[3]);
}
#[test]
fn find_null_in_array_test() {
let arr: [u8; 4] = [0x64, 0x32, 0x00, 0x20];
assert_eq!(2, find_null_in_array(&arr));
}
#[test]
fn complete_address_test() {
let address = "192.168.0.1";
let port = 27015;
assert_eq!(complete_address(address, port), "192.168.0.1:27015");
}
}

View file

@ -1,15 +0,0 @@
#[cfg(test)]
mod tests {
use gamedig::protocols::valve::ValveProtocol;
#[test]
fn tf2() {
let response = ValveProtocol::query("5.15.202.107", 27015);
match response {
Err(_) => println!("fuck"),
Ok(r) => println!("{}", r.name)
}
assert_eq!(4, 4);
}
}