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