]> git.lizzy.rs Git - mt_net.git/blob - src/to_srv.rs
Add wrappers around mt_rudp
[mt_net.git] / src / to_srv.rs
1 use super::*;
2
3 #[mt_derive(to = "srv", repr = "u32", enumset)]
4 pub enum Key {
5     Forward,
6     Backward,
7     Left,
8     Right,
9     Jump,
10     Special,
11     Sneak,
12     Dig,
13     Place,
14     Zoom,
15 }
16
17 #[mt_derive(to = "srv")]
18 pub struct PlayerPos {
19     pub pos_100: [i32; 3],
20     pub vel_100: [i32; 3],
21     pub pitch_100: i32,
22     pub yaw_100: i32,
23     pub keys: EnumSet<Key>,
24     pub fov_80: u8,
25     pub wanted_range: u8,
26 }
27
28 #[mt_derive(to = "srv", repr = "u8")]
29 pub enum Interaction {
30     Dig = 0,
31     StopDigging,
32     Dug,
33     Place,
34     Use,
35     Activate,
36 }
37
38 #[mt_derive(to = "srv", repr = "u8", tag = "type")]
39 #[mt(const_before = "0u8")] // version
40 pub enum PointedThing {
41     None = 0,
42     Node { under: [i16; 3], above: [i16; 3] },
43     Obj { obj: u16 },
44 }
45
46 #[mt_derive(to = "srv", repr = "u16", tag = "type", content = "data")]
47 pub enum ToSrvPkt {
48     Nil = 0,
49     Init {
50         serialize_version: u8,
51         #[mt(const_before = "1u16")] // supported compression
52         min_proto_version: u16,
53         max_proto_version: u16,
54         player_name: String,
55         #[mt(default)]
56         send_full_item_meta: bool,
57     } = 2,
58     Init2 {
59         lang: String,
60     } = 17,
61     JoinModChan {
62         channel: String,
63     } = 23,
64     LeaveModChan {
65         channel: String,
66     } = 24,
67     MsgModChan {
68         channel: String,
69         msg: String,
70     } = 25,
71     PlayerPos(PlayerPos) = 35,
72     GotBlocks {
73         #[mt(len = "u8")]
74         blocks: Vec<[i16; 3]>,
75     } = 36,
76     DeletedBlocks {
77         #[mt(len = "u8")]
78         blocks: Vec<[i16; 3]>,
79     } = 37,
80     HaveMedia {
81         #[mt(len = "u8")]
82         tokens: Vec<u32>,
83     } = 41,
84     InvAction {
85         #[mt(len = "()")]
86         action: String,
87     } = 49,
88     ChatMsg {
89         #[mt(len = "Utf16")]
90         msg: String,
91     } = 50,
92     FallDmg {
93         amount: u16,
94     } = 53,
95     SelectItem {
96         select_item: u16,
97     } = 55,
98     Respawn = 56,
99     Interact {
100         action: Interaction,
101         item_slot: u16,
102         #[mt(size = "u32")]
103         pointed: PointedThing,
104         pos: PlayerPos,
105     } = 57,
106     RemovedSounds {
107         ids: Vec<i32>,
108     } = 58,
109     NodeMetaFields {
110         pos: [i16; 3],
111         formname: String,
112         #[mt(len = "(DefCfg, (DefCfg, u32))")]
113         fields: HashMap<String, String>,
114     } = 59,
115     InvFields {
116         formname: String,
117         #[mt(len = "(DefCfg, (DefCfg, u32))")]
118         fields: HashMap<String, String>,
119     } = 60,
120     RequestMedia {
121         filenames: Vec<String>,
122     } = 64,
123     CltReady {
124         major: u8,
125         minor: u8,
126         patch: u8,
127         reserved: u8,
128         version: String,
129         formspec: u16,
130     } = 67,
131     FirstSrp {
132         salt: Vec<u8>,
133         verifier: Vec<u8>,
134         empty_passwd: bool,
135     } = 80,
136     SrpBytesA {
137         a: Vec<u8>,
138         no_sha1: bool,
139     } = 81,
140     SrpBytesM {
141         m: Vec<u8>,
142     } = 82,
143     Disco = 0xffff,
144 }
145
146 impl PktInfo for ToSrvPkt {
147     fn pkt_info(&self) -> (u8, bool) {
148         use ToSrvPkt::*;
149
150         match self {
151             Init { .. } => (1, false),
152             Init2 { .. }
153             | RequestMedia { .. }
154             | CltReady { .. }
155             | FirstSrp { .. }
156             | SrpBytesA { .. }
157             | SrpBytesM { .. } => (1, true),
158             PlayerPos { .. } => (0, false),
159             GotBlocks { .. } | HaveMedia { .. } | DeletedBlocks { .. } | RemovedSounds { .. } => {
160                 (2, true)
161             }
162             _ => (0, true),
163         }
164     }
165 }