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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
/// Get in notifyservergrouplist

#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct ServerGroup {
	pub id: ServerGroupId,
	pub name: String,
	pub group_type: GroupType,
	pub icon: IconId,
	/// If the group is saved to the server database

	pub is_permanent: bool,
	pub sort_id: i32,
	pub naming_mode: GroupNamingMode,
	pub needed_modify_power: i32,
	pub needed_member_add_power: i32,
	pub needed_member_remove_power: Option<i32>,
}

/// Get in notifychannelgrouplist

#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct ChannelGroup {
	pub id: ChannelGroupId,
	pub name: String,
	pub group_type: GroupType,
	pub icon: IconId,
	/// If the group is saved to the server database

	pub is_permanent: bool,
	pub sort_id: i32,
	pub naming_mode: GroupNamingMode,
	pub needed_modify_power: i32,
	pub needed_member_add_power: i32,
	pub needed_member_remove_power: Option<i32>,
}

/// Get in notifychanneledited by channelgetdescription

#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct OptionalChannelData {
	pub channel_id: ChannelId,
	pub description: String,
}

/// Get in channellist

#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct Channel {
	pub id: ChannelId,
	pub guid: Option<String>,
	/// 0 means root channel

	pub parent: ChannelId,
	pub name: String,
	pub topic: Option<String>,
	pub codec: Codec,
	pub codec_quality: Option<u8>,
	/// The maximum number of clients in the channel.

	pub max_clients: Option<MaxClients>,
	/// Maximum number of clients in this and all child channels.

	pub max_family_clients: Option<MaxClients>,
	/// The preceding channel id.

	pub order: ChannelId,
	pub channel_type: ChannelType,
	/// Whether it is the default channel

	pub is_default: Option<bool>,
	/// Whether this channel has a password

	pub has_password: Option<bool>,
	/// TODO Type?

	pub codec_latency_factor: Option<i32>,
	pub is_unencrypted: Option<bool>,
	pub delete_delay: Option<Duration>,
	pub needed_talk_power: Option<i32>,
	pub forced_silence: bool,
	pub phonetic_name: Option<String>,
	pub icon: Option<IconId>,
	pub is_private: Option<bool>,
	pub subscribed: bool,
	pub permission_hints: Option<ChannelPermissionHint>,
	pub optional_data: Option<OptionalChannelData>,
}

/// Get in notifyclientupdated by clientgetvariables

#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct OptionalClientData {
	pub client_id: ClientId,
	pub version: String,
	pub version_sign: Option<String>,
	pub platform: String,
	/// Set only for server queries

	pub login_name: Option<String>,
	pub created: OffsetDateTime,
	pub last_connected: OffsetDateTime,
	pub connections_total: u32,
	pub bytes_uploaded_month: u64,
	pub bytes_downloaded_month: u64,
	pub bytes_uploaded_total: u64,
	pub bytes_downloaded_total: u64,
}

/// Get in notifyconnectioninfo by getconnectioninfo

#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct ConnectionClientData {
	pub client_id: ClientId,
	pub ping: Option<Duration>,
	pub ping_deviation: Option<Duration>,
	pub connected_time: Option<Duration>,
	/// Only available if we have the permission to view it

	pub client_address: Option<SocketAddr>,
	pub packets_sent_speech: Option<u64>,
	pub packets_sent_keepalive: Option<u64>,
	pub packets_sent_control: Option<u64>,
	pub bytes_sent_speech: Option<u64>,
	pub bytes_sent_keepalive: Option<u64>,
	pub bytes_sent_control: Option<u64>,
	pub packets_received_speech: Option<u64>,
	pub packets_received_keepalive: Option<u64>,
	pub packets_received_control: Option<u64>,
	pub bytes_received_speech: Option<u64>,
	pub bytes_received_keepalive: Option<u64>,
	pub bytes_received_control: Option<u64>,
	pub server_to_client_packetloss_speech: Option<f32>,
	pub server_to_client_packetloss_keepalive: Option<f32>,
	pub server_to_client_packetloss_control: Option<f32>,
	pub server_to_client_packetloss_total: Option<f32>,
	pub client_to_server_packetloss_speech: f32,
	pub client_to_server_packetloss_keepalive: f32,
	pub client_to_server_packetloss_control: f32,
	pub client_to_server_packetloss_total: f32,
	pub bandwidth_sent_last_second_speech: Option<u64>,
	pub bandwidth_sent_last_second_keepalive: Option<u64>,
	pub bandwidth_sent_last_second_control: Option<u64>,
	pub bandwidth_sent_last_minute_speech: Option<u64>,
	pub bandwidth_sent_last_minute_keepalive: Option<u64>,
	pub bandwidth_sent_last_minute_control: Option<u64>,
	pub bandwidth_received_last_second_speech: Option<u64>,
	pub bandwidth_received_last_second_keepalive: Option<u64>,
	pub bandwidth_received_last_second_control: Option<u64>,
	pub bandwidth_received_last_minute_speech: Option<u64>,
	pub bandwidth_received_last_minute_keepalive: Option<u64>,
	pub bandwidth_received_last_minute_control: Option<u64>,
	pub filetransfer_bandwidth_sent: Option<u64>,
	pub filetransfer_bandwidth_received: Option<u64>,
	pub idle_time: Duration,
}

/// Get in notifycliententerview

#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct Client {
	pub id: ClientId,
	pub channel: ChannelId,
	/// Unique Identifier

	pub uid: Option<UidBuf>,
	pub name: String,
	/// `true` if muted, `false` otherwise

	pub input_muted: bool,
	/// `true` if muted, `false` otherwise

	pub output_muted: bool,
	/// `true` if muted, `false` otherwise

	pub output_only_muted: bool,
	/// `true` if enabled, `false` if disabled

	pub input_hardware_enabled: bool,
	/// `true` if enabled, `false` if disabled

	pub output_hardware_enabled: bool,
	/// If the client is granted talk power

	pub talk_power_granted: bool,
	/// Set by client

	pub metadata: String,
	/// Whether the client is recording

	pub is_recording: bool,
	pub database_id: ClientDbId,
	pub channel_group: ChannelGroupId,
	pub server_groups: HashSet<ServerGroupId>,
	/// Contains the away message if the client is away

	pub away_message: Option<String>,
	/// If this client is a server query or not

	pub client_type: ClientType,
	/// MD5 hash of the avatar, used to retrieve the avatar

	pub avatar_hash: String,
	pub talk_power: i32,
	/// Contains a message and timestamp from the client if he requests talk power

	pub talk_power_request: Option<TalkPowerRequest>,
	pub description: String,
	pub is_priority_speaker: bool,
	pub unread_messages: u32,
	pub phonetic_name: String,
	pub needed_serverquery_view_power: i32,
	pub icon: IconId,
	pub is_channel_commander: bool,
	/// Like US, DE

	pub country_code: String,
	pub inherited_channel_group_from_channel: ChannelId,
	pub badges: String,
	pub permission_hints: Option<ClientPermissionHint>,
	pub optional_data: Option<OptionalClientData>,
	pub connection_data: Option<ConnectionClientData>,
}

/// Get by notifyserverupdated after requested by servergetvariables

#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct OptionalServerData {
	pub uptime: Duration,
	pub has_password: bool,
	/// The channel group which will be given to channel creators

	pub default_channel_admin_group: ChannelGroupId,
	pub max_download_bandwidth_total: u64,
	pub max_upload_bandwidth_total: u64,
	pub complain_autoban_count: u32,
	pub complain_autoban_time: Duration,
	pub complain_remove_time: Duration,
	/// How many clients can be in a server before silence is forced

	pub min_clients_in_channel_before_forced_silence: u16,
	pub antiflood_points_tick_reduce: u32,
	pub antiflood_points_to_command_block: u32,
	pub antiflood_points_to_ip_block: u32,
	pub antiflood_points_to_plugin_block: u32,
	/// The amount of connections on this server.
	/// 
	/// This includes normal clients and server queries.

	pub connection_count_total: u64,
	/// The amount of channels on the server

	pub channel_count: u64,
	/// The amount of clients which are online on the server

	pub client_count: u16,
	/// Amount of server queries connected to the server

	pub query_count_total: u64,
	/// Amount of server queries connected and online/visible on the server

	pub query_count: u32,
	pub download_quota: u64,
	pub upload_quota: u64,
	pub bytes_downloaded_month: u64,
	pub bytes_uploaded_month: u64,
	pub bytes_downloaded_total: u64,
	pub bytes_uploaded_total: u64,
	pub port: u16,
	pub autostart: bool,
	pub machine_id: String,
	pub needed_identity_security_level: u8,
	pub log_client: bool,
	pub log_query: bool,
	pub log_channel: bool,
	pub log_permissions: bool,
	pub log_server: bool,
	pub log_filetransfer: bool,
	pub min_client_version: OffsetDateTime,
	pub reserved_slots: u16,
	pub total_packetloss_speech: f32,
	pub total_packetloss_keepalive: f32,
	pub total_packetloss_control: f32,
	pub total_packetloss: f32,
	pub total_ping: Duration,
	pub weblist_enabled: bool,
	/// TODO Maybe str

	pub min_android_version: OffsetDateTime,
	pub min_ios_version: OffsetDateTime,
}

/// Get by notifyserverconnectioninfo after serverrequestconnectioninfo

#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct ConnectionServerData {
	pub filetransfer_bandwidth_sent: u64,
	pub filetransfer_bandwidth_received: u64,
	pub filetransfer_bytes_sent_total: u64,
	pub filetransfer_bytes_received_total: u64,
	pub packets_sent_total: u64,
	pub bytes_sent_total: u64,
	pub packets_received_total: u64,
	pub bytes_received_total: u64,
	pub bandwidth_sent_last_second_total: u64,
	pub bandwidth_sent_last_minute_total: u64,
	pub bandwidth_received_last_second_total: u64,
	pub bandwidth_received_last_minute_total: u64,
	pub connected_time: Duration,
	pub packetloss_total: f32,
	pub ping: Duration,
}

/// Get in initserver

#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct Server {
	pub public_key: EccKeyPubP256,
	/// The virtual server id

	pub id: u64,
	pub name: String,
	pub nickname: Option<String>,
	/// Welcome message when conecting to a server

	pub welcome_message: String,
	pub platform: String,
	pub version: String,
	/// The maximum number of clients on the server

	pub max_clients: u16,
	/// Seems to be always 0

	pub created: OffsetDateTime,
	pub codec_encryption_mode: CodecEncryptionMode,
	pub hostmessage: String,
	pub hostmessage_mode: HostMessageMode,
	pub default_server_group: ServerGroupId,
	pub default_channel_group: ChannelGroupId,
	pub hostbanner_url: String,
	pub hostbanner_gfx_url: String,
	/// How often the hostbanner should be updated

	pub hostbanner_gfx_interval: Duration,
	pub priority_speaker_dimm_modificator: f32,
	pub hostbutton_tooltip: String,
	pub hostbutton_url: String,
	pub hostbutton_gfx_url: String,
	pub phonetic_name: String,
	/// Should be an u32, sometimes the server sends an u64 or an i32 for reasons which has to be cut to 32 bit

	pub icon: IconId,
	/// A list of listen ips, can be empty

	pub ips: Vec<IpAddr>,
	pub ask_for_privilegekey: bool,
	pub hostbanner_mode: HostBannerMode,
	pub temp_channel_default_delete_delay: Duration,
	pub protocol_version: u16,
	pub license: LicenseType,
	pub optional_data: Option<OptionalServerData>,
	pub connection_data: Option<ConnectionServerData>,
}

/// A connection from our client to a server

#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct Connection {
	/// The id of our own client on the server

	pub own_client: ClientId,
	/// The server of this connection

	pub server: Server,
	/// All clients which are visible for us

	pub clients: HashMap<ClientId, Client>,
	/// All channels on the server

	pub channels: HashMap<ChannelId, Channel>,
	/// All server groups on the server

	pub server_groups: HashMap<ServerGroupId, ServerGroup>,
	/// All channel groups on the server

	pub channel_groups: HashMap<ChannelGroupId, ChannelGroup>,
}