]> git.lizzy.rs Git - minetest.git/blob - src/clientserver.h
Create node metadata when placing nodes again
[minetest.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_TEXTURES
32                 Add TOCLIENT_TOOLDEF
33                 Add TOCLIENT_NODEDEF
34                 Add TOCLIENT_CRAFTITEMDEF
35                 Add TOSERVER_INTERACT
36                 Obsolete TOSERVER_CLICK_ACTIVEOBJECT
37                 Obsolete TOSERVER_GROUND_ACTION
38         PROTOCOL_VERSION 5:
39                 Make players to be handled mostly as ActiveObjects
40         PROTOCOL_VERSION 6:
41                 Only non-cached textures are sent
42         PROTOCOL_VERSION 7:
43                 Add TOCLIENT_ITEMDEF
44                 Obsolete TOCLIENT_TOOLDEF
45                 Obsolete TOCLIENT_CRAFTITEMDEF
46                 Compress the contents of TOCLIENT_ITEMDEF and TOCLIENT_NODEDEF
47 */
48
49 #define PROTOCOL_VERSION 7
50
51 #define PROTOCOL_ID 0x4f457403
52
53 #define PASSWORD_SIZE 28       // Maximum password length. Allows for
54                                // base64-encoded SHA-1 (27+\0).
55
56 #define TEXTURENAME_ALLOWED_CHARS "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_."
57
58 enum ToClientCommand
59 {
60         TOCLIENT_INIT = 0x10,
61         /*
62                 Server's reply to TOSERVER_INIT.
63                 Sent second after connected.
64
65                 [0] u16 TOSERVER_INIT
66                 [2] u8 deployed version
67                 [3] v3s16 player's position + v3f(0,BS/2,0) floatToInt'd 
68                 [12] u64 map seed (new as of 2011-02-27)
69
70                 NOTE: The position in here is deprecated; position is
71                       explicitly sent afterwards
72         */
73
74         TOCLIENT_BLOCKDATA = 0x20, //TODO: Multiple blocks
75         TOCLIENT_ADDNODE = 0x21,
76         TOCLIENT_REMOVENODE = 0x22,
77         
78         TOCLIENT_PLAYERPOS = 0x23, // Obsolete
79         /*
80                 [0] u16 command
81                 // Followed by an arbitary number of these:
82                 // Number is determined from packet length.
83                 [N] u16 peer_id
84                 [N+2] v3s32 position*100
85                 [N+2+12] v3s32 speed*100
86                 [N+2+12+12] s32 pitch*100
87                 [N+2+12+12+4] s32 yaw*100
88         */
89
90         TOCLIENT_PLAYERINFO = 0x24, // Obsolete
91         /*
92                 [0] u16 command
93                 // Followed by an arbitary number of these:
94                 // Number is determined from packet length.
95                 [N] u16 peer_id
96                 [N] char[20] name
97         */
98         
99         TOCLIENT_OPT_BLOCK_NOT_FOUND = 0x25, // Obsolete
100
101         TOCLIENT_SECTORMETA = 0x26, // Obsolete
102         /*
103                 [0] u16 command
104                 [2] u8 sector count
105                 [3...] v2s16 pos + sector metadata
106         */
107
108         TOCLIENT_INVENTORY = 0x27,
109         /*
110                 [0] u16 command
111                 [2] serialized inventory
112         */
113         
114         TOCLIENT_OBJECTDATA = 0x28, // Obsolete
115         /*
116                 Sent as unreliable.
117
118                 u16 command
119                 u16 number of player positions
120                 for each player:
121                         u16 peer_id
122                         v3s32 position*100
123                         v3s32 speed*100
124                         s32 pitch*100
125                         s32 yaw*100
126                 u16 count of blocks
127                 for each block:
128                         v3s16 blockpos
129                         block objects
130         */
131
132         TOCLIENT_TIME_OF_DAY = 0x29,
133         /*
134                 u16 command
135                 u16 time (0-23999)
136         */
137
138         // (oops, there is some gap here)
139
140         TOCLIENT_CHAT_MESSAGE = 0x30,
141         /*
142                 u16 command
143                 u16 length
144                 wstring message
145         */
146
147         TOCLIENT_ACTIVE_OBJECT_REMOVE_ADD = 0x31,
148         /*
149                 u16 command
150                 u16 count of removed objects
151                 for all removed objects {
152                         u16 id
153                 }
154                 u16 count of added objects
155                 for all added objects {
156                         u16 id
157                         u8 type
158                         u32 initialization data length
159                         string initialization data
160                 }
161         */
162         
163         TOCLIENT_ACTIVE_OBJECT_MESSAGES = 0x32,
164         /*
165                 u16 command
166                 for all objects
167                 {
168                         u16 id
169                         u16 message length
170                         string message
171                 }
172         */
173
174         TOCLIENT_HP = 0x33,
175         /*
176                 u16 command
177                 u8 hp
178         */
179
180         TOCLIENT_MOVE_PLAYER = 0x34,
181         /*
182                 u16 command
183                 v3f1000 player position
184                 f1000 player pitch
185                 f1000 player yaw
186         */
187
188         TOCLIENT_ACCESS_DENIED = 0x35,
189         /*
190                 u16 command
191                 u16 reason_length
192                 wstring reason
193         */
194
195         TOCLIENT_PLAYERITEM = 0x36,
196         /*
197                 u16 command
198                 u16 count of player items
199                 for all player items {
200                         u16 peer id
201                         u16 length of serialized item
202                         string serialized item
203                 }
204         */
205
206         TOCLIENT_DEATHSCREEN = 0x37,
207         /*
208                 u16 command
209                 u8 bool set camera point target
210                 v3f1000 camera point target (to point the death cause or whatever)
211         */
212
213         TOCLIENT_TEXTURES = 0x38,
214         /*
215                 u16 command
216                 u16 total number of texture bunches
217                 u16 index of this bunch
218                 u32 number of textures in this bunch
219                 for each texture {
220                         u16 length of name
221                         string name
222                         u32 length of data
223                         data
224                 }
225         */
226         
227         TOCLIENT_TOOLDEF = 0x39,
228         /*
229                 u16 command
230                 u32 length of the next item
231                 serialized ToolDefManager
232         */
233         
234         TOCLIENT_NODEDEF = 0x3a,
235         /*
236                 u16 command
237                 u32 length of the next item
238                 serialized NodeDefManager
239         */
240         
241         TOCLIENT_CRAFTITEMDEF = 0x3b,
242         /*
243                 u16 command
244                 u32 length of the next item
245                 serialized CraftiItemDefManager
246         */
247
248         TOCLIENT_ANNOUNCE_TEXTURES = 0x3c,
249
250         /*
251                 u16 command
252                 u32 number of textures
253                 for each texture {
254                         u16 length of name
255                         string name
256                         u16 length of sha1_digest
257                         string sha1_digest
258                 }
259         */
260
261         TOCLIENT_ITEMDEF = 0x3d,
262         /*
263                 u16 command
264                 u32 length of next item
265                 serialized ItemDefManager
266         */
267
268 };
269
270 enum ToServerCommand
271 {
272         TOSERVER_INIT=0x10,
273         /*
274                 Sent first after connected.
275
276                 [0] u16 TOSERVER_INIT
277                 [2] u8 SER_FMT_VER_HIGHEST
278                 [3] u8[20] player_name
279                 [23] u8[28] password (new in some version)
280                 [51] u16 client network protocol version (new in some version)
281         */
282
283         TOSERVER_INIT2 = 0x11,
284         /*
285                 Sent as an ACK for TOCLIENT_INIT.
286                 After this, the server can send data.
287
288                 [0] u16 TOSERVER_INIT2
289         */
290
291         TOSERVER_GETBLOCK=0x20, // Obsolete
292         TOSERVER_ADDNODE = 0x21, // Obsolete
293         TOSERVER_REMOVENODE = 0x22, // Obsolete
294
295         TOSERVER_PLAYERPOS = 0x23,
296         /*
297                 [0] u16 command
298                 [2] v3s32 position*100
299                 [2+12] v3s32 speed*100
300                 [2+12+12] s32 pitch*100
301                 [2+12+12+4] s32 yaw*100
302         */
303
304         TOSERVER_GOTBLOCKS = 0x24,
305         /*
306                 [0] u16 command
307                 [2] u8 count
308                 [3] v3s16 pos_0
309                 [3+6] v3s16 pos_1
310                 ...
311         */
312
313         TOSERVER_DELETEDBLOCKS = 0x25,
314         /*
315                 [0] u16 command
316                 [2] u8 count
317                 [3] v3s16 pos_0
318                 [3+6] v3s16 pos_1
319                 ...
320         */
321
322         TOSERVER_ADDNODE_FROM_INVENTORY = 0x26, // Obsolete
323         /*
324                 [0] u16 command
325                 [2] v3s16 pos
326                 [8] u16 i
327         */
328
329         TOSERVER_CLICK_OBJECT = 0x27, // Obsolete
330         /*
331                 length: 13
332                 [0] u16 command
333                 [2] u8 button (0=left, 1=right)
334                 [3] v3s16 blockpos
335                 [9] s16 id
336                 [11] u16 item
337         */
338
339         TOSERVER_GROUND_ACTION = 0x28, // Obsolete
340         /*
341                 length: 17
342                 [0] u16 command
343                 [2] u8 action
344                 [3] v3s16 nodepos_undersurface
345                 [9] v3s16 nodepos_abovesurface
346                 [15] u16 item
347                 actions:
348                 0: start digging (from undersurface)
349                 1: place block (to abovesurface)
350                 2: stop digging (all parameters ignored)
351                 3: digging completed
352         */
353         
354         TOSERVER_RELEASE = 0x29, // Obsolete
355
356         // (oops, there is some gap here)
357
358         TOSERVER_SIGNTEXT = 0x30, // Old signs, obsolete
359         /*
360                 u16 command
361                 v3s16 blockpos
362                 s16 id
363                 u16 textlen
364                 textdata
365         */
366
367         TOSERVER_INVENTORY_ACTION = 0x31,
368         /*
369                 See InventoryAction in inventory.h
370         */
371
372         TOSERVER_CHAT_MESSAGE = 0x32,
373         /*
374                 u16 command
375                 u16 length
376                 wstring message
377         */
378
379         TOSERVER_SIGNNODETEXT = 0x33,
380         /*
381                 u16 command
382                 v3s16 p
383                 u16 textlen
384                 textdata
385         */
386
387         TOSERVER_CLICK_ACTIVEOBJECT = 0x34, // Obsolete
388         /*
389                 length: 7
390                 [0] u16 command
391                 [2] u8 button (0=left, 1=right)
392                 [3] u16 id
393                 [5] u16 item
394         */
395         
396         TOSERVER_DAMAGE = 0x35,
397         /*
398                 u16 command
399                 u8 amount
400         */
401
402         TOSERVER_PASSWORD=0x36,
403         /*
404                 Sent to change password.
405
406                 [0] u16 TOSERVER_PASSWORD
407                 [2] u8[28] old password
408                 [30] u8[28] new password
409         */
410
411         TOSERVER_PLAYERITEM=0x37,
412         /*
413                 Sent to change selected item.
414
415                 [0] u16 TOSERVER_PLAYERITEM
416                 [2] u16 item
417         */
418         
419         TOSERVER_RESPAWN=0x38,
420         /*
421                 u16 TOSERVER_RESPAWN
422         */
423
424         TOSERVER_INTERACT = 0x39,
425         /*
426                 [0] u16 command
427                 [2] u8 action
428                 [3] u16 item
429                 [5] u32 length of the next item
430                 [9] serialized PointedThing
431                 actions:
432                 0: start digging (from undersurface) or use
433                 1: stop digging (all parameters ignored)
434                 2: digging completed
435                 3: place block or item (to abovesurface)
436                 4: use item
437
438                 (Obsoletes TOSERVER_GROUND_ACTION and TOSERVER_CLICK_ACTIVEOBJECT.)
439         */
440         
441         TOSERVER_REQUEST_TEXTURES = 0x40,
442
443         /*
444                         u16 command
445                         u16 number of textures requested
446                         for each texture {
447                                 u16 length of name
448                                 string name
449                         }
450          */
451
452 };
453
454 inline SharedBuffer<u8> makePacket_TOCLIENT_TIME_OF_DAY(u16 time)
455 {
456         SharedBuffer<u8> data(2+2);
457         writeU16(&data[0], TOCLIENT_TIME_OF_DAY);
458         writeU16(&data[2], time);
459         return data;
460 }
461
462 #endif
463