mirror of
https://github.com/EQEmu/Server.git
synced 2025-12-13 10:31:29 +00:00
[Cleanup] Cleanup Client File Exporting (#4348)
* [Cleanup] Cleanup Client File Exporting * Update base_data_repository.h * Update db_str_repository.h * Update base_data_repository.h * Update skill_caps_repository.h * Update skill_caps_repository.h * Update skill_caps_repository.h * Update main.cpp * Push
This commit is contained in:
parent
2ef959c5ed
commit
aa700f8960
@ -29,7 +29,10 @@
|
|||||||
#include "../../common/content/world_content_service.h"
|
#include "../../common/content/world_content_service.h"
|
||||||
#include "../../common/zone_store.h"
|
#include "../../common/zone_store.h"
|
||||||
#include "../../common/path_manager.h"
|
#include "../../common/path_manager.h"
|
||||||
|
#include "../../common/repositories/base_data_repository.h"
|
||||||
|
#include "../../common/repositories/db_str_repository.h"
|
||||||
#include "../../common/repositories/skill_caps_repository.h"
|
#include "../../common/repositories/skill_caps_repository.h"
|
||||||
|
#include "../../common/repositories/spells_new_repository.h"
|
||||||
#include "../../common/file.h"
|
#include "../../common/file.h"
|
||||||
#include "../../common/events/player_event_logs.h"
|
#include "../../common/events/player_event_logs.h"
|
||||||
#include "../../common/skill_caps.h"
|
#include "../../common/skill_caps.h"
|
||||||
@ -99,25 +102,22 @@ int main(int argc, char **argv)
|
|||||||
->LoadLogDatabaseSettings()
|
->LoadLogDatabaseSettings()
|
||||||
->StartFileLogs();
|
->StartFileLogs();
|
||||||
|
|
||||||
std::string arg_1;
|
std::string export_type;
|
||||||
|
|
||||||
if (argv[1]) {
|
if (argv[1]) {
|
||||||
arg_1 = argv[1];
|
export_type = argv[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (arg_1 == "spells") {
|
if (Strings::EqualFold(export_type, "spells")) {
|
||||||
ExportSpells(&content_db);
|
ExportSpells(&content_db);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
} else if (Strings::EqualFold(export_type, "skills")) {
|
||||||
if (arg_1 == "skills") {
|
|
||||||
ExportSkillCaps(&content_db);
|
ExportSkillCaps(&content_db);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
} else if (Strings::EqualFold(export_type, "basedata") || Strings::EqualFold(export_type, "base_data")) {
|
||||||
if (arg_1 == "basedata") {
|
|
||||||
ExportBaseData(&content_db);
|
ExportBaseData(&content_db);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
} else if (Strings::EqualFold(export_type, "dbstr") || Strings::EqualFold(export_type, "dbstring")) {
|
||||||
if (arg_1 == "dbstring") {
|
|
||||||
ExportDBStrings(&database);
|
ExportDBStrings(&database);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -132,180 +132,79 @@ int main(int argc, char **argv)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExportSpells(SharedDatabase *db)
|
void ExportSpells(SharedDatabase* db)
|
||||||
{
|
{
|
||||||
LogInfo("Exporting Spells");
|
std::ofstream file(fmt::format("{}/export/spells_us.txt", path.GetServerPath()));
|
||||||
|
if (!file || !file.is_open()) {
|
||||||
std::string file = fmt::format("{}/export/spells_us.txt", path.GetServerPath());
|
|
||||||
FILE *f = fopen(file.c_str(), "w");
|
|
||||||
if (!f) {
|
|
||||||
LogError("Unable to open export/spells_us.txt to write, skipping.");
|
LogError("Unable to open export/spells_us.txt to write, skipping.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string query = "SELECT * FROM spells_new ORDER BY id";
|
const auto& lines = SpellsNewRepository::GetSpellFileLines(*db);
|
||||||
auto results = db->QueryDatabase(query);
|
|
||||||
|
|
||||||
if (results.Success()) {
|
const std::string& file_string = Strings::Implode("\n", lines);
|
||||||
for (auto row = results.begin(); row != results.end(); ++row) {
|
|
||||||
std::string line;
|
|
||||||
unsigned int fields = results.ColumnCount();
|
|
||||||
for (unsigned int i = 0; i < fields; ++i) {
|
|
||||||
if (i != 0) {
|
|
||||||
line.push_back('^');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (row[i] != nullptr) {
|
file << file_string;
|
||||||
line += row[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fprintf(f, "%s\n", line.c_str());
|
file.close();
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
}
|
|
||||||
|
|
||||||
fclose(f);
|
LogInfo("Exported [{}] Spell{}", lines.size(), lines.size() != 1 ? "s" : "");
|
||||||
}
|
|
||||||
|
|
||||||
bool SkillUsable(SharedDatabase* db, int skill_id, int class_id)
|
|
||||||
{
|
|
||||||
const auto& l = SkillCapsRepository::GetWhere(
|
|
||||||
*db,
|
|
||||||
fmt::format(
|
|
||||||
"`class_id` = {} AND `skill_id` = {} ORDER BY `cap` DESC LIMIT 1",
|
|
||||||
class_id,
|
|
||||||
skill_id
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
return !l.empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32 GetSkill(SharedDatabase* db, int skill_id, int class_id, int level)
|
|
||||||
{
|
|
||||||
const auto& l = SkillCapsRepository::GetWhere(
|
|
||||||
*db,
|
|
||||||
fmt::format(
|
|
||||||
"`class_id` = {} AND `skill_id` = {} AND `level` = {}",
|
|
||||||
class_id,
|
|
||||||
skill_id,
|
|
||||||
level
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
if (l.empty()) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto e = l.front();
|
|
||||||
|
|
||||||
return e.cap;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExportSkillCaps(SharedDatabase* db)
|
void ExportSkillCaps(SharedDatabase* db)
|
||||||
{
|
{
|
||||||
LogInfo("Exporting Skill Caps");
|
|
||||||
|
|
||||||
std::ofstream file(fmt::format("{}/export/SkillCaps.txt", path.GetServerPath()));
|
std::ofstream file(fmt::format("{}/export/SkillCaps.txt", path.GetServerPath()));
|
||||||
if (!file || !file.is_open()) {
|
if (!file || !file.is_open()) {
|
||||||
LogError("Unable to open export/SkillCaps.txt to write, skipping.");
|
LogError("Unable to open export/SkillCaps.txt to write, skipping.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (uint8 class_id = Class::Warrior; class_id <= Class::Berserker; class_id++) {
|
const auto& lines = SkillCapsRepository::GetSkillCapFileLines(*db);
|
||||||
for (uint8 skill_id = EQ::skills::Skill1HBlunt; skill_id <= EQ::skills::Skill2HPiercing; skill_id++) {
|
|
||||||
if (SkillUsable(db, skill_id, class_id)) {
|
|
||||||
uint32 previous_cap = 0;
|
|
||||||
|
|
||||||
for (
|
const std::string& file_string = Strings::Implode("\n", lines);
|
||||||
uint8 level = 1;
|
|
||||||
level <= SkillCaps::GetSkillCapMaxLevel(class_id, static_cast<EQ::skills::SkillType>(skill_id));
|
|
||||||
level++
|
|
||||||
) {
|
|
||||||
uint32 cap = GetSkill(db, skill_id, class_id, level);
|
|
||||||
if (cap < previous_cap) {
|
|
||||||
cap = previous_cap;
|
|
||||||
}
|
|
||||||
|
|
||||||
file << fmt::format("{}^{}^{}^{}^0", class_id, skill_id, level, cap) << std::endl;
|
file << file_string;
|
||||||
|
|
||||||
previous_cap = cap;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
file.close();
|
file.close();
|
||||||
|
|
||||||
|
LogInfo("Exported [{}] Skill Cap{}", lines.size(), lines.size() != 1 ? "s" : "");
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExportBaseData(SharedDatabase *db)
|
void ExportBaseData(SharedDatabase *db)
|
||||||
{
|
{
|
||||||
LogInfo("Exporting Base Data");
|
std::ofstream file(fmt::format("{}/export/BaseData.txt", path.GetServerPath()));
|
||||||
|
if (!file || !file.is_open()) {
|
||||||
std::string file = fmt::format("{}/export/BaseData.txt", path.GetServerPath());
|
|
||||||
FILE *f = fopen(file.c_str(), "w");
|
|
||||||
if (!f) {
|
|
||||||
LogError("Unable to open export/BaseData.txt to write, skipping.");
|
LogError("Unable to open export/BaseData.txt to write, skipping.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string query = "SELECT * FROM base_data ORDER BY level, class";
|
const auto& lines = BaseDataRepository::GetBaseDataFileLines(*db);
|
||||||
auto results = db->QueryDatabase(query);
|
|
||||||
if (results.Success()) {
|
|
||||||
for (auto row = results.begin(); row != results.end(); ++row) {
|
|
||||||
std::string line;
|
|
||||||
unsigned int fields = results.ColumnCount();
|
|
||||||
for (unsigned int rowIndex = 0; rowIndex < fields; ++rowIndex) {
|
|
||||||
if (rowIndex != 0) {
|
|
||||||
line.push_back('^');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (row[rowIndex] != nullptr) {
|
const std::string& file_string = Strings::Implode("\n", lines);
|
||||||
line += row[rowIndex];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fprintf(f, "%s\n", line.c_str());
|
file << file_string;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fclose(f);
|
file.close();
|
||||||
|
|
||||||
|
LogInfo("Exported [{}] Base Data Entr{}", lines.size(), lines.size() != 1 ? "ies" : "y");
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExportDBStrings(SharedDatabase *db)
|
void ExportDBStrings(SharedDatabase *db)
|
||||||
{
|
{
|
||||||
LogInfo("Exporting DB Strings");
|
std::ofstream file(fmt::format("{}/export/dbstr_us.txt", path.GetServerPath()));
|
||||||
|
if (!file || !file.is_open()) {
|
||||||
std::string file = fmt::format("{}/export/dbstr_us.txt", path.GetServerPath());
|
|
||||||
FILE *f = fopen(file.c_str(), "w");
|
|
||||||
if (!f) {
|
|
||||||
LogError("Unable to open export/dbstr_us.txt to write, skipping.");
|
LogError("Unable to open export/dbstr_us.txt to write, skipping.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(f, "Major^Minor^String(New)\n");
|
const auto& lines = DbStrRepository::GetDBStrFileLines(*db);
|
||||||
const std::string query = "SELECT * FROM db_str ORDER BY id, type";
|
|
||||||
auto results = db->QueryDatabase(query);
|
|
||||||
if (results.Success()) {
|
|
||||||
for (auto row = results.begin(); row != results.end(); ++row) {
|
|
||||||
std::string line;
|
|
||||||
unsigned int fields = results.ColumnCount();
|
|
||||||
for (unsigned int rowIndex = 0; rowIndex < fields; ++rowIndex) {
|
|
||||||
if (rowIndex != 0) {
|
|
||||||
line.push_back('^');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (row[rowIndex] != nullptr) {
|
const std::string& file_string = Strings::Implode("\n", lines);
|
||||||
line += row[rowIndex];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fprintf(f, "%s\n", line.c_str());
|
file << file_string;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fclose(f);
|
file.close();
|
||||||
|
|
||||||
|
LogInfo("Exported [{}] Database String{}", lines.size(), lines.size() != 1 ? "s" : "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -44,7 +44,24 @@ public:
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// Custom extended repository methods here
|
// Custom extended repository methods here
|
||||||
|
static std::vector<std::string> GetBaseDataFileLines(Database& db)
|
||||||
|
{
|
||||||
|
std::vector<std::string> lines;
|
||||||
|
|
||||||
|
auto results = db.QueryDatabase(
|
||||||
|
fmt::format(
|
||||||
|
"SELECT CONCAT_WS('^', {}) FROM {} ORDER BY `level`, `class` ASC",
|
||||||
|
ColumnsRaw(),
|
||||||
|
TableName()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
for (auto row : results) {
|
||||||
|
lines.emplace_back(row[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return lines;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //EQEMU_BASE_DATA_REPOSITORY_H
|
#endif //EQEMU_BASE_DATA_REPOSITORY_H
|
||||||
|
|||||||
@ -44,7 +44,24 @@ public:
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// Custom extended repository methods here
|
// Custom extended repository methods here
|
||||||
|
static std::vector<std::string> GetDBStrFileLines(Database& db)
|
||||||
|
{
|
||||||
|
std::vector<std::string> lines;
|
||||||
|
|
||||||
|
auto results = db.QueryDatabase(
|
||||||
|
fmt::format(
|
||||||
|
"SELECT CONCAT(CONCAT_WS('^', {}), '^0') FROM {} ORDER BY `id`, `type` ASC",
|
||||||
|
ColumnsRaw(),
|
||||||
|
TableName()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
for (auto row : results) {
|
||||||
|
lines.emplace_back(row[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return lines;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //EQEMU_DB_STR_REPOSITORY_H
|
#endif //EQEMU_DB_STR_REPOSITORY_H
|
||||||
|
|||||||
@ -44,7 +44,23 @@ public:
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// Custom extended repository methods here
|
// Custom extended repository methods here
|
||||||
|
static std::vector<std::string> GetSkillCapFileLines(Database& db)
|
||||||
|
{
|
||||||
|
std::vector<std::string> lines;
|
||||||
|
|
||||||
|
auto results = db.QueryDatabase(
|
||||||
|
fmt::format(
|
||||||
|
"SELECT CONCAT_WS('^', `class_id`, `skill_id`, `level`, `cap`, `class_`) FROM {} ORDER BY `class_id`, `skill_id`, `level` ASC",
|
||||||
|
TableName()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
for (auto row : results) {
|
||||||
|
lines.emplace_back(row[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return lines;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //EQEMU_SKILL_CAPS_REPOSITORY_H
|
#endif //EQEMU_SKILL_CAPS_REPOSITORY_H
|
||||||
|
|||||||
@ -44,7 +44,25 @@ public:
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// Custom extended repository methods here
|
// Custom extended repository methods here
|
||||||
|
static std::vector<std::string> GetSpellFileLines(Database& db)
|
||||||
|
{
|
||||||
|
std::vector<std::string> lines;
|
||||||
|
|
||||||
|
auto results = db.QueryDatabase(
|
||||||
|
fmt::format(
|
||||||
|
"SELECT CONCAT_WS('^', {}) FROM {} ORDER BY {} ASC",
|
||||||
|
ColumnsRaw(),
|
||||||
|
TableName(),
|
||||||
|
PrimaryKey()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
for (auto row : results) {
|
||||||
|
lines.emplace_back(row[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return lines;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //EQEMU_SPELLS_NEW_REPOSITORY_H
|
#endif //EQEMU_SPELLS_NEW_REPOSITORY_H
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user