DEVELOPMENT ENVIRONMENT

~liljamo/deck-builder

ref: 5b6558cd0dc6791d7504f28428324a5022a78178 deck-builder/server/src/main.rs -rw-r--r-- 1.8 KiB
5b6558cdJonni Liljamo feat(client, server): finally handle AfterAuth properly 1 year, 7 months ago
                                                                                
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
 * 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_core::CorePlugin;
use bevy_ecs::system::Resource;
use bevy_log::{info, LogPlugin};

use naia_bevy_server::{Plugin as ServerPlugin, 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<UserKey, (String, String)>,
}

#[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(CorePlugin::default())
        .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_system(systems::event::auth_events)
        .add_system(systems::event::connect_events)
        .add_system(systems::event::disconnect_events)
        .add_system(systems::event::error_events)
        .add_system(systems::event::tick_events);

    info!("Laurelin server starting");
    server.run();
}