Skip to content

feat: palworld support #210

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions crates/lib/src/games/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
//! Currently supported games.

#[cfg(feature = "serde")]
pub mod palworld;

#[cfg(feature = "serde")]
pub use palworld::*;

Check warning on line 7 in crates/lib/src/games/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

unused import: `palworld::*`

warning: unused import: `palworld::*` --> crates/lib/src/games/mod.rs:7:9 | 7 | pub use palworld::*; | ^^^^^^^^^^^ | = note: `#[warn(unused_imports)]` on by default

Check warning on line 7 in crates/lib/src/games/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

unused import: `palworld::*`

warning: unused import: `palworld::*` --> crates/lib/src/games/mod.rs:7:9 | 7 | pub use palworld::*; | ^^^^^^^^^^^ | = note: `#[warn(unused_imports)]` on by default

#[cfg(feature = "tls")]
pub mod epic;
pub mod gamespy;
Expand Down
2 changes: 2 additions & 0 deletions crates/lib/src/games/palworld/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mod protocol;
mod types;
39 changes: 39 additions & 0 deletions crates/lib/src/games/palworld/protocol.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
use crate::http::HttpClient;
use crate::palworld::types::{Endpoint, Response};
use crate::GDErrorKind::SocketConnect;
use crate::{GDResult, TimeoutSettings};
use base64::prelude::BASE64_STANDARD;
use base64::Engine;
use serde_json::Value;
use std::net::IpAddr;
use url::Url;

fn make_call(client: &mut HttpClient, endpoint: Endpoint) -> GDResult<Value> {

Check warning on line 11 in crates/lib/src/games/palworld/protocol.rs

View workflow job for this annotation

GitHub Actions / clippy

function `make_call` is never used

warning: function `make_call` is never used --> crates/lib/src/games/palworld/protocol.rs:11:4 | 11 | fn make_call(client: &mut HttpClient, endpoint: Endpoint) -> GDResult<Value> { | ^^^^^^^^^ | = note: `#[warn(dead_code)]` on by default

Check warning on line 11 in crates/lib/src/games/palworld/protocol.rs

View workflow job for this annotation

GitHub Actions / clippy

function `make_call` is never used

warning: function `make_call` is never used --> crates/lib/src/games/palworld/protocol.rs:11:4 | 11 | fn make_call(client: &mut HttpClient, endpoint: Endpoint) -> GDResult<Value> { | ^^^^^^^^^ | = note: `#[warn(dead_code)]` on by default
client.get_json(endpoint.into(), Default::default())
}

pub fn query(

Check warning on line 15 in crates/lib/src/games/palworld/protocol.rs

View workflow job for this annotation

GitHub Actions / clippy

function `query` is never used

warning: function `query` is never used --> crates/lib/src/games/palworld/protocol.rs:15:8 | 15 | pub fn query( | ^^^^^

Check warning on line 15 in crates/lib/src/games/palworld/protocol.rs

View workflow job for this annotation

GitHub Actions / clippy

function `query` is never used

warning: function `query` is never used --> crates/lib/src/games/palworld/protocol.rs:15:8 | 15 | pub fn query( | ^^^^^
address: &IpAddr,
port: Option<u16>,
username: String,
password: String,
timeout_settings: TimeoutSettings,
) -> GDResult<Response> {
let url = Url::parse(&format!("{address}:{}", port.unwrap_or(8212))).map_err(|e| SocketConnect.context(e))?;

let auth_format = format!("{}:{}", username, password);
let auth_base = BASE64_STANDARD.encode(auth_format);
let auth = format!("Basic {}", auth_base.as_str());
let authorization = auth.as_str();
let headers = [
("Authorization", authorization),
("Accept", "application/json"),
];

let mut client = HttpClient::from_url(url, &Some(timeout_settings), Some((&headers).to_vec()))?;

Check warning on line 33 in crates/lib/src/games/palworld/protocol.rs

View workflow job for this annotation

GitHub Actions / clippy

this expression borrows a value the compiler would automatically borrow

warning: this expression borrows a value the compiler would automatically borrow --> crates/lib/src/games/palworld/protocol.rs:33:78 | 33 | let mut client = HttpClient::from_url(url, &Some(timeout_settings), Some((&headers).to_vec()))?; | ^^^^^^^^^^ help: change this to: `headers` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow = note: `#[warn(clippy::needless_borrow)]` on by default

Check warning on line 33 in crates/lib/src/games/palworld/protocol.rs

View workflow job for this annotation

GitHub Actions / clippy

this expression borrows a value the compiler would automatically borrow

warning: this expression borrows a value the compiler would automatically borrow --> crates/lib/src/games/palworld/protocol.rs:33:78 | 33 | let mut client = HttpClient::from_url(url, &Some(timeout_settings), Some((&headers).to_vec()))?; | ^^^^^^^^^^ help: change this to: `headers` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow = note: `#[warn(clippy::needless_borrow)]` on by default

let info = make_call(&mut client, Endpoint::Info)?;
println!("{info:#?}");

Ok(Response {})
}
22 changes: 22 additions & 0 deletions crates/lib/src/games/palworld/types.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Debug)]
pub struct Response {}

pub enum Endpoint {
Info,

Check warning on line 7 in crates/lib/src/games/palworld/types.rs

View workflow job for this annotation

GitHub Actions / clippy

variants `Info`, `Players`, `Settings`, and `Metrics` are never constructed

warning: variants `Info`, `Players`, `Settings`, and `Metrics` are never constructed --> crates/lib/src/games/palworld/types.rs:7:5 | 6 | pub enum Endpoint { | -------- variants in this enum 7 | Info, | ^^^^ 8 | Players, | ^^^^^^^ 9 | Settings, | ^^^^^^^^ 10 | Metrics, | ^^^^^^^

Check warning on line 7 in crates/lib/src/games/palworld/types.rs

View workflow job for this annotation

GitHub Actions / clippy

variants `Info`, `Players`, `Settings`, and `Metrics` are never constructed

warning: variants `Info`, `Players`, `Settings`, and `Metrics` are never constructed --> crates/lib/src/games/palworld/types.rs:7:5 | 6 | pub enum Endpoint { | -------- variants in this enum 7 | Info, | ^^^^ 8 | Players, | ^^^^^^^ 9 | Settings, | ^^^^^^^^ 10 | Metrics, | ^^^^^^^
Players,
Settings,
Metrics,
}

impl<'a> Into<&'a str> for Endpoint {

Check warning on line 13 in crates/lib/src/games/palworld/types.rs

View workflow job for this annotation

GitHub Actions / clippy

an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true

warning: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true --> crates/lib/src/games/palworld/types.rs:13:1 | 13 | impl<'a> Into<&'a str> for Endpoint { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: `impl From<Local> for Foreign` is allowed by the orphan rules, for more information see https://doc.rust-lang.org/reference/items/implementations.html#trait-implementation-coherence = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#from_over_into = note: `#[warn(clippy::from_over_into)]` on by default help: replace the `Into` implementation with `From<games::palworld::types::Endpoint>` | 13 ~ impl<'a> From<Endpoint> for &'a str { 14 ~ fn from(val: Endpoint) -> Self { 15 ~ match val { |

Check warning on line 13 in crates/lib/src/games/palworld/types.rs

View workflow job for this annotation

GitHub Actions / clippy

an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true

warning: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true --> crates/lib/src/games/palworld/types.rs:13:1 | 13 | impl<'a> Into<&'a str> for Endpoint { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: `impl From<Local> for Foreign` is allowed by the orphan rules, for more information see https://doc.rust-lang.org/reference/items/implementations.html#trait-implementation-coherence = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#from_over_into = note: `#[warn(clippy::from_over_into)]` on by default help: replace the `Into` implementation with `From<games::palworld::types::Endpoint>` | 13 ~ impl<'a> From<Endpoint> for &'a str { 14 ~ fn from(val: Endpoint) -> Self { 15 ~ match val { |
fn into(self) -> &'a str {
match self {
Endpoint::Info => "info",
Endpoint::Players => "players",
Endpoint::Settings => "settings",
Endpoint::Metrics => "metrics",
}
}
}
Loading