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