-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: initial minetest support * move player to master, remove comments * add markdown lines * oops, change player namespace * fix some edge cases * add entry to responses, tweak field names
- Loading branch information
1 parent
30ae60e
commit bcc92d1
Showing
10 changed files
with
246 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/// The implementation. | ||
/// Reference: [Node-GameGig](https://github.com/gamedig/node-gamedig/blob/master/protocols/minetest.js) | ||
pub mod protocol; | ||
/// All types used by the implementation. | ||
pub mod types; | ||
|
||
pub use protocol::*; | ||
pub use types::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
use crate::minetest::Response; | ||
use crate::{minetest_master_server, GDErrorKind, GDResult, TimeoutSettings}; | ||
use std::net::IpAddr; | ||
|
||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<Response> { query_with_timeout(address, port, &None) } | ||
|
||
pub fn query_with_timeout( | ||
address: &IpAddr, | ||
port: Option<u16>, | ||
timeout_settings: &Option<TimeoutSettings>, | ||
) -> GDResult<Response> { | ||
let address = address.to_string(); | ||
let port = port.unwrap_or(30000); | ||
|
||
let servers = minetest_master_server::query(timeout_settings.unwrap_or_default())?; | ||
for server in servers.list { | ||
if server.ip == address && server.port == port { | ||
return Ok(server.into()); | ||
} | ||
} | ||
|
||
Err(GDErrorKind::AutoQuery.context("Server not found in the master query list.")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
use crate::minetest_master_server::Server; | ||
use crate::protocols::types::{CommonPlayer, CommonResponse, GenericPlayer}; | ||
use crate::protocols::GenericResponse; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)] | ||
pub struct Player { | ||
pub name: String, | ||
} | ||
|
||
impl CommonPlayer for Player { | ||
fn as_original(&self) -> GenericPlayer { GenericPlayer::Minetest(self) } | ||
|
||
fn name(&self) -> &str { &self.name } | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] | ||
pub struct Response { | ||
pub name: String, | ||
pub description: String, | ||
pub game_version: String, | ||
pub players_maximum: u32, | ||
pub players_online: u32, | ||
pub has_password: Option<bool>, | ||
pub players: Vec<Player>, | ||
pub id: String, | ||
pub ip: String, | ||
pub port: u16, | ||
pub creative: Option<bool>, | ||
pub damage: bool, | ||
pub game_time: u32, | ||
pub lag: Option<f32>, | ||
pub proto_max: u16, | ||
pub proto_min: u16, | ||
pub pvp: bool, | ||
pub uptime: u32, | ||
pub url: Option<String>, | ||
pub update_time: u32, | ||
pub start: u32, | ||
pub clients_top: u32, | ||
pub updates: u32, | ||
pub pop_v: f32, | ||
pub geo_continent: Option<String>, | ||
pub ping: f32, | ||
} | ||
|
||
impl From<Server> for Response { | ||
fn from(server: Server) -> Self { | ||
Self { | ||
name: server.name, | ||
description: server.description, | ||
game_version: server.version, | ||
players_maximum: server.clients_max, | ||
players_online: server.total_clients, | ||
has_password: server.password, | ||
players: server | ||
.clients_list | ||
.unwrap_or_default() | ||
.into_iter() | ||
.map(|name| Player { name }) | ||
.collect(), | ||
ip: server.address, | ||
creative: server.creative, | ||
damage: server.damage, | ||
game_time: server.game_time, | ||
id: server.gameid, | ||
lag: server.lag, | ||
port: server.port, | ||
proto_max: server.proto_max, | ||
proto_min: server.proto_min, | ||
pvp: server.pvp, | ||
uptime: server.uptime, | ||
url: server.url, | ||
update_time: server.update_time, | ||
start: server.start, | ||
clients_top: server.clients_top, | ||
updates: server.updates, | ||
pop_v: server.pop_v, | ||
geo_continent: server.geo_continent, | ||
ping: server.ping, | ||
} | ||
} | ||
} | ||
|
||
impl CommonResponse for Response { | ||
fn as_original(&self) -> GenericResponse { GenericResponse::Minetest(self) } | ||
|
||
fn name(&self) -> Option<&str> { Some(&self.name) } | ||
|
||
fn description(&self) -> Option<&str> { Some(&self.description) } | ||
|
||
fn game_version(&self) -> Option<&str> { Some(&self.game_version) } | ||
|
||
fn players_maximum(&self) -> u32 { self.players_maximum } | ||
|
||
fn players_online(&self) -> u32 { self.players_online } | ||
|
||
fn has_password(&self) -> Option<bool> { self.has_password } | ||
|
||
fn players(&self) -> Option<Vec<&dyn CommonPlayer>> { | ||
Some( | ||
self.players | ||
.iter() | ||
.map(|p| p as &dyn CommonPlayer) | ||
.collect(), | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters