aboutsummaryrefslogtreecommitdiff
path: root/src/message/signalproxy/rpccall/client.rs
blob: 7e311351884e653969013fb0aa8f8b97c7b8f816 (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
use crate::primitive::Variant;

use super::{Direction, RpcCallType};

#[derive(Clone, Debug, PartialEq)]
pub struct KickClient {
    /// Client id of client to be kicked. Ids can be found in [CoreInfo]
    id: i32,
}

impl RpcCallType for KickClient {
    const NAME: &str = "2kickClient(int)";
    const DIRECTION: Direction = Direction::ClientToServer;

    fn to_network(&self) -> Result<Vec<crate::primitive::Variant>, crate::ProtocolError> {
        Ok(vec![
            Variant::ByteArray(Self::NAME.to_string()),
            self.id.into(),
        ])
    }

    fn from_network(
        size: usize,
        input: &mut crate::primitive::VariantList,
    ) -> Result<(usize, super::RpcCall), crate::ProtocolError>
    where
        Self: Sized,
    {
        Ok((
            size,
            Self {
                id: input.remove(0).try_into().unwrap(),
            }
            .into(),
        ))
    }
}

/// Requests the current client to disconnect from the core. Only this client sees this message.
#[derive(Clone, Debug, PartialEq)]
pub struct DisconnectFromCore;

impl RpcCallType for DisconnectFromCore {
    const NAME: &str = "2disconnectFromCore()";
    const DIRECTION: Direction = Direction::ServerToClient;

    fn to_network(&self) -> Result<Vec<crate::primitive::Variant>, crate::ProtocolError> {
        Ok(vec![Variant::ByteArray(Self::NAME.to_string())])
    }

    fn from_network(
        size: usize,
        _input: &mut crate::primitive::VariantList,
    ) -> Result<(usize, super::RpcCall), crate::ProtocolError>
    where
        Self: Sized,
    {
        Ok((size, Self {}.into()))
    }
}