From ec6c5519a5eb7e0001c9858cf4a8d4d7b15b3b7e Mon Sep 17 00:00:00 2001 From: KimLS Date: Mon, 21 Oct 2013 16:41:34 -0700 Subject: [PATCH] More work on importing... I need my escape stuff from other branch for this though --- client_files/export/main.cpp | 8 +++--- client_files/import/main.cpp | 50 ++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 4 deletions(-) diff --git a/client_files/export/main.cpp b/client_files/export/main.cpp index 33904f579..260743424 100644 --- a/client_files/export/main.cpp +++ b/client_files/export/main.cpp @@ -95,7 +95,7 @@ void ExportSpells(SharedDatabase *db) { fclose(f); } -bool skill_usable(SharedDatabase *db, int skill_id, int class_id) { +bool SkillUsable(SharedDatabase *db, int skill_id, int class_id) { char errbuf[MYSQL_ERRMSG_SIZE]; char *query = nullptr; MYSQL_RES *result; @@ -117,7 +117,7 @@ bool skill_usable(SharedDatabase *db, int skill_id, int class_id) { return res; } -int get_skill(SharedDatabase *db, int skill_id, int class_id, int level) { +int GetSkill(SharedDatabase *db, int skill_id, int class_id, int level) { char errbuf[MYSQL_ERRMSG_SIZE]; char *query = nullptr; MYSQL_RES *result; @@ -148,10 +148,10 @@ void ExportSkillCaps(SharedDatabase *db) { for(int cl = 1; cl <= 16; ++cl) { for(int skill = 0; skill <= 77; ++skill) { - if(skill_usable(db, skill, cl)) { + if(SkillUsable(db, skill, cl)) { int previous_cap = 0; for(int level = 1; level <= 100; ++level) { - int cap = get_skill(db, skill, cl, level); + int cap = GetSkill(db, skill, cl, level); if(cap < previous_cap) { cap = previous_cap; } diff --git a/client_files/import/main.cpp b/client_files/import/main.cpp index a40b073bd..6b31ac6c4 100644 --- a/client_files/import/main.cpp +++ b/client_files/import/main.cpp @@ -22,6 +22,7 @@ #include "../../common/platform.h" #include "../../common/crash.h" #include "../../common/rulesys.h" +#include "../../common/StringUtil.h" void ImportSpells(SharedDatabase *db); void ImportSkillCaps(SharedDatabase *db); @@ -58,11 +59,60 @@ int main(int argc, char **argv) { return 0; } +int GetSpellColumns(SharedDatabase *db) { + char errbuf[MYSQL_ERRMSG_SIZE]; + char *query = "DESCRIBE spells_new"; + MYSQL_RES *result; + MYSQL_ROW row; + int res = 0; + if(db->RunQuery(query, strlen(query), errbuf, &result)) { + while(row = mysql_fetch_row(result)) { + ++res; + } + mysql_free_result(result); + } else { + LogFile->write(EQEMuLog::Error, "Error in GetSpellColumns query '%s' %s", query, errbuf); + } + + return res; +} + void ImportSpells(SharedDatabase *db) { + LogFile->write(EQEMuLog::Status, "Importing Spells..."); + FILE *f = fopen("import/spells_us.txt", "r"); + if(!f) { + LogFile->write(EQEMuLog::Error, "Unable to open import/spells_us.txt to read, skipping."); + return; + } + + int columns = GetSpellColumns(db); + + char buffer[2048]; + while(fgets(buffer, 2048, f)) { + auto split = SplitString(buffer, '^'); + } + + fclose(f); } void ImportSkillCaps(SharedDatabase *db) { + LogFile->write(EQEMuLog::Status, "Importing Skill Caps..."); + FILE *f = fopen("import/SkillCaps.txt", "r"); + if(!f) { + LogFile->write(EQEMuLog::Error, "Unable to open import/SkillCaps.txt to read, skipping."); + return; + } + + fclose(f); } void ImportBaseData(SharedDatabase *db) { + LogFile->write(EQEMuLog::Status, "Importing Base Data..."); + FILE *f = fopen("import/BaseData.txt", "r"); + if(!f) { + LogFile->write(EQEMuLog::Error, "Unable to open import/BaseData.txt to read, skipping."); + return; + } + + fclose(f); } \ No newline at end of file