]> git.lizzy.rs Git - minetest.git/blob - src/clientserver.h
Clean up constants.h a bit
[minetest.git] / src / clientserver.h
1 /*
2 Minetest-c55
3 Copyright (C) 2010 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 "utility.h"
24
25 /*
26         changes by PROTOCOL_VERSION:
27
28         PROTOCOL_VERSION 3:
29                 Base for writing changes here
30         PROTOCOL_VERSION 4:
31                 Add TOCLIENT_MEDIA
32                 Add TOCLIENT_TOOLDEF
33                 Add TOCLIENT_NODEDEF
34                 Add TOCLIENT_CRAFTITEMDEF
35                 Add TOSERVER_INTERACT
36                 Obsolete TOSERVER_CLICK_ACTIVEOBJECT
37                 Obsolete TOSERVER_GROUND_ACTION
38         PROTOCOL_VERSION 5:
39                 Make players to be handled mostly as ActiveObjects
40         PROTOCOL_VERSION 6:
41                 Only non-cached textures are sent
42         PROTOCOL_VERSION 7:
43                 Add TOCLIENT_ITEMDEF
44                 Obsolete TOCLIENT_TOOLDEF
45                 Obsolete TOCLIENT_CRAFTITEMDEF
46                 Compress the contents of TOCLIENT_ITEMDEF and TOCLIENT_NODEDEF
47         PROTOCOL_VERSION 8:
48                 Digging based on item groups
49                 Many things
50         PROTOCOL_VERSION 9:
51                 ContentFeatures and NodeDefManager use a different serialization
52                     format; better for future version cross-compatibility
53                 Many things
54         PROTOCOL_VERSION 10:
55                 TOCLIENT_PRIVILEGES
56                 Version raised to force 'fly' and 'fast' privileges into effect.
57                 Node metadata change (came in later; somewhat incompatible)
58                 TileDef in ContentFeatures (non-TileDef deserialization is supported)
59 */
60
61 #define PROTOCOL_VERSION 10
62
63 #define PROTOCOL_ID 0x4f457403
64
65 #define PASSWORD_SIZE 28       // Maximum password length. Allows for
66                                // base64-encoded SHA-1 (27+\0).
67
68 #define TEXTURENAME_ALLOWED_CHARS "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_."
69
70 enum ToClientCommand
71 {
72         TOCLIENT_INIT = 0x10,
73         /*
74                 Server's reply to TOSERVER_INIT.
75                 Sent second after connected.
76
77                 [0] u16 TOSERVER_INIT
78                 [2] u8 deployed version
79                 [3] v3s16 player's position + v3f(0,BS/2,0) floatToInt'd 
80                 [12] u64 map seed (new as of 2011-02-27)
81
82                 NOTE: The position in here is deprecated; position is
83                       explicitly sent afterwards
84         */
85
86         TOCLIENT_BLOCKDATA = 0x20, //TODO: Multiple blocks
87         TOCLIENT_ADDNODE = 0x21,
88         TOCLIENT_REMOVENODE = 0x22,
89         
90         TOCLIENT_PLAYERPOS = 0x23, // Obsolete
91         /*
92                 [0] u16 command
93                 // Followed by an arbitary number of these:
94                 // Number is determined from packet length.
95                 [N] u16 peer_id
96                 [N+2] v3s32 position*100
97                 [N+2+12] v3s32 speed*100
98                 [N+2+12+12] s32 pitch*100
99                 [N+2+12+12+4] s32 yaw*100
100         */
101
102         TOCLIENT_PLAYERINFO = 0x24, // Obsolete
103         /*
104                 [0] u16 command
105                 // Followed by an arbitary number of these:
106                 // Number is determined from packet length.
107                 [N] u16 peer_id
108                 [N] char[20] name
109         */
110         
111         TOCLIENT_OPT_BLOCK_NOT_FOUND = 0x25, // Obsolete
112
113         TOCLIENT_SECTORMETA = 0x26, // Obsolete
114         /*
115                 [0] u16 command
116                 [2] u8 sector count
117                 [3...] v2s16 pos + sector metadata
118         */
119
120         TOCLIENT_INVENTORY = 0x27,
121         /*
122                 [0] u16 command
123                 [2] serialized inventory
124         */
125         
126         TOCLIENT_OBJECTDATA = 0x28, // Obsolete
127         /*
128                 Sent as unreliable.
129
130                 u16 command
131                 u16 number of player positions
132                 for each player:
133                         u16 peer_id
134                         v3s32 position*100
135                         v3s32 speed*100
136                         s32 pitch*100
137                         s32 yaw*100
138                 u16 count of blocks
139                 for each block:
140                         v3s16 blockpos
141                         block objects
142         */
143
144         TOCLIENT_TIME_OF_DAY = 0x29,
145         /*
146                 u16 command
147                 u16 time (0-23999)
148                 Added in a later version:
149                 f1000 time_speed
150         */
151
152         // (oops, there is some gap here)
153
154         TOCLIENT_CHAT_MESSAGE = 0x30,
155         /*
156                 u16 command
157                 u16 length
158                 wstring message
159         */
160
161         TOCLIENT_ACTIVE_OBJECT_REMOVE_ADD = 0x31,
162         /*
163                 u16 command
164                 u16 count of removed objects
165                 for all removed objects {
166                         u16 id
167                 }
168                 u16 count of added objects
169                 for all added objects {
170                         u16 id
171                         u8 type
172                         u32 initialization data length
173                         string initialization data
174                 }
175         */
176         
177         TOCLIENT_ACTIVE_OBJECT_MESSAGES = 0x32,
178         /*
179                 u16 command
180                 for all objects
181                 {
182                         u16 id
183                         u16 message length
184                         string message
185                 }
186         */
187
188         TOCLIENT_HP = 0x33,
189         /*
190                 u16 command
191                 u8 hp
192         */
193
194         TOCLIENT_MOVE_PLAYER = 0x34,
195         /*
196                 u16 command
197                 v3f1000 player position
198                 f1000 player pitch
199                 f1000 player yaw
200         */
201
202         TOCLIENT_ACCESS_DENIED = 0x35,
203         /*
204                 u16 command
205                 u16 reason_length
206                 wstring reason
207         */
208
209         TOCLIENT_PLAYERITEM = 0x36, // Obsolete
210         /*
211                 u16 command
212                 u16 count of player items
213                 for all player items {
214                         u16 peer id
215                         u16 length of serialized item
216                         string serialized item
217                 }
218         */
219
220         TOCLIENT_DEATHSCREEN = 0x37,
221         /*
222                 u16 command
223                 u8 bool set camera point target
224                 v3f1000 camera point target (to point the death cause or whatever)
225         */
226
227         TOCLIENT_MEDIA = 0x38,
228         /*
229                 u16 command
230                 u16 total number of texture bunches
231                 u16 index of this bunch
232                 u32 number of files in this bunch
233                 for each file {
234                         u16 length of name
235                         string name
236                         u32 length of data
237                         data
238                 }
239         */
240         
241         TOCLIENT_TOOLDEF = 0x39,
242         /*
243                 u16 command
244                 u32 length of the next item
245                 serialized ToolDefManager
246         */
247         
248         TOCLIENT_NODEDEF = 0x3a,
249         /*
250                 u16 command
251                 u32 length of the next item
252                 serialized NodeDefManager
253         */
254         
255         TOCLIENT_CRAFTITEMDEF = 0x3b,
256         /*
257                 u16 command
258                 u32 length of the next item
259                 serialized CraftiItemDefManager
260         */
261
262         TOCLIENT_ANNOUNCE_MEDIA = 0x3c,
263
264         /*
265                 u16 command
266                 u32 number of files
267                 for each texture {
268                         u16 length of name
269                         string name
270                         u16 length of sha1_digest
271                         string sha1_digest
272                 }
273         */
274
275         TOCLIENT_ITEMDEF = 0x3d,
276         /*
277                 u16 command
278                 u32 length of next item
279                 serialized ItemDefManager
280         */
281         
282         TOCLIENT_PLAY_SOUND = 0x3f,
283         /*
284                 u16 command
285                 s32 sound_id
286                 u16 len
287                 u8[len] sound name
288                 s32 gain*1000
289                 u8 type (0=local, 1=positional, 2=object)
290                 s32[3] pos_nodes*10000
291                 u16 object_id
292                 u8 loop (bool)
293         */
294
295         TOCLIENT_STOP_SOUND = 0x40,
296         /*
297                 u16 command
298                 s32 sound_id
299         */
300
301         TOCLIENT_PRIVILEGES = 0x41,
302         /*
303                 u16 command
304                 u16 number of privileges
305                 for each privilege
306                         u16 len
307                         u8[len] privilege
308         */
309 };
310
311 enum ToServerCommand
312 {
313         TOSERVER_INIT=0x10,
314         /*
315                 Sent first after connected.
316
317                 [0] u16 TOSERVER_INIT
318                 [2] u8 SER_FMT_VER_HIGHEST
319                 [3] u8[20] player_name
320                 [23] u8[28] password (new in some version)
321                 [51] u16 client network protocol version (new in some version)
322         */
323
324         TOSERVER_INIT2 = 0x11,
325         /*
326                 Sent as an ACK for TOCLIENT_INIT.
327                 After this, the server can send data.
328
329                 [0] u16 TOSERVER_INIT2
330         */
331
332         TOSERVER_GETBLOCK=0x20, // Obsolete
333         TOSERVER_ADDNODE = 0x21, // Obsolete
334         TOSERVER_REMOVENODE = 0x22, // Obsolete
335
336         TOSERVER_PLAYERPOS = 0x23,
337         /*
338                 [0] u16 command
339                 [2] v3s32 position*100
340                 [2+12] v3s32 speed*100
341                 [2+12+12] s32 pitch*100
342                 [2+12+12+4] s32 yaw*100
343         */
344
345         TOSERVER_GOTBLOCKS = 0x24,
346         /*
347                 [0] u16 command
348                 [2] u8 count
349                 [3] v3s16 pos_0
350                 [3+6] v3s16 pos_1
351                 ...
352         */
353
354         TOSERVER_DELETEDBLOCKS = 0x25,
355         /*
356                 [0] u16 command
357                 [2] u8 count
358                 [3] v3s16 pos_0
359                 [3+6] v3s16 pos_1
360                 ...
361         */
362
363         TOSERVER_ADDNODE_FROM_INVENTORY = 0x26, // Obsolete
364         /*
365                 [0] u16 command
366                 [2] v3s16 pos
367                 [8] u16 i
368         */
369
370         TOSERVER_CLICK_OBJECT = 0x27, // Obsolete
371         /*
372                 length: 13
373                 [0] u16 command
374                 [2] u8 button (0=left, 1=right)
375                 [3] v3s16 blockpos
376                 [9] s16 id
377                 [11] u16 item
378         */
379
380         TOSERVER_GROUND_ACTION = 0x28, // Obsolete
381         /*
382                 length: 17
383                 [0] u16 command
384                 [2] u8 action
385                 [3] v3s16 nodepos_undersurface
386                 [9] v3s16 nodepos_abovesurface
387                 [15] u16 item
388                 actions:
389                 0: start digging (from undersurface)
390                 1: place block (to abovesurface)
391                 2: stop digging (all parameters ignored)
392                 3: digging completed
393         */
394         
395         TOSERVER_RELEASE = 0x29, // Obsolete
396
397         // (oops, there is some gap here)
398
399         TOSERVER_SIGNTEXT = 0x30, // Old signs, obsolete
400         /*
401                 u16 command
402                 v3s16 blockpos
403                 s16 id
404                 u16 textlen
405                 textdata
406         */
407
408         TOSERVER_INVENTORY_ACTION = 0x31,
409         /*
410                 See InventoryAction in inventory.h
411         */
412
413         TOSERVER_CHAT_MESSAGE = 0x32,
414         /*
415                 u16 command
416                 u16 length
417                 wstring message
418         */
419
420         TOSERVER_SIGNNODETEXT = 0x33, // obsolete
421         /*
422                 u16 command
423                 v3s16 p
424                 u16 textlen
425                 textdata
426         */
427
428         TOSERVER_CLICK_ACTIVEOBJECT = 0x34, // Obsolete
429         /*
430                 length: 7
431                 [0] u16 command
432                 [2] u8 button (0=left, 1=right)
433                 [3] u16 id
434                 [5] u16 item
435         */
436         
437         TOSERVER_DAMAGE = 0x35,
438         /*
439                 u16 command
440                 u8 amount
441         */
442
443         TOSERVER_PASSWORD=0x36,
444         /*
445                 Sent to change password.
446
447                 [0] u16 TOSERVER_PASSWORD
448                 [2] u8[28] old password
449                 [30] u8[28] new password
450         */
451
452         TOSERVER_PLAYERITEM=0x37,
453         /*
454                 Sent to change selected item.
455
456                 [0] u16 TOSERVER_PLAYERITEM
457                 [2] u16 item
458         */
459         
460         TOSERVER_RESPAWN=0x38,
461         /*
462                 u16 TOSERVER_RESPAWN
463         */
464
465         TOSERVER_INTERACT = 0x39,
466         /*
467                 [0] u16 command
468                 [2] u8 action
469                 [3] u16 item
470                 [5] u32 length of the next item
471                 [9] serialized PointedThing
472                 actions:
473                 0: start digging (from undersurface) or use
474                 1: stop digging (all parameters ignored)
475                 2: digging completed
476                 3: place block or item (to abovesurface)
477                 4: use item
478
479                 (Obsoletes TOSERVER_GROUND_ACTION and TOSERVER_CLICK_ACTIVEOBJECT.)
480         */
481         
482         TOSERVER_REMOVED_SOUNDS = 0x3a,
483         /*
484                 u16 command
485                 u16 len
486                 s32[len] sound_id
487         */
488
489         TOSERVER_NODEMETA_FIELDS = 0x3b,
490         /*
491                 u16 command
492                 v3s16 p
493                 u16 len
494                 u8[len] form name (reserved for future use)
495                 u16 number of fields
496                 for each field:
497                         u16 len
498                         u8[len] field name
499                         u32 len
500                         u8[len] field value
501         */
502
503         TOSERVER_REQUEST_MEDIA = 0x40,
504         /*
505                 u16 command
506                 u16 number of files requested
507                 for each file {
508                         u16 length of name
509                         string name
510                 }
511          */
512
513 };
514
515 inline SharedBuffer<u8> makePacket_TOCLIENT_TIME_OF_DAY(u16 time, float time_speed)
516 {
517         SharedBuffer<u8> data(2+2+4);
518         writeU16(&data[0], TOCLIENT_TIME_OF_DAY);
519         writeU16(&data[2], time);
520         writeF1000(&data[4], time_speed);
521         return data;
522 }
523
524 #endif
525