/*
* This file is part of laurelin/server
* Copyright (C) 2023 Jonni Liljamo <jonni@liljamo.com>
*
* Licensed under GPL-3.0-only.
* See LICENSE for licensing information.
*/
use std::collections::HashMap;
use bevy_app::{App, ScheduleRunnerPlugin};
use bevy_ecs::system::Resource;
use bevy_log::{info, LogPlugin};
use bevy_quinnet::{server::QuinnetServerPlugin, shared::ClientId};
mod systems;
#[derive(Resource)]
pub struct Config {
pub api_address: String,
}
/*
/// Temporary runtime data
#[derive(Resource)]
pub struct RuntimeTemp {
pub afterauth_details: HashMap<UserKey, (UserPub, String)>,
}
*/
#[derive(Resource)]
pub struct Global {
pub client_to_user_map: HashMap<ClientId, String>,
}
fn main() {
let mut server = App::new();
let api_address = std::env::var("LAURELIN_API_URL").expect("LAURELIN_API_URL");
server
// plugins
.add_plugin(ScheduleRunnerPlugin::default())
.add_plugin(LogPlugin {
// NOTE: overridden by RUST_LOG environment variable
level: bevy_log::Level::INFO,
..Default::default()
})
.add_plugin(QuinnetServerPlugin::default())
// config
.insert_resource(Config { api_address })
/*
// temp runtime data
.insert_resource(RuntimeTemp {
afterauth_details: HashMap::new(),
})
*/
// global data
.insert_resource(Global {
client_to_user_map: HashMap::new(),
})
// init system
.add_startup_system(systems::init::init)
// events
.add_systems((
systems::event::handle_client_messages,
systems::event::handle_server_events,
));
info!("Laurelin server starting");
server.run();
}