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