tidying up client struct
This commit is contained in:
parent
f06f4e3ca2
commit
7165c60fa7
|
|
@ -5,16 +5,29 @@ pub mod traits;
|
|||
use serde::{Serialize, Deserialize};
|
||||
use std::net::TcpStream;
|
||||
use std::sync::Weak;
|
||||
use std::sync::Arc;
|
||||
use uuid::Uuid;
|
||||
|
||||
use super::traits::TClientManager;
|
||||
use super::ClientManager;
|
||||
use traits::TClient;
|
||||
|
||||
|
||||
pub enum ClientMessage {
|
||||
a,
|
||||
b,
|
||||
}
|
||||
|
||||
/// # Client
|
||||
/// This struct represents a connected user.
|
||||
///
|
||||
/// ## Attrubutes
|
||||
/// - uuid: The id of the connected user.
|
||||
/// - username: The username of the connected user.
|
||||
/// - address: The the address of the connected client.
|
||||
///
|
||||
/// - stream: The socket for the connected client.
|
||||
/// - owner: An optional reference to the owning object.
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct Client {
|
||||
uuid: String,
|
||||
|
|
@ -28,3 +41,14 @@ pub struct Client {
|
|||
owner: Option<Weak<ClientManager>>
|
||||
}
|
||||
|
||||
impl TClient<ClientMessage> for Client {
|
||||
fn new(uuid: Uuid, name: String, addr: String) -> Arc<Client> { todo!() }
|
||||
|
||||
fn send(&self, bytes: Vec<u8>) -> Result<(), &str> { todo!() }
|
||||
fn recv(&self) -> Option<Vec<u8>> { todo!() }
|
||||
|
||||
fn send_msg(&self, msg: ClientMessage) -> Result<(), &str> { todo!() }
|
||||
fn recv_msg(&self) -> Option<ClientMessage> { todo!() }
|
||||
|
||||
fn tick(&self) { }
|
||||
}
|
||||
|
|
@ -1,13 +1,25 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use uuid::Uuid;
|
||||
|
||||
/// # TClient
|
||||
/// This trait represents the methods that a client must implement
|
||||
/// in order to be used with a client manager
|
||||
///
|
||||
/// # Methods
|
||||
/// - new: creates a new client from an id, username and a address.
|
||||
/// - send: send a message to the client.
|
||||
/// - recv: if there is a message in the queue, returns the message
|
||||
/// - send_msg: sends a event message to the client
|
||||
/// - recv_msg: used by the client to receive and process event messages
|
||||
pub trait TClient<TClientMessage> {
|
||||
fn new(uuid: Uuid, name: String, addr: String);
|
||||
fn new(uuid: Uuid, name: String, addr: String) -> Arc<Self>;
|
||||
|
||||
fn send(&self, bytes: Vec<u8>) -> Result<(), &str>;
|
||||
fn recv(&self) -> Option<Vec<u8>>;
|
||||
|
||||
fn sendMsg(&self, msg: TClientMessage) -> Result<(), &str>;
|
||||
fn recvMsg(&self) -> Option<TClientMessage>;
|
||||
fn send_msg(&self, msg: TClientMessage) -> Result<(), &str>;
|
||||
fn recv_msg(&self) -> Option<TClientMessage>;
|
||||
|
||||
fn tick(&self);
|
||||
}
|
||||
|
|
@ -4,6 +4,9 @@ use uuid::Uuid;
|
|||
|
||||
use super::client::traits;
|
||||
|
||||
/**
|
||||
* @michael-bailey
|
||||
*/
|
||||
pub trait TClientManager<TClient,TClientMessage> {
|
||||
fn addClient(&self, client: Arc<TClient>);
|
||||
fn removeClient(&self, id: Uuid);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
pub mod client_management;
|
||||
pub mod server;
|
||||
pub mod server_v3;
|
||||
// pub mod server;
|
||||
// pub mod server_v3;
|
||||
|
||||
pub struct Server {}
|
||||
|
|
|
|||
Loading…
Reference in New Issue