misc(refactor): extract command handlers and centralize error handling

- Move command-specific logic out of main.rs into Server::handle_* methods
  (parsing remains in main and handlers accept already-parsed input).
- Handlers now return Result and return Err("ERROR:...") instead of sending
  error messages directly to clients.
- main.rs now logs handler errors to console and sends the error string to
  the client (removed `continue` statements after error sends).
- Move end_game_check from main.rs into lib.rs for reuse.
- Update handler implementations to follow the new error-returning pattern.
This commit is contained in:
2025-12-30 22:26:26 -05:00
Unverified
parent b5d71051a6
commit b416dc17ad
5 changed files with 1143 additions and 878 deletions

View File

@@ -2,16 +2,18 @@ use std::net::SocketAddr;
use async_trait::async_trait;
use crate::{*};
use crate::*;
pub mod round_robin;
pub use round_robin::RoundRobin;
#[async_trait]
pub trait Tournament {
fn new(ready_players: &[SocketAddr]) -> Self where Self: Sized;
async fn next(&mut self, clients: &Clients, matches: &Matches, observers: &Observers);
async fn start(&mut self, clients: &Clients, matches: &Matches);
async fn cancel(&mut self, clients: &Clients, matches: &Matches, observers: &Observers);
fn is_completed(&self) -> bool;
}
fn new(ready_players: &[SocketAddr]) -> Self
where
Self: Sized;
async fn next(&mut self, clients: &Clients, matches: &Matches, observers: &Observers);
async fn start(&mut self, clients: &Clients, matches: &Matches);
async fn cancel(&mut self, clients: &Clients, matches: &Matches, observers: &Observers);
fn is_completed(&self) -> bool;
}