1 /**
2 Copyright: Copyright (c) 2015-2016 Andrey Penechko.
3 License: $(WEB boost.org/LICENSE_1_0.txt, Boost License 1.0).
4 Authors: Andrey Penechko.
5 */
6 module voxelman.core.packets;
7 
8 import netlib.connection;
9 import dlib.math.vector;
10 import voxelman.storage.chunk : BlockChange, BlockData, BlockType;
11 
12 void registerPackets(Connection c)
13 {
14 	// Common
15 	c.registerPacket!ClientPositionPacket;
16 
17 	// Server -> Client
18 	c.registerPacket!ChunkDataPacket;
19 	c.registerPacket!MultiblockChangePacket;
20 	c.registerPacket!SpawnPacket;
21 
22 	// Client -> Server
23 	c.registerPacket!ViewRadiusPacket;
24 	c.registerPacket!PlaceBlockPacket;
25 	c.registerPacket!CommandPacket;
26 }
27 
28 // sent by client when position/heading changes.
29 struct ClientPositionPacket
30 {
31 	vec3 pos = vec3(0, 0, 0);
32 	vec2 heading = vec2(0, 0);
33 }
34 
35 // sent by client after receiving SessionInfoPacket
36 struct ViewRadiusPacket
37 {
38 	int viewRadius;
39 }
40 
41 struct ChunkDataPacket
42 {
43 	ivec3 chunkPos;
44 	BlockData blockData;
45 }
46 
47 struct MultiblockChangePacket
48 {
49 	ivec3 chunkPos;
50 	BlockChange[] blockChanges;
51 }
52 
53 struct PlaceBlockPacket
54 {
55 	ivec3 blockPos;
56 	BlockType blockType;
57 }
58 
59 struct SpawnPacket
60 {
61 }
62 
63 struct CommandPacket
64 {
65 	string command;
66 }