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