44#include < robinhood/robinhood.h>
55
66#include < asio/asio.hpp>
7- #include < RTree/RTree.h>
8-
97#include < entt/entt.hpp>
8+ #include < libsodium/sodium.h>
9+ #include < RTree/RTree.h>
10+ #include < spake2-ee/crypto_spake.h>
1011
1112#include < memory>
1213
@@ -16,19 +17,82 @@ namespace Network
1617 class GameMessageRouter ;
1718}
1819
19- namespace ECS ::Singletons
20+ namespace ECS
2021{
21- struct NetworkState
22+ enum class AuthenticationStage : u8
23+ {
24+ None = 0 ,
25+ Step1 = 1 ,
26+ Step2 = 2 ,
27+ Failed = 3 ,
28+ Completed = 4
29+ };
30+
31+ struct CharacterListEntry
32+ {
33+ public:
34+ std::string name;
35+ u8 race;
36+ u8 gender;
37+ u8 unitClass;
38+ u16 level;
39+ u16 mapID;
40+ };
41+
42+ struct AuthenticationInfo
43+ {
44+ public:
45+ void Reset ()
46+ {
47+ stage = AuthenticationStage::None;
48+ username.clear ();
49+ password.clear ();
50+ sodium_memzero (&state, sizeof (state));
51+ sodium_memzero (&sharedKeys, sizeof (sharedKeys));
52+ }
53+
54+ public:
55+ AuthenticationStage stage = AuthenticationStage::None;
56+ std::string username = " " ;
57+ std::string password = " " ;
58+
59+ crypto_spake_client_state state;
60+ crypto_spake_shared_keys_ sharedKeys;
61+ };
62+
63+ struct CharacterListInfo
2264 {
2365 public:
24- static constexpr u64 PING_INTERVAL = 5000 ;
66+ void Reset ()
67+ {
68+ characterSelected = false ;
69+ list.clear ();
70+ nameHashToIndex.clear ();
71+ nameHashToSortingIndex.clear ();
72+ }
73+
74+ public:
75+ bool characterSelected = false ;
76+ std::vector<CharacterListEntry> list;
77+ robin_hood::unordered_map<u32 , u32 > nameHashToIndex;
78+ robin_hood::unordered_map<u32 , u32 > nameHashToSortingIndex;
79+ };
2580
26- std::thread asioThread;
27- asio::io_context asioContext;
28- std::shared_ptr<asio::ip::tcp::resolver> resolver;
29- std::unique_ptr<Network::Client> client;
30- std::unique_ptr<Network::GameMessageRouter> gameMessageRouter;
81+ struct PingInfo
82+ {
83+ public:
84+ void Reset ()
85+ {
86+ lastPingTime = 0u ;
87+ lastPongTime = 0u ;
88+ ping = 0 ;
89+ serverUpdateDiff = 0 ;
90+ pingHistoryIndex = 0 ;
91+ pingHistory.fill (0 );
92+ pingHistorySize = 0 ;
93+ }
3194
95+ public:
3296 u64 lastPingTime = 0 ;
3397 u64 lastPongTime = 0 ;
3498
@@ -37,10 +101,31 @@ namespace ECS::Singletons
37101 u8 serverUpdateDiff = 0 ;
38102 std::array<u16 , 6 > pingHistory = { 0 , 0 , 0 , 0 , 0 , 0 };
39103 u8 pingHistorySize = 0 ;
40- bool isLoadingMap = false ;
41-
42- robin_hood::unordered_map<ObjectGUID, entt::entity> networkIDToEntity;
43- robin_hood::unordered_map<entt::entity, ObjectGUID> entityToNetworkID;
44- RTree<ObjectGUID, f32 , 3 >* networkVisTree;
45104 };
105+
106+ namespace Singletons
107+ {
108+ struct NetworkState
109+ {
110+ public:
111+ static constexpr u64 PING_INTERVAL = 5000 ;
112+
113+ std::thread asioThread;
114+ asio::io_context asioContext;
115+ std::shared_ptr<asio::ip::tcp::resolver> resolver;
116+ std::unique_ptr<Network::Client> client;
117+ std::unique_ptr<Network::GameMessageRouter> gameMessageRouter;
118+
119+ bool isLoadingMap = false ;
120+ bool isInWorld = false ;
121+
122+ AuthenticationInfo authInfo;
123+ CharacterListInfo characterListInfo;
124+ PingInfo pingInfo;
125+
126+ robin_hood::unordered_map<ObjectGUID, entt::entity> networkIDToEntity;
127+ robin_hood::unordered_map<entt::entity, ObjectGUID> entityToNetworkID;
128+ RTree<ObjectGUID, f32 , 3 >* networkVisTree = nullptr ;
129+ };
130+ }
46131}
0 commit comments