aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
blob: 368f4395723f03be1dc7e2cafec7d8ed3c70be6c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#![feature(iterator_try_collect)]
use config::Config;
use game::{server::game_server, Game};
use spectate::server::spectate_server;
use std::sync::Arc;
use tokio::{
    spawn,
    sync::{broadcast, RwLock},
};

pub mod config;
pub mod game;
pub mod spectate;

pub struct State {
    tick: broadcast::Sender<bool>, // true for new game
    game: RwLock<Game>,
}

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    env_logger::init_from_env("LOG");
    let config = Config::load()?;
    let state = Arc::new(State {
        tick: broadcast::channel(16).0,
        game: Game::new(vec![]).into(),
    });
    spawn(spectate_server(config.spectate, state.clone()));
    game_server(config.game, state.clone()).await?;
    Ok(())
}