Skip to content
This repository was archived by the owner on Jun 7, 2026. It is now read-only.

Commit 987d09e

Browse files
committed
Internal game data imports
1 parent de10d4f commit 987d09e

40 files changed

Lines changed: 554 additions & 504 deletions

modules/Deps.cmake

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,12 @@ CPMAddPackage(
100100

101101
if (sentry_ADDED)
102102
set_target_properties(sentry PROPERTIES C_STANDARD 11 C_EXTENSIONS ON)
103-
endif()
103+
endif()
104+
105+
CPMAddPackage(
106+
NAME pugixml
107+
GITHUB_REPOSITORY zeux/pugixml
108+
GIT_TAG v1.15
109+
OPTIONS
110+
"BUILD_SHARED_LIBS OFF"
111+
)

src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ target_link_libraries(${PROJECT_NAME} PRIVATE
5151
libzip::zip
5252
sentry::sentry
5353
yaml-cpp::yaml-cpp
54+
pugixml::pugixml
5455
)
5556

5657
# ##############################################################################

src/api/v1/system.cc

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#include <models/Project.h>
66
#include <service/auth.h>
77
#include <service/serializers.h>
8-
#include <service/system/data_import.h>
98
#include <service/util.h>
109
#include <version.h>
1110

@@ -14,6 +13,7 @@
1413
#include <service/system/access_keys.h>
1514
#include <service/system/lang.h>
1615
#include "base.h"
16+
#include "system/game_data.h"
1717

1818
using namespace std;
1919
using namespace drogon;
@@ -33,8 +33,7 @@ namespace api::v1 {
3333
NLOHMANN_DEFINE_TYPE_INTRUSIVE(DataMigration, id, title, desc)
3434
};
3535

36-
std::vector<DataMigration> dataMigrations = {
37-
{"deployments", "Project deployments", "Run initial project deployments", sys::runInitialDeployments}};
36+
std::vector<DataMigration> dataMigrations = {};
3837

3938
Task<bool> authAccessKey(const HttpRequestPtr req) {
4039
const auto authHeader = req->getHeader("Authorization");
@@ -89,12 +88,11 @@ namespace api::v1 {
8988
co_await global::auth->ensurePrivilegedAccess(req);
9089
}
9190

92-
const auto json(BaseProjectController::jsonBody(req));
91+
const auto body(BaseProjectController::jsonBody(req));
92+
const auto updateLoader = body.contains("update_loader") ? body["update_loader"].get<bool>() : false;
93+
const auto result = co_await global::gameData->importGameData(updateLoader);
9394

94-
constexpr sys::SystemDataImporter importer;
95-
const auto result = co_await importer.importData(json);
96-
97-
callback(statusResponse(result == Error::Ok ? k200OK : k500InternalServerError));
95+
callback(statusResponse(result ? k200OK : k500InternalServerError));
9896
}
9997

10098
Task<> SystemController::getAvailableMigrations(const HttpRequestPtr req,

src/api/v1/system.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace api::v1 {
1010
METHOD_LIST_BEGIN
1111
// Public
1212
ADD_METHOD_TO(SystemController::getLocales, "/api/v1/system/locales", drogon::Get, "AuthFilter");
13-
ADD_METHOD_TO(SystemController::importData, "/api/v1/system/import", drogon::Post);
13+
ADD_METHOD_TO(SystemController::importData, "/api/v1/system/import", drogon::Post, "AuthFilter");
1414
// Internal
1515
ADD_METHOD_TO(SystemController::getSystemInformation, "/api/v1/system/info", drogon::Get, "AuthFilter");
1616
ADD_METHOD_TO(SystemController::getDataImports, "/api/v1/system/imports", drogon::Get, "AuthFilter");

src/main.cc

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,21 @@
1616
#include <log/log.h>
1717

1818
#include <service/database/database.h>
19-
#include <service/external/github.h>
20-
#include <service/storage/realtime.h>
21-
#include <service/system/lang.h>
2219
#include <service/external/crowdin.h>
2320
#include <service/external/frontend.h>
21+
#include <service/external/github.h>
22+
#include <service/project/virtual/virtual.h>
23+
#include <service/storage/ingestor/recipe/recipe_builtin.h>
24+
#include <service/storage/realtime.h>
2425
#include <service/system/access_keys.h>
2526
#include <service/system/game_data.h>
26-
#include <service/storage/ingestor/recipe/recipe_builtin.h>
27-
#include <service/project/virtual/virtual.h>
27+
#include <service/system/lang.h>
2828
#include <service/system/startup.h>
2929

3030
using namespace drogon;
3131
using namespace logging;
3232
using namespace service;
33+
namespace fs = std::filesystem;
3334

3435
namespace service {
3536
trantor::EventLoopThreadPool cacheAwaiterThreadPool{10};
@@ -65,11 +66,11 @@ void globalExceptionHandler(const std::exception &e, const HttpRequestPtr &req,
6566
callback(statusResponse(k500InternalServerError));
6667
}
6768

68-
Task<> runStartupTaks() {
69-
global::virtualProject = co_await createVirtualProject();
69+
Task<> runStartupTaks(const fs::path gameFilesPath) {
70+
global::virtualProject = co_await createVirtualProject(gameFilesPath);
7071

7172
co_await cleanupLoadingDeployments();
72-
co_await global::gameData->setupGameData();
73+
co_await global::gameData->importGameData(false);
7374
co_await global::crowdin->getAvailableLocales();
7475
}
7576

@@ -82,13 +83,16 @@ int main() {
8283
app().setLogLevel(level).addListener("0.0.0.0", port).setThreadNum(16);
8384
configureLoggingLevel();
8485

85-
const auto [authConfig, githubAppConfig, mrApp, crowdinConfig, sentryConfig, appUrl, curseForgeKey, storagePath,
86-
salt, local] = config::configure();
86+
const auto [authConfig, githubAppConfig, mrApp, crowdinConfig, sentryConfig, appUrl, curseForgeKey, storagePath, salt, local] =
87+
config::configure();
8788

8889
if (!sentryConfig.dsn.empty()) {
8990
monitor::initSentry(sentryConfig.dsn);
9091
}
9192

93+
const auto gameFilesPath = fs::path(storagePath) / ".game";
94+
fs::create_directories(gameFilesPath);
95+
9296
global::database = std::make_shared<Database>();
9397
global::cache = std::make_shared<MemoryCache>();
9498
global::github = std::make_shared<GitHub>();
@@ -97,7 +101,7 @@ int main() {
97101
global::auth = std::make_shared<Auth>(appUrl, OAuthApp{githubAppConfig.clientId, githubAppConfig.clientSecret},
98102
OAuthApp{mrApp.clientId, mrApp.clientSecret});
99103
global::lang = std::make_shared<LangService>();
100-
global::gameData = std::make_shared<GameDataService>(storagePath);
104+
global::gameData = std::make_shared<GameDataService>();
101105
global::crowdin = std::make_shared<Crowdin>(crowdinConfig);
102106
global::accessKeys = std::make_shared<AccessKeys>(salt);
103107
global::frontend = std::make_shared<FrontendService>(authConfig.frontendUrl, authConfig.frontendApiKey);
@@ -131,7 +135,7 @@ int main() {
131135

132136
content::loadBuiltinRecipeTypes();
133137

134-
app().getLoop()->queueInLoop(async_func([]() -> Task<> { co_await runStartupTaks(); }));
138+
app().getLoop()->queueInLoop(async_func([=]() -> Task<> { co_await runStartupTaks(gameFilesPath); }));
135139

136140
app().run();
137141

src/schemas/definition/game-recipe.schema.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,8 @@
377377
"description": "An item ID.",
378378
"type": "string"
379379
}
380-
}
380+
},
381+
"required": ["id"]
381382
}
382383
},
383384
"description": "Configuration file defining a recipe for a data pack for Minecraft.",

src/service/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ add_library(service STATIC
2424
external/frontend.cc
2525
external/github.cc
2626

27+
project/virtual/format.cc
2728
project/virtual/virtual.cc
2829
project/cached/cached.cc
2930
project/content.cc
@@ -50,7 +51,6 @@ add_library(service STATIC
5051
storage/realtime.cc
5152

5253
system/access_keys.cc
53-
system/data_import.cc
5454
system/game_data.cc
5555
system/lang.cc
5656
system/startup.cc
@@ -73,6 +73,7 @@ target_link_libraries(service PRIVATE
7373
OpenSSL::Crypto
7474
libzip::zip
7575
yaml-cpp::yaml-cpp
76+
pugixml::pugixml
7677
)
7778

7879
target_include_directories(service PUBLIC

src/service/database/database.cc

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -303,11 +303,7 @@ namespace service {
303303
co_return res.value_or({});
304304
}
305305

306-
Task<TaskResult<DataImport>> Database::addDataImportRecord(const DataImport data) const {
307-
co_return co_await handleDatabaseOperation([&data](const DbClientPtr &client) -> Task<DataImport> {
308-
CoroMapper<DataImport> mapper(client);
309-
310-
co_return co_await mapper.insert(data);
311-
});
306+
Task<TaskResult<DataImport>> Database::getDataImport(std::string gameVersion) const {
307+
co_return co_await findOne<DataImport>(Criteria(DataImport::Cols::_game_version, CompareOperator::EQ, gameVersion));
312308
}
313309
}

src/service/database/database.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#include <models/Deployment.h>
1010
#include <models/ProjectIssue.h>
1111
#include <models/ProjectVersion.h>
12-
#include <models/Recipe.h>
1312
#include <models/Report.h>
1413
#include <nlohmann/json.hpp>
1514
#include <service/error.h>
@@ -97,16 +96,11 @@ namespace service {
9796

9897
// Content
9998
drogon::Task<TaskResult<>> refreshFlatTagItemView() const;
100-
// TODO Remove after data imports are reworked
101-
drogon::Task<int64_t> addRecipe(std::string id, std::string type) const;
102-
drogon::Task<TaskResult<>> addRecipeIngredientItem(int64_t recipe_id, std::string item, int slot, int count, bool input) const;
103-
drogon::Task<TaskResult<>> addRecipeIngredientTag(int64_t recipe_id, std::string tag, int slot, int count, bool input) const;
104-
10599
drogon::Task<std::vector<std::string>> getItemSourceProjects(int64_t item) const;
106100
drogon::Task<std::vector<GlobalItem>> getGlobalTagItems(int64_t tagId) const;
107101

108102
// System data
109-
drogon::Task<TaskResult<DataImport>> addDataImportRecord(DataImport data) const;
103+
drogon::Task<TaskResult<DataImport>> getDataImport(std::string gameVersion) const;
110104
drogon::Task<PaginatedData<DataImport>> getDataImports(std::string searchQuery, int page) const;
111105

112106
// Deployments

src/service/database/database_base.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#pragma once
22

3-
#include <drogon/HttpAppFramework.h>
43
#include <drogon/orm/CoroMapper.h>
54
#include <drogon/utils/coroutine.h>
65
#include <log/log.h>

0 commit comments

Comments
 (0)