allow sending resposne to specific id
This commit is contained in:
parent
b4e6a3fe39
commit
1beeb9fdbc
5 changed files with 21 additions and 21 deletions
12
src/lib.rs
12
src/lib.rs
|
@ -19,7 +19,7 @@ impl GameServer {
|
|||
}
|
||||
}
|
||||
|
||||
pub async fn server_loop(mut self, mut msgs: mpsc::Receiver<(String, api::Request)>, broadcast: broadcast::Sender<api::Response>) {
|
||||
pub async fn server_loop(mut self, mut msgs: mpsc::Receiver<(String, api::Request)>, broadcast: broadcast::Sender<(Option<String>, api::Response)>) {
|
||||
while let Some(req) = msgs.recv().await {
|
||||
// TODO: do stuff yo!
|
||||
let (id, req) = req;
|
||||
|
@ -44,9 +44,9 @@ impl GameServer {
|
|||
msg.source = id.clone();
|
||||
}
|
||||
self.chat.push((id.clone(), msg.clone()));
|
||||
_ = broadcast.send(api::Response::Message(msg));
|
||||
_ = broadcast.send((None, api::Response::Message(msg)));
|
||||
},
|
||||
api::Request::Quit => { _ = broadcast.send(api::Response::Quit { id })},
|
||||
api::Request::Quit => { _ = broadcast.send((None, api::Response::Quit { id }))},
|
||||
api::Request::Shutdown => todo!(),
|
||||
api::Request::GetChatHistory { mut amount, from: last_msg } => {
|
||||
if amount == 0 { amount = self.chat.len(); }
|
||||
|
@ -55,7 +55,7 @@ impl GameServer {
|
|||
.take(amount)
|
||||
.map(|m| m.1.clone())
|
||||
.collect();
|
||||
_ = broadcast.send(api::Response::GetChatHistory(history));
|
||||
_ = broadcast.send((Some(id), api::Response::GetChatHistory(history)));
|
||||
},
|
||||
api::Request::GetLastMessages { mut amount } => {
|
||||
if amount == 0 { amount = self.chat.len(); }
|
||||
|
@ -64,10 +64,10 @@ impl GameServer {
|
|||
.skip(start)
|
||||
.map(|m| m.1.clone())
|
||||
.collect();
|
||||
_ = broadcast.send(api::Response::GetChatHistory(history));
|
||||
_ = broadcast.send((Some(id), api::Response::GetChatHistory(history)));
|
||||
},
|
||||
}
|
||||
}
|
||||
_ = broadcast.send(api::Response::Shutdown);
|
||||
_ = broadcast.send((None, api::Response::Shutdown));
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue