misc: formatting and compile fix

This commit is contained in:
2026-03-22 14:51:00 -04:00
Unverified
parent 677c70a763
commit c5738741f1
7 changed files with 1890 additions and 1903 deletions

View File

@@ -2,15 +2,15 @@ use std::{collections::HashMap, net::SocketAddr, sync::Arc};
use rand::RngExt;
use tokio::sync::{
mpsc::{error::SendError, UnboundedSender},
RwLock,
mpsc::{error::SendError, UnboundedSender},
RwLock,
};
use tokio_tungstenite::tungstenite::Message;
use tracing::error;
use crate::{
tournaments::Tournament,
types::{Client, Color, Match},
tournaments::Tournament,
types::{Client, Color, Match},
};
pub mod server;
@@ -28,34 +28,34 @@ pub const SERVER_PLAYER_USERNAME: &str = "The Server";
pub const SERVER_PLAYER_ADDR: &str = "127.0.0.1:6666";
pub async fn broadcast_message(observers: &Observers, addrs: &Vec<SocketAddr>, msg: &str) {
for addr in addrs {
let observers_guard = observers.read().await;
let tx = observers_guard.get(addr);
if tx.is_none() {
continue;
}
let _ = send(tx.unwrap(), msg);
for addr in addrs {
let observers_guard = observers.read().await;
let tx = observers_guard.get(addr);
if tx.is_none() {
continue;
}
let _ = send(tx.unwrap(), msg);
}
}
pub async fn gen_match_id(matches: &Matches) -> u32 {
let matches_guard = matches.read().await;
let mut result = rand::rng().random_range(100000..=999999);
while matches_guard.get(&result).is_some() {
result = rand::rng().random_range(100000..=999999);
}
result
let matches_guard = matches.read().await;
let mut result = rand::rng().random_range(100000..=999999);
while matches_guard.get(&result).is_some() {
result = rand::rng().random_range(100000..=999999);
}
result
}
pub fn random_move(board: &[Vec<Color>]) -> usize {
let mut random = rand::rng().random_range(0..7);
while board[random][5] != Color::None {
random = rand::rng().random_range(0..7);
}
let mut random = rand::rng().random_range(0..7);
while board[random][5] != Color::None {
random = rand::rng().random_range(0..7);
}
random
random
}
pub fn send(tx: &UnboundedSender<Message>, text: &str) -> Result<(), SendError<Message>> {
tx.send(Message::text(text))
tx.send(Message::text(text))
}