bb7e1181efafbe16b688530de51b3962af922127
[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                 u16 len
363                 u8[len] formspec
364         */
365 };
366
367 enum ToServerCommand
368 {
369         TOSERVER_INIT=0x10,
370         /*
371                 Sent first after connected.
372
373                 [0] u16 TOSERVER_INIT
374                 [2] u8 SER_FMT_VER_HIGHEST
375                 [3] u8[20] player_name
376                 [23] u8[28] password (new in some version)
377                 [51] u16 minimum supported network protocol version (added sometime)
378                 [53] u16 maximum supported network protocol version (added later than the previous one)
379         */
380
381         TOSERVER_INIT2 = 0x11,
382         /*
383                 Sent as an ACK for TOCLIENT_INIT.
384                 After this, the server can send data.
385
386                 [0] u16 TOSERVER_INIT2
387         */
388
389         TOSERVER_GETBLOCK=0x20, // Obsolete
390         TOSERVER_ADDNODE = 0x21, // Obsolete
391         TOSERVER_REMOVENODE = 0x22, // Obsolete
392
393         TOSERVER_PLAYERPOS = 0x23,
394         /*
395                 [0] u16 command
396                 [2] v3s32 position*100
397                 [2+12] v3s32 speed*100
398                 [2+12+12] s32 pitch*100
399                 [2+12+12+4] s32 yaw*100
400                 [2+12+12+4+4] u32 keyPressed
401         */
402
403         TOSERVER_GOTBLOCKS = 0x24,
404         /*
405                 [0] u16 command
406                 [2] u8 count
407                 [3] v3s16 pos_0
408                 [3+6] v3s16 pos_1
409                 ...
410         */
411
412         TOSERVER_DELETEDBLOCKS = 0x25,
413         /*
414                 [0] u16 command
415                 [2] u8 count
416                 [3] v3s16 pos_0
417                 [3+6] v3s16 pos_1
418                 ...
419         */
420
421         TOSERVER_ADDNODE_FROM_INVENTORY = 0x26, // Obsolete
422         /*
423                 [0] u16 command
424                 [2] v3s16 pos
425                 [8] u16 i
426         */
427
428         TOSERVER_CLICK_OBJECT = 0x27, // Obsolete
429         /*
430                 length: 13
431                 [0] u16 command
432                 [2] u8 button (0=left, 1=right)
433                 [3] v3s16 blockpos
434                 [9] s16 id
435                 [11] u16 item
436         */
437
438         TOSERVER_GROUND_ACTION = 0x28, // Obsolete
439         /*
440                 length: 17
441                 [0] u16 command
442                 [2] u8 action
443                 [3] v3s16 nodepos_undersurface
444                 [9] v3s16 nodepos_abovesurface
445                 [15] u16 item
446                 actions:
447                 0: start digging (from undersurface)
448                 1: place block (to abovesurface)
449                 2: stop digging (all parameters ignored)
450                 3: digging completed
451         */
452         
453         TOSERVER_RELEASE = 0x29, // Obsolete
454
455         // (oops, there is some gap here)
456
457         TOSERVER_SIGNTEXT = 0x30, // Old signs, obsolete
458         /*
459                 u16 command
460                 v3s16 blockpos
461                 s16 id
462                 u16 textlen
463                 textdata
464         */
465
466         TOSERVER_INVENTORY_ACTION = 0x31,
467         /*
468                 See InventoryAction in inventory.h
469         */
470
471         TOSERVER_CHAT_MESSAGE = 0x32,
472         /*
473                 u16 command
474                 u16 length
475                 wstring message
476         */
477
478         TOSERVER_SIGNNODETEXT = 0x33, // obsolete
479         /*
480                 u16 command
481                 v3s16 p
482                 u16 textlen
483                 textdata
484         */
485
486         TOSERVER_CLICK_ACTIVEOBJECT = 0x34, // Obsolete
487         /*
488                 length: 7
489                 [0] u16 command
490                 [2] u8 button (0=left, 1=right)
491                 [3] u16 id
492                 [5] u16 item
493         */
494         
495         TOSERVER_DAMAGE = 0x35,
496         /*
497                 u16 command
498                 u8 amount
499         */
500
501         TOSERVER_PASSWORD=0x36,
502         /*
503                 Sent to change password.
504
505                 [0] u16 TOSERVER_PASSWORD
506                 [2] u8[28] old password
507                 [30] u8[28] new password
508         */
509
510         TOSERVER_PLAYERITEM=0x37,
511         /*
512                 Sent to change selected item.
513
514                 [0] u16 TOSERVER_PLAYERITEM
515                 [2] u16 item
516         */
517         
518         TOSERVER_RESPAWN=0x38,
519         /*
520                 u16 TOSERVER_RESPAWN
521         */
522
523         TOSERVER_INTERACT = 0x39,
524         /*
525                 [0] u16 command
526                 [2] u8 action
527                 [3] u16 item
528                 [5] u32 length of the next item
529                 [9] serialized PointedThing
530                 actions:
531                 0: start digging (from undersurface) or use
532                 1: stop digging (all parameters ignored)
533                 2: digging completed
534                 3: place block or item (to abovesurface)
535                 4: use item
536
537                 (Obsoletes TOSERVER_GROUND_ACTION and TOSERVER_CLICK_ACTIVEOBJECT.)
538         */
539         
540         TOSERVER_REMOVED_SOUNDS = 0x3a,
541         /*
542                 u16 command
543                 u16 len
544                 s32[len] sound_id
545         */
546
547         TOSERVER_NODEMETA_FIELDS = 0x3b,
548         /*
549                 u16 command
550                 v3s16 p
551                 u16 len
552                 u8[len] form name (reserved for future use)
553                 u16 number of fields
554                 for each field:
555                         u16 len
556                         u8[len] field name
557                         u32 len
558                         u8[len] field value
559         */
560
561         TOSERVER_INVENTORY_FIELDS = 0x3c,
562         /*
563                 u16 command
564                 u16 len
565                 u8[len] form name (reserved for future use)
566                 u16 number of fields
567                 for each field:
568                         u16 len
569                         u8[len] field name
570                         u32 len
571                         u8[len] field value
572         */
573
574         TOSERVER_REQUEST_MEDIA = 0x40,
575         /*
576                 u16 command
577                 u16 number of files requested
578                 for each file {
579                         u16 length of name
580                         string name
581                 }
582          */
583
584         TOSERVER_RECEIVED_MEDIA = 0x41,
585         /*
586                 u16 command
587         */
588 };
589
590 #endif
591