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