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