-
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.
- Loading branch information
1 parent
41a3d88
commit ed8eceb
Showing
8 changed files
with
104 additions
and
1 deletion.
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
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_master_server::Server; | ||
use crate::{minetest_master_server, GDErrorKind, GDResult, TimeoutSettings}; | ||
use std::net::IpAddr; | ||
|
||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<Server> { query_with_timeout(address, port, &None) } | ||
|
||
pub fn query_with_timeout( | ||
address: &IpAddr, | ||
port: Option<u16>, | ||
timeout_settings: &Option<TimeoutSettings>, | ||
) -> GDResult<Server> { | ||
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); | ||
} | ||
} | ||
|
||
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,43 @@ | ||
use crate::minetest_master_server::Server; | ||
use crate::protocols::types::{CommonPlayer, CommonResponse, GenericPlayer}; | ||
use crate::protocols::GenericResponse; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] | ||
#[derive(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 } | ||
} | ||
|
||
impl CommonResponse for Server { | ||
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.version) } | ||
|
||
fn players_maximum(&self) -> u32 { self.clients_max } | ||
|
||
fn players_online(&self) -> u32 { self.clients } | ||
|
||
fn has_password(&self) -> Option<bool> { Some(self.password) } | ||
|
||
fn players(&self) -> Option<Vec<&dyn CommonPlayer>> { | ||
None | ||
// Some( | ||
// self.clients_list | ||
// .iter() | ||
// .map(|p| Player { name: p.clone() }) | ||
// .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