Rename User to Session
This commit is contained in:
parent
620285d1d1
commit
fec541b7aa
4 changed files with 27 additions and 20 deletions
|
|
@ -2,8 +2,8 @@ mod id;
|
|||
mod macros;
|
||||
mod message;
|
||||
pub mod packets;
|
||||
mod user;
|
||||
mod session;
|
||||
|
||||
pub use self::id::*;
|
||||
pub use self::message::*;
|
||||
pub use self::user::*;
|
||||
pub use self::session::*;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::macros::packets;
|
||||
use crate::{Message, MessageId, User};
|
||||
use crate::{Message, MessageId, Session};
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct HelloCmd {
|
||||
|
|
@ -14,8 +14,8 @@ pub struct HelloCmd {
|
|||
#[serde(tag = "type")]
|
||||
pub enum HelloRpl {
|
||||
Success {
|
||||
you: User,
|
||||
others: Vec<User>,
|
||||
you: Session,
|
||||
others: Vec<Session>,
|
||||
last_message: MessageId,
|
||||
},
|
||||
InvalidRoom {
|
||||
|
|
@ -60,23 +60,23 @@ pub struct WhoCmd {}
|
|||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct WhoRpl {
|
||||
pub you: User,
|
||||
pub others: Vec<User>,
|
||||
pub you: Session,
|
||||
pub others: Vec<Session>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct JoinNtf {
|
||||
pub user: User,
|
||||
pub who: Session,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct NickNtf {
|
||||
pub user: User,
|
||||
pub who: Session,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct PartNtf {
|
||||
pub user: User,
|
||||
pub who: Session,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@ use serde::{Deserialize, Serialize};
|
|||
use crate::{Identity, SessionId};
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
pub struct User {
|
||||
pub struct Session {
|
||||
pub id: SessionId,
|
||||
pub nick: String,
|
||||
pub identity: Identity,
|
||||
pub sid: SessionId,
|
||||
}
|
||||
|
|
@ -2,16 +2,17 @@ use cove_core::packets::{
|
|||
Cmd, HelloCmd, HelloRpl, JoinNtf, NickCmd, NickNtf, NickRpl, Ntf, Packet, PartNtf, Rpl,
|
||||
SendCmd, SendNtf, SendRpl, WhoCmd, WhoRpl,
|
||||
};
|
||||
use cove_core::{Identity, Message, MessageId, SessionId, User};
|
||||
use cove_core::{Identity, Message, MessageId, Session, SessionId};
|
||||
use futures::{future, StreamExt, TryStreamExt};
|
||||
use tokio::net::{TcpListener, TcpStream};
|
||||
use tokio::sync::mpsc::Sender;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
let user = User {
|
||||
let session = Session {
|
||||
id: SessionId::of("12345"),
|
||||
nick: "Garmy".to_string(),
|
||||
identity: Identity::of("random garbage"),
|
||||
sid: SessionId::of("12345"),
|
||||
};
|
||||
let message = Message {
|
||||
pred: MessageId::of("pred"),
|
||||
|
|
@ -37,7 +38,7 @@ async fn main() {
|
|||
serde_json::to_string_pretty(&Packet::Rpl {
|
||||
id: 67890,
|
||||
rpl: Rpl::Hello(HelloRpl::Success {
|
||||
you: user.clone(),
|
||||
you: session.clone(),
|
||||
others: vec![],
|
||||
last_message: MessageId::of("Blarg")
|
||||
})
|
||||
|
|
@ -127,7 +128,7 @@ async fn main() {
|
|||
serde_json::to_string_pretty(&Packet::Rpl {
|
||||
id: 67890,
|
||||
rpl: Rpl::Who(WhoRpl {
|
||||
you: user.clone(),
|
||||
you: session.clone(),
|
||||
others: vec![]
|
||||
})
|
||||
})
|
||||
|
|
@ -136,21 +137,27 @@ async fn main() {
|
|||
println!(
|
||||
"{}",
|
||||
serde_json::to_string_pretty(&Packet::Ntf {
|
||||
ntf: Ntf::Join(JoinNtf { user: user.clone() })
|
||||
ntf: Ntf::Join(JoinNtf {
|
||||
who: session.clone()
|
||||
})
|
||||
})
|
||||
.unwrap()
|
||||
);
|
||||
println!(
|
||||
"{}",
|
||||
serde_json::to_string_pretty(&Packet::Ntf {
|
||||
ntf: Ntf::Nick(NickNtf { user: user.clone() })
|
||||
ntf: Ntf::Nick(NickNtf {
|
||||
who: session.clone()
|
||||
})
|
||||
})
|
||||
.unwrap()
|
||||
);
|
||||
println!(
|
||||
"{}",
|
||||
serde_json::to_string_pretty(&Packet::Ntf {
|
||||
ntf: Ntf::Part(PartNtf { user: user.clone() })
|
||||
ntf: Ntf::Part(PartNtf {
|
||||
who: session.clone()
|
||||
})
|
||||
})
|
||||
.unwrap()
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue