From 84a16afc56aa5a93dae2c83a9b1482ab52e90c31 Mon Sep 17 00:00:00 2001 From: Haru Date: Sat, 19 Dec 2015 16:07:22 +0100 Subject: Removed duplicate code from the db2sql plugin Signed-off-by: Haru --- src/plugins/db2sql.c | 60 +++++++++++++++++++++------------------------------- 1 file changed, 24 insertions(+), 36 deletions(-) (limited to 'src/plugins/db2sql.c') diff --git a/src/plugins/db2sql.c b/src/plugins/db2sql.c index 5b5d79bac..abbb42ee0 100644 --- a/src/plugins/db2sql.c +++ b/src/plugins/db2sql.c @@ -49,7 +49,7 @@ struct { char *p; size_t len; } buf[4]; - char *db_name; + const char *db_name; } tosql; bool torun = false; @@ -328,53 +328,41 @@ void totable(void) { ") ENGINE=MyISAM;\n" "\n", year, tosql.db_name,tosql.db_name,tosql.db_name); } -void do_db2sql(void) { +void do_db2sql(void) +{ + int i; + struct convert_db_files { + const char *name; + const char *source; + const char *destination; + } files[] = { + {"item_db", "re/item_db.conf", "sql-files/item_db_re.sql"}, + {"item_db", "pre-re/item_db.conf", "sql-files/item_db.sql"}, + {"item_db2", "item_db2.conf", "sql-files/item_db2.sql"}, + }; + /* link */ itemdb_readdb_libconfig_sub = itemdb->readdb_libconfig_sub; itemdb->readdb_libconfig_sub = db2sql; /* */ - if ((tosql.fp = fopen("sql-files/item_db_re.sql", "wt+")) == NULL) { - ShowError("itemdb_tosql: File not found \"%s\".\n", "sql-files/item_db_re.sql"); - return; - } - - tosql.db_name = "item_db"; - totable(); - - memset(&tosql.buf, 0, sizeof(tosql.buf) ); - + memset(&tosql.buf, 0, sizeof(tosql.buf)); itemdb->clear(false); - itemdb->readdb_libconfig("re/item_db.conf"); - fclose(tosql.fp); - - if ((tosql.fp = fopen("sql-files/item_db.sql", "wt+")) == NULL) { - ShowError("itemdb_tosql: File not found \"%s\".\n", "sql-files/item_db.sql"); - return; - } - - tosql.db_name = "item_db"; - totable(); + for (i = 0; i < ARRAYLENGTH(files); i++) { + if ((tosql.fp = fopen(files[i].destination, "wt+")) == NULL) { + ShowError("itemdb_tosql: File not found \"%s\".\n", files[i].destination); + return; + } - itemdb->clear(false); - itemdb->readdb_libconfig("pre-re/item_db.conf"); + tosql.db_name = files[i].name; + totable(); - fclose(tosql.fp); + itemdb->readdb_libconfig(files[i].source); - if ((tosql.fp = fopen("sql-files/item_db2.sql", "wt+")) == NULL) { - ShowError("itemdb_tosql: File not found \"%s\".\n", "sql-files/item_db2.sql"); - return; + fclose(tosql.fp); } - tosql.db_name = "item_db2"; - totable(); - - itemdb->clear(false); - itemdb->readdb_libconfig("item_db2.conf"); - - fclose(tosql.fp); - /* unlink */ itemdb->readdb_libconfig_sub = itemdb_readdb_libconfig_sub; -- cgit v1.2.3-70-g09d2 From 9e922317933de98bb25146045ceb56ac4e6d1a24 Mon Sep 17 00:00:00 2001 From: Haru Date: Sat, 19 Dec 2015 16:11:43 +0100 Subject: Changed DB2SQL plugin to not cross-convert databases - To convert a renewal database, compile the server and plugin as renewal, and to convert a pre-renewal database, compile both as pre-renewal. - This is a necessary evil, for future compatibility. Signed-off-by: Haru --- src/plugins/db2sql.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/plugins/db2sql.c') diff --git a/src/plugins/db2sql.c b/src/plugins/db2sql.c index abbb42ee0..32df45e84 100644 --- a/src/plugins/db2sql.c +++ b/src/plugins/db2sql.c @@ -43,6 +43,12 @@ HPExport struct hplugin_info pinfo = { HPM_VERSION, // HPM Version (don't change, macro is automatically updated) }; +#ifdef RENEWAL +#define DBSUFFIX "_re" +#else // not RENEWAL +#define DBSUFFIX "" +#endif + struct { FILE *fp; struct { @@ -336,8 +342,7 @@ void do_db2sql(void) const char *source; const char *destination; } files[] = { - {"item_db", "re/item_db.conf", "sql-files/item_db_re.sql"}, - {"item_db", "pre-re/item_db.conf", "sql-files/item_db.sql"}, + {"item_db", DBPATH"item_db.conf", "sql-files/item_db" DBSUFFIX ".sql"}, {"item_db2", "item_db2.conf", "sql-files/item_db2.sql"}, }; -- cgit v1.2.3-70-g09d2 From 25451ef2213026d6868645f673570607f96f1272 Mon Sep 17 00:00:00 2001 From: Haru Date: Sun, 6 Dec 2015 18:40:27 +0100 Subject: Renamed some db2sql* plugin functions to itemdb2sql* Signed-off-by: Haru --- .../xcshareddata/xcschemes/db2sql.xcscheme | 40 +--- db2sql.bat | 4 +- src/plugins/db2sql.c | 210 ++++++++++++++------- 3 files changed, 144 insertions(+), 110 deletions(-) (limited to 'src/plugins/db2sql.c') diff --git a/Hercules.xcodeproj/xcshareddata/xcschemes/db2sql.xcscheme b/Hercules.xcodeproj/xcshareddata/xcschemes/db2sql.xcscheme index e39416fce..603e02228 100644 --- a/Hercules.xcodeproj/xcshareddata/xcschemes/db2sql.xcscheme +++ b/Hercules.xcodeproj/xcshareddata/xcschemes/db2sql.xcscheme @@ -56,44 +56,6 @@ debugDocumentVersioning = "YES" debugServiceExtension = "internal" allowLocationSimulation = "YES"> - - - - - - - - - - - - - - - - - - - - diff --git a/db2sql.bat b/db2sql.bat index 0784105cd..9bad06ef2 100644 --- a/db2sql.bat +++ b/db2sql.bat @@ -36,10 +36,10 @@ ECHO http://herc.ws/board/ ECHO. ECHO. -ECHO Exporting item databases to 'sql-files' folder... +ECHO Exporting databases to 'sql-files' folder... PING -n 3 -w 1 127.0.0.1 > nul -map-server.exe --db2sql +map-server.exe --load-plugin db2sql --db2sql ECHO. PING -n 10 -w 1 127.0.0.1 > nul diff --git a/src/plugins/db2sql.c b/src/plugins/db2sql.c index 32df45e84..7cc227e7c 100644 --- a/src/plugins/db2sql.c +++ b/src/plugins/db2sql.c @@ -24,12 +24,10 @@ #include "common/conf.h" #include "common/memmgr.h" #include "common/mmo.h" +#include "common/nullpo.h" #include "common/strlib.h" -#include "common/timer.h" -#include "map/clif.h" #include "map/itemdb.h" #include "map/map.h" -#include "map/pc.h" #include "common/HPMDataCheck.h" @@ -49,38 +47,93 @@ HPExport struct hplugin_info pinfo = { #define DBSUFFIX "" #endif +/// Conversion state tracking. struct { - FILE *fp; + FILE *fp; ///< Currently open file pointer struct { - char *p; - size_t len; - } buf[4]; - const char *db_name; + char *p; ///< Buffer pointer + size_t len; ///< Buffer length + } buf[4]; ///< Output buffer + const char *db_name; ///< Database table name } tosql; -bool torun = false; +/// Whether the item_db converter will automatically run. +bool itemdb2sql_torun = false; + +/// Backup of the original item_db parser function pointer. int (*itemdb_readdb_libconfig_sub) (config_setting_t *it, int n, const char *source); -void hstr(const char *str) { - if( strlen(str) > tosql.buf[3].len ) { + +/** + * Normalizes and appends a string to the output buffer. + * + * @param str The string to append. + */ +void hstr(const char *str) +{ + if (strlen(str) > tosql.buf[3].len) { tosql.buf[3].len = tosql.buf[3].len + strlen(str) + 1000; RECREATE(tosql.buf[3].p,char,tosql.buf[3].len); } safestrncpy(tosql.buf[3].p,str,strlen(str)); normalize_name(tosql.buf[3].p,"\t\n "); } -int db2sql(config_setting_t *entry, int n, const char *source) { + +/** + * Prints a SQL file header for the current item_db file. + */ +void db2sql_fileheader(void) +{ + time_t t = time(NULL); + struct tm *lt = localtime(&t); + int year = lt->tm_year+1900; + + fprintf(tosql.fp, + "-- This file is part of Hercules.\n" + "-- http://herc.ws - http://github.com/HerculesWS/Hercules\n" + "--\n" + "-- Copyright (C) 2013-%d Hercules Dev Team\n" + "--\n" + "-- Hercules is free software: you can redistribute it and/or modify\n" + "-- it under the terms of the GNU General Public License as published by\n" + "-- the Free Software Foundation, either version 3 of the License, or\n" + "-- (at your option) any later version.\n" + "--\n" + "-- This program is distributed in the hope that it will be useful,\n" + "-- but WITHOUT ANY WARRANTY; without even the implied warranty of\n" + "-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" + "-- GNU General Public License for more details.\n" + "--\n" + "-- You should have received a copy of the GNU General Public License\n" + "-- along with this program. If not, see .\n\n" + + "-- NOTE: This file was auto-generated and should never be manually edited,\n" + "-- as it will get overwritten. If you need to modify this file,\n" + "-- please consider modifying the corresponding .conf file inside\n" + "-- the db folder, and then re-run the db2sql plugin.\n" + "\n", year); +} + +/** + * Converts an Item DB entry to SQL. + * + * @see itemdb_readdb_libconfig_sub. + */ +int itemdb2sql_sub(config_setting_t *entry, int n, const char *source) +{ struct item_data *it = NULL; - if( (it = itemdb->exists(itemdb_readdb_libconfig_sub(entry,n,source))) ) { + if ((it = itemdb->exists(itemdb_readdb_libconfig_sub(entry,n,source)))) { char e_name[ITEM_NAME_LENGTH*2+1]; const char *bonus = NULL; char *str; int i32; - unsigned int ui32; + uint32 ui32; config_setting_t *t = NULL; StringBuf buf; + nullpo_ret(entry); + StrBuf->Init(&buf); // id @@ -98,10 +151,10 @@ int db2sql(config_setting_t *entry, int n, const char *source) { StrBuf->Printf(&buf, "'%u',", it->flag.delay_consume?IT_DELAYCONSUME:it->type); // price_buy - StrBuf->Printf(&buf, "'%u',", it->value_buy); + StrBuf->Printf(&buf, "'%d',", it->value_buy); // price_sell - StrBuf->Printf(&buf, "'%u',", it->value_sell); + StrBuf->Printf(&buf, "'%d',", it->value_sell); // weight StrBuf->Printf(&buf, "'%u',", it->weight); @@ -122,15 +175,15 @@ int db2sql(config_setting_t *entry, int n, const char *source) { StrBuf->Printf(&buf, "'%u',", it->slot); // equip_jobs - if( libconfig->setting_lookup_int(entry, "Job", &i32) ) // This is an unsigned value, do not check for >= 0 - ui32 = (unsigned int)i32; + if (libconfig->setting_lookup_int(entry, "Job", &i32)) // This is an unsigned value, do not check for >= 0 + ui32 = (uint32)i32; else ui32 = UINT_MAX; StrBuf->Printf(&buf, "'%u',", ui32); // equip_upper - if( libconfig->setting_lookup_int(entry, "Upper", &i32) && i32 >= 0 ) - ui32 = (unsigned int)i32; + if (libconfig->setting_lookup_int(entry, "Upper", &i32) && i32 >= 0) + ui32 = (uint32)i32; else ui32 = ITEMUPPER_ALL; StrBuf->Printf(&buf, "'%u',", ui32); @@ -148,7 +201,7 @@ int db2sql(config_setting_t *entry, int n, const char *source) { StrBuf->Printf(&buf, "'%u',", it->elv); // equip_level_max - if( (t = libconfig->setting_get_member(entry, "EquipLv")) && config_setting_is_aggregate(t) && libconfig->setting_length(t) >= 2 ) + if ((t = libconfig->setting_get_member(entry, "EquipLv")) && config_setting_is_aggregate(t) && libconfig->setting_length(t) >= 2) StrBuf->Printf(&buf, "'%u',", it->elvmax); else StrBuf->AppendStr(&buf, "NULL,"); @@ -259,36 +312,15 @@ int db2sql(config_setting_t *entry, int n, const char *source) { return it?it->nameid:0; } -void totable(void) { - time_t t; - struct tm *lt; - t = time(NULL); - lt = localtime(&t); - int year = lt->tm_year+1900; - fprintf(tosql.fp, - "-- This file is part of Hercules.\n" - "-- http://herc.ws - http://github.com/HerculesWS/Hercules\n" - "--\n" - "-- Copyright (C) 2013-%d Hercules Dev Team\n" - "--\n" - "-- Hercules is free software: you can redistribute it and/or modify\n" - "-- it under the terms of the GNU General Public License as published by\n" - "-- the Free Software Foundation, either version 3 of the License, or\n" - "-- (at your option) any later version.\n" - "--\n" - "-- This program is distributed in the hope that it will be useful,\n" - "-- but WITHOUT ANY WARRANTY; without even the implied warranty of\n" - "-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" - "-- GNU General Public License for more details.\n" - "--\n" - "-- You should have received a copy of the GNU General Public License\n" - "-- along with this program. If not, see .\n\n" - "-- NOTE: This file was auto-generated and should never be manually edited,\n" - "-- as it will get overwritten. If you need to modify this file,\n" - "-- please consider modifying the corresponding .conf file inside\n" - "-- the db folder, and then re-run the db2sql plugin.\n" - "\n" +/** + * Prints a SQL table header for the current item_db table. + */ +void itemdb2sql_tableheader(void) +{ + db2sql_fileheader(); + + fprintf(tosql.fp, "--\n" "-- Table structure for table `%s`\n" "--\n" @@ -332,9 +364,15 @@ void totable(void) { " `unequip_script` text,\n" " PRIMARY KEY (`id`)\n" ") ENGINE=MyISAM;\n" - "\n", year, tosql.db_name,tosql.db_name,tosql.db_name); + "\n", tosql.db_name,tosql.db_name,tosql.db_name); } -void do_db2sql(void) + +/** + * Plugin main function. + * + * Converts Item DB and Item DB2 to SQL scripts. + */ +void do_itemdb2sql(void) { int i; struct convert_db_files { @@ -348,8 +386,7 @@ void do_db2sql(void) /* link */ itemdb_readdb_libconfig_sub = itemdb->readdb_libconfig_sub; - itemdb->readdb_libconfig_sub = db2sql; - /* */ + itemdb->readdb_libconfig_sub = itemdb2sql_sub; memset(&tosql.buf, 0, sizeof(tosql.buf)); itemdb->clear(false); @@ -361,7 +398,7 @@ void do_db2sql(void) } tosql.db_name = files[i].name; - totable(); + itemdb2sql_tableheader(); itemdb->readdb_libconfig(files[i].source); @@ -371,27 +408,62 @@ void do_db2sql(void) /* unlink */ itemdb->readdb_libconfig_sub = itemdb_readdb_libconfig_sub; - if( tosql.buf[0].p ) aFree(tosql.buf[0].p); - if( tosql.buf[1].p ) aFree(tosql.buf[1].p); - if( tosql.buf[2].p ) aFree(tosql.buf[2].p); - if( tosql.buf[3].p ) aFree(tosql.buf[3].p); + for (i = 0; i < ARRAYLENGTH(tosql.buf); i++) { + if (tosql.buf[i].p) + aFree(tosql.buf[i].p); + } +} + +/** + * Console command db2sql. + */ +CPCMD(db2sql) +{ + do_itemdb2sql(); } -CPCMD(db2sql) { - do_db2sql(); + +/** + * Console command itemdb2sql. + */ +CPCMD(itemdb2sql) +{ + do_itemdb2sql(); } + +/** + * Command line argument handler for --db2sql + */ CMDLINEARG(db2sql) { - map->minimal = torun = true; + map->minimal = true; + itemdb2sql_torun = true; + return true; +} + +/** + * Command line argument handler for --itemdb2sql + */ +CMDLINEARG(itemdb2sql) +{ + map->minimal = true; + itemdb2sql_torun = true; return true; } -HPExport void server_preinit(void) { - addArg("--db2sql",false,db2sql,NULL); +HPExport void server_preinit(void) +{ + addArg("--db2sql", false, db2sql, NULL); + addArg("--itemdb2sql", false, itemdb2sql, NULL); } -HPExport void plugin_init(void) { - addCPCommand("server:tools:db2sql",db2sql); + +HPExport void plugin_init(void) +{ + addCPCommand("server:tools:db2sql", db2sql); + addCPCommand("server:tools:itemdb2sql", itemdb2sql); } -HPExport void server_online(void) { - if( torun ) - do_db2sql(); + +HPExport void server_online(void) +{ + if (itemdb2sql_torun) + do_itemdb2sql(); } -- cgit v1.2.3-70-g09d2 From e1c55560f5cd5034e80eab8bf637ca99c9831ec7 Mon Sep 17 00:00:00 2001 From: Haru Date: Mon, 7 Dec 2015 04:29:55 +0100 Subject: Added modb2sql converter to the db2sql plugin Signed-off-by: Haru --- src/plugins/db2sql.c | 308 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 306 insertions(+), 2 deletions(-) (limited to 'src/plugins/db2sql.c') diff --git a/src/plugins/db2sql.c b/src/plugins/db2sql.c index 7cc227e7c..44e2bac3c 100644 --- a/src/plugins/db2sql.c +++ b/src/plugins/db2sql.c @@ -26,7 +26,9 @@ #include "common/mmo.h" #include "common/nullpo.h" #include "common/strlib.h" +#include "map/battle.h" #include "map/itemdb.h" +#include "map/mob.h" #include "map/map.h" #include "common/HPMDataCheck.h" @@ -59,10 +61,13 @@ struct { /// Whether the item_db converter will automatically run. bool itemdb2sql_torun = false; +/// Whether the mob_db converter will automatically run. +bool mobdb2sql_torun = false; /// Backup of the original item_db parser function pointer. int (*itemdb_readdb_libconfig_sub) (config_setting_t *it, int n, const char *source); - +/// Backup of the original mob_db parser function pointer. +int (*mob_read_db_sub) (config_setting_t *it, int n, const char *source); /** * Normalizes and appends a string to the output buffer. @@ -368,7 +373,7 @@ void itemdb2sql_tableheader(void) } /** - * Plugin main function. + * Item DB Conversion. * * Converts Item DB and Item DB2 to SQL scripts. */ @@ -414,12 +419,288 @@ void do_itemdb2sql(void) } } +/** + * Converts a Mob DB entry to SQL. + * + * @see mobdb_readdb_libconfig_sub. + */ +int mobdb2sql_sub(config_setting_t *mobt, int n, const char *source) +{ + struct mob_db *md = NULL; + nullpo_ret(mobt); + + if ((md = mob->db(mob_read_db_sub(mobt, n, source))) != mob->dummy) { + char e_name[NAME_LENGTH*2+1]; + StringBuf buf; + int card_idx = 9, i; + + StrBuf->Init(&buf); + + // id + StrBuf->Printf(&buf, "%u,", md->mob_id); + + // Sprite + SQL->EscapeString(NULL, e_name, md->sprite); + StrBuf->Printf(&buf, "'%s',", e_name); + + // kName + SQL->EscapeString(NULL, e_name, md->name); + StrBuf->Printf(&buf, "'%s',", e_name); + + // iName + SQL->EscapeString(NULL, e_name, md->jname); + StrBuf->Printf(&buf, "'%s',", e_name); + + // LV + StrBuf->Printf(&buf, "%u,", md->lv); + + // HP + StrBuf->Printf(&buf, "%u,", md->status.max_hp); + + // SP + StrBuf->Printf(&buf, "%u,", md->status.max_sp); + + // EXP + StrBuf->Printf(&buf, "%u,", md->base_exp); + + // JEXP + StrBuf->Printf(&buf, "%u,", md->job_exp); + + // Range1 + StrBuf->Printf(&buf, "%u,", md->status.rhw.range); + + // ATK1 + StrBuf->Printf(&buf, "%u,", md->status.rhw.atk); + + // ATK2 + StrBuf->Printf(&buf, "%u,", md->status.rhw.atk2); + + // DEF + StrBuf->Printf(&buf, "%u,", md->status.def); + + // MDEF + StrBuf->Printf(&buf, "%u,", md->status.mdef); + + // STR + StrBuf->Printf(&buf, "%u,", md->status.str); + + // AGI + StrBuf->Printf(&buf, "%u,", md->status.agi); + + // VIT + StrBuf->Printf(&buf, "%u,", md->status.vit); + + // INT + StrBuf->Printf(&buf, "%u,", md->status.int_); + + // DEX + StrBuf->Printf(&buf, "%u,", md->status.dex); + + // LUK + StrBuf->Printf(&buf, "%u,", md->status.luk); + + // Range2 + StrBuf->Printf(&buf, "%u,", md->range2); + + // Range3 + StrBuf->Printf(&buf, "%u,", md->range3); + + // Scale + StrBuf->Printf(&buf, "%u,", md->status.size); + + // Race + StrBuf->Printf(&buf, "%u,", md->status.race); + + // Element + StrBuf->Printf(&buf, "%u,", md->status.def_ele + 20 * md->status.ele_lv); + + // Mode + StrBuf->Printf(&buf, "0x%X,", md->status.mode); + + // Speed + StrBuf->Printf(&buf, "%u,", md->status.speed); + + // aDelay + StrBuf->Printf(&buf, "%u,", md->status.adelay); + + // aMotion + StrBuf->Printf(&buf, "%u,", md->status.amotion); + + // dMotion + StrBuf->Printf(&buf, "%u,", md->status.dmotion); + + // MEXP + StrBuf->Printf(&buf, "%u,", md->mexp); + + for (i = 0; i < 3; i++) { + // MVP{i}id + StrBuf->Printf(&buf, "%u,", md->mvpitem[i].nameid); + // MVP{i}per + StrBuf->Printf(&buf, "%u,", md->mvpitem[i].p); + } + + // Scan for cards + for (i = 0; i < 10; i++) { + struct item_data *it = NULL; + if (md->dropitem[i].nameid != 0 && (it = itemdb->exists(md->dropitem[i].nameid)) != NULL && it->type == IT_CARD) + card_idx = i; + } + + for (i = 0; i < 10; i++) { + if (card_idx == i) + continue; + // Drop{i}id + StrBuf->Printf(&buf, "%u,", md->dropitem[i].nameid); + // Drop{i}per + StrBuf->Printf(&buf, "%u,", md->dropitem[i].p); + } + + // DropCardid + StrBuf->Printf(&buf, "%u,", md->dropitem[card_idx].nameid); + // DropCardper + StrBuf->Printf(&buf, "%u", md->dropitem[card_idx].p); + + fprintf(tosql.fp, "REPLACE INTO `%s` VALUES (%s);\n", tosql.db_name, StrBuf->Value(&buf)); + + StrBuf->Destroy(&buf); + } + + return md ? md->mob_id : 0; +} + +/** + * Prints a SQL table header for the current mob_db table. + */ +void mobdb2sql_tableheader(void) +{ + db2sql_fileheader(); + + fprintf(tosql.fp, + "--\n" + "-- Table structure for table `%s`\n" + "--\n" + "\n" + "DROP TABLE IF EXISTS `%s`;\n" + "CREATE TABLE `%s` (\n" + " `ID` MEDIUMINT(9) UNSIGNED NOT NULL DEFAULT '0',\n" + " `Sprite` TEXT NOT NULL,\n" + " `kName` TEXT NOT NULL,\n" + " `iName` TEXT NOT NULL,\n" + " `LV` TINYINT(6) UNSIGNED NOT NULL DEFAULT '0',\n" + " `HP` INT(9) UNSIGNED NOT NULL DEFAULT '0',\n" + " `SP` MEDIUMINT(9) UNSIGNED NOT NULL DEFAULT '0',\n" + " `EXP` MEDIUMINT(9) UNSIGNED NOT NULL DEFAULT '0',\n" + " `JEXP` MEDIUMINT(9) UNSIGNED NOT NULL DEFAULT '0',\n" + " `Range1` TINYINT(4) UNSIGNED NOT NULL DEFAULT '0',\n" + " `ATK1` SMALLINT(6) UNSIGNED NOT NULL DEFAULT '0',\n" + " `ATK2` SMALLINT(6) UNSIGNED NOT NULL DEFAULT '0',\n" + " `DEF` SMALLINT(6) UNSIGNED NOT NULL DEFAULT '0',\n" + " `MDEF` SMALLINT(6) UNSIGNED NOT NULL DEFAULT '0',\n" + " `STR` SMALLINT(6) UNSIGNED NOT NULL DEFAULT '0',\n" + " `AGI` SMALLINT(6) UNSIGNED NOT NULL DEFAULT '0',\n" + " `VIT` SMALLINT(6) UNSIGNED NOT NULL DEFAULT '0',\n" + " `INT` SMALLINT(6) UNSIGNED NOT NULL DEFAULT '0',\n" + " `DEX` SMALLINT(6) UNSIGNED NOT NULL DEFAULT '0',\n" + " `LUK` SMALLINT(6) UNSIGNED NOT NULL DEFAULT '0',\n" + " `Range2` TINYINT(4) UNSIGNED NOT NULL DEFAULT '0',\n" + " `Range3` TINYINT(4) UNSIGNED NOT NULL DEFAULT '0',\n" + " `Scale` TINYINT(4) UNSIGNED NOT NULL DEFAULT '0',\n" + " `Race` TINYINT(4) UNSIGNED NOT NULL DEFAULT '0',\n" + " `Element` TINYINT(4) UNSIGNED NOT NULL DEFAULT '0',\n" + " `Mode` SMALLINT(6) UNSIGNED NOT NULL DEFAULT '0',\n" + " `Speed` SMALLINT(6) UNSIGNED NOT NULL DEFAULT '0',\n" + " `aDelay` SMALLINT(6) UNSIGNED NOT NULL DEFAULT '0',\n" + " `aMotion` SMALLINT(6) UNSIGNED NOT NULL DEFAULT '0',\n" + " `dMotion` SMALLINT(6) UNSIGNED NOT NULL DEFAULT '0',\n" + " `MEXP` MEDIUMINT(9) UNSIGNED NOT NULL DEFAULT '0',\n" + " `MVP1id` SMALLINT(9) UNSIGNED NOT NULL DEFAULT '0',\n" + " `MVP1per` SMALLINT(9) UNSIGNED NOT NULL DEFAULT '0',\n" + " `MVP2id` SMALLINT(9) UNSIGNED NOT NULL DEFAULT '0',\n" + " `MVP2per` SMALLINT(9) UNSIGNED NOT NULL DEFAULT '0',\n" + " `MVP3id` SMALLINT(9) UNSIGNED NOT NULL DEFAULT '0',\n" + " `MVP3per` SMALLINT(9) UNSIGNED NOT NULL DEFAULT '0',\n" + " `Drop1id` SMALLINT(9) UNSIGNED NOT NULL DEFAULT '0',\n" + " `Drop1per` SMALLINT(9) UNSIGNED NOT NULL DEFAULT '0',\n" + " `Drop2id` SMALLINT(9) UNSIGNED NOT NULL DEFAULT '0',\n" + " `Drop2per` SMALLINT(9) UNSIGNED NOT NULL DEFAULT '0',\n" + " `Drop3id` SMALLINT(9) UNSIGNED NOT NULL DEFAULT '0',\n" + " `Drop3per` SMALLINT(9) UNSIGNED NOT NULL DEFAULT '0',\n" + " `Drop4id` SMALLINT(9) UNSIGNED NOT NULL DEFAULT '0',\n" + " `Drop4per` SMALLINT(9) UNSIGNED NOT NULL DEFAULT '0',\n" + " `Drop5id` SMALLINT(9) UNSIGNED NOT NULL DEFAULT '0',\n" + " `Drop5per` SMALLINT(9) UNSIGNED NOT NULL DEFAULT '0',\n" + " `Drop6id` SMALLINT(9) UNSIGNED NOT NULL DEFAULT '0',\n" + " `Drop6per` SMALLINT(9) UNSIGNED NOT NULL DEFAULT '0',\n" + " `Drop7id` SMALLINT(9) UNSIGNED NOT NULL DEFAULT '0',\n" + " `Drop7per` SMALLINT(9) UNSIGNED NOT NULL DEFAULT '0',\n" + " `Drop8id` SMALLINT(9) UNSIGNED NOT NULL DEFAULT '0',\n" + " `Drop8per` SMALLINT(9) UNSIGNED NOT NULL DEFAULT '0',\n" + " `Drop9id` SMALLINT(9) UNSIGNED NOT NULL DEFAULT '0',\n" + " `Drop9per` SMALLINT(9) UNSIGNED NOT NULL DEFAULT '0',\n" + " `DropCardid` SMALLINT(9) UNSIGNED NOT NULL DEFAULT '0',\n" + " `DropCardper` SMALLINT(9) UNSIGNED NOT NULL DEFAULT '0',\n" + " PRIMARY KEY (`ID`)\n" + ") ENGINE=MyISAM;\n" + "\n", tosql.db_name, tosql.db_name, tosql.db_name); +} + +/** + * Mob DB Conversion. + * + * Converts Mob DB and Mob DB2 to SQL scripts. + */ +void do_mobdb2sql(void) +{ + int i; + struct convert_db_files { + const char *name; + const char *source; + const char *destination; + } files[] = { + {"mob_db", DBPATH"mob_db.conf", "sql-files/mob_db" DBSUFFIX ".sql"}, + {"mob_db2", "mob_db2.conf", "sql-files/mob_db2.sql"}, + }; + + /* link */ + mob_read_db_sub = mob->read_db_sub; + mob->read_db_sub = mobdb2sql_sub; + + if (map->minimal) { + // Set up modifiers + battle->config_set_defaults(); + } + + memset(&tosql.buf, 0, sizeof(tosql.buf)); + for (i = 0; i < ARRAYLENGTH(files); i++) { + if ((tosql.fp = fopen(files[i].destination, "wt+")) == NULL) { + ShowError("mobdb_tosql: File not found \"%s\".\n", files[i].destination); + return; + } + + tosql.db_name = files[i].name; + mobdb2sql_tableheader(); + + mob->read_libconfig(files[i].source, false); + + fclose(tosql.fp); + } + + /* unlink */ + mob->read_db_sub = mob_read_db_sub; + + for (i = 0; i < ARRAYLENGTH(tosql.buf); i++) { + if (tosql.buf[i].p) + aFree(tosql.buf[i].p); + } +} + /** * Console command db2sql. */ CPCMD(db2sql) { do_itemdb2sql(); + do_mobdb2sql(); } /** @@ -430,6 +711,14 @@ CPCMD(itemdb2sql) do_itemdb2sql(); } +/** + * Console command mobdb2sql. + */ +CPCMD(mobdb2sql) +{ + do_mobdb2sql(); +} + /** * Command line argument handler for --db2sql */ @@ -437,6 +726,7 @@ CMDLINEARG(db2sql) { map->minimal = true; itemdb2sql_torun = true; + mobdb2sql_torun = true; return true; } @@ -450,20 +740,34 @@ CMDLINEARG(itemdb2sql) return true; } +/** + * Command line argument handler for --mobdb2sql + */ +CMDLINEARG(mobdb2sql) +{ + map->minimal = true; + mobdb2sql_torun = true; + return true; +} + HPExport void server_preinit(void) { addArg("--db2sql", false, db2sql, NULL); addArg("--itemdb2sql", false, itemdb2sql, NULL); + addArg("--mobdb2sql", false, mobdb2sql, NULL); } HPExport void plugin_init(void) { addCPCommand("server:tools:db2sql", db2sql); addCPCommand("server:tools:itemdb2sql", itemdb2sql); + addCPCommand("server:tools:mobdb2sql", mobdb2sql); } HPExport void server_online(void) { if (itemdb2sql_torun) do_itemdb2sql(); + if (mobdb2sql_torun) + do_mobdb2sql(); } -- cgit v1.2.3-70-g09d2