DEVELOPMENT ENVIRONMENT

~liljamo/deck-builder

03fb82e2b1d3a8b4dd29ebb891c9e7b53f01bf1d — Jonni Liljamo 1 year, 9 months ago 0cedb50
feat(server): handle connect, disconnect and error events
2 files changed, 28 insertions(+), 2 deletions(-)

M server/src/main.rs
M server/src/systems/event/mod.rs
M server/src/main.rs => server/src/main.rs +4 -1
@@ 42,7 42,10 @@ fn main() {
        // init system
        .add_startup_system(systems::init::init)
        // events
        .add_system(systems::event::auth_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);

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

M server/src/systems/event/mod.rs => server/src/systems/event/mod.rs +24 -1
@@ 7,11 7,15 @@
 */

use bevy_ecs::{event::EventReader, system::Res};
use bevy_log::info;
use laurelin_shared::{
    api::user::{login, register, ResponseLogin, ResponseRegister},
    server::messages::Auth,
};
use naia_bevy_server::{events::AuthEvents, Server};
use naia_bevy_server::{
    events::{AuthEvents, ConnectEvent, DisconnectEvent, ErrorEvent},
    Server,
};

use crate::Config;



@@ 44,3 48,22 @@ pub(crate) fn auth_events(
        }
    }
}

pub(crate) fn connect_events(mut ev: EventReader<ConnectEvent>, mut server: Server) {
    for ConnectEvent(user_key) in ev.iter() {
        let address = server.user(user_key).address();
        info!("Naia Server connected to: {:?}", address);
    }
}

pub(crate) fn disconnect_events(mut ev: EventReader<DisconnectEvent>) {
    for DisconnectEvent(_user_key, user) in ev.iter() {
        info!("Naia Server disconnected from: {:?}", user.address);
    }
}

pub(crate) fn error_events(mut ev: EventReader<ErrorEvent>) {
    for ErrorEvent(error) in ev.iter() {
        info!("Naia Server Error: {:?}", error);
    }
}