Browse Source

run cargo fmt

main
ThePerkinrex 4 years ago
parent
commit
22f6974288
No known key found for this signature in database GPG Key ID: FD81DE6D75E20917
  1. 12
      server/src/db.rs
  2. 6
      server/src/games/run.rs
  3. 27
      server/src/server/game.rs

12
server/src/db.rs

@ -79,7 +79,6 @@ impl Db {
.unwrap()
}
pub fn get_uuids_in_lobby_where_user_is(&mut self, uuid: Uuid) -> Vec<Uuid> {
let mut prepared = self.conn.prepare_cached("SELECT UUID FROM Users WHERE UUID in (SELECT UserId FROM UsersInLobbies WHERE LobbyId = (SELECT LobbyId FROM UsersInLobbies WHERE UserId = ?))").unwrap();
prepared
@ -92,7 +91,6 @@ impl Db {
.unwrap()
}
pub fn get_name_for_uuid(&mut self, uuid: Uuid) -> String {
let mut prepared = self
.conn
@ -104,7 +102,6 @@ impl Db {
.unwrap()
}
pub fn create_lobby(&mut self, public: bool) -> u32 {
let id = rand::random();
@ -128,7 +125,6 @@ impl Db {
log::info!("{} joined the lobby {}", user, lobby);
}
pub fn leave_lobby(&mut self, user: Uuid) {
log::info!("{} leaving the lobby", user);
self.delete_vote(user);
@ -146,7 +142,6 @@ impl Db {
}
}
pub fn disconnect(&mut self, user: Uuid) {
self.leave_lobby(user);
log::info!("{} disconnecting", user);
@ -160,7 +155,6 @@ impl Db {
// log::error!("Disconnect DB result{:?}", r);
}
pub fn get_lobby_for_user(&mut self, user: Uuid) -> Option<u32> {
match self.conn.query_row(
"SELECT LobbyID from UsersInLobbies WHERE UserID = ?",
@ -187,7 +181,6 @@ impl Db {
.unwrap()
}
fn delete_vote(&mut self, user: Uuid) {
self.conn
.execute(
@ -197,7 +190,6 @@ impl Db {
.unwrap();
}
pub fn vote(&mut self, user: Uuid, game: u32) {
self.delete_vote(user);
self.conn
@ -208,7 +200,6 @@ impl Db {
.unwrap();
}
pub fn vote_ready(&mut self, user: Uuid) {
// self.delete_vote(user);
self.conn
@ -219,7 +210,6 @@ impl Db {
.unwrap();
}
pub fn get_votes(&mut self, lobby: u32) -> Vec<(String, u32, bool)> {
let mut prepared = self.conn.prepare_cached("SELECT Users.Name, Votes.GameID, Votes.Ready FROM Votes JOIN Users ON Users.UUID = Votes.UserID WHERE Votes.UserID IN (SELECT UserID FROM UsersInLobbies WHERE LobbyID = ?)").unwrap();
prepared
@ -234,7 +224,6 @@ impl Db {
.unwrap()
}
pub fn is_poll_finished(&mut self, lobby: u32) -> bool {
self.conn.query_row(
"SELECT (SELECT COUNT(*) FROM UsersInLobbies where LobbyID = ?) = (SELECT COUNT(*) FROM Votes WHERE UserID IN (SELECT UserID FROM UsersInLobbies WHERE LobbyID = ?) AND Ready = TRUE)",
@ -243,7 +232,6 @@ impl Db {
).unwrap()
}
pub fn delete_votes(&mut self, lobby: u32) {
self.conn
.execute("DELETE FROM Votes WHERE UserId IN (SELECT UserID FROM UsersInLobbies WHERE LobbyID = ?)", params![lobby as i32]).unwrap();

6
server/src/games/run.rs

@ -131,12 +131,12 @@ impl RunningGame {
let turn_end: bool = arr[1].clone().cast();
if turn_end {
self.turn_end()
}else{
} else {
Ok(())
}
}
fn turn_end(&mut self) -> RhaiResult<()> {
fn turn_end(&mut self) -> RhaiResult<()> {
let data = self.data_as_dynamic()?;
let mut arr = self.functions.turn_end(data, self.current_player)?;
self.save_data(&arr[0])?;
@ -145,7 +145,7 @@ impl RunningGame {
self.turn_start()
}
fn turn_start(&mut self) -> RhaiResult<()> {
fn turn_start(&mut self) -> RhaiResult<()> {
let data = self.data_as_dynamic()?;
let data = self
.functions

27
server/src/server/game.rs

@ -3,11 +3,19 @@ use super::{
socket_manager::SocketManager,
ServiceData,
};
use crate::{games::{CardId, CardIdx, PileKind, RunningPile}, server::protos::{game::game_status::CustomInfoMessage, protocol::server_client_packet::{self, Data}}};
use crate::{
games::{CardId, CardIdx, PileKind, RunningPile},
server::protos::{
game::game_status::CustomInfoMessage,
protocol::server_client_packet::{self, Data},
},
};
use anyhow::{anyhow, Result};
pub(super) async fn get_status(data: &mut ServiceData,
socket_mgr: &SocketManager,) -> Result<GameStatus> {
pub(super) async fn get_status(
data: &mut ServiceData,
socket_mgr: &SocketManager,
) -> Result<GameStatus> {
let uuid = data.user_id.get()?;
log::info!("Creating a new status for {}", uuid);
let lobby: u32 = match data.db.get_lobby_for_user(uuid).await {
@ -101,8 +109,17 @@ pub(super) async fn get_status(data: &mut ServiceData,
if status.has_finished {
log::info!("Game has finished: {}", name);
data.running_games.write().await.remove(&lobby);
let s = super::lobby::get_status(data).await.expect("Unexpected error getting lobby status");
socket_mgr.broadcast_to_lobby(&mut data.db, data.user_id.0.unwrap(), server_client_packet::Data::LobbyStatus(s)).await.expect("Error sending finished game ");
let s = super::lobby::get_status(data)
.await
.expect("Unexpected error getting lobby status");
socket_mgr
.broadcast_to_lobby(
&mut data.db,
data.user_id.0.unwrap(),
server_client_packet::Data::LobbyStatus(s),
)
.await
.expect("Error sending finished game ");
}
Ok(status)
}

Loading…
Cancel
Save