]> git.lizzy.rs Git - dragonfireclient.git/blob - src/clientserver.h
a8cd2ea70d119c11118cc7d67c9432dbe1443bd9
[dragonfireclient.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         */
476
477         TOCLIENT_HUDRM = 0x4a,
478         /*
479                 u16 command
480                 u32 id
481         */
482
483         TOCLIENT_HUDCHANGE = 0x4b,
484         /*
485                 u16 command
486                 u32 id
487                 u8 stat
488                 [v2f1000 data |
489                  u32 len
490                  u8[len] data |
491                  u32 data]
492         */
493
494         TOCLIENT_HUD_SET_FLAGS = 0x4c,
495         /*
496                 u16 command
497                 u32 flags
498                 u32 mask
499         */
500
501         TOCLIENT_HUD_SET_PARAM = 0x4d,
502         /*
503                 u16 command
504                 u16 param
505                 u16 len
506                 u8[len] value
507         */
508
509         TOCLIENT_BREATH = 0x4e,
510         /*
511                 u16 command
512                 u16 breath
513         */
514
515         TOCLIENT_SET_SKY = 0x4f,
516         /*
517                 u16 command
518                 u8[4] color (ARGB)
519                 u8 len
520                 u8[len] type
521                 u16 count
522                 foreach count:
523                         u8 len
524                         u8[len] param
525         */
526
527         TOCLIENT_OVERRIDE_DAY_NIGHT_RATIO = 0x50,
528         /*
529                 u16 command
530                 u8 do_override (boolean)
531                 u16 day-night ratio 0...65535
532         */
533         
534         TOCLIENT_LOCAL_PLAYER_ANIMATIONS = 0x51,
535         /*
536                 u16 command
537                 v2f1000 stand/idle
538                 v2f1000 walk
539                 v2f1000 dig
540                 v2f1000 walk+dig
541                 f1000 frame_speed
542         */
543
544         TOCLIENT_EYE_OFFSET = 0x52,
545         /*
546                 u16 command
547                 v3f1000 first
548                 v3f1000 third
549         */
550 };
551
552 enum ToServerCommand
553 {
554         TOSERVER_INIT=0x10,
555         /*
556                 Sent first after connected.
557
558                 [0] u16 TOSERVER_INIT
559                 [2] u8 SER_FMT_VER_HIGHEST_READ
560                 [3] u8[20] player_name
561                 [23] u8[28] password (new in some version)
562                 [51] u16 minimum supported network protocol version (added sometime)
563                 [53] u16 maximum supported network protocol version (added later than the previous one)
564         */
565
566         TOSERVER_INIT2 = 0x11,
567         /*
568                 Sent as an ACK for TOCLIENT_INIT.
569                 After this, the server can send data.
570
571                 [0] u16 TOSERVER_INIT2
572         */
573
574         TOSERVER_GETBLOCK=0x20, // Obsolete
575         TOSERVER_ADDNODE = 0x21, // Obsolete
576         TOSERVER_REMOVENODE = 0x22, // Obsolete
577
578         TOSERVER_PLAYERPOS = 0x23,
579         /*
580                 [0] u16 command
581                 [2] v3s32 position*100
582                 [2+12] v3s32 speed*100
583                 [2+12+12] s32 pitch*100
584                 [2+12+12+4] s32 yaw*100
585                 [2+12+12+4+4] u32 keyPressed
586         */
587
588         TOSERVER_GOTBLOCKS = 0x24,
589         /*
590                 [0] u16 command
591                 [2] u8 count
592                 [3] v3s16 pos_0
593                 [3+6] v3s16 pos_1
594                 ...
595         */
596
597         TOSERVER_DELETEDBLOCKS = 0x25,
598         /*
599                 [0] u16 command
600                 [2] u8 count
601                 [3] v3s16 pos_0
602                 [3+6] v3s16 pos_1
603                 ...
604         */
605
606         TOSERVER_ADDNODE_FROM_INVENTORY = 0x26, // Obsolete
607         /*
608                 [0] u16 command
609                 [2] v3s16 pos
610                 [8] u16 i
611         */
612
613         TOSERVER_CLICK_OBJECT = 0x27, // Obsolete
614         /*
615                 length: 13
616                 [0] u16 command
617                 [2] u8 button (0=left, 1=right)
618                 [3] v3s16 blockpos
619                 [9] s16 id
620                 [11] u16 item
621         */
622
623         TOSERVER_GROUND_ACTION = 0x28, // Obsolete
624         /*
625                 length: 17
626                 [0] u16 command
627                 [2] u8 action
628                 [3] v3s16 nodepos_undersurface
629                 [9] v3s16 nodepos_abovesurface
630                 [15] u16 item
631                 actions:
632                 0: start digging (from undersurface)
633                 1: place block (to abovesurface)
634                 2: stop digging (all parameters ignored)
635                 3: digging completed
636         */
637         
638         TOSERVER_RELEASE = 0x29, // Obsolete
639
640         // (oops, there is some gap here)
641
642         TOSERVER_SIGNTEXT = 0x30, // Old signs, obsolete
643         /*
644                 u16 command
645                 v3s16 blockpos
646                 s16 id
647                 u16 textlen
648                 textdata
649         */
650
651         TOSERVER_INVENTORY_ACTION = 0x31,
652         /*
653                 See InventoryAction in inventory.h
654         */
655
656         TOSERVER_CHAT_MESSAGE = 0x32,
657         /*
658                 u16 command
659                 u16 length
660                 wstring message
661         */
662
663         TOSERVER_SIGNNODETEXT = 0x33, // obsolete
664         /*
665                 u16 command
666                 v3s16 p
667                 u16 textlen
668                 textdata
669         */
670
671         TOSERVER_CLICK_ACTIVEOBJECT = 0x34, // Obsolete
672         /*
673                 length: 7
674                 [0] u16 command
675                 [2] u8 button (0=left, 1=right)
676                 [3] u16 id
677                 [5] u16 item
678         */
679         
680         TOSERVER_DAMAGE = 0x35,
681         /*
682                 u16 command
683                 u8 amount
684         */
685
686         TOSERVER_PASSWORD=0x36,
687         /*
688                 Sent to change password.
689
690                 [0] u16 TOSERVER_PASSWORD
691                 [2] u8[28] old password
692                 [30] u8[28] new password
693         */
694
695         TOSERVER_PLAYERITEM=0x37,
696         /*
697                 Sent to change selected item.
698
699                 [0] u16 TOSERVER_PLAYERITEM
700                 [2] u16 item
701         */
702         
703         TOSERVER_RESPAWN=0x38,
704         /*
705                 u16 TOSERVER_RESPAWN
706         */
707
708         TOSERVER_INTERACT = 0x39,
709         /*
710                 [0] u16 command
711                 [2] u8 action
712                 [3] u16 item
713                 [5] u32 length of the next item
714                 [9] serialized PointedThing
715                 actions:
716                 0: start digging (from undersurface) or use
717                 1: stop digging (all parameters ignored)
718                 2: digging completed
719                 3: place block or item (to abovesurface)
720                 4: use item
721
722                 (Obsoletes TOSERVER_GROUND_ACTION and TOSERVER_CLICK_ACTIVEOBJECT.)
723         */
724         
725         TOSERVER_REMOVED_SOUNDS = 0x3a,
726         /*
727                 u16 command
728                 u16 len
729                 s32[len] sound_id
730         */
731
732         TOSERVER_NODEMETA_FIELDS = 0x3b,
733         /*
734                 u16 command
735                 v3s16 p
736                 u16 len
737                 u8[len] form name (reserved for future use)
738                 u16 number of fields
739                 for each field:
740                         u16 len
741                         u8[len] field name
742                         u32 len
743                         u8[len] field value
744         */
745
746         TOSERVER_INVENTORY_FIELDS = 0x3c,
747         /*
748                 u16 command
749                 u16 len
750                 u8[len] form name (reserved for future use)
751                 u16 number of fields
752                 for each field:
753                         u16 len
754                         u8[len] field name
755                         u32 len
756                         u8[len] field value
757         */
758
759         TOSERVER_REQUEST_MEDIA = 0x40,
760         /*
761                 u16 command
762                 u16 number of files requested
763                 for each file {
764                         u16 length of name
765                         string name
766                 }
767          */
768
769         TOSERVER_RECEIVED_MEDIA = 0x41,
770         /*
771                 u16 command
772         */
773
774         TOSERVER_BREATH = 0x42,
775         /*
776                 u16 command
777                 u16 breath
778         */
779
780         TOSERVER_CLIENT_READY = 0x43,
781         /*
782                 u8 major
783                 u8 minor
784                 u8 patch
785                 u8 reserved
786                 u16 len
787                 u8[len] full_version_string
788         */
789 };
790
791 #endif
792