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
use crate::packet::serde::WritablePacket;
use crate::types;
use serde_derive::{Deserialize, Serialize};
pub trait Packet: WritablePacket {
const PACKET_TYPE: u8;
}
impl<T: Packet> WritablePacket for T {
const PACKET_TYPE: u8 = <T as Packet>::PACKET_TYPE;
}
#[derive(Serialize, Deserialize, Copy, Clone, Debug, Eq, PartialEq)]
pub struct Join<'a> {
pub password: &'a str,
pub name: &'a str,
pub version: &'a str,
}
impl<'a> Packet for Join<'a> {
const PACKET_TYPE: u8 = 0;
}
#[derive(Serialize, Deserialize, Copy, Clone, Debug, Eq, PartialEq)]
pub struct Quit;
impl Packet for Quit {
const PACKET_TYPE: u8 = 1;
}
#[derive(Serialize, Deserialize, Copy, Clone, Debug, Eq, PartialEq)]
pub struct UpdateFrequency {
pub update_type: types::AdminUpdateType,
pub frequency: types::UpdateFrequencies,
}
impl Packet for UpdateFrequency {
const PACKET_TYPE: u8 = 2;
}
#[derive(Serialize, Deserialize, Copy, Clone, Debug, Eq, PartialEq)]
pub struct Poll {
pub update_type: types::AdminUpdateType,
pub id: u32,
}
impl Packet for Poll {
const PACKET_TYPE: u8 = 3;
}
#[derive(Serialize, Deserialize, Copy, Clone, Debug, Eq, PartialEq)]
pub struct Chat<'a> {
pub action: u8,
pub destination_type: u8,
pub destination_id: u32,
pub message: &'a str,
}
impl Packet for Chat<'_> {
const PACKET_TYPE: u8 = 4;
}
#[derive(Serialize, Deserialize, Copy, Clone, Debug, Eq, PartialEq)]
pub struct Rcon<'a> {
pub command: &'a str,
}
impl Packet for Rcon<'_> {
const PACKET_TYPE: u8 = 5;
}
#[derive(Serialize, Deserialize, Copy, Clone, Debug, Eq, PartialEq)]
pub struct Gamescript<'a> {
pub json: &'a str,
}
impl Packet for Gamescript<'_> {
const PACKET_TYPE: u8 = 6;
}
#[derive(Serialize, Deserialize, Copy, Clone, Debug, Eq, PartialEq)]
pub struct Ping {
pub id: u32,
}
impl Packet for Ping {
const PACKET_TYPE: u8 = 7;
}