]> git.lizzy.rs Git - mt_net.git/blob - src/to_clt.rs
Add wrappers around mt_rudp
[mt_net.git] / src / to_clt.rs
1 use super::*;
2
3 #[mt_derive(to = "clt")]
4 pub struct Color {
5     pub a: u8,
6     pub r: u8,
7     pub g: u8,
8     pub b: u8,
9 }
10
11 #[mt_derive(to = "clt", repr = "u8")]
12 pub enum ModChanSig {
13     JoinOk = 0,
14     JoinFail,
15     LeaveOk,
16     LeaveFail,
17     NotRegistered,
18     SetState,
19 }
20
21 #[mt_derive(to = "clt", repr = "u32", enumset)]
22 pub enum AuthMethod {
23     LegacyPasswd,
24     Srp,
25     FirstSrp,
26 }
27
28 #[mt_derive(to = "clt", repr = "u64", enumset)]
29 pub enum CsmRestrictionFlag {
30     NoCsms,
31     NoChatMsgs,
32     NoItemDefs,
33     NoNodeDefs,
34     LimitMapRange,
35     NoPlayerList,
36 }
37
38 #[mt_derive(to = "clt", repr = "u8")]
39 pub enum ChatMsgType {
40     Raw = 0,
41     Normal,
42     Announce,
43     System,
44 }
45
46 #[mt_derive(to = "clt", repr = "u8")]
47 pub enum PlayerListUpdateType {
48     Init = 0,
49     Add,
50     Remove,
51 }
52
53 mod hud;
54 mod inv;
55 mod kick;
56 mod map;
57 mod media;
58 mod obj;
59 mod sky;
60
61 pub use hud::*;
62 pub use inv::*;
63 pub use kick::*;
64 pub use map::*;
65 pub use media::*;
66 pub use obj::*;
67 pub use sky::*;
68
69 #[mt_derive(to = "clt", repr = "u16", tag = "type", content = "data")]
70 pub enum ToCltPkt {
71     Hello {
72         serialize_version: u8,
73         #[mt(const_before = "1u16")] // compression
74         proto_version: u16,
75         auth_methods: EnumSet<AuthMethod>,
76         username: String,
77     } = 2,
78     AcceptAuth {
79         player_pos: [f32; 3],
80         map_seed: u64,
81         send_interval: f32,
82         sudo_auth_methods: EnumSet<AuthMethod>,
83     } = 3,
84     AcceptSudoMode {
85         #[mt(const_after = "[0u8; 15]")]
86         sudo_auth_methods: EnumSet<AuthMethod>,
87     } = 4,
88     DenySudoMode = 5,
89     Kick(KickReason) = 10,
90     BlockData {
91         pos: [i16; 3],
92         #[mt(zstd)]
93         block: Box<MapBlock>,
94     } = 32,
95     AddNode {
96         pos: [i16; 3],
97         param0: u16,
98         param1: u8,
99         param2: u8,
100         keep_meta: bool,
101     } = 33,
102     RemoveNode {
103         pos: [i16; 3],
104     } = 34,
105     Inv {
106         #[mt(len = "()")]
107         inv: String,
108     } = 39,
109     TimeOfDay {
110         time: u16,
111         speed: f32,
112     } = 41,
113     CsmRestrictionFlags {
114         flags: EnumSet<CsmRestrictionFlag>,
115         map_range: u32,
116     } = 42,
117     AddPlayerVelocity {
118         vel: [f32; 3],
119     } = 43,
120     MediaPush {
121         raw_hash: String,
122         filename: String,
123         callback_token: u32,
124         should_cache: bool,
125     } = 44,
126     ChatMsg {
127         #[mt(const_before = "1u8")]
128         msg_type: ChatMsgType,
129         #[mt(len = "Utf16")]
130         sender: String,
131         #[mt(len = "Utf16")]
132         text: String,
133         timestamp: i64, // unix time
134     } = 47,
135     ObjRemoveAdd {
136         remove: Vec<u16>,
137         add: Vec<ObjAdd>,
138     } = 49,
139     ObjMsgs {
140         #[mt(len = "()")]
141         msgs: Vec<ObjIdMsg>,
142     } = 50,
143     Hp {
144         hp: u16,
145         #[mt(default)]
146         damage_effect: bool,
147     } = 51,
148     MovePlayer {
149         pos: [f32; 3],
150         pitch: f32,
151         yaw: f32,
152     } = 52,
153     LegacyKick {
154         #[mt(len = "Utf16")]
155         reason: String,
156     } = 53,
157     Fov {
158         fov: f32,
159         multiplier: bool,
160         transition_time: f32,
161     } = 54,
162     DeathScreen {
163         point_cam: bool,
164         point_at: [f32; 3],
165     } = 55,
166     Media {
167         n: u16,
168         i: u16,
169         #[mt(len = "(u32, (DefCfg, u32))")]
170         files: HashMap<String, Vec<u8>>, // name -> payload
171     } = 56,
172     #[mt(size = "u32", zlib)]
173     NodeDefs(#[mt(const_before = "1u8")] NodeDefs) = 58,
174     AnnounceMedia {
175         files: HashMap<String, String>, // name -> base64 sha1 hash
176         url: String,
177     } = 60,
178     #[mt(size = "u32", zlib)]
179     ItemDefs {
180         #[mt(const_before = "0u8")] // version
181         defs: Vec<ItemDef>,
182         aliases: HashMap<String, String>,
183     } = 61,
184     PlaySound {
185         id: u32,
186         name: String,
187         gain: f32,
188         source: SoundSource,
189         pos: [f32; 3],
190         src_obj_id: u16,
191         #[serde(rename = "loop")]
192         sound_loop: bool,
193         fade: f32,
194         pitch: f32,
195         ephermeral: bool,
196     } = 63,
197     StopSound {
198         id: u32,
199     } = 64,
200     Privs {
201         privs: HashSet<String>,
202     } = 65,
203     InvFormspec {
204         #[mt(size = "u32")]
205         formspec: String,
206     } = 66,
207     DetachedInv {
208         name: String,
209         keep: bool,
210         len: u16,
211         #[mt(len = "()")]
212         inv: String,
213     } = 67,
214     ShowFormspec {
215         #[mt(len = "u32")]
216         formspec: String,
217         formname: String,
218     } = 68,
219     Movement {
220         default_accel: f32,
221         air_accel: f32,
222         fast_accel: f32,
223         walk_speed: f32,
224         crouch_speed: f32,
225         fast_speed: f32,
226         climb_speed: f32,
227         jump_speed: f32,
228         fluidity: f32,
229         smoothing: f32,
230         sink: f32,
231         gravity: f32,
232     } = 69,
233     SpawnParticle {
234         pos: [f32; 3],
235         vel: [f32; 3],
236         acc: [f32; 3],
237         expiration_time: f32,
238         size: f32,
239         collide: bool,
240         #[mt(len = "u32")]
241         texture: String,
242         vertical: bool,
243         collision_rm: bool,
244         anim_params: TileAnim,
245         glow: u8,
246         obj_collision: bool,
247         node_param0: u16,
248         node_param2: u8,
249         node_tile: u8,
250     } = 70,
251     AddParticleSpawner {
252         amount: u16,
253         duration: f32,
254         pos: RangeInclusive<[f32; 3]>,
255         vel: RangeInclusive<[f32; 3]>,
256         acc: RangeInclusive<[f32; 3]>,
257         expiration_time: RangeInclusive<f32>,
258         size: RangeInclusive<f32>,
259         collide: bool,
260         #[mt(len = "u32")]
261         texture: String,
262         id: u32,
263         vertical: bool,
264         collision_rm: bool,
265         attached_obj_id: u16,
266         anim_params: TileAnim,
267         glow: u8,
268         obj_collision: bool,
269         node_param0: u16,
270         node_param2: u8,
271         node_tile: u8,
272     } = 71,
273     AddHud {
274         id: u32,
275         hud: HudElement,
276     } = 73,
277     RemoveHud {
278         id: u32,
279     } = 74,
280     ChangeHud {
281         id: u32,
282         change: HudChange,
283     } = 75,
284     HudFlags {
285         flags: EnumSet<HudFlag>,
286         mask: EnumSet<HudFlag>,
287     } = 76,
288     HotbarParam(HotbarParam) = 77,
289     Breath {
290         breath: u16,
291     } = 78,
292     SkyParams(SkyParams) = 79,
293     OverrideDayNightRatio {
294         #[serde(rename = "override")]
295         ratio_override: bool,
296         ratio: u16,
297     } = 80,
298     LocalPlayerAnim {
299         idle: [i32; 2],
300         walk: [i32; 2],
301         dig: [i32; 2],
302         walk_dig: [i32; 2],
303         speed: f32,
304     } = 81,
305     EyeOffset {
306         first: [f32; 3],
307         third: [f32; 3],
308     } = 82,
309     RemoveParticleSpawner {
310         id: u32,
311     } = 83,
312     CloudParams(CloudParams) = 84,
313     FadeSound {
314         id: u32,
315         step: f32,
316         gain: f32,
317     } = 85,
318     UpdatePlayerList {
319         update_type: PlayerListUpdateType,
320         players: HashSet<String>,
321     } = 86,
322     ModChanMsg {
323         channel: String,
324         sender: String,
325         msg: String,
326     } = 87,
327     ModChanSig {
328         signal: ModChanSig,
329         channel: String,
330     } = 88,
331     NodeMetasChanged {
332         #[mt(size = "u32", zlib)]
333         #[mt(len = "NodeMetasLen")]
334         changed: HashMap<[i16; 3], NodeMeta>,
335     } = 89,
336     SunParams(SunParams) = 90,
337     MoonParams(MoonParams) = 91,
338     StarParams(StarParams) = 92,
339     SrpBytesSaltB {
340         salt: Vec<u8>,
341         b: Vec<u8>,
342     } = 96,
343     FormspecPrepend {
344         prepend: String,
345     } = 97,
346     MinimapModes(MinimapModesPkt) = 98,
347 }
348
349 impl PktInfo for ToCltPkt {
350     fn pkt_info(&self) -> (u8, bool) {
351         use ToCltPkt::*;
352
353         match self {
354             BlockData { .. } | Media { .. } => (2, true),
355             AddHud { .. }
356             | ChangeHud { .. }
357             | RemoveHud { .. }
358             | HudFlags { .. }
359             | HotbarParam(_) => (1, true),
360             _ => (0, true),
361         }
362     }
363 }