|
|
@ -224,15 +224,23 @@ async fn state_client_loop<STATE, S, R, E>(state: Arc<Mutex<STATE>>, |
|
|
|
match action {
|
|
|
|
ClientAction::NewClient(client_id, sender) => {
|
|
|
|
clients.insert(client_id, sender.clone());
|
|
|
|
for action in state.on_connect(client_id).await {
|
|
|
|
match action {
|
|
|
|
OnConnect::Cipher((inc, outc)) => {
|
|
|
|
sender.send(ServerStateAction::Cipher(inc, outc)).await;
|
|
|
|
},
|
|
|
|
OnConnect::Packet(pkt) => {
|
|
|
|
sender.send(ServerStateAction::Packet(pkt)).await;
|
|
|
|
let actions = state.on_connect(client_id).await;
|
|
|
|
match actions {
|
|
|
|
Ok(actions) => {
|
|
|
|
for action in actions {
|
|
|
|
match action {
|
|
|
|
OnConnect::Cipher((inc, outc)) => {
|
|
|
|
sender.send(ServerStateAction::Cipher(inc, outc)).await;
|
|
|
|
},
|
|
|
|
OnConnect::Packet(pkt) => {
|
|
|
|
sender.send(ServerStateAction::Packet(pkt)).await;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Err(err) => {
|
|
|
|
warn!("[client {:?} state on_connect error] {:?}", client_id, err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
ClientAction::Packet(client_id, pkt) => {
|
|
|
@ -252,14 +260,21 @@ async fn state_client_loop<STATE, S, R, E>(state: Arc<Mutex<STATE>>, |
|
|
|
},
|
|
|
|
ClientAction::Disconnect(client_id) => {
|
|
|
|
let pkts = state.on_disconnect(client_id).await;
|
|
|
|
for (client_id, pkt) in pkts {
|
|
|
|
if let Some(client) = clients.get_mut(&client_id) {
|
|
|
|
client.send(ServerStateAction::Packet(pkt)).await;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
match pkts {
|
|
|
|
Ok(pkts) => {
|
|
|
|
for (client_id, pkt) in pkts {
|
|
|
|
if let Some(client) = clients.get_mut(&client_id) {
|
|
|
|
client.send(ServerStateAction::Packet(pkt)).await;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if let Some(client) = clients.get_mut(&client_id) {
|
|
|
|
client.send(ServerStateAction::Disconnect).await;
|
|
|
|
if let Some(client) = clients.get_mut(&client_id) {
|
|
|
|
client.send(ServerStateAction::Disconnect).await;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Err(err) => {
|
|
|
|
warn!("[client {:?} state on_disconnect error] {:?}", client_id, err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|