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