/* * This file is part of laurelin/server * Copyright (C) 2023 Jonni Liljamo * * Licensed under GPL-3.0-only. * See LICENSE for licensing information. */ use std::{collections::HashMap, time::Duration}; use bevy_app::{App, ScheduleRunnerPlugin, ScheduleRunnerSettings}; use bevy_core::{FrameCountPlugin, TaskPoolPlugin, TypeRegistrationPlugin}; use bevy_ecs::{schedule::IntoSystemConfigs, system::Resource}; use bevy_log::{info, LogPlugin}; use naia_bevy_server::{Plugin as ServerPlugin, ReceiveEvents, ServerConfig, UserKey}; use laurelin_shared::server::protocol::protocol; mod systems; #[derive(Resource)] pub struct Config { pub api_address: String, } /// Temporary runtime data #[derive(Resource)] pub struct RuntimeTemp { pub afterauth_details: HashMap, } #[derive(Resource)] pub struct Global {} fn main() { let mut server = App::new(); let api_address = std::env::var("LAURELIN_API_URL").expect("LAURELIN_API_URL"); server // plugins .add_plugin(TaskPoolPlugin::default()) .add_plugin(TypeRegistrationPlugin::default()) .add_plugin(FrameCountPlugin::default()) .insert_resource(ScheduleRunnerSettings::run_loop(Duration::from_millis(3))) .add_plugin(ScheduleRunnerPlugin::default()) .add_plugin(LogPlugin { // NOTE: overridden by RUST_LOG environment variable level: bevy_log::Level::INFO, ..Default::default() }) .add_plugin(ServerPlugin::new(ServerConfig::default(), protocol())) // config .insert_resource(Config { api_address }) // temp runtime data .insert_resource(RuntimeTemp { afterauth_details: HashMap::new(), }) // init system .add_startup_system(systems::init::init) // events .add_systems( ( systems::event::auth_events, systems::event::connect_events, systems::event::disconnect_events, systems::event::error_events, systems::event::tick_events, ) .chain() .in_set(ReceiveEvents), ); info!("Laurelin server starting"); server.run(); }