(fix): fix connection issues
This commit is contained in:
parent
b94dbd7006
commit
be0cad295d
2 changed files with 11 additions and 5 deletions
|
|
@ -245,17 +245,21 @@ impl OmikronConnection {
|
||||||
}
|
}
|
||||||
pub async fn close(self: Arc<Self>) {
|
pub async fn close(self: Arc<Self>) {
|
||||||
log_in!(
|
log_in!(
|
||||||
self.get_omikron_id().await.unwrap_or(0),
|
self.id as i64,
|
||||||
PrintType::Omega,
|
PrintType::Omega,
|
||||||
"Omikron connection Closed"
|
"Omikron connection Closed"
|
||||||
);
|
);
|
||||||
|
if let Some(sender) = self.sender.lock().await.take() {
|
||||||
|
sender.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
async fn cleanup(self: Arc<Self>) {
|
async fn cleanup(self: Arc<Self>) {
|
||||||
if self.id != 0 {
|
if self.id != 0 {
|
||||||
log_in!(self.id as i64, PrintType::Omega, "Omikron disconnected");
|
log_in!(self.id as i64, PrintType::Omega, "Omikron disconnected");
|
||||||
omikron_manager::remove_omikron(self.id as i64).await;
|
if omikron_manager::remove_omikron(self.id as i64, &self).await {
|
||||||
crate::sql::user_online_tracker::untrack_omikron(self.id as i64).await;
|
crate::sql::user_online_tracker::untrack_omikron(self.id as i64).await;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if let Some(handle) = self.cleanup_handle.lock().unwrap().take() {
|
if let Some(handle) = self.cleanup_handle.lock().unwrap().take() {
|
||||||
handle.abort();
|
handle.abort();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,8 +22,10 @@ pub async fn add_omikron(conn: Arc<OmikronConnection>) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn remove_omikron(omikron_id: i64) {
|
pub async fn remove_omikron(omikron_id: i64, connection: &Arc<OmikronConnection>) -> bool {
|
||||||
OMIKRON_CONNECTIONS.remove(&omikron_id);
|
OMIKRON_CONNECTIONS
|
||||||
|
.remove_if(&omikron_id, |_, current| Arc::ptr_eq(current, connection))
|
||||||
|
.is_some()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_connected_omikron(omikron_id: i64) -> Option<Arc<OmikronConnection>> {
|
pub fn get_connected_omikron(omikron_id: i64) -> Option<Arc<OmikronConnection>> {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue