1
Fork 0
mirror of https://github.com/redstrate/Kawari.git synced 2025-04-22 23:27:46 +00:00

Remove separate InternalMsg enum

I think the current way I'll accomplish this for now is to use the other
task to send all messages from the global server state back into the
main connection loop.
This commit is contained in:
Joshua Goins 2025-03-30 16:44:07 -04:00
parent caaa9c9b13
commit d35845c134

View file

@ -117,11 +117,6 @@ struct ClientData {
connection: ZoneConnection,
}
#[derive(Debug)]
enum InternalMsg {
Message(String),
}
/// Spawn a new client actor.
pub fn spawn_client(info: ZoneConnection) {
let (send, recv) = channel(64);
@ -173,13 +168,11 @@ async fn start_client(my_handle: oneshot::Receiver<ClientHandle>, mut data: Clie
async fn client_server_loop(
mut data: Receiver<FromServer>,
internal_send: UnboundedSender<InternalMsg>,
internal_send: UnboundedSender<FromServer>,
) {
loop {
match data.recv().await {
Some(msg) => match msg {
FromServer::Message(msg) => internal_send.send(InternalMsg::Message(msg)).unwrap(),
},
Some(msg) => internal_send.send(msg).unwrap(),
None => break,
}
}
@ -187,7 +180,7 @@ async fn client_server_loop(
async fn client_loop(
mut connection: ZoneConnection,
mut internal_recv: UnboundedReceiver<InternalMsg>,
mut internal_recv: UnboundedReceiver<FromServer>,
) {
let database = connection.database.clone();
let game_data = connection.gamedata.clone();
@ -1023,7 +1016,7 @@ async fn client_loop(
}
msg = internal_recv.recv() => match msg {
Some(msg) => match msg {
InternalMsg::Message(msg) => connection.send_message(&msg).await,
FromServer::Message(msg) => connection.send_message(&msg).await,
},
None => break,
}