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