]> git.lizzy.rs Git - dragonfireclient.git/blob - src/clientserver.h
Node definitions transfer
[dragonfireclient.git] / src / clientserver.h
1 /*
2 Minetest-c55
3 Copyright (C) 2010 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #ifndef CLIENTSERVER_HEADER
21 #define CLIENTSERVER_HEADER
22
23 #include "utility.h"
24
25 /*
26         changes by PROTOCOL_VERSION:
27
28         PROTOCOL_VERSION 3:
29                 Base for writing changes here
30         PROTOCOL_VERSION 4:
31                 Add TOCLIENT_TOOLDEF
32                 Add TOCLIENT_TEXTURES
33                 Add TOCLIENT_NODEDEF
34 */
35
36 #define PROTOCOL_VERSION 4
37
38 #define PROTOCOL_ID 0x4f457403
39
40 #define PASSWORD_SIZE 28       // Maximum password length. Allows for
41                                // base64-encoded SHA-1 (27+\0).
42
43 enum ToClientCommand
44 {
45         TOCLIENT_INIT = 0x10,
46         /*
47                 Server's reply to TOSERVER_INIT.
48                 Sent second after connected.
49
50                 [0] u16 TOSERVER_INIT
51                 [2] u8 deployed version
52                 [3] v3s16 player's position + v3f(0,BS/2,0) floatToInt'd 
53                 [12] u64 map seed (new as of 2011-02-27)
54
55                 NOTE: The position in here is deprecated; position is
56                       explicitly sent afterwards
57         */
58
59         TOCLIENT_BLOCKDATA = 0x20, //TODO: Multiple blocks
60         TOCLIENT_ADDNODE = 0x21,
61         TOCLIENT_REMOVENODE = 0x22,
62         
63         TOCLIENT_PLAYERPOS = 0x23, // Obsolete
64         /*
65                 [0] u16 command
66                 // Followed by an arbitary number of these:
67                 // Number is determined from packet length.
68                 [N] u16 peer_id
69                 [N+2] v3s32 position*100
70                 [N+2+12] v3s32 speed*100
71                 [N+2+12+12] s32 pitch*100
72                 [N+2+12+12+4] s32 yaw*100
73         */
74
75         TOCLIENT_PLAYERINFO = 0x24,
76         /*
77                 [0] u16 command
78                 // Followed by an arbitary number of these:
79                 // Number is determined from packet length.
80                 [N] u16 peer_id
81                 [N] char[20] name
82         */
83         
84         TOCLIENT_OPT_BLOCK_NOT_FOUND = 0x25, // Obsolete
85
86         TOCLIENT_SECTORMETA = 0x26, // Obsolete
87         /*
88                 [0] u16 command
89                 [2] u8 sector count
90                 [3...] v2s16 pos + sector metadata
91         */
92
93         TOCLIENT_INVENTORY = 0x27,
94         /*
95                 [0] u16 command
96                 [2] serialized inventory
97         */
98         
99         TOCLIENT_OBJECTDATA = 0x28,
100         /*
101                 Sent as unreliable.
102
103                 u16 command
104                 u16 number of player positions
105                 for each player:
106                         u16 peer_id
107                         v3s32 position*100
108                         v3s32 speed*100
109                         s32 pitch*100
110                         s32 yaw*100
111                 u16 count of blocks
112                 for each block:
113                         v3s16 blockpos
114                         block objects
115         */
116
117         TOCLIENT_TIME_OF_DAY = 0x29,
118         /*
119                 u16 command
120                 u16 time (0-23999)
121         */
122
123         // (oops, there is some gap here)
124
125         TOCLIENT_CHAT_MESSAGE = 0x30,
126         /*
127                 u16 command
128                 u16 length
129                 wstring message
130         */
131
132         TOCLIENT_ACTIVE_OBJECT_REMOVE_ADD = 0x31,
133         /*
134                 u16 command
135                 u16 count of removed objects
136                 for all removed objects {
137                         u16 id
138                 }
139                 u16 count of added objects
140                 for all added objects {
141                         u16 id
142                         u8 type
143                         u32 initialization data length
144                         string initialization data
145                 }
146         */
147         
148         TOCLIENT_ACTIVE_OBJECT_MESSAGES = 0x32,
149         /*
150                 u16 command
151                 for all objects
152                 {
153                         u16 id
154                         u16 message length
155                         string message
156                 }
157         */
158
159         TOCLIENT_HP = 0x33,
160         /*
161                 u16 command
162                 u8 hp
163         */
164
165         TOCLIENT_MOVE_PLAYER = 0x34,
166         /*
167                 u16 command
168                 v3f1000 player position
169                 f1000 player pitch
170                 f1000 player yaw
171         */
172
173         TOCLIENT_ACCESS_DENIED = 0x35,
174         /*
175                 u16 command
176                 u16 reason_length
177                 wstring reason
178         */
179
180         TOCLIENT_PLAYERITEM = 0x36,
181         /*
182                 u16 command
183                 u16 count of player items
184                 for all player items {
185                         u16 peer id
186                         u16 length of serialized item
187                         string serialized item
188                 }
189         */
190
191         TOCLIENT_DEATHSCREEN = 0x37,
192         /*
193                 u16 command
194                 u8 bool set camera point target
195                 v3f1000 camera point target (to point the death cause or whatever)
196         */
197
198         TOCLIENT_TOOLDEF = 0x38,
199         /*
200                 u16 command
201                 u32 length of the next item
202                 serialized ToolDefManager
203         */
204         
205         TOCLIENT_TEXTURES = 0x39,
206         /*
207                 u16 command
208                 u32 number of textures
209                 for each texture {
210                         u16 length of name
211                         string name
212                         u32 length of data
213                         data
214                 }
215         */
216         
217         TOCLIENT_NODEDEF = 0x3a,
218         /*
219                 u16 command
220                 u32 length of the next item
221                 serialized NodeDefManager
222         */
223         
224         //TOCLIENT_CONTENT_SENDING_MODE = 0x38,
225         /*
226                 u16 command
227                 u8 mode (0 = off, 1 = on)
228         */
229 };
230
231 enum ToServerCommand
232 {
233         TOSERVER_INIT=0x10,
234         /*
235                 Sent first after connected.
236
237                 [0] u16 TOSERVER_INIT
238                 [2] u8 SER_FMT_VER_HIGHEST
239                 [3] u8[20] player_name
240                 [23] u8[28] password (new in some version)
241                 [51] u16 client network protocol version (new in some version)
242         */
243
244         TOSERVER_INIT2 = 0x11,
245         /*
246                 Sent as an ACK for TOCLIENT_INIT.
247                 After this, the server can send data.
248
249                 [0] u16 TOSERVER_INIT2
250         */
251
252         TOSERVER_GETBLOCK=0x20, // Obsolete
253         TOSERVER_ADDNODE = 0x21, // Obsolete
254         TOSERVER_REMOVENODE = 0x22, // Obsolete
255
256         TOSERVER_PLAYERPOS = 0x23,
257         /*
258                 [0] u16 command
259                 [2] v3s32 position*100
260                 [2+12] v3s32 speed*100
261                 [2+12+12] s32 pitch*100
262                 [2+12+12+4] s32 yaw*100
263         */
264
265         TOSERVER_GOTBLOCKS = 0x24,
266         /*
267                 [0] u16 command
268                 [2] u8 count
269                 [3] v3s16 pos_0
270                 [3+6] v3s16 pos_1
271                 ...
272         */
273
274         TOSERVER_DELETEDBLOCKS = 0x25,
275         /*
276                 [0] u16 command
277                 [2] u8 count
278                 [3] v3s16 pos_0
279                 [3+6] v3s16 pos_1
280                 ...
281         */
282
283         TOSERVER_ADDNODE_FROM_INVENTORY = 0x26, // Obsolete
284         /*
285                 [0] u16 command
286                 [2] v3s16 pos
287                 [8] u16 i
288         */
289
290         TOSERVER_CLICK_OBJECT = 0x27,
291         /*
292                 length: 13
293                 [0] u16 command
294                 [2] u8 button (0=left, 1=right)
295                 [3] v3s16 blockpos
296                 [9] s16 id
297                 [11] u16 item
298         */
299
300         TOSERVER_GROUND_ACTION = 0x28,
301         /*
302                 length: 17
303                 [0] u16 command
304                 [2] u8 action
305                 [3] v3s16 nodepos_undersurface
306                 [9] v3s16 nodepos_abovesurface
307                 [15] u16 item
308                 actions:
309                 0: start digging (from undersurface)
310                 1: place block (to abovesurface)
311                 2: stop digging (all parameters ignored)
312                 3: digging completed
313         */
314         
315         TOSERVER_RELEASE = 0x29, // Obsolete
316
317         // (oops, there is some gap here)
318
319         TOSERVER_SIGNTEXT = 0x30, // Old signs
320         /*
321                 u16 command
322                 v3s16 blockpos
323                 s16 id
324                 u16 textlen
325                 textdata
326         */
327
328         TOSERVER_INVENTORY_ACTION = 0x31,
329         /*
330                 See InventoryAction in inventory.h
331         */
332
333         TOSERVER_CHAT_MESSAGE = 0x32,
334         /*
335                 u16 command
336                 u16 length
337                 wstring message
338         */
339
340         TOSERVER_SIGNNODETEXT = 0x33,
341         /*
342                 u16 command
343                 v3s16 p
344                 u16 textlen
345                 textdata
346         */
347
348         TOSERVER_CLICK_ACTIVEOBJECT = 0x34,
349         /*
350                 length: 7
351                 [0] u16 command
352                 [2] u8 button (0=left, 1=right)
353                 [3] u16 id
354                 [5] u16 item
355         */
356         
357         TOSERVER_DAMAGE = 0x35,
358         /*
359                 u16 command
360                 u8 amount
361         */
362
363         TOSERVER_PASSWORD=0x36,
364         /*
365                 Sent to change password.
366
367                 [0] u16 TOSERVER_PASSWORD
368                 [2] u8[28] old password
369                 [30] u8[28] new password
370         */
371
372         TOSERVER_PLAYERITEM=0x37,
373         /*
374                 Sent to change selected item.
375
376                 [0] u16 TOSERVER_PLAYERITEM
377                 [2] u16 item
378         */
379         
380         TOSERVER_RESPAWN=0x38,
381         /*
382                 u16 TOSERVER_RESPAWN
383         */
384 };
385
386 inline SharedBuffer<u8> makePacket_TOCLIENT_TIME_OF_DAY(u16 time)
387 {
388         SharedBuffer<u8> data(2+2);
389         writeU16(&data[0], TOCLIENT_TIME_OF_DAY);
390         writeU16(&data[2], time);
391         return data;
392 }
393
394 #endif
395