mirror of
https://github.com/redstrate/Kawari.git
synced 2025-04-22 15:27:44 +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:
parent
caaa9c9b13
commit
d35845c134
1 changed files with 4 additions and 11 deletions
|
@ -117,11 +117,6 @@ struct ClientData {
|
||||||
connection: ZoneConnection,
|
connection: ZoneConnection,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
enum InternalMsg {
|
|
||||||
Message(String),
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Spawn a new client actor.
|
/// Spawn a new client actor.
|
||||||
pub fn spawn_client(info: ZoneConnection) {
|
pub fn spawn_client(info: ZoneConnection) {
|
||||||
let (send, recv) = channel(64);
|
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(
|
async fn client_server_loop(
|
||||||
mut data: Receiver<FromServer>,
|
mut data: Receiver<FromServer>,
|
||||||
internal_send: UnboundedSender<InternalMsg>,
|
internal_send: UnboundedSender<FromServer>,
|
||||||
) {
|
) {
|
||||||
loop {
|
loop {
|
||||||
match data.recv().await {
|
match data.recv().await {
|
||||||
Some(msg) => match msg {
|
Some(msg) => internal_send.send(msg).unwrap(),
|
||||||
FromServer::Message(msg) => internal_send.send(InternalMsg::Message(msg)).unwrap(),
|
|
||||||
},
|
|
||||||
None => break,
|
None => break,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -187,7 +180,7 @@ async fn client_server_loop(
|
||||||
|
|
||||||
async fn client_loop(
|
async fn client_loop(
|
||||||
mut connection: ZoneConnection,
|
mut connection: ZoneConnection,
|
||||||
mut internal_recv: UnboundedReceiver<InternalMsg>,
|
mut internal_recv: UnboundedReceiver<FromServer>,
|
||||||
) {
|
) {
|
||||||
let database = connection.database.clone();
|
let database = connection.database.clone();
|
||||||
let game_data = connection.gamedata.clone();
|
let game_data = connection.gamedata.clone();
|
||||||
|
@ -1023,7 +1016,7 @@ async fn client_loop(
|
||||||
}
|
}
|
||||||
msg = internal_recv.recv() => match msg {
|
msg = internal_recv.recv() => match msg {
|
||||||
Some(msg) => match msg {
|
Some(msg) => match msg {
|
||||||
InternalMsg::Message(msg) => connection.send_message(&msg).await,
|
FromServer::Message(msg) => connection.send_message(&msg).await,
|
||||||
},
|
},
|
||||||
None => break,
|
None => break,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue