aboutsummaryrefslogtreecommitdiff
path: root/src/message/signalproxy/objects/coreinfo.rs
blob: ac493f1e8c8644bb45d1bc507186a4a758b4b4b7 (plain)
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
use libquassel_derive::{NetworkList, NetworkMap};

use crate::message::signalproxy::translation::NetworkMap;
use crate::message::Syncable;
use crate::primitive::{DateTime, StringList};

#[derive(Debug, Clone, PartialEq, NetworkList, NetworkMap)]
#[network(repr = "map")]
pub struct CoreInfo {
    #[network(rename = "coreData", variant = "VariantMap", network)]
    core_data: CoreData,
}

impl CoreInfo {
    pub fn set_core_data(&mut self, data: CoreData) {
        #[cfg(feature = "server")]
        libquassel_derive::sync!("setCoreData", [data.to_network_map()]);

        self.core_data = data;
    }
}

#[cfg(feature = "client")]
impl crate::message::StatefulSyncableClient for CoreInfo {
    fn sync_custom(&mut self, mut msg: crate::message::SyncMessage)
    where
        Self: Sized,
    {
        match msg.slot_name.as_str() {
            "setCoreData" => self.set_core_data(CoreData::from_network_map(&mut get_param!(msg))),
            _ => (),
        }
    }

    /// Not Implemented
    fn request_update(&mut self)
    where
        Self: Sized,
    {
    }
}

#[cfg(feature = "server")]
impl crate::message::StatefulSyncableServer for CoreInfo {
    /// Not Implemented
    fn request_update(&mut self, mut _param: <CoreInfo as NetworkMap>::Item)
    where
        Self: Sized,
    {
    }
}

impl Syncable for CoreInfo {
    const CLASS: &'static str = "CoreInfo";
}

#[derive(Debug, Clone, PartialEq, NetworkMap)]
#[network(repr = "map")]
pub struct CoreData {
    #[network(rename = "quasselVersion")]
    quassel_version: String,
    #[network(rename = "quasselBuildDate")]
    quassel_build_date: String,
    #[network(rename = "startTime")]
    start_time: DateTime,
    #[network(rename = "sessionConnectedClients")]
    session_connected_clients: i32,
    #[network(
        rename = "sessionConnectedClientData",
        variant = "VariantList",
        network,
        map
    )]
    session_connected_client_data: Vec<ConnectedClient>,
}

#[derive(Debug, Clone, PartialEq, NetworkMap)]
#[network(repr = "map")]
pub struct ConnectedClient {
    #[network(rename = "id")]
    id: i32,
    #[network(rename = "remoteAddress")]
    remote_address: String,
    #[network(rename = "location")]
    location: String,
    #[network(rename = "clientVersion")]
    client_version: String,
    #[network(rename = "clientVersionDate")]
    client_version_date: String,
    #[network(rename = "connectedSince")]
    connected_since: DateTime,
    #[network(rename = "secure")]
    secure: bool,
    #[network(rename = "features")]
    features: i32,
    #[network(rename = "featureList")]
    feature_list: StringList,
}