Reorganize routes

This commit is contained in:
Pierre HUBERT 2022-09-12 16:07:46 +02:00
parent 4fb952a59f
commit c0b6067d34
3 changed files with 8 additions and 13 deletions

View File

@ -1,7 +1,7 @@
use crate::data::GameRules;
use actix::Addr; use actix::Addr;
use uuid::Uuid; use uuid::Uuid;
use crate::data::GameRules;
use crate::game::{Game, Player}; use crate::game::{Game, Player};
use crate::human_player_ws::{ClientMessage, HumanPlayerWS, ServerMessage}; use crate::human_player_ws::{ClientMessage, HumanPlayerWS, ServerMessage};
@ -22,8 +22,9 @@ impl Player for HumanPlayer {
} }
fn query_boats_layout(&self, rules: &GameRules) { fn query_boats_layout(&self, rules: &GameRules) {
self.player self.player.do_send(ServerMessage::QueryBoatsLayout {
.do_send(ServerMessage::QueryBoatsLayout(rules.clone())); rules: rules.clone(),
});
} }
} }

View File

@ -31,7 +31,7 @@ pub enum ClientMessage {
#[serde(tag = "type")] #[serde(tag = "type")]
pub enum ServerMessage { pub enum ServerMessage {
WaitingForOtherPlayer, WaitingForOtherPlayer,
QueryBoatsLayout(GameRules), QueryBoatsLayout { rules: GameRules },
} }
#[derive(Default)] #[derive(Default)]

View File

@ -31,7 +31,7 @@ async fn not_found() -> impl Responder {
} }
/// Get bot configuration /// Get bot configuration
async fn bot_configuration() -> impl Responder { async fn game_configuration() -> impl Responder {
HttpResponse::Ok().json(PlayConfiguration::default()) HttpResponse::Ok().json(PlayConfiguration::default())
} }
@ -54,11 +54,6 @@ async fn start_bot_play(
resp resp
} }
/// Random play configuration
async fn random_play_config() -> impl Responder {
HttpResponse::Ok().json(GameRules::random_players_rules())
}
#[actix_web::main] #[actix_web::main]
async fn main() -> std::io::Result<()> { async fn main() -> std::io::Result<()> {
env_logger::Builder::from_env(Env::default().default_filter_or("info")).init(); env_logger::Builder::from_env(Env::default().default_filter_or("info")).init();
@ -76,9 +71,8 @@ async fn main() -> std::io::Result<()> {
App::new() App::new()
.wrap(cors) .wrap(cors)
.route("/bot/config", web::get().to(bot_configuration)) .route("/config", web::get().to(game_configuration))
.route("/bot/play", web::get().to(start_bot_play)) .route("/play/bot", web::get().to(start_bot_play))
.route("/random/config", web::get().to(random_play_config))
.route("/", web::get().to(index)) .route("/", web::get().to(index))
.route("{tail:.*}", web::get().to(not_found)) .route("{tail:.*}", web::get().to(not_found))
}) })