forked from lavina/lavina
1
0
Fork 0

make PlayerCommand mod-private

This commit is contained in:
Nikita Vilunov 2023-02-15 21:49:52 +01:00
parent 8b4e963d39
commit 1e17e017cf
2 changed files with 7 additions and 7 deletions

View File

@ -89,8 +89,10 @@ impl PlayerConnection {
.await; .await;
} }
pub async fn send(&self, command: PlayerCommand) { pub async fn get_rooms(&self) -> Result<Vec<RoomInfo>> {
self.player_handle.send(command).await; let (promise, deferred) = oneshot();
self.player_handle.send(PlayerCommand::GetRooms(promise)).await;
Ok(deferred.await?)
} }
} }
@ -153,7 +155,7 @@ impl PlayerHandle {
} }
} }
pub enum PlayerCommand { enum PlayerCommand {
/** Commands from connections */ /** Commands from connections */
AddConnection { AddConnection {
sender: Sender<Updates>, sender: Sender<Updates>,

View File

@ -7,7 +7,7 @@ use tokio::net::tcp::{ReadHalf, WriteHalf};
use tokio::net::{TcpListener, TcpStream}; use tokio::net::{TcpListener, TcpStream};
use tokio::sync::oneshot::channel; use tokio::sync::oneshot::channel;
use crate::core::player::{PlayerCommand, PlayerConnection, PlayerId, PlayerRegistry, Updates}; use crate::core::player::{PlayerConnection, PlayerId, PlayerRegistry, Updates};
use crate::core::room::{RoomId, RoomInfo, RoomRegistry}; use crate::core::room::{RoomId, RoomInfo, RoomRegistry};
use crate::prelude::*; use crate::prelude::*;
use crate::protos::irc::client::{client_message, ClientMessage}; use crate::protos::irc::client::{client_message, ClientMessage};
@ -196,9 +196,7 @@ async fn handle_registered_socket<'a>(
.write_async(writer) .write_async(writer)
.await?; .await?;
let (promise, deferred) = oneshot(); let rooms_list = connection.get_rooms().await?;
connection.send(PlayerCommand::GetRooms(promise)).await;
let rooms_list = deferred.await?;
for room in &rooms_list { for room in &rooms_list {
produce_on_join_cmd_messages( produce_on_join_cmd_messages(
&config, &config,