THIS WORKS BUT IS UGLY AND I DON'T CARE

This commit is contained in:
Hamcha 2020-10-04 15:45:24 +02:00
parent b03514b8bd
commit 36b5063637
Signed by: hamcha
GPG Key ID: 41467804B19A3315
2 changed files with 7 additions and 5 deletions

View File

@ -6,7 +6,7 @@ mod systems;
use crate::config::Settings; use crate::config::Settings;
use crate::game::Game; use crate::game::Game;
use crate::network::{listen, NetworkManager}; use crate::network::listen;
use async_std::sync::Arc; use async_std::sync::Arc;
use async_std::{sync::channel, task}; use async_std::{sync::channel, task};
use env_logger::Env; use env_logger::Env;

View File

@ -34,17 +34,19 @@ impl NetworkManager {
self.connections.insert(conn.conn_id, conn); self.connections.insert(conn.conn_id, conn);
} }
async fn send(&self, message: NetworkMessage) { async fn send(&mut self, message: NetworkMessage) {
let conn = self let conn = self
.connections .connections
.get(&message.conn_id) .get_mut(&message.conn_id)
.expect("cant send message to an unregistered connection"); .expect("cant send message to an unregistered connection");
conn.stream.send(message.data).await; conn.stream
.send(message.data)
.await
.expect("could not send message to connection");
} }
} }
pub async fn listen( pub async fn listen(
net: Arc<NetworkManager>,
bind: String, bind: String,
incoming: Sender<NetworkMessage>, incoming: Sender<NetworkMessage>,
outgoing: Receiver<NetworkMessage>, outgoing: Receiver<NetworkMessage>,