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