DEVELOPMENT ENVIRONMENT

~liljamo/deck-builder

ref: 9e99a5db0520e795605360c3640661900b9cf2e9 deck-builder/client/src/plugins/networking/systems/events.rs -rw-r--r-- 1.2 KiB
9e99a5dbJonni Liljamo feat(shared): derive deserialize for APIError 1 year, 9 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
/*
 * 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.");
    }
}