misc: formatting and compile fix
This commit is contained in:
@@ -1,2 +1,3 @@
|
|||||||
combine_control_expr = false
|
combine_control_expr = false
|
||||||
chain_width = 100
|
chain_width = 100
|
||||||
|
tab_spaces = 2
|
||||||
42
src/main.rs
42
src/main.rs
@@ -74,9 +74,7 @@ async fn handle_connection(
|
|||||||
"CONNECT" => {
|
"CONNECT" => {
|
||||||
if parts.len() > 1 {
|
if parts.len() > 1 {
|
||||||
let requested_username = parts[1].to_string();
|
let requested_username = parts[1].to_string();
|
||||||
if let Err(e) =
|
if let Err(e) = sd.handle_connect_cmd(addr, tx.clone(), requested_username).await {
|
||||||
sd.handle_connect_cmd(addr, tx.clone(), requested_username).await
|
|
||||||
{
|
|
||||||
error!("handle_connect: {}", e);
|
error!("handle_connect: {}", e);
|
||||||
let _ = send(&tx, e.to_string().as_str());
|
let _ = send(&tx, e.to_string().as_str());
|
||||||
}
|
}
|
||||||
@@ -87,9 +85,7 @@ async fn handle_connection(
|
|||||||
"RECONNECT" => {
|
"RECONNECT" => {
|
||||||
if parts.len() > 1 {
|
if parts.len() > 1 {
|
||||||
let requested_username = parts[1].to_string();
|
let requested_username = parts[1].to_string();
|
||||||
if let Err(e) =
|
if let Err(e) = sd.handle_reconnect_cmd(addr, tx.clone(), requested_username).await {
|
||||||
sd.handle_reconnect_cmd(addr, tx.clone(), requested_username).await
|
|
||||||
{
|
|
||||||
error!("handle_reconnect: {}", e);
|
error!("handle_reconnect: {}", e);
|
||||||
let _ = send(&tx, e.to_string().as_str());
|
let _ = send(&tx, e.to_string().as_str());
|
||||||
}
|
}
|
||||||
@@ -145,9 +141,7 @@ async fn handle_connection(
|
|||||||
} else if parts.get(1) == Some(&"WATCH") && parts.len() > 2 {
|
} else if parts.get(1) == Some(&"WATCH") && parts.len() > 2 {
|
||||||
match parts[2].parse::<u32>() {
|
match parts[2].parse::<u32>() {
|
||||||
Ok(match_id) => {
|
Ok(match_id) => {
|
||||||
if let Err(e) =
|
if let Err(e) = sd.handle_game_watch(tx.clone(), match_id, addr).await {
|
||||||
sd.handle_game_watch(tx.clone(), match_id, addr).await
|
|
||||||
{
|
|
||||||
error!("handle_game_watch: {}", e);
|
error!("handle_game_watch: {}", e);
|
||||||
let _ = send(&tx, e.to_string().as_str());
|
let _ = send(&tx, e.to_string().as_str());
|
||||||
}
|
}
|
||||||
@@ -172,9 +166,7 @@ async fn handle_connection(
|
|||||||
match parts[2].parse::<u32>() {
|
match parts[2].parse::<u32>() {
|
||||||
Ok(match_id) => {
|
Ok(match_id) => {
|
||||||
let winner = parts[3].to_string();
|
let winner = parts[3].to_string();
|
||||||
if let Err(e) =
|
if let Err(e) = sd.handle_game_award_winner(addr, match_id, winner).await {
|
||||||
sd.handle_game_award_winner(addr, match_id, winner).await
|
|
||||||
{
|
|
||||||
error!("handle_game_award_winner: {}", e);
|
error!("handle_game_award_winner: {}", e);
|
||||||
let _ = send(&tx, e.to_string().as_str());
|
let _ = send(&tx, e.to_string().as_str());
|
||||||
}
|
}
|
||||||
@@ -189,9 +181,7 @@ async fn handle_connection(
|
|||||||
}
|
}
|
||||||
"ADMIN" => {
|
"ADMIN" => {
|
||||||
if parts.get(1) == Some(&"AUTH") && parts.len() > 2 {
|
if parts.get(1) == Some(&"AUTH") && parts.len() > 2 {
|
||||||
if let Err(e) =
|
if let Err(e) = sd.handle_admin_auth(tx.clone(), addr, parts[2].to_string()).await {
|
||||||
sd.handle_admin_auth(tx.clone(), addr, parts[2].to_string()).await
|
|
||||||
{
|
|
||||||
error!("handle_admin_auth: {}", e);
|
error!("handle_admin_auth: {}", e);
|
||||||
let _ = send(&tx, e.to_string().as_str());
|
let _ = send(&tx, e.to_string().as_str());
|
||||||
}
|
}
|
||||||
@@ -206,9 +196,7 @@ async fn handle_connection(
|
|||||||
}
|
}
|
||||||
"TOURNAMENT" => {
|
"TOURNAMENT" => {
|
||||||
if parts.get(1) == Some(&"START") && parts.len() > 2 {
|
if parts.get(1) == Some(&"START") && parts.len() > 2 {
|
||||||
if let Err(e) =
|
if let Err(e) = sd.handle_tournament_start(addr, parts[2].to_string()).await {
|
||||||
sd.handle_tournament_start(addr, parts[2].to_string()).await
|
|
||||||
{
|
|
||||||
error!("handle_tournament_start: {}", e);
|
error!("handle_tournament_start: {}", e);
|
||||||
let _ = send(&tx, e.to_string().as_str());
|
let _ = send(&tx, e.to_string().as_str());
|
||||||
}
|
}
|
||||||
@@ -223,9 +211,7 @@ async fn handle_connection(
|
|||||||
}
|
}
|
||||||
"GET" => {
|
"GET" => {
|
||||||
if let Some(data_id) = parts.get(1) {
|
if let Some(data_id) = parts.get(1) {
|
||||||
if let Err(e) =
|
if let Err(e) = sd.handle_get_data(tx.clone(), data_id.to_string()).await {
|
||||||
sd.handle_get_data(tx.clone(), data_id.to_string()).await
|
|
||||||
{
|
|
||||||
error!("handle_get_data: {}", e);
|
error!("handle_get_data: {}", e);
|
||||||
let _ = send(&tx, e.to_string().as_str());
|
let _ = send(&tx, e.to_string().as_str());
|
||||||
}
|
}
|
||||||
@@ -237,9 +223,7 @@ async fn handle_connection(
|
|||||||
if parts.len() > 2 {
|
if parts.len() > 2 {
|
||||||
let data_id = parts[1].to_string();
|
let data_id = parts[1].to_string();
|
||||||
let data_value = parts[2].to_string();
|
let data_value = parts[2].to_string();
|
||||||
if let Err(e) =
|
if let Err(e) = sd.handle_set_data(tx.clone(), addr, data_id, data_value).await {
|
||||||
sd.handle_set_data(tx.clone(), addr, data_id, data_value).await
|
|
||||||
{
|
|
||||||
error!("handle_set_data: {}", e);
|
error!("handle_set_data: {}", e);
|
||||||
let _ = send(&tx, e.to_string().as_str());
|
let _ = send(&tx, e.to_string().as_str());
|
||||||
}
|
}
|
||||||
@@ -259,7 +243,10 @@ async fn handle_connection(
|
|||||||
let player1_username = usernames[0].to_string();
|
let player1_username = usernames[0].to_string();
|
||||||
let player2_username = usernames[1].to_string();
|
let player2_username = usernames[1].to_string();
|
||||||
|
|
||||||
if let Err(e) = sd.handle_reservation_add(tx.clone(), addr, player1_username, player2_username).await {
|
if let Err(e) = sd
|
||||||
|
.handle_reservation_add(tx.clone(), addr, player1_username, player2_username)
|
||||||
|
.await
|
||||||
|
{
|
||||||
error!("handle_reservation_add: {}", e);
|
error!("handle_reservation_add: {}", e);
|
||||||
let _ = send(&tx, e.to_string().as_str());
|
let _ = send(&tx, e.to_string().as_str());
|
||||||
}
|
}
|
||||||
@@ -274,7 +261,10 @@ async fn handle_connection(
|
|||||||
let player1_username = usernames[0].to_string();
|
let player1_username = usernames[0].to_string();
|
||||||
let player2_username = usernames[1].to_string();
|
let player2_username = usernames[1].to_string();
|
||||||
|
|
||||||
if let Err(e) = sd.handle_reservation_delete(tx.clone(), addr, player1_username, player2_username).await {
|
if let Err(e) = sd
|
||||||
|
.handle_reservation_delete(tx.clone(), addr, player1_username, player2_username)
|
||||||
|
.await
|
||||||
|
{
|
||||||
error!("handle_reservation_delete: {}", e);
|
error!("handle_reservation_delete: {}", e);
|
||||||
let _ = send(&tx, e.to_string().as_str());
|
let _ = send(&tx, e.to_string().as_str());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -303,7 +303,8 @@ impl Server {
|
|||||||
opponent.current_match = Some(match_id);
|
opponent.current_match = Some(match_id);
|
||||||
opponent.color = !client.color;
|
opponent.color = !client.color;
|
||||||
|
|
||||||
self.reservations
|
self
|
||||||
|
.reservations
|
||||||
.write()
|
.write()
|
||||||
.await
|
.await
|
||||||
.retain(|(p1, p2)| !(p1 == &client.username && p2 == &opponent.username));
|
.retain(|(p1, p2)| !(p1 == &client.username && p2 == &opponent.username));
|
||||||
@@ -670,12 +671,9 @@ impl Server {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn handle_game_list(
|
pub async fn handle_game_list(&self, tx: UnboundedSender<Message>) -> Result<(), anyhow::Error> {
|
||||||
&self,
|
|
||||||
tx: UnboundedSender<Message>,
|
|
||||||
) -> Result<(), anyhow::Error> {
|
|
||||||
let matches_guard = self.matches.read().await;
|
|
||||||
let clients_guard = self.clients.read().await;
|
let clients_guard = self.clients.read().await;
|
||||||
|
let matches_guard = self.matches.read().await;
|
||||||
let mut to_send = "GAME:LIST:".to_string();
|
let mut to_send = "GAME:LIST:".to_string();
|
||||||
for match_guard in matches_guard.values() {
|
for match_guard in matches_guard.values() {
|
||||||
let a_match = match_guard.read().await;
|
let a_match = match_guard.read().await;
|
||||||
@@ -979,8 +977,7 @@ impl Server {
|
|||||||
// Clear any pending reservations when a tournament starts
|
// Clear any pending reservations when a tournament starts
|
||||||
self.reservations.write().await.clear();
|
self.reservations.write().await.clear();
|
||||||
|
|
||||||
self.broadcast_message_all_observers(&format!("TOURNAMENT:START:{}", tournament_type))
|
self.broadcast_message_all_observers(&format!("TOURNAMENT:START:{}", tournament_type)).await;
|
||||||
.await;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1128,7 +1125,8 @@ impl Server {
|
|||||||
player2.current_match = Some(match_id);
|
player2.current_match = Some(match_id);
|
||||||
player2.color = !player1.color;
|
player2.color = !player1.color;
|
||||||
|
|
||||||
self.reservations
|
self
|
||||||
|
.reservations
|
||||||
.write()
|
.write()
|
||||||
.await
|
.await
|
||||||
.retain(|(p1, p2)| !(p1 == &player1_username && p2 == &player2_username));
|
.retain(|(p1, p2)| !(p1 == &player1_username && p2 == &player2_username));
|
||||||
@@ -1149,7 +1147,8 @@ impl Server {
|
|||||||
return Err(anyhow::anyhow!("ERROR:INVALID:AUTH"));
|
return Err(anyhow::anyhow!("ERROR:INVALID:AUTH"));
|
||||||
}
|
}
|
||||||
|
|
||||||
self.reservations
|
self
|
||||||
|
.reservations
|
||||||
.write()
|
.write()
|
||||||
.await
|
.await
|
||||||
.retain(|(p1, p2)| !(p1 == &player1_username && p2 == &player2_username));
|
.retain(|(p1, p2)| !(p1 == &player1_username && p2 == &player2_username));
|
||||||
|
|||||||
@@ -124,10 +124,7 @@ impl Match {
|
|||||||
vertical_end = false;
|
vertical_end = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if x + i >= 7
|
if x + i >= 7 || y + i >= 6 || self.board[x + i][y + i] != color && diagonal_end_up {
|
||||||
|| y + i >= 6
|
|
||||||
|| self.board[x + i][y + i] != color && diagonal_end_up
|
|
||||||
{
|
|
||||||
diagonal_end_up = false;
|
diagonal_end_up = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user