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