/*
* This file is part of laurelin/client
* Copyright (C) 2023 Jonni Liljamo <jonni@liljamo.com>
*
* Licensed under GPL-3.0-only.
* See LICENSE for licensing information.
*/
use bevy::prelude::*;
use naia_bevy_client::{
events::{ConnectEvent, DisconnectEvent, RejectEvent},
Client,
};
use crate::plugins::menu::ui::connect::{ConnectScreenData, ConnectState};
pub fn connect_events(mut ev: EventReader<ConnectEvent>, client: Client) {
for _ in ev.iter() {
info!("?");
if let Ok(server_address) = client.server_address() {
info!("Laurelin client connected to: '{}'", server_address);
}
}
}
pub fn reject_events(mut ev: EventReader<RejectEvent>, mut data: ResMut<ConnectScreenData>) {
for _ in ev.iter() {
warn!("Laurelin client rejected from connecting to server!");
data.error = "rejected from connecting".to_string();
data.state = if data.state == ConnectState::LoggingIn {
ConnectState::Login
} else {
ConnectState::Register
}
}
}
pub fn disconnect_events(mut ev: EventReader<DisconnectEvent>) {
for _ in ev.iter() {
info!("Laurelin client disconnected from server.");
}
}