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