Enhance README with CLI room checking instructions and implement room name resolution in command handling. Updated handle_init_command and handle_join_command to use resolved room names, improving room access validation. Added CLI command handling in main.rs to list available rooms from the database or fallback configuration.

This commit is contained in:
Torsten Schulz (local)
2026-03-04 17:55:53 +01:00
parent aca290f1d0
commit 9478e6a91a
4 changed files with 105 additions and 23 deletions

View File

@@ -38,6 +38,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
allowed_users: db::parse_allowed_users(),
db_client,
});
if handle_cli_commands().as_deref() == Some("--list-rooms") {
print_rooms_for_cli(&config).await?;
return Ok(());
}
let rooms = db::load_room_configs(&config).await.unwrap_or_else(|_| {
vec![types::RoomMeta {
name: "lobby".to_string(),
@@ -212,6 +216,47 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
Ok(())
}
fn handle_cli_commands() -> Option<String> {
env::args().nth(1)
}
async fn print_rooms_for_cli(
config: &ServerConfig,
) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
let rooms = db::load_room_configs(config)
.await
.map_err(std::io::Error::other)?;
println!(
"yourchat2 rooms source: {}",
if config.db_client.is_some() { "database" } else { "fallback" }
);
println!(
"{:<30} {:<8} {:<8} {:<8} {:<10}",
"name", "public", "min_age", "max_age", "password"
);
println!("{}", "-".repeat(72));
for room in rooms {
println!(
"{:<30} {:<8} {:<8} {:<8} {:<10}",
room.name,
if room.is_public { "yes" } else { "no" },
room.min_age
.map(|v| v.to_string())
.unwrap_or_else(|| "-".to_string()),
room.max_age
.map(|v| v.to_string())
.unwrap_or_else(|| "-".to_string()),
if room.password.as_deref().unwrap_or("").is_empty() {
"none"
} else {
"set"
},
);
}
Ok(())
}
async fn handle_client<S>(
stream: S,
state: Arc<RwLock<ChatState>>,