]> git.lizzy.rs Git - dragonfireclient.git/blob - src/clientserver.h
Suppress MSVC warning in chat.cpp
[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         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
561 enum ToServerCommand
562 {
563         TOSERVER_INIT=0x10,
564         /*
565                 Sent first after connected.
566
567                 [0] u16 TOSERVER_INIT
568                 [2] u8 SER_FMT_VER_HIGHEST_READ
569                 [3] u8[20] player_name
570                 [23] u8[28] password (new in some version)
571                 [51] u16 minimum supported network protocol version (added sometime)
572                 [53] u16 maximum supported network protocol version (added later than the previous one)
573         */
574
575         TOSERVER_INIT2 = 0x11,
576         /*
577                 Sent as an ACK for TOCLIENT_INIT.
578                 After this, the server can send data.
579
580                 [0] u16 TOSERVER_INIT2
581         */
582
583         TOSERVER_GETBLOCK=0x20, // Obsolete
584         TOSERVER_ADDNODE = 0x21, // Obsolete
585         TOSERVER_REMOVENODE = 0x22, // Obsolete
586
587         TOSERVER_PLAYERPOS = 0x23,
588         /*
589                 [0] u16 command
590                 [2] v3s32 position*100
591                 [2+12] v3s32 speed*100
592                 [2+12+12] s32 pitch*100
593                 [2+12+12+4] s32 yaw*100
594                 [2+12+12+4+4] u32 keyPressed
595         */
596
597         TOSERVER_GOTBLOCKS = 0x24,
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_DELETEDBLOCKS = 0x25,
607         /*
608                 [0] u16 command
609                 [2] u8 count
610                 [3] v3s16 pos_0
611                 [3+6] v3s16 pos_1
612                 ...
613         */
614
615         TOSERVER_ADDNODE_FROM_INVENTORY = 0x26, // Obsolete
616         /*
617                 [0] u16 command
618                 [2] v3s16 pos
619                 [8] u16 i
620         */
621
622         TOSERVER_CLICK_OBJECT = 0x27, // Obsolete
623         /*
624                 length: 13
625                 [0] u16 command
626                 [2] u8 button (0=left, 1=right)
627                 [3] v3s16 blockpos
628                 [9] s16 id
629                 [11] u16 item
630         */
631
632         TOSERVER_GROUND_ACTION = 0x28, // Obsolete
633         /*
634                 length: 17
635                 [0] u16 command
636                 [2] u8 action
637                 [3] v3s16 nodepos_undersurface
638                 [9] v3s16 nodepos_abovesurface
639                 [15] u16 item
640                 actions:
641                 0: start digging (from undersurface)
642                 1: place block (to abovesurface)
643                 2: stop digging (all parameters ignored)
644                 3: digging completed
645         */
646
647         TOSERVER_RELEASE = 0x29, // Obsolete
648
649         // (oops, there is some gap here)
650
651         TOSERVER_SIGNTEXT = 0x30, // Old signs, obsolete
652         /*
653                 u16 command
654                 v3s16 blockpos
655                 s16 id
656                 u16 textlen
657                 textdata
658         */
659
660         TOSERVER_INVENTORY_ACTION = 0x31,
661         /*
662                 See InventoryAction in inventory.h
663         */
664
665         TOSERVER_CHAT_MESSAGE = 0x32,
666         /*
667                 u16 command
668                 u16 length
669                 wstring message
670         */
671
672         TOSERVER_SIGNNODETEXT = 0x33, // obsolete
673         /*
674                 u16 command
675                 v3s16 p
676                 u16 textlen
677                 textdata
678         */
679
680         TOSERVER_CLICK_ACTIVEOBJECT = 0x34, // Obsolete
681         /*
682                 length: 7
683                 [0] u16 command
684                 [2] u8 button (0=left, 1=right)
685                 [3] u16 id
686                 [5] u16 item
687         */
688
689         TOSERVER_DAMAGE = 0x35,
690         /*
691                 u16 command
692                 u8 amount
693         */
694
695         TOSERVER_PASSWORD=0x36,
696         /*
697                 Sent to change password.
698
699                 [0] u16 TOSERVER_PASSWORD
700                 [2] u8[28] old password
701                 [30] u8[28] new password
702         */
703
704         TOSERVER_PLAYERITEM=0x37,
705         /*
706                 Sent to change selected item.
707
708                 [0] u16 TOSERVER_PLAYERITEM
709                 [2] u16 item
710         */
711
712         TOSERVER_RESPAWN=0x38,
713         /*
714                 u16 TOSERVER_RESPAWN
715         */
716
717         TOSERVER_INTERACT = 0x39,
718         /*
719                 [0] u16 command
720                 [2] u8 action
721                 [3] u16 item
722                 [5] u32 length of the next item
723                 [9] serialized PointedThing
724                 actions:
725                 0: start digging (from undersurface) or use
726                 1: stop digging (all parameters ignored)
727                 2: digging completed
728                 3: place block or item (to abovesurface)
729                 4: use item
730
731                 (Obsoletes TOSERVER_GROUND_ACTION and TOSERVER_CLICK_ACTIVEOBJECT.)
732         */
733
734         TOSERVER_REMOVED_SOUNDS = 0x3a,
735         /*
736                 u16 command
737                 u16 len
738                 s32[len] sound_id
739         */
740
741         TOSERVER_NODEMETA_FIELDS = 0x3b,
742         /*
743                 u16 command
744                 v3s16 p
745                 u16 len
746                 u8[len] form name (reserved for future use)
747                 u16 number of fields
748                 for each field:
749                         u16 len
750                         u8[len] field name
751                         u32 len
752                         u8[len] field value
753         */
754
755         TOSERVER_INVENTORY_FIELDS = 0x3c,
756         /*
757                 u16 command
758                 u16 len
759                 u8[len] form name (reserved for future use)
760                 u16 number of fields
761                 for each field:
762                         u16 len
763                         u8[len] field name
764                         u32 len
765                         u8[len] field value
766         */
767
768         TOSERVER_REQUEST_MEDIA = 0x40,
769         /*
770                 u16 command
771                 u16 number of files requested
772                 for each file {
773                         u16 length of name
774                         string name
775                 }
776          */
777
778         TOSERVER_RECEIVED_MEDIA = 0x41,
779         /*
780                 u16 command
781         */
782
783         TOSERVER_BREATH = 0x42,
784         /*
785                 u16 command
786                 u16 breath
787         */
788
789         TOSERVER_CLIENT_READY = 0x43,
790         /*
791                 u8 major
792                 u8 minor
793                 u8 patch
794                 u8 reserved
795                 u16 len
796                 u8[len] full_version_string
797         */
798 };
799
800 #endif
801