split client module
This commit is contained in:
parent
db3e0f846e
commit
2ddd24fc82
2 changed files with 27 additions and 26 deletions
|
|
@ -1,30 +1,6 @@
|
|||
use std::{fmt::Display, io::{self, Read, Write}, net::{TcpStream, ToSocketAddrs}};
|
||||
|
||||
#[derive(Clone, Copy, PartialEq)]
|
||||
enum PacketType {
|
||||
Login = 3,
|
||||
Command = 2,
|
||||
Response = 0
|
||||
}
|
||||
|
||||
impl PacketType {
|
||||
fn to_le_bytes(self) -> [u8; 4] {
|
||||
(self as i32).to_le_bytes()
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<i32> for PacketType {
|
||||
type Error = ();
|
||||
|
||||
fn try_from(value: i32) -> Result<Self, Self::Error> {
|
||||
match value {
|
||||
x if x == Self::Login as i32 => Ok(Self::Login),
|
||||
x if x == Self::Command as i32 => Ok(Self::Command),
|
||||
x if x == Self::Response as i32 => Ok(Self::Response),
|
||||
_ => Err(())
|
||||
}
|
||||
}
|
||||
}
|
||||
mod packet_type;
|
||||
use packet_type::PacketType;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum RconError {
|
||||
25
src/client/packet_type.rs
Normal file
25
src/client/packet_type.rs
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
#[derive(Clone, Copy, PartialEq)]
|
||||
pub enum PacketType {
|
||||
Login = 3,
|
||||
Command = 2,
|
||||
Response = 0
|
||||
}
|
||||
|
||||
impl PacketType {
|
||||
pub fn to_le_bytes(self) -> [u8; 4] {
|
||||
(self as i32).to_le_bytes()
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<i32> for PacketType {
|
||||
type Error = ();
|
||||
|
||||
fn try_from(value: i32) -> Result<Self, Self::Error> {
|
||||
match value {
|
||||
x if x == Self::Login as i32 => Ok(Self::Login),
|
||||
x if x == Self::Command as i32 => Ok(Self::Command),
|
||||
x if x == Self::Response as i32 => Ok(Self::Response),
|
||||
_ => Err(())
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue