]> git.lizzy.rs Git - minetest.git/blob - src/clientserver.h
Run updatepo.sh
[minetest.git] / src / clientserver.h
1 /*
2 Minetest
3 Copyright (C) 2010-2013 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 /*
24         changes by PROTOCOL_VERSION:
25
26         PROTOCOL_VERSION 3:
27                 Base for writing changes here
28         PROTOCOL_VERSION 4:
29                 Add TOCLIENT_MEDIA
30                 Add TOCLIENT_TOOLDEF
31                 Add TOCLIENT_NODEDEF
32                 Add TOCLIENT_CRAFTITEMDEF
33                 Add TOSERVER_INTERACT
34                 Obsolete TOSERVER_CLICK_ACTIVEOBJECT
35                 Obsolete TOSERVER_GROUND_ACTION
36         PROTOCOL_VERSION 5:
37                 Make players to be handled mostly as ActiveObjects
38         PROTOCOL_VERSION 6:
39                 Only non-cached textures are sent
40         PROTOCOL_VERSION 7:
41                 Add TOCLIENT_ITEMDEF
42                 Obsolete TOCLIENT_TOOLDEF
43                 Obsolete TOCLIENT_CRAFTITEMDEF
44                 Compress the contents of TOCLIENT_ITEMDEF and TOCLIENT_NODEDEF
45         PROTOCOL_VERSION 8:
46                 Digging based on item groups
47                 Many things
48         PROTOCOL_VERSION 9:
49                 ContentFeatures and NodeDefManager use a different serialization
50                     format; better for future version cross-compatibility
51                 Many things
52         PROTOCOL_VERSION 10:
53                 TOCLIENT_PRIVILEGES
54                 Version raised to force 'fly' and 'fast' privileges into effect.
55                 Node metadata change (came in later; somewhat incompatible)
56         PROTOCOL_VERSION 11:
57                 TileDef in ContentFeatures
58                 Nodebox drawtype
59                 (some dev snapshot)
60                 TOCLIENT_INVENTORY_FORMSPEC
61                 (0.4.0, 0.4.1)
62         PROTOCOL_VERSION 12:
63                 TOSERVER_INVENTORY_FIELDS
64                 16-bit node ids
65                 TOCLIENT_DETACHED_INVENTORY
66         PROTOCOL_VERSION 13:
67                 InventoryList field "Width" (deserialization fails with old versions)
68         PROTOCOL_VERSION 14:
69                 Added transfer of player pressed keys to the server
70                 Added new messages for mesh and bone animation, as well as attachments
71                 GENERIC_CMD_SET_ANIMATION
72                 GENERIC_CMD_SET_BONE_POSITION
73                 GENERIC_CMD_SET_ATTACHMENT
74         PROTOCOL_VERSION 15:
75                 Serialization format changes
76         PROTOCOL_VERSION 16:
77                 TOCLIENT_SHOW_FORMSPEC
78         PROTOCOL_VERSION 17:
79                 Serialization format change: include backface_culling flag in TileDef
80                 Added rightclickable field in nodedef
81                 TOCLIENT_SPAWN_PARTICLE
82                 TOCLIENT_ADD_PARTICLESPAWNER
83                 TOCLIENT_DELETE_PARTICLESPAWNER
84         PROTOCOL_VERSION 18:
85                 damageGroups added to ToolCapabilities
86                 sound_place added to ItemDefinition
87         PROTOCOL_VERSION 19:
88                 GENERIC_CMD_SET_PHYSICS_OVERRIDE
89         PROTOCOL_VERSION 20:
90                 TOCLIENT_HUDADD
91                 TOCLIENT_HUDRM
92                 TOCLIENT_HUDCHANGE
93                 TOCLIENT_HUD_SET_FLAGS
94         PROTOCOL_VERSION 21:
95                 TOCLIENT_BREATH
96                 TOSERVER_BREATH
97                 range added to ItemDefinition
98                 drowning, leveled and liquid_range added to ContentFeatures
99                 stepheight and collideWithObjects added to object properties
100                 version, heat and humidity transfer in MapBock
101                 automatic_face_movement_dir and automatic_face_movement_dir_offset
102                         added to object properties
103 */
104
105 #define LATEST_PROTOCOL_VERSION 21
106
107 // Server's supported network protocol range
108 #define SERVER_PROTOCOL_VERSION_MIN 13
109 #define SERVER_PROTOCOL_VERSION_MAX LATEST_PROTOCOL_VERSION
110
111 // Client's supported network protocol range
112 #define CLIENT_PROTOCOL_VERSION_MIN 13
113 #define CLIENT_PROTOCOL_VERSION_MAX LATEST_PROTOCOL_VERSION
114
115 // Constant that differentiates the protocol from random data and other protocols
116 #define PROTOCOL_ID 0x4f457403
117
118 #define PASSWORD_SIZE 28       // Maximum password length. Allows for
119                                // base64-encoded SHA-1 (27+\0).
120
121 #define TEXTURENAME_ALLOWED_CHARS "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_."
122
123 enum ToClientCommand
124 {
125         TOCLIENT_INIT = 0x10,
126         /*
127                 Server's reply to TOSERVER_INIT.
128                 Sent second after connected.
129
130                 [0] u16 TOSERVER_INIT
131                 [2] u8 deployed version
132                 [3] v3s16 player's position + v3f(0,BS/2,0) floatToInt'd 
133                 [12] u64 map seed (new as of 2011-02-27)
134                 [20] f1000 recommended send interval (in seconds) (new as of 14)
135
136                 NOTE: The position in here is deprecated; position is
137                       explicitly sent afterwards
138         */
139
140         TOCLIENT_BLOCKDATA = 0x20, //TODO: Multiple blocks
141         TOCLIENT_ADDNODE = 0x21,
142         TOCLIENT_REMOVENODE = 0x22,
143         
144         TOCLIENT_PLAYERPOS = 0x23, // Obsolete
145         /*
146                 [0] u16 command
147                 // Followed by an arbitary number of these:
148                 // Number is determined from packet length.
149                 [N] u16 peer_id
150                 [N+2] v3s32 position*100
151                 [N+2+12] v3s32 speed*100
152                 [N+2+12+12] s32 pitch*100
153                 [N+2+12+12+4] s32 yaw*100
154         */
155
156         TOCLIENT_PLAYERINFO = 0x24, // Obsolete
157         /*
158                 [0] u16 command
159                 // Followed by an arbitary number of these:
160                 // Number is determined from packet length.
161                 [N] u16 peer_id
162                 [N] char[20] name
163         */
164         
165         TOCLIENT_OPT_BLOCK_NOT_FOUND = 0x25, // Obsolete
166
167         TOCLIENT_SECTORMETA = 0x26, // Obsolete
168         /*
169                 [0] u16 command
170                 [2] u8 sector count
171                 [3...] v2s16 pos + sector metadata
172         */
173
174         TOCLIENT_INVENTORY = 0x27,
175         /*
176                 [0] u16 command
177                 [2] serialized inventory
178         */
179         
180         TOCLIENT_OBJECTDATA = 0x28, // Obsolete
181         /*
182                 Sent as unreliable.
183
184                 u16 command
185                 u16 number of player positions
186                 for each player:
187                         u16 peer_id
188                         v3s32 position*100
189                         v3s32 speed*100
190                         s32 pitch*100
191                         s32 yaw*100
192                 u16 count of blocks
193                 for each block:
194                         v3s16 blockpos
195                         block objects
196         */
197
198         TOCLIENT_TIME_OF_DAY = 0x29,
199         /*
200                 u16 command
201                 u16 time (0-23999)
202                 Added in a later version:
203                 f1000 time_speed
204         */
205
206         // (oops, there is some gap here)
207
208         TOCLIENT_CHAT_MESSAGE = 0x30,
209         /*
210                 u16 command
211                 u16 length
212                 wstring message
213         */
214
215         TOCLIENT_ACTIVE_OBJECT_REMOVE_ADD = 0x31,
216         /*
217                 u16 command
218                 u16 count of removed objects
219                 for all removed objects {
220                         u16 id
221                 }
222                 u16 count of added objects
223                 for all added objects {
224                         u16 id
225                         u8 type
226                         u32 initialization data length
227                         string initialization data
228                 }
229         */
230         
231         TOCLIENT_ACTIVE_OBJECT_MESSAGES = 0x32,
232         /*
233                 u16 command
234                 for all objects
235                 {
236                         u16 id
237                         u16 message length
238                         string message
239                 }
240         */
241
242         TOCLIENT_HP = 0x33,
243         /*
244                 u16 command
245                 u8 hp
246         */
247
248         TOCLIENT_MOVE_PLAYER = 0x34,
249         /*
250                 u16 command
251                 v3f1000 player position
252                 f1000 player pitch
253                 f1000 player yaw
254         */
255
256         TOCLIENT_ACCESS_DENIED = 0x35,
257         /*
258                 u16 command
259                 u16 reason_length
260                 wstring reason
261         */
262
263         TOCLIENT_PLAYERITEM = 0x36, // Obsolete
264         /*
265                 u16 command
266                 u16 count of player items
267                 for all player items {
268                         u16 peer id
269                         u16 length of serialized item
270                         string serialized item
271                 }
272         */
273
274         TOCLIENT_DEATHSCREEN = 0x37,
275         /*
276                 u16 command
277                 u8 bool set camera point target
278                 v3f1000 camera point target (to point the death cause or whatever)
279         */
280
281         TOCLIENT_MEDIA = 0x38,
282         /*
283                 u16 command
284                 u16 total number of texture bunches
285                 u16 index of this bunch
286                 u32 number of files in this bunch
287                 for each file {
288                         u16 length of name
289                         string name
290                         u32 length of data
291                         data
292                 }
293                 u16 length of remote media server url (if applicable)
294                 string url
295         */
296         
297         TOCLIENT_TOOLDEF = 0x39,
298         /*
299                 u16 command
300                 u32 length of the next item
301                 serialized ToolDefManager
302         */
303         
304         TOCLIENT_NODEDEF = 0x3a,
305         /*
306                 u16 command
307                 u32 length of the next item
308                 serialized NodeDefManager
309         */
310         
311         TOCLIENT_CRAFTITEMDEF = 0x3b,
312         /*
313                 u16 command
314                 u32 length of the next item
315                 serialized CraftiItemDefManager
316         */
317
318         TOCLIENT_ANNOUNCE_MEDIA = 0x3c,
319
320         /*
321                 u16 command
322                 u32 number of files
323                 for each texture {
324                         u16 length of name
325                         string name
326                         u16 length of sha1_digest
327                         string sha1_digest
328                 }
329         */
330
331         TOCLIENT_ITEMDEF = 0x3d,
332         /*
333                 u16 command
334                 u32 length of next item
335                 serialized ItemDefManager
336         */
337         
338         TOCLIENT_PLAY_SOUND = 0x3f,
339         /*
340                 u16 command
341                 s32 sound_id
342                 u16 len
343                 u8[len] sound name
344                 s32 gain*1000
345                 u8 type (0=local, 1=positional, 2=object)
346                 s32[3] pos_nodes*10000
347                 u16 object_id
348                 u8 loop (bool)
349         */
350
351         TOCLIENT_STOP_SOUND = 0x40,
352         /*
353                 u16 command
354                 s32 sound_id
355         */
356
357         TOCLIENT_PRIVILEGES = 0x41,
358         /*
359                 u16 command
360                 u16 number of privileges
361                 for each privilege
362                         u16 len
363                         u8[len] privilege
364         */
365
366         TOCLIENT_INVENTORY_FORMSPEC = 0x42,
367         /*
368                 u16 command
369                 u32 len
370                 u8[len] formspec
371         */
372
373         TOCLIENT_DETACHED_INVENTORY = 0x43,
374         /*
375                 [0] u16 command
376                 u16 len
377                 u8[len] name
378                 [2] serialized inventory
379         */
380
381         TOCLIENT_SHOW_FORMSPEC = 0x44,
382         /*
383                 [0] u16 command
384                 u32 len
385                 u8[len] formspec
386                 u16 len
387                 u8[len] formname
388         */
389
390         TOCLIENT_MOVEMENT = 0x45,
391         /*
392                 u16 command
393                 f1000 movement_acceleration_default
394                 f1000 movement_acceleration_air
395                 f1000 movement_acceleration_fast
396                 f1000 movement_speed_walk
397                 f1000 movement_speed_crouch
398                 f1000 movement_speed_fast
399                 f1000 movement_speed_climb
400                 f1000 movement_speed_jump
401                 f1000 movement_liquid_fluidity
402                 f1000 movement_liquid_fluidity_smooth
403                 f1000 movement_liquid_sink
404                 f1000 movement_gravity
405         */
406
407         TOCLIENT_SPAWN_PARTICLE = 0x46,
408         /*
409                 u16 command
410                 v3f1000 pos
411                 v3f1000 velocity
412                 v3f1000 acceleration
413                 f1000 expirationtime
414                 f1000 size
415                 u8 bool collisiondetection
416                 u32 len
417                 u8[len] texture
418         */
419
420         TOCLIENT_ADD_PARTICLESPAWNER = 0x47,
421         /*
422                 u16 command
423                 u16 amount
424                 f1000 spawntime
425                 v3f1000 minpos
426                 v3f1000 maxpos
427                 v3f1000 minvel
428                 v3f1000 maxvel
429                 v3f1000 minacc
430                 v3f1000 maxacc
431                 f1000 minexptime
432                 f1000 maxexptime
433                 f1000 minsize
434                 f1000 maxsize
435                 u8 bool collisiondetection
436                 u32 len
437                 u8[len] texture
438                 u32 id
439         */
440
441         TOCLIENT_DELETE_PARTICLESPAWNER = 0x48,
442         /*
443                 u16 command
444                 u32 id
445         */
446
447         TOCLIENT_HUDADD = 0x49,
448         /*
449                 u16 command
450                 u32 id
451                 u8 type
452                 v2f1000 pos
453                 u32 len
454                 u8[len] name
455                 v2f1000 scale
456                 u32 len2
457                 u8[len2] text
458                 u32 number
459                 u32 item
460                 u32 dir
461                 v2f1000 align
462                 v2f1000 offset
463         */
464
465         TOCLIENT_HUDRM = 0x4a,
466         /*
467                 u16 command
468                 u32 id
469         */
470
471         TOCLIENT_HUDCHANGE = 0x4b,
472         /*
473                 u16 command
474                 u32 id
475                 u8 stat
476                 [v2f1000 data |
477                  u32 len
478                  u8[len] data |
479                  u32 data]
480         */
481
482         TOCLIENT_HUD_SET_FLAGS = 0x4c,
483         /*
484                 u16 command
485                 u32 flags
486                 u32 mask
487         */
488
489         TOCLIENT_HUD_SET_PARAM = 0x4d,
490         /*
491                 u16 command
492                 u16 param
493                 u16 len
494                 u8[len] value
495         */
496
497         TOCLIENT_BREATH = 0x4e,
498         /*
499                 u16 command
500                 u16 breath
501         */
502 };
503
504 enum ToServerCommand
505 {
506         TOSERVER_INIT=0x10,
507         /*
508                 Sent first after connected.
509
510                 [0] u16 TOSERVER_INIT
511                 [2] u8 SER_FMT_VER_HIGHEST_READ
512                 [3] u8[20] player_name
513                 [23] u8[28] password (new in some version)
514                 [51] u16 minimum supported network protocol version (added sometime)
515                 [53] u16 maximum supported network protocol version (added later than the previous one)
516         */
517
518         TOSERVER_INIT2 = 0x11,
519         /*
520                 Sent as an ACK for TOCLIENT_INIT.
521                 After this, the server can send data.
522
523                 [0] u16 TOSERVER_INIT2
524         */
525
526         TOSERVER_GETBLOCK=0x20, // Obsolete
527         TOSERVER_ADDNODE = 0x21, // Obsolete
528         TOSERVER_REMOVENODE = 0x22, // Obsolete
529
530         TOSERVER_PLAYERPOS = 0x23,
531         /*
532                 [0] u16 command
533                 [2] v3s32 position*100
534                 [2+12] v3s32 speed*100
535                 [2+12+12] s32 pitch*100
536                 [2+12+12+4] s32 yaw*100
537                 [2+12+12+4+4] u32 keyPressed
538         */
539
540         TOSERVER_GOTBLOCKS = 0x24,
541         /*
542                 [0] u16 command
543                 [2] u8 count
544                 [3] v3s16 pos_0
545                 [3+6] v3s16 pos_1
546                 ...
547         */
548
549         TOSERVER_DELETEDBLOCKS = 0x25,
550         /*
551                 [0] u16 command
552                 [2] u8 count
553                 [3] v3s16 pos_0
554                 [3+6] v3s16 pos_1
555                 ...
556         */
557
558         TOSERVER_ADDNODE_FROM_INVENTORY = 0x26, // Obsolete
559         /*
560                 [0] u16 command
561                 [2] v3s16 pos
562                 [8] u16 i
563         */
564
565         TOSERVER_CLICK_OBJECT = 0x27, // Obsolete
566         /*
567                 length: 13
568                 [0] u16 command
569                 [2] u8 button (0=left, 1=right)
570                 [3] v3s16 blockpos
571                 [9] s16 id
572                 [11] u16 item
573         */
574
575         TOSERVER_GROUND_ACTION = 0x28, // Obsolete
576         /*
577                 length: 17
578                 [0] u16 command
579                 [2] u8 action
580                 [3] v3s16 nodepos_undersurface
581                 [9] v3s16 nodepos_abovesurface
582                 [15] u16 item
583                 actions:
584                 0: start digging (from undersurface)
585                 1: place block (to abovesurface)
586                 2: stop digging (all parameters ignored)
587                 3: digging completed
588         */
589         
590         TOSERVER_RELEASE = 0x29, // Obsolete
591
592         // (oops, there is some gap here)
593
594         TOSERVER_SIGNTEXT = 0x30, // Old signs, obsolete
595         /*
596                 u16 command
597                 v3s16 blockpos
598                 s16 id
599                 u16 textlen
600                 textdata
601         */
602
603         TOSERVER_INVENTORY_ACTION = 0x31,
604         /*
605                 See InventoryAction in inventory.h
606         */
607
608         TOSERVER_CHAT_MESSAGE = 0x32,
609         /*
610                 u16 command
611                 u16 length
612                 wstring message
613         */
614
615         TOSERVER_SIGNNODETEXT = 0x33, // obsolete
616         /*
617                 u16 command
618                 v3s16 p
619                 u16 textlen
620                 textdata
621         */
622
623         TOSERVER_CLICK_ACTIVEOBJECT = 0x34, // Obsolete
624         /*
625                 length: 7
626                 [0] u16 command
627                 [2] u8 button (0=left, 1=right)
628                 [3] u16 id
629                 [5] u16 item
630         */
631         
632         TOSERVER_DAMAGE = 0x35,
633         /*
634                 u16 command
635                 u8 amount
636         */
637
638         TOSERVER_PASSWORD=0x36,
639         /*
640                 Sent to change password.
641
642                 [0] u16 TOSERVER_PASSWORD
643                 [2] u8[28] old password
644                 [30] u8[28] new password
645         */
646
647         TOSERVER_PLAYERITEM=0x37,
648         /*
649                 Sent to change selected item.
650
651                 [0] u16 TOSERVER_PLAYERITEM
652                 [2] u16 item
653         */
654         
655         TOSERVER_RESPAWN=0x38,
656         /*
657                 u16 TOSERVER_RESPAWN
658         */
659
660         TOSERVER_INTERACT = 0x39,
661         /*
662                 [0] u16 command
663                 [2] u8 action
664                 [3] u16 item
665                 [5] u32 length of the next item
666                 [9] serialized PointedThing
667                 actions:
668                 0: start digging (from undersurface) or use
669                 1: stop digging (all parameters ignored)
670                 2: digging completed
671                 3: place block or item (to abovesurface)
672                 4: use item
673
674                 (Obsoletes TOSERVER_GROUND_ACTION and TOSERVER_CLICK_ACTIVEOBJECT.)
675         */
676         
677         TOSERVER_REMOVED_SOUNDS = 0x3a,
678         /*
679                 u16 command
680                 u16 len
681                 s32[len] sound_id
682         */
683
684         TOSERVER_NODEMETA_FIELDS = 0x3b,
685         /*
686                 u16 command
687                 v3s16 p
688                 u16 len
689                 u8[len] form name (reserved for future use)
690                 u16 number of fields
691                 for each field:
692                         u16 len
693                         u8[len] field name
694                         u32 len
695                         u8[len] field value
696         */
697
698         TOSERVER_INVENTORY_FIELDS = 0x3c,
699         /*
700                 u16 command
701                 u16 len
702                 u8[len] form name (reserved for future use)
703                 u16 number of fields
704                 for each field:
705                         u16 len
706                         u8[len] field name
707                         u32 len
708                         u8[len] field value
709         */
710
711         TOSERVER_REQUEST_MEDIA = 0x40,
712         /*
713                 u16 command
714                 u16 number of files requested
715                 for each file {
716                         u16 length of name
717                         string name
718                 }
719          */
720
721         TOSERVER_RECEIVED_MEDIA = 0x41,
722         /*
723                 u16 command
724         */
725
726         TOSERVER_BREATH = 0x42,
727         /*
728                 u16 command
729                 u16 breath
730         */
731 };
732
733 #endif
734