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:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user