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