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