1 /**
2 Copyright: Copyright (c) 2015-2017 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;
9 import voxelman.math;
10 import voxelman.core.config : DimensionId;
11 import voxelman.geometry.box : Box;
12 import voxelman.world.storage.worldbox : WorldBox;
13 import voxelman.world.storage.coordinates : ClientDimPos;
14 
15 void registerPackets(Connection)(Connection c)
16 {
17 	// Common
18 	c.registerPacket!ClientPositionPacket;
19 	c.registerPacket!FillBlockBoxPacket;
20 	c.registerPacket!PlaceBlockEntityPacket;
21 	c.registerPacket!RemoveBlockEntityPacket;
22 
23 	// Server -> Client
24 	c.registerPacket!ChunkDataPacket;
25 	c.registerPacket!DimensionInfoPacket;
26 	c.registerPacket!SpawnPacket;
27 	c.registerPacket!MultiblockChangePacket;
28 
29 	// Client -> Server
30 	c.registerPacket!ViewRadiusPacket;
31 	c.registerPacket!CommandPacket;
32 }
33 
34 // sent by client when position/heading changes.
35 struct ClientPositionPacket
36 {
37 	ClientDimPos dimPos;
38 	DimensionId dimension;
39 	ubyte positionKey;
40 }
41 
42 // sent by client after receiving SessionInfoPacket
43 struct ViewRadiusPacket
44 {
45 	int viewRadius;
46 }
47 
48 struct ChunkDataPacket
49 {
50 	import voxelman.world.storage.chunk : ChunkLayerData;
51 	ivec4 chunkPos;
52 	ChunkLayerData[] layers;
53 }
54 
55 struct DimensionInfoPacket
56 {
57 	DimensionId dimension;
58 	Box borders;
59 }
60 
61 struct MultiblockChangePacket
62 {
63 	import voxelman.world.storage.chunk : BlockChange;
64 	ivec4 chunkPos;
65 	BlockChange[] blockChanges;
66 }
67 
68 struct FillBlockBoxPacket
69 {
70 	import voxelman.core.config : BlockId, BlockMetadata;
71 	WorldBox box;
72 	BlockId blockId;
73 	BlockMetadata blockMeta;
74 }
75 
76 struct PlaceBlockEntityPacket
77 {
78 	WorldBox box;
79 	ulong data;
80 }
81 
82 struct RemoveBlockEntityPacket
83 {
84 	ivec4 blockPos;
85 }
86 
87 struct SpawnPacket
88 {
89 }
90 
91 struct CommandPacket
92 {
93 	string command;
94 }