Browse Source

protocol: move Os to server_info module

master
Denis Drakhnia 2 months ago
parent
commit
fe763c3e60
  1. 6
      protocol/src/cursor/read.rs
  2. 14
      protocol/src/cursor/write.rs
  3. 70
      protocol/src/net/server.rs
  4. 45
      protocol/src/server_info.rs

6
protocol/src/cursor/read.rs

@ -77,6 +77,12 @@ impl GetKeyValue<'_> for crate::server_info::ServerType { @@ -77,6 +77,12 @@ impl GetKeyValue<'_> for crate::server_info::ServerType {
}
}
impl GetKeyValue<'_> for crate::server_info::Os {
fn get_key_value(cur: &mut Cursor) -> Result<Self, CursorError> {
cur.get_key_value_raw()?.try_into()
}
}
macro_rules! impl_get_value {
($($t:ty),+ $(,)?) => {
$(impl<'a> GetKeyValue<'a> for $t {

14
protocol/src/cursor/write.rs

@ -49,6 +49,20 @@ impl PutKeyValue for crate::server_info::ServerType { @@ -49,6 +49,20 @@ impl PutKeyValue for crate::server_info::ServerType {
}
}
impl PutKeyValue for crate::server_info::Os {
fn put_key_value<'a, 'b>(
&self,
cur: &'b mut CursorMut<'a>,
) -> Result<&'b mut CursorMut<'a>, CursorError> {
match self {
Self::Linux => cur.put_str("l"),
Self::Windows => cur.put_str("w"),
Self::Mac => cur.put_str("m"),
Self::Unknown => cur.put_str("?"),
}
}
}
macro_rules! impl_put_key_value {
($($t:ty),+ $(,)?) => {
$(impl PutKeyValue for $t {

70
protocol/src/net/server.rs

@ -3,8 +3,6 @@ @@ -3,8 +3,6 @@
//! Game server packets.
use core::fmt;
use crate::{
cursor::{Cursor, CursorMut, GetKeyValue, PutKeyValue},
filter::Version,
@ -21,6 +19,9 @@ pub use crate::server_info::ServerType; @@ -21,6 +19,9 @@ pub use crate::server_info::ServerType;
#[deprecated(since = "0.2.1", note = "use server_info::ServerFlags instead")]
pub use crate::server_info::ServerFlags;
#[deprecated(since = "0.2.1", note = "use server_info::Os instead")]
pub use crate::server_info::Os;
/// Sended to a master server before `ServerAdd` packet.
#[derive(Clone, Debug, PartialEq)]
pub struct Challenge {
@ -61,71 +62,6 @@ impl Challenge { @@ -61,71 +62,6 @@ impl Challenge {
}
}
/// The operating system on which the game server runs.
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(u8)]
pub enum Os {
/// GNU/Linux.
Linux,
/// Microsoft Windows
Windows,
/// Apple macOS, OS X, Mac OS X
Mac,
/// Unknown
Unknown,
}
impl Default for Os {
fn default() -> Os {
Os::Unknown
}
}
impl TryFrom<&[u8]> for Os {
type Error = CursorError;
fn try_from(value: &[u8]) -> Result<Self, Self::Error> {
match value {
b"l" => Ok(Os::Linux),
b"w" => Ok(Os::Windows),
b"m" => Ok(Os::Mac),
_ => Ok(Os::Unknown),
}
}
}
impl GetKeyValue<'_> for Os {
fn get_key_value(cur: &mut Cursor) -> Result<Self, CursorError> {
cur.get_key_value_raw()?.try_into()
}
}
impl PutKeyValue for Os {
fn put_key_value<'a, 'b>(
&self,
cur: &'b mut CursorMut<'a>,
) -> Result<&'b mut CursorMut<'a>, CursorError> {
match self {
Self::Linux => cur.put_str("l"),
Self::Windows => cur.put_str("w"),
Self::Mac => cur.put_str("m"),
Self::Unknown => cur.put_str("?"),
}
}
}
impl fmt::Display for Os {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
let s = match self {
Os::Linux => "Linux",
Os::Windows => "Windows",
Os::Mac => "Mac",
Os::Unknown => "Unknown",
};
write!(fmt, "{}", s)
}
}
/// Add/update game server information on the master server.
#[derive(Clone, Debug, PartialEq, Default)]
pub struct ServerAdd<T> {

45
protocol/src/server_info.rs

@ -132,6 +132,51 @@ bitflags! { @@ -132,6 +132,51 @@ bitflags! {
}
}
/// The operating system on which the game server runs.
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(u8)]
pub enum Os {
/// GNU/Linux.
Linux,
/// Microsoft Windows
Windows,
/// Apple macOS, OS X, Mac OS X
Mac,
/// Unknown
Unknown,
}
impl Default for Os {
fn default() -> Os {
Os::Unknown
}
}
impl TryFrom<&[u8]> for Os {
type Error = CursorError;
fn try_from(value: &[u8]) -> Result<Self, Self::Error> {
match value {
b"l" => Ok(Os::Linux),
b"w" => Ok(Os::Windows),
b"m" => Ok(Os::Mac),
_ => Ok(Os::Unknown),
}
}
}
impl fmt::Display for Os {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
let s = match self {
Os::Linux => "Linux",
Os::Windows => "Windows",
Os::Mac => "Mac",
Os::Unknown => "Unknown",
};
write!(fmt, "{}", s)
}
}
/// Game server information.
#[derive(Clone, Debug)]
pub struct ServerInfo<T> {

Loading…
Cancel
Save