split client module

This commit is contained in:
Raptorox 2026-07-28 22:38:59 +02:00
parent db3e0f846e
commit 2ddd24fc82
No known key found for this signature in database
GPG key ID: 8B3556FC3ED1F6D8
2 changed files with 27 additions and 26 deletions

View file

@ -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
View 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(())
}
}
}