Skip to content

Commit

Permalink
feat: add minetest master server service (#209)
Browse files Browse the repository at this point in the history
* feat: add minetest master server service"

* restore tf2 example

* chore: replace default with None

* fix: make it available only on TLS and serde

* docs: update changelog
  • Loading branch information
CosminPerRam authored Jul 21, 2024
1 parent 397817b commit 41a3d88
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 3 deletions.
7 changes: 4 additions & 3 deletions SERVICES.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Supported services:

| Name | Documentation reference |
|---------------------|-------------------------------------------------------------------------------------------------------|
| Valve Master Server | [Master Server Query Protocol](https://developer.valvesoftware.com/wiki/Master_Server_Query_Protocol) |
| Name | Documentation reference |
|------------------------|-------------------------------------------------------------------------------------------------------|
| Valve Master Server | [Master Server Query Protocol](https://developer.valvesoftware.com/wiki/Master_Server_Query_Protocol) |
| MineTest Master Server | [Node-GameDig](https://github.com/gamedig/node-gamedig/blob/master/protocols/minetest.js) |

## Planned to add support:

Expand Down
4 changes: 4 additions & 0 deletions crates/lib/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ Games:

- [Soulmask](https://store.steampowered.com/app/2646460/Soulmask/) support.

Services:

- MineTest Master Server support (available only on the `tls` and `serde` feature).

# 0.5.1 - 12/05/2024

Games:
Expand Down
7 changes: 7 additions & 0 deletions crates/lib/src/services/minetest_master_server/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/// The implementation.
pub mod service;
/// All types used by the implementation.
pub mod types;

pub use service::*;
pub use types::*;
13 changes: 13 additions & 0 deletions crates/lib/src/services/minetest_master_server/service.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use crate::http::HttpClient;
use crate::minetest_master_server::types::Response;
use crate::{GDResult, TimeoutSettings};

pub fn query(timeout_settings: TimeoutSettings) -> GDResult<Response> {
let mut client = HttpClient::from_url(
"https://servers.minetest.net",
&Some(timeout_settings),
None,
)?;

client.get_json("/list", None)
}
46 changes: 46 additions & 0 deletions crates/lib/src/services/minetest_master_server/types.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Debug)]
pub struct Server {
pub address: String,
pub clients: u32,
pub clients_list: Vec<String>,
pub clients_max: u32,
pub creative: bool,
pub damage: bool,
pub description: String,
pub game_time: u32,
pub gameid: String,
pub lag: Option<f32>,
pub name: String,
pub password: bool,
pub port: u16,
pub proto_max: u16,
pub proto_min: u16,
pub pvp: bool,
pub uptime: u32,
pub url: Option<String>,
pub version: String,
pub ip: String,
pub update_time: u32,
pub start: u32,
pub clients_top: u32,
pub updates: u32,
pub total_clients: u32,
pub pop_v: f32,
pub geo_continent: Option<String>,
pub ping: f32,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct ServersClients {
pub servers: u32,
pub clients: u32,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct Response {
pub total: ServersClients,
pub total_max: ServersClients,
pub list: Vec<Server>,
}
4 changes: 4 additions & 0 deletions crates/lib/src/services/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@
/// Reference: [Master Server Query Protocol](https://developer.valvesoftware.com/wiki/Master_Server_Query_Protocol)
pub mod valve_master_server;

/// Reference: [Node-GameDig](https://github.com/gamedig/node-gamedig/blob/master/protocols/minetest.js)
#[cfg(all(feature = "serde", feature = "tls"))]
pub mod minetest_master_server;

0 comments on commit 41a3d88

Please sign in to comment.