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