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