-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: move backend structure to shared module
Signed-off-by: iverly <[email protected]>
- Loading branch information
Showing
3 changed files
with
73 additions
and
78 deletions.
There are no files selected for viewing
This file was deleted.
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 |
---|---|---|
@@ -1,6 +1,68 @@ | ||
/// A backend is a Minecraft server that the proxy can connect to. | ||
/// | ||
/// Properties: | ||
/// | ||
/// * `host`: The hostname of the backend server. | ||
/// * `port`: The port that the backend server is listening on. | ||
#[derive(Debug, Clone)] | ||
pub struct Backend { | ||
pub hostname: String, | ||
pub redirect_ip: String, | ||
pub redirect_port: u16, | ||
} | ||
|
||
impl Backend { | ||
/// Creates a new instance of the `Backend` struct | ||
/// | ||
/// Arguments: | ||
/// | ||
/// * `host` - The host of the backend | ||
/// * `port` - The port of the backend | ||
/// | ||
/// Returns: | ||
/// | ||
/// A new instance of the struct. | ||
pub fn new(hostname: String, redirect_ip: String, redirect_port: u16) -> Self { | ||
Self { | ||
hostname, | ||
redirect_ip, | ||
redirect_port, | ||
} | ||
} | ||
|
||
/// It returns the host of the backend | ||
/// | ||
/// Returns: | ||
/// | ||
/// The host of the backend | ||
pub fn hostname(&self) -> &str { | ||
self.hostname.as_str() | ||
} | ||
|
||
/// It returns the ip of the backend | ||
/// | ||
/// Returns: | ||
/// | ||
/// The ip of the backend | ||
pub fn redirect_ip(&self) -> &str { | ||
self.redirect_ip.as_str() | ||
} | ||
|
||
/// It returns the port of the backend | ||
/// | ||
/// Returns: | ||
/// | ||
/// The port of the backend | ||
pub fn redirect_port(&self) -> u16 { | ||
self.redirect_port | ||
} | ||
|
||
/// It returns the address of the backend | ||
/// | ||
/// Returns: | ||
/// | ||
/// The address of the backend | ||
pub fn addr(&self) -> String { | ||
self.redirect_ip.clone() + ":" + &self.redirect_port.to_string() | ||
} | ||
} |