s'more chat progress
This commit is contained in:
parent
acf96db186
commit
b4e6a3fe39
5 changed files with 33 additions and 4 deletions
|
@ -14,6 +14,7 @@ pub enum Request {
|
|||
Login(login::LoginRequest),
|
||||
Message(ChatMessage),
|
||||
GetChatHistory { amount: usize, from: usize },
|
||||
GetLastMessages { amount: usize, },
|
||||
Quit,
|
||||
Shutdown
|
||||
}
|
||||
|
|
|
@ -57,6 +57,15 @@ impl GameServer {
|
|||
.collect();
|
||||
_ = broadcast.send(api::Response::GetChatHistory(history));
|
||||
},
|
||||
api::Request::GetLastMessages { mut amount } => {
|
||||
if amount == 0 { amount = self.chat.len(); }
|
||||
let start = if amount >= self.chat.len() { self.chat.len() } else { self.chat.len() - amount };
|
||||
let history: Vec<ChatMessage> = self.chat.iter()
|
||||
.skip(start)
|
||||
.map(|m| m.1.clone())
|
||||
.collect();
|
||||
_ = broadcast.send(api::Response::GetChatHistory(history));
|
||||
},
|
||||
}
|
||||
}
|
||||
_ = broadcast.send(api::Response::Shutdown);
|
||||
|
|
|
@ -70,11 +70,11 @@ async fn handle_socket(mut socket: ws::WebSocket, msend: mpsc::Sender<(String, R
|
|||
println!("Got unauthorized message: {:?}", t);
|
||||
match req {
|
||||
// TODO: Actual signing in mechanism with multiple ids :)
|
||||
Request::Login(r) => if r.username == "rusty" {
|
||||
Request::Login(r) => if r.username == "rusty" || r.username == "honey" {
|
||||
_ = socket.send(Message::Text(
|
||||
serde_json::to_string(&Response::Login(open_tavern::api::login::LoginResult { success: true })).unwrap()
|
||||
)).await;
|
||||
id = Some(String::from("rusty"));
|
||||
id = Some(String::from(r.username));
|
||||
break;
|
||||
}
|
||||
else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue