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