-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathDataDirector.hpp
More file actions
211 lines (175 loc) · 8 KB
/
Copy pathDataDirector.hpp
File metadata and controls
211 lines (175 loc) · 8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
/**
* Alicia Server - dedicated server software
* Copyright (C) 2024 Story Of Alicia
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
**/
#ifndef DATADIRECTOR_HPP
#define DATADIRECTOR_HPP
#include "DataDefinitions.hpp"
#include "DataSource.hpp"
#include "DataStorage.hpp"
#include "libserver/util/Scheduler.hpp"
namespace server
{
// Forward declaration
class FileDataSource;
class DataDirector
{
public:
using UserStorage = DataStorage<std::string, data::User>;
using InfractionStorage = DataStorage<data::Uid, data::Infraction>;
using CharacterStorage = DataStorage<data::Uid, data::Character>;
using HorseStorage = DataStorage<data::Uid, data::Horse>;
using ItemStorage = DataStorage<data::Uid, data::Item>;
using EggStorage = DataStorage<data::Uid, data::Egg>;
using PetStorage = DataStorage<data::Uid, data::Pet>;
using StorageItemStorage = DataStorage<data::Uid, data::StorageItem>;
using HousingStorage = DataStorage<data::Uid, data::Housing>;
using GuildStorage = DataStorage<data::Uid, data::Guild>;
using SettingsStorage = DataStorage<data::Uid, data::Settings>;
using DailyQuestGroupStorage = DataStorage<data::Uid, data::DailyQuestGroup>;
using MailStorage = DataStorage<data::Uid, data::Mail>;
using QuestStorage = DataStorage<data::Uid, data::Quest>;
using StallionStorage = DataStorage<data::Uid, data::Stallion>;
//! Default constructor.
explicit DataDirector(const std::filesystem::path& basePath);
//! Default destructor.
~DataDirector();
//! Initializes the director.
void Initialize();
//! Terminates the director.
void Terminate();
//! Ticks the director.
void Tick();
//! Requests a load of user data.
//! @param userName Name of the user.
void RequestLoadUserData(const std::string& userName);
//! Requests a load of character data.
//! @param userName Name of the user.
//! @param characterUid UID of the character.
void RequestLoadCharacterData(const std::string& userName, data::Uid characterUid);
//! Returns whether the data of a user (either user data or character data) are being loaded.
//! @param userName name of the user.
bool AreDataBeingLoaded(const std::string& userName);
//! Returns whether the data of a user are fully loaded.
//! @param userName name of the user.
bool AreUserDataLoaded(const std::string& userName);
//! Returns whether the data of a character are fully loaded.
//! @param userName name of the user.
bool AreCharacterDataLoaded(const std::string& userName);
[[nodiscard]] Record<data::User> CreateUser();
[[nodiscard]] Record<data::User> GetUser(const std::string& userName);
[[nodiscard]] UserStorage& GetUserCache();
//! Gets a character.
//! @param characterUid UID of the character.
//! @returns The character record.
[[nodiscard]] Record<data::Character> GetCharacter(data::Uid characterUid) noexcept;
[[nodiscard]] Record<data::Character> CreateCharacter() noexcept;
[[nodiscard]] CharacterStorage& GetCharacterCache();
[[nodiscard]] Record<data::Infraction> CreateInfraction() noexcept;
[[nodiscard]] InfractionStorage& GetInfractionCache();
[[nodiscard]] Record<data::Horse> GetHorse(data::Uid horseUid) noexcept;
[[nodiscard]] Record<data::Horse> CreateHorse() noexcept;
[[nodiscard]] HorseStorage& GetHorseCache();
[[nodiscard]] Record<data::Item> GetItem(data::Uid itemUid) noexcept;
[[nodiscard]] Record<data::Item> CreateItem() noexcept;
[[nodiscard]] ItemStorage& GetItemCache();
[[nodiscard]] Record<data::StorageItem> GetStorageItemCache(data::Uid storedItemUid) noexcept;
[[nodiscard]] Record<data::StorageItem> CreateStorageItem() noexcept;
[[nodiscard]] StorageItemStorage& GetStorageItemCache();
[[nodiscard]] Record<data::Egg> GetEgg(data::Uid eggUid) noexcept;
[[nodiscard]] Record<data::Egg> CreateEgg() noexcept;
[[nodiscard]] EggStorage& GetEggCache();
[[nodiscard]] Record<data::Pet> GetPet(data::Uid petUid) noexcept;
[[nodiscard]] Record<data::Pet> CreatePet() noexcept;
[[nodiscard]] PetStorage& GetPetCache();
[[nodiscard]] Record<data::Guild> GetGuild(data::Uid guildUid) noexcept;
[[nodiscard]] Record<data::Guild> CreateGuild() noexcept;
[[nodiscard]] GuildStorage& GetGuildCache();
[[nodiscard]] Record<data::Housing> GetHousingCache(data::Uid housingUid) noexcept;
[[nodiscard]] Record<data::Housing> CreateHousing() noexcept;
[[nodiscard]] HousingStorage& GetHousingCache();
[[nodiscard]] Record<data::Settings> GetSettings(data::Uid settingsUid) noexcept;
[[nodiscard]] Record<data::Settings> CreateSettings() noexcept;
[[nodiscard]] SettingsStorage& GetSettingsCache();
[[nodiscard]] Record<data::DailyQuestGroup> GetDailyQuestGroup(data::Uid dailyQuestGroupUid) noexcept;
[[nodiscard]] Record<data::DailyQuestGroup> CreateDailyQuestGroup() noexcept;
[[nodiscard]] DailyQuestGroupStorage& GetDailyQuestGroupCache();
[[nodiscard]] Record<data::Mail> GetMail(data::Uid mailUid) noexcept;
[[nodiscard]] Record<data::Mail> CreateMail() noexcept;
[[nodiscard]] MailStorage& GetMailCache();
[[nodiscard]] Record<data::Quest> GetQuest(data::Uid questUid) noexcept;
[[nodiscard]] Record<data::Quest> CreateQuest() noexcept;
[[nodiscard]] QuestStorage& GetQuestCache();
[[nodiscard]] Record<data::Stallion> GetStallion(data::Uid stallionUid) noexcept;
[[nodiscard]] Record<data::Stallion> CreateStallion() noexcept;
[[nodiscard]] StallionStorage& GetStallionCache();
[[nodiscard]] std::vector<data::Uid> ListRegisteredStallions();
[[nodiscard]] DataSource& GetDataSource() noexcept;
private:
//! An underlying data source of the data director.
std::unique_ptr<DataSource> _primaryDataSource;
Scheduler _scheduler;
struct UserDataContext
{
//! A flag indicating whether a load is in progress.
std::atomic_bool isBeingLoaded = false;
//! A flag indicating whether an unload is in progress.
std::atomic_bool isBeingUnloaded = false;
//! A flag indicating whether the user data are loaded.
std::atomic_bool isUserDataLoaded = false;
//! A flag indicating whether the user character data are loaded.
std::atomic_bool isCharacterDataLoaded = false;
std::string debugMessage;
//! The time point when loading or unloading times out.
Scheduler::Clock::time_point timeout;
};
std::unordered_map<std::string, UserDataContext> _userDataContext;
void ScheduleUserLoad(UserDataContext& userDataContext, const std::string& userName);
void ScheduleCharacterLoad(UserDataContext& userDataContext, data::Uid characterUid);
//! An user storage.
UserStorage _userStorage;
//! An infraction storage.
InfractionStorage _infractionStorage;
//! A character storage.
CharacterStorage _characterStorage;
//! A horse storage.
HorseStorage _horseStorage;
//! An item storage.
ItemStorage _itemStorage;
//! A storage item storage.
StorageItemStorage _storageItemStorage;
//! An egg storage.
EggStorage _eggStorage;
//! A pet storage.
PetStorage _petStorage;
//! A housing storage.
HousingStorage _housingStorage;
//! A guild storage.
GuildStorage _guildStorage;
//! A character Keybind settings storage.
SettingsStorage _settingsStorage;
//! A daily quest group storage.
DailyQuestGroupStorage _dailyQuestGroupStorage;
//! A mail storage.
MailStorage _mailStorage;
//! A quest storage.
QuestStorage _questStorage;
//! A stallion storage.
StallionStorage _stallionStorage;
};
} // namespace server
#endif // DATADIRECTOR_HPP