|
|
@ -103,15 +103,7 @@ pub async fn start( |
|
|
// }
|
|
|
// }
|
|
|
// }
|
|
|
// }
|
|
|
|
|
|
|
|
|
pub async fn serve( |
|
|
type RunningGames = Arc< |
|
|
mut pool: db::DbClient, |
|
|
|
|
|
games: Vec<crate::games::Game>, |
|
|
|
|
|
properties: crate::server_properties::ServerProperties, |
|
|
|
|
|
) -> Result<(), std::io::Error> { |
|
|
|
|
|
let properties = Arc::new(properties); |
|
|
|
|
|
let games = Arc::new(games); |
|
|
|
|
|
let voting = votes::VotingSystem::new(pool.clone().await); |
|
|
|
|
|
let running_games: Arc< |
|
|
|
|
|
RwLock< |
|
|
RwLock< |
|
|
HashMap< |
|
|
HashMap< |
|
|
u32, |
|
|
u32, |
|
|
@ -122,8 +114,18 @@ pub async fn serve( |
|
|
)>, |
|
|
)>, |
|
|
>, |
|
|
>, |
|
|
>, |
|
|
>, |
|
|
> = Default::default(); |
|
|
>; |
|
|
let listener = TcpListener::bind(properties.addr.clone()).await?; |
|
|
|
|
|
|
|
|
pub async fn serve( |
|
|
|
|
|
mut pool: db::DbClient, |
|
|
|
|
|
games: Vec<crate::games::Game>, |
|
|
|
|
|
properties: crate::server_properties::ServerProperties, |
|
|
|
|
|
) -> Result<(), std::io::Error> { |
|
|
|
|
|
let properties = Arc::new(properties); |
|
|
|
|
|
let games = Arc::new(games); |
|
|
|
|
|
let voting = votes::VotingSystem::new(pool.clone().await); |
|
|
|
|
|
let running_games: RunningGames = Default::default(); |
|
|
|
|
|
let listener = TcpListener::bind(properties.addr).await?; |
|
|
let socket_manager = Arc::new(SocketManager::new()); |
|
|
let socket_manager = Arc::new(SocketManager::new()); |
|
|
loop { |
|
|
loop { |
|
|
let (stream, addr) = listener.accept().await?; |
|
|
let (stream, addr) = listener.accept().await?; |
|
|
@ -205,9 +207,9 @@ pub async fn serve( |
|
|
&mut service_data, |
|
|
&mut service_data, |
|
|
writer |
|
|
writer |
|
|
.take() |
|
|
.take() |
|
|
.ok_or(anyhow::anyhow!( |
|
|
.ok_or_else(|| { |
|
|
"Connect shouldn't be called more than once" |
|
|
anyhow::anyhow!("Connect shouldn't be called more than once") |
|
|
)) |
|
|
}) |
|
|
.unwrap(), |
|
|
.unwrap(), |
|
|
&socket_manager, |
|
|
&socket_manager, |
|
|
name, |
|
|
name, |
|
|
@ -280,18 +282,7 @@ struct ServiceData { |
|
|
properties: Arc<ServerProperties>, |
|
|
properties: Arc<ServerProperties>, |
|
|
games: Arc<Vec<crate::games::Game>>, |
|
|
games: Arc<Vec<crate::games::Game>>, |
|
|
voting: VotingSystem, |
|
|
voting: VotingSystem, |
|
|
running_games: Arc< |
|
|
running_games: RunningGames, |
|
|
RwLock< |
|
|
|
|
|
HashMap< |
|
|
|
|
|
u32, |
|
|
|
|
|
RwLock<( |
|
|
|
|
|
u32, |
|
|
|
|
|
RunningGame, |
|
|
|
|
|
votes::Modifiable<Option<protos::game::GameStatus>>, |
|
|
|
|
|
)>, |
|
|
|
|
|
>, |
|
|
|
|
|
>, |
|
|
|
|
|
>, |
|
|
|
|
|
addr: SocketAddr, |
|
|
addr: SocketAddr, |
|
|
db: db::DbClient, |
|
|
db: db::DbClient, |
|
|
} |
|
|
} |
|
|
@ -313,12 +304,13 @@ impl UserId { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
pub fn get(self) -> Result<Uuid> { |
|
|
pub fn get(self) -> Result<Uuid> { |
|
|
self.0.ok_or(anyhow::anyhow!("User should have connected")) |
|
|
self.0 |
|
|
|
|
|
.ok_or_else(|| anyhow::anyhow!("User should have connected")) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
pub fn get_ref(&self) -> Result<&Uuid> { |
|
|
pub fn get_ref(&self) -> Result<&Uuid> { |
|
|
self.0 |
|
|
self.0 |
|
|
.as_ref() |
|
|
.as_ref() |
|
|
.ok_or(anyhow::anyhow!("User should have connected")) |
|
|
.ok_or_else(|| anyhow::anyhow!("User should have connected")) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|