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