]> git.lizzy.rs Git - minetest.git/blob - src/clientserver.h
Improve node timer format (map format version 25) and update mapformat.txt
[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 Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser 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 "util/serialize.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_MEDIA
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         PROTOCOL_VERSION 8:
48                 Digging based on item groups
49                 Many things
50         PROTOCOL_VERSION 9:
51                 ContentFeatures and NodeDefManager use a different serialization
52                     format; better for future version cross-compatibility
53                 Many things
54         PROTOCOL_VERSION 10:
55                 TOCLIENT_PRIVILEGES
56                 Version raised to force 'fly' and 'fast' privileges into effect.
57                 Node metadata change (came in later; somewhat incompatible)
58         PROTOCOL_VERSION 11:
59                 TileDef in ContentFeatures
60                 Nodebox drawtype
61                 (some dev snapshot)
62                 TOCLIENT_INVENTORY_FORMSPEC
63                 (0.4.0, 0.4.1)
64         PROTOCOL_VERSION 12:
65                 TOSERVER_INVENTORY_FIELDS
66                 16-bit node ids
67 */
68
69 #define PROTOCOL_VERSION 12
70
71 #define PROTOCOL_ID 0x4f457403
72
73 #define PASSWORD_SIZE 28       // Maximum password length. Allows for
74                                // base64-encoded SHA-1 (27+\0).
75
76 #define TEXTURENAME_ALLOWED_CHARS "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_."
77
78 enum ToClientCommand
79 {
80         TOCLIENT_INIT = 0x10,
81         /*
82                 Server's reply to TOSERVER_INIT.
83                 Sent second after connected.
84
85                 [0] u16 TOSERVER_INIT
86                 [2] u8 deployed version
87                 [3] v3s16 player's position + v3f(0,BS/2,0) floatToInt'd 
88                 [12] u64 map seed (new as of 2011-02-27)
89
90                 NOTE: The position in here is deprecated; position is
91                       explicitly sent afterwards
92         */
93
94         TOCLIENT_BLOCKDATA = 0x20, //TODO: Multiple blocks
95         TOCLIENT_ADDNODE = 0x21,
96         TOCLIENT_REMOVENODE = 0x22,
97         
98         TOCLIENT_PLAYERPOS = 0x23, // Obsolete
99         /*
100                 [0] u16 command
101                 // Followed by an arbitary number of these:
102                 // Number is determined from packet length.
103                 [N] u16 peer_id
104                 [N+2] v3s32 position*100
105                 [N+2+12] v3s32 speed*100
106                 [N+2+12+12] s32 pitch*100
107                 [N+2+12+12+4] s32 yaw*100
108         */
109
110         TOCLIENT_PLAYERINFO = 0x24, // Obsolete
111         /*
112                 [0] u16 command
113                 // Followed by an arbitary number of these:
114                 // Number is determined from packet length.
115                 [N] u16 peer_id
116                 [N] char[20] name
117         */
118         
119         TOCLIENT_OPT_BLOCK_NOT_FOUND = 0x25, // Obsolete
120
121         TOCLIENT_SECTORMETA = 0x26, // Obsolete
122         /*
123                 [0] u16 command
124                 [2] u8 sector count
125                 [3...] v2s16 pos + sector metadata
126         */
127
128         TOCLIENT_INVENTORY = 0x27,
129         /*
130                 [0] u16 command
131                 [2] serialized inventory
132         */
133         
134         TOCLIENT_OBJECTDATA = 0x28, // Obsolete
135         /*
136                 Sent as unreliable.
137
138                 u16 command
139                 u16 number of player positions
140                 for each player:
141                         u16 peer_id
142                         v3s32 position*100
143                         v3s32 speed*100
144                         s32 pitch*100
145                         s32 yaw*100
146                 u16 count of blocks
147                 for each block:
148                         v3s16 blockpos
149                         block objects
150         */
151
152         TOCLIENT_TIME_OF_DAY = 0x29,
153         /*
154                 u16 command
155                 u16 time (0-23999)
156                 Added in a later version:
157                 f1000 time_speed
158         */
159
160         // (oops, there is some gap here)
161
162         TOCLIENT_CHAT_MESSAGE = 0x30,
163         /*
164                 u16 command
165                 u16 length
166                 wstring message
167         */
168
169         TOCLIENT_ACTIVE_OBJECT_REMOVE_ADD = 0x31,
170         /*
171                 u16 command
172                 u16 count of removed objects
173                 for all removed objects {
174                         u16 id
175                 }
176                 u16 count of added objects
177                 for all added objects {
178                         u16 id
179                         u8 type
180                         u32 initialization data length
181                         string initialization data
182                 }
183         */
184         
185         TOCLIENT_ACTIVE_OBJECT_MESSAGES = 0x32,
186         /*
187                 u16 command
188                 for all objects
189                 {
190                         u16 id
191                         u16 message length
192                         string message
193                 }
194         */
195
196         TOCLIENT_HP = 0x33,
197         /*
198                 u16 command
199                 u8 hp
200         */
201
202         TOCLIENT_MOVE_PLAYER = 0x34,
203         /*
204                 u16 command
205                 v3f1000 player position
206                 f1000 player pitch
207                 f1000 player yaw
208         */
209
210         TOCLIENT_ACCESS_DENIED = 0x35,
211         /*
212                 u16 command
213                 u16 reason_length
214                 wstring reason
215         */
216
217         TOCLIENT_PLAYERITEM = 0x36, // Obsolete
218         /*
219                 u16 command
220                 u16 count of player items
221                 for all player items {
222                         u16 peer id
223                         u16 length of serialized item
224                         string serialized item
225                 }
226         */
227
228         TOCLIENT_DEATHSCREEN = 0x37,
229         /*
230                 u16 command
231                 u8 bool set camera point target
232                 v3f1000 camera point target (to point the death cause or whatever)
233         */
234
235         TOCLIENT_MEDIA = 0x38,
236         /*
237                 u16 command
238                 u16 total number of texture bunches
239                 u16 index of this bunch
240                 u32 number of files in this bunch
241                 for each file {
242                         u16 length of name
243                         string name
244                         u32 length of data
245                         data
246                 }
247         */
248         
249         TOCLIENT_TOOLDEF = 0x39,
250         /*
251                 u16 command
252                 u32 length of the next item
253                 serialized ToolDefManager
254         */
255         
256         TOCLIENT_NODEDEF = 0x3a,
257         /*
258                 u16 command
259                 u32 length of the next item
260                 serialized NodeDefManager
261         */
262         
263         TOCLIENT_CRAFTITEMDEF = 0x3b,
264         /*
265                 u16 command
266                 u32 length of the next item
267                 serialized CraftiItemDefManager
268         */
269
270         TOCLIENT_ANNOUNCE_MEDIA = 0x3c,
271
272         /*
273                 u16 command
274                 u32 number of files
275                 for each texture {
276                         u16 length of name
277                         string name
278                         u16 length of sha1_digest
279                         string sha1_digest
280                 }
281         */
282
283         TOCLIENT_ITEMDEF = 0x3d,
284         /*
285                 u16 command
286                 u32 length of next item
287                 serialized ItemDefManager
288         */
289         
290         TOCLIENT_PLAY_SOUND = 0x3f,
291         /*
292                 u16 command
293                 s32 sound_id
294                 u16 len
295                 u8[len] sound name
296                 s32 gain*1000
297                 u8 type (0=local, 1=positional, 2=object)
298                 s32[3] pos_nodes*10000
299                 u16 object_id
300                 u8 loop (bool)
301         */
302
303         TOCLIENT_STOP_SOUND = 0x40,
304         /*
305                 u16 command
306                 s32 sound_id
307         */
308
309         TOCLIENT_PRIVILEGES = 0x41,
310         /*
311                 u16 command
312                 u16 number of privileges
313                 for each privilege
314                         u16 len
315                         u8[len] privilege
316         */
317
318         TOCLIENT_INVENTORY_FORMSPEC = 0x42,
319         /*
320                 u16 command
321                 u32 len
322                 u8[len] formspec
323         */
324 };
325
326 enum ToServerCommand
327 {
328         TOSERVER_INIT=0x10,
329         /*
330                 Sent first after connected.
331
332                 [0] u16 TOSERVER_INIT
333                 [2] u8 SER_FMT_VER_HIGHEST
334                 [3] u8[20] player_name
335                 [23] u8[28] password (new in some version)
336                 [51] u16 client network protocol version (new in some version)
337         */
338
339         TOSERVER_INIT2 = 0x11,
340         /*
341                 Sent as an ACK for TOCLIENT_INIT.
342                 After this, the server can send data.
343
344                 [0] u16 TOSERVER_INIT2
345         */
346
347         TOSERVER_GETBLOCK=0x20, // Obsolete
348         TOSERVER_ADDNODE = 0x21, // Obsolete
349         TOSERVER_REMOVENODE = 0x22, // Obsolete
350
351         TOSERVER_PLAYERPOS = 0x23,
352         /*
353                 [0] u16 command
354                 [2] v3s32 position*100
355                 [2+12] v3s32 speed*100
356                 [2+12+12] s32 pitch*100
357                 [2+12+12+4] s32 yaw*100
358         */
359
360         TOSERVER_GOTBLOCKS = 0x24,
361         /*
362                 [0] u16 command
363                 [2] u8 count
364                 [3] v3s16 pos_0
365                 [3+6] v3s16 pos_1
366                 ...
367         */
368
369         TOSERVER_DELETEDBLOCKS = 0x25,
370         /*
371                 [0] u16 command
372                 [2] u8 count
373                 [3] v3s16 pos_0
374                 [3+6] v3s16 pos_1
375                 ...
376         */
377
378         TOSERVER_ADDNODE_FROM_INVENTORY = 0x26, // Obsolete
379         /*
380                 [0] u16 command
381                 [2] v3s16 pos
382                 [8] u16 i
383         */
384
385         TOSERVER_CLICK_OBJECT = 0x27, // Obsolete
386         /*
387                 length: 13
388                 [0] u16 command
389                 [2] u8 button (0=left, 1=right)
390                 [3] v3s16 blockpos
391                 [9] s16 id
392                 [11] u16 item
393         */
394
395         TOSERVER_GROUND_ACTION = 0x28, // Obsolete
396         /*
397                 length: 17
398                 [0] u16 command
399                 [2] u8 action
400                 [3] v3s16 nodepos_undersurface
401                 [9] v3s16 nodepos_abovesurface
402                 [15] u16 item
403                 actions:
404                 0: start digging (from undersurface)
405                 1: place block (to abovesurface)
406                 2: stop digging (all parameters ignored)
407                 3: digging completed
408         */
409         
410         TOSERVER_RELEASE = 0x29, // Obsolete
411
412         // (oops, there is some gap here)
413
414         TOSERVER_SIGNTEXT = 0x30, // Old signs, obsolete
415         /*
416                 u16 command
417                 v3s16 blockpos
418                 s16 id
419                 u16 textlen
420                 textdata
421         */
422
423         TOSERVER_INVENTORY_ACTION = 0x31,
424         /*
425                 See InventoryAction in inventory.h
426         */
427
428         TOSERVER_CHAT_MESSAGE = 0x32,
429         /*
430                 u16 command
431                 u16 length
432                 wstring message
433         */
434
435         TOSERVER_SIGNNODETEXT = 0x33, // obsolete
436         /*
437                 u16 command
438                 v3s16 p
439                 u16 textlen
440                 textdata
441         */
442
443         TOSERVER_CLICK_ACTIVEOBJECT = 0x34, // Obsolete
444         /*
445                 length: 7
446                 [0] u16 command
447                 [2] u8 button (0=left, 1=right)
448                 [3] u16 id
449                 [5] u16 item
450         */
451         
452         TOSERVER_DAMAGE = 0x35,
453         /*
454                 u16 command
455                 u8 amount
456         */
457
458         TOSERVER_PASSWORD=0x36,
459         /*
460                 Sent to change password.
461
462                 [0] u16 TOSERVER_PASSWORD
463                 [2] u8[28] old password
464                 [30] u8[28] new password
465         */
466
467         TOSERVER_PLAYERITEM=0x37,
468         /*
469                 Sent to change selected item.
470
471                 [0] u16 TOSERVER_PLAYERITEM
472                 [2] u16 item
473         */
474         
475         TOSERVER_RESPAWN=0x38,
476         /*
477                 u16 TOSERVER_RESPAWN
478         */
479
480         TOSERVER_INTERACT = 0x39,
481         /*
482                 [0] u16 command
483                 [2] u8 action
484                 [3] u16 item
485                 [5] u32 length of the next item
486                 [9] serialized PointedThing
487                 actions:
488                 0: start digging (from undersurface) or use
489                 1: stop digging (all parameters ignored)
490                 2: digging completed
491                 3: place block or item (to abovesurface)
492                 4: use item
493
494                 (Obsoletes TOSERVER_GROUND_ACTION and TOSERVER_CLICK_ACTIVEOBJECT.)
495         */
496         
497         TOSERVER_REMOVED_SOUNDS = 0x3a,
498         /*
499                 u16 command
500                 u16 len
501                 s32[len] sound_id
502         */
503
504         TOSERVER_NODEMETA_FIELDS = 0x3b,
505         /*
506                 u16 command
507                 v3s16 p
508                 u16 len
509                 u8[len] form name (reserved for future use)
510                 u16 number of fields
511                 for each field:
512                         u16 len
513                         u8[len] field name
514                         u32 len
515                         u8[len] field value
516         */
517
518         TOSERVER_INVENTORY_FIELDS = 0x3c,
519         /*
520                 u16 command
521                 u16 len
522                 u8[len] form name (reserved for future use)
523                 u16 number of fields
524                 for each field:
525                         u16 len
526                         u8[len] field name
527                         u32 len
528                         u8[len] field value
529         */
530
531         TOSERVER_REQUEST_MEDIA = 0x40,
532         /*
533                 u16 command
534                 u16 number of files requested
535                 for each file {
536                         u16 length of name
537                         string name
538                 }
539          */
540
541 };
542
543 inline SharedBuffer<u8> makePacket_TOCLIENT_TIME_OF_DAY(u16 time, float time_speed)
544 {
545         SharedBuffer<u8> data(2+2+4);
546         writeU16(&data[0], TOCLIENT_TIME_OF_DAY);
547         writeU16(&data[2], time);
548         writeF1000(&data[4], time_speed);
549         return data;
550 }
551
552 #endif
553