rust_openttd_admin/packet/admin/
client_packets.rs

1//! This module contains the definitions for the admin packets that can be
2//! sent to the server.
3
4use crate::packet::serde::WritablePacket;
5use crate::types;
6use serde_derive::{Deserialize, Serialize};
7
8/// Implemented by all admin client-sendable types.
9pub trait Packet: WritablePacket {
10    const PACKET_TYPE: u8;
11}
12impl<T: Packet> WritablePacket for T {
13    const PACKET_TYPE: u8 = <T as Packet>::PACKET_TYPE;
14}
15
16/// The admin announces and authenticates itself to the server.
17#[derive(Serialize, Deserialize, Copy, Clone, Debug, Eq, PartialEq)]
18pub struct Join<'a> {
19    /// Password the server is expecting for this network.
20    pub password: &'a str,
21    /// Name of the application being used to connect.
22    pub name: &'a str,
23    /// Version string of the application being used to connect.
24    pub version: &'a str,
25}
26impl<'a> Packet for Join<'a> {
27    const PACKET_TYPE: u8 = 0;
28}
29
30/// Notification to the server that this admin is quitting.
31#[derive(Serialize, Deserialize, Copy, Clone, Debug, Eq, PartialEq)]
32pub struct Quit;
33impl Packet for Quit {
34    const PACKET_TYPE: u8 = 1;
35}
36
37/// Register updates to be sent at certain frequencies (as announced in the PROTOCOL packet).
38#[derive(Serialize, Deserialize, Copy, Clone, Debug, Eq, PartialEq)]
39pub struct UpdateFrequency {
40    /// Update type (see [`AdminUpdateType`]).
41    pub update_type: types::AdminUpdateType,
42    /// Update frequency (see #AdminUpdateFrequency), setting #ADMIN_FREQUENCY_POLL is always ignored.
43    pub frequency: types::UpdateFrequencies,
44}
45impl Packet for UpdateFrequency {
46    const PACKET_TYPE: u8 = 2;
47}
48
49/// Poll the server for certain updates, an invalid poll (e.g. not existent id) gets silently dropped.
50#[derive(Serialize, Deserialize, Copy, Clone, Debug, Eq, PartialEq)]
51pub struct Poll {
52    /// [`AdminUpdateType`] the server should answer for, only if #AdminUpdateFrequency #ADMIN_FREQUENCY_POLL is advertised in the PROTOCOL packet.
53    pub update_type: types::AdminUpdateType,
54    /// ID relevant to the packet type, e.g.
55    /// - the client ID for #ADMIN_UPDATE_CLIENT_INFO. Use UINT32_MAX to show all clients.
56    /// - the company ID for #ADMIN_UPDATE_COMPANY_INFO. Use UINT32_MAX to show all companies.
57    pub id: u32,
58}
59impl Packet for Poll {
60    const PACKET_TYPE: u8 = 3;
61}
62
63/// Send chat as the server.
64#[derive(Serialize, Deserialize, Copy, Clone, Debug, Eq, PartialEq)]
65pub struct Chat<'a> {
66    /// Action such as NETWORK_ACTION_CHAT_CLIENT (see #NetworkAction).
67    pub action: u8,
68    /// Destination type such as DESTTYPE_BROADCAST (see #DestType).
69    pub destination_type: u8,
70    /// ID of the destination such as company or client id.
71    pub destination_id: u32,
72    /// Message.
73    pub message: &'a str,
74}
75impl Packet for Chat<'_> {
76    const PACKET_TYPE: u8 = 4;
77}
78
79/// Execute a command on the servers console.
80#[derive(Serialize, Deserialize, Copy, Clone, Debug, Eq, PartialEq)]
81pub struct Rcon<'a> {
82    /// Command to be executed.
83    pub command: &'a str,
84}
85impl Packet for Rcon<'_> {
86    const PACKET_TYPE: u8 = 5;
87}
88
89/// Send a JSON string to the current active GameScript.
90#[derive(Serialize, Deserialize, Copy, Clone, Debug, Eq, PartialEq)]
91pub struct Gamescript<'a> {
92    /// JSON string for the GameScript.
93    pub json: &'a str,
94}
95impl Packet for Gamescript<'_> {
96    const PACKET_TYPE: u8 = 6;
97}
98
99/// Ping the server, requiring the server to reply with a pong packet.
100#[derive(Serialize, Deserialize, Copy, Clone, Debug, Eq, PartialEq)]
101pub struct Ping {
102    ///  Integer value to pass to the server, which is quoted in the reply.
103    pub id: u32,
104}
105impl Packet for Ping {
106    const PACKET_TYPE: u8 = 7;
107}