aboutsummaryrefslogtreecommitdiff
path: root/core/src/data/message/message_enums.rs
blob: fd369a9c9e372aa4fd3cb77d282df1a345eabfb6 (plain) (blame)
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
use bincode::{Decode, Encode};
use crate::data::game::types::GameInfo;
use crate::data::player::player_data::Player;

/// Control messages.
/// Messages sent from controller to game pad_client after establishing persistent connection
#[derive(Default, Encode, Decode, PartialEq, Debug, Clone)]
pub enum ControlMessage {
    /// Plain message containing a string
    /// The message will be handed over to the game for its own processing
    Msg(String),

    /// Press event
    /// Indicates that a button has been pressed
    Pressed(u8),

    /// Release event
    /// Indicates that a button has been released
    Released(u8),

    /// Axis input
    /// Indicates that the value of an axis has been changed
    Axis(u8, f64),

    /// Directional input
    /// Indicates that the value of a direction has been changed
    Dir(u8, (f64, f64)),

    /// Exit command
    /// Sends a disconnect request to the pad_server
    Exit,

    #[default]
    /// Error state
    Err,

    /// Indicates the termination message, which is the final message in a long-lived connection.
    End
}

/// Game messages.
/// Messages sent from game pad_client to controller after establishing persistent connection
#[derive(Default, Encode, Decode, PartialEq, Debug, Clone)]
pub enum GameMessage {
    /// Event trigger
    /// Sends an event to the controller; if skins are enabled, this will trigger corresponding animations, sounds, vibrations, etc.
    EventTrigger(u8),

    /// Plain message containing a string
    /// The message will be handed over to the controller for its own processing
    Msg(String),

    /// Disconnect request
    /// Notifies the pad_client that the connection will be terminated
    LetExit(ExitReason),

    /// Error state
    #[default]
    Err,

    /// Indicates the termination message, which is the final message in a long-lived connection.
    End
}

/// Exit reasons.
/// Reason provided when requesting disconnection
#[derive(Default, Encode, Decode, PartialEq, Debug, Clone)]
pub enum ExitReason {
    /// Normal exit
    /// No specific reason, simply requesting to disconnect
    Exit,

    /// Game has ended
    GameOver,

    /// Server shutdown (normal)
    ServerClosed,

    /// Kicked by pad_server
    YouAreKicked,

    /// Account banned
    YouAreBanned,

    /// Error state
    #[default]
    Err
}

/// Connection messages.
/// Messages sent by pad_client when requesting pad_server connection
#[derive(Default, Encode, Decode, PartialEq, Debug, Clone)]
pub enum ConnectionMessage {
    /// Requests to join the game
    Join(Player),

    /// Request for game information
    RequestGameInfos,

    /// Request for game layout configuration file
    RequestLayoutConfigure,

    /// Request to download game skin assets
    RequestSkinPackage,

    /// Ready state to establish persistent connection
    Ready,

    /// Error state
    #[default]
    Err
}

/// Connection Response.
/// Messages from pad_server responding to pad_client connection requests
#[derive(Default, Encode, Decode, PartialEq, Debug, Clone)]
pub enum ConnectionResponseMessage {
    /// Game information data
    GameInfos(GameInfo),

    /// Rejection with reason
    Deny(JoinFailedMessage),

    /// Failure with reason
    Fail(JoinFailedMessage),

    /// Approval confirmation
    Ok,

    /// Welcome acknowledgment
    Welcome,

    /// Error state
    #[default]
    Err
}

/// Game Join Failure Information.
/// Reason provided when pad_client fails to join
#[derive(Default, Encode, Decode, PartialEq, Debug, Clone)]
pub enum JoinFailedMessage {
    /// Game already contains identical player
    ContainIdenticalPlayer,

    /// Player is banned
    PlayerBanned,

    /// Game is locked, no further joins allowed
    GameLocked,

    /// Unknown error
    #[default]
    UnknownError
}