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
|
use super::*;
#[mt_derive(to = "srv", repr = "u32", enumset)]
pub enum Key {
Forward,
Backward,
Left,
Right,
Jump,
Special,
Sneak,
Dig,
Place,
Zoom,
}
#[mt_derive(to = "srv")]
pub struct PlayerPos {
pub pos_100: [i32; 3],
pub vel_100: [i32; 3],
pub pitch_100: i32,
pub yaw_100: i32,
pub keys: EnumSet<Key>,
pub fov_80: u8,
pub wanted_range: u8,
}
#[mt_derive(to = "srv", repr = "u8")]
pub enum Interaction {
Dig = 0,
StopDigging,
Dug,
Place,
Use,
Activate,
}
#[mt_derive(to = "srv", repr = "u8", tag = "type")]
#[mt(const_before = "0u8")] // version
pub enum PointedThing {
None = 0,
Node { under: [i16; 3], above: [i16; 3] },
Obj { obj: u16 },
}
#[mt_derive(to = "srv", repr = "u16", tag = "type", content = "data")]
pub enum ToSrvPkt {
Nil = 0,
Init {
serialize_version: u8,
#[mt(const_before = "1u16")] // supported compression
min_proto_version: u16,
max_proto_version: u16,
player_name: String,
#[mt(default)]
send_full_item_meta: bool,
} = 2,
Init2 {
lang: String,
} = 17,
JoinModChan {
channel: String,
} = 23,
LeaveModChan {
channel: String,
} = 24,
MsgModChan {
channel: String,
msg: String,
} = 25,
PlayerPos(PlayerPos) = 35,
GotBlocks {
#[mt(len = "u8")]
blocks: Vec<[i16; 3]>,
} = 36,
DeletedBlocks {
#[mt(len = "u8")]
blocks: Vec<[i16; 3]>,
} = 37,
HaveMedia {
#[mt(len = "u8")]
tokens: Vec<u32>,
} = 41,
InvAction {
#[mt(len = "()")]
action: String,
} = 49,
ChatMsg {
#[mt(len = "Utf16")]
msg: String,
} = 50,
FallDmg {
amount: u16,
} = 53,
SelectItem {
select_item: u16,
} = 55,
Respawn = 56,
Interact {
action: Interaction,
item_slot: u16,
#[mt(size = "u32")]
pointed: PointedThing,
pos: PlayerPos,
} = 57,
RemovedSounds {
ids: Vec<i32>,
} = 58,
NodeMetaFields {
pos: [i16; 3],
formname: String,
#[mt(len = "(DefCfg, (DefCfg, u32))")]
fields: HashMap<String, String>,
} = 59,
InvFields {
formname: String,
#[mt(len = "(DefCfg, (DefCfg, u32))")]
fields: HashMap<String, String>,
} = 60,
RequestMedia {
filenames: Vec<String>,
} = 64,
CltReady {
major: u8,
minor: u8,
patch: u8,
reserved: u8,
version: String,
formspec: u16,
} = 67,
FirstSrp {
salt: Vec<u8>,
verifier: Vec<u8>,
empty_passwd: bool,
} = 80,
SrpBytesA {
a: Vec<u8>,
no_sha1: bool,
} = 81,
SrpBytesM {
m: Vec<u8>,
} = 82,
Disco = 0xffff,
}
impl PktInfo for ToSrvPkt {
fn pkt_info(&self) -> (u8, bool) {
use ToSrvPkt::*;
match self {
Init { .. } => (1, false),
Init2 { .. }
| RequestMedia { .. }
| CltReady { .. }
| FirstSrp { .. }
| SrpBytesA { .. }
| SrpBytesM { .. } => (1, true),
PlayerPos { .. } => (0, false),
GotBlocks { .. } | HaveMedia { .. } | DeletedBlocks { .. } | RemovedSounds { .. } => {
(2, true)
}
_ => (0, true),
}
}
}
|