1 /**
2 Copyright: Copyright (c) 2016-2018 Andrey Penechko.
3 License: $(WEB boost.org/LICENSE_1_0.txt, Boost License 1.0).
4 Authors: Andrey Penechko.
5 */
6 module voxelman.session.components;
7 
8 import cbor : ignore;
9 import netlib : SessionId;
10 import datadriven;
11 import voxelman.math;
12 import voxelman.core.config;
13 import voxelman.world.storage;
14 
15 void registerSessionComponents(EntityManager* eman)
16 {
17 	eman.registerComponent!ClientPosition();
18 	eman.registerComponent!LoggedInFlag();
19 	eman.registerComponent!SpawnedFlag();
20 	eman.registerComponent!ClientSettings();
21 	eman.registerComponent!ClientSessionInfo();
22 }
23 
24 @Component("session.SpawnedFlag", Replication.none)
25 struct SpawnedFlag
26 {}
27 
28 @Component("session.LoggedInFlag", Replication.none)
29 struct LoggedInFlag
30 {}
31 
32 @Component("session.ClientPosition", Replication.toDb)
33 struct ClientPosition
34 {
35 	ClientDimPos dimPos;
36 	DimensionId dimension;
37 
38 	/// Used to reject wrong positions from client.
39 	/// Client sends positions updates with latest known key and server only accepts
40 	/// positions matching this key.
41 	/// After dimension change key is incremented.
42 	@ignore ubyte positionKey;
43 
44 	ChunkWorldPos chunk() {
45 		ChunkWorldPos cwp = BlockWorldPos(dimPos.pos, dimension);
46 		return cwp;
47 	}
48 }
49 
50 @Component("session.ClientSettings", Replication.toDb)
51 struct ClientSettings
52 {
53 	int viewRadius = DEFAULT_VIEW_RADIUS;
54 }
55 
56 @Component("session.ClientSessionInfo", Replication.none)
57 struct ClientSessionInfo
58 {
59 	string name;
60 	SessionId sessionId;
61 }