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