Skip to content

Commit

Permalink
Removed support for the deprecated SQL item, mob, mob_skill databases.
Browse files Browse the repository at this point in the history
Follow-up to 84e02ac

Signed-off-by: Haru <haru@dotalux.com>
  • Loading branch information
MishimaHaruna committed Oct 22, 2015
1 parent e4c30ae commit 95c3844
Show file tree
Hide file tree
Showing 10 changed files with 13 additions and 342 deletions.
26 changes: 0 additions & 26 deletions conf/inter-server.conf
Expand Up @@ -117,35 +117,9 @@ char_reg_str_db: char_reg_str_db
char_reg_num_db: char_reg_num_db

// Map Database Tables
item_db_db: item_db
item_db2_db: item_db2
mob_db_db: mob_db
mob_db2_db: mob_db2
mob_skill_db_db: mob_skill_db
mob_skill_db2_db: mob_skill_db2
mapreg_db: mapreg
autotrade_merchants_db: autotrade_merchants
autotrade_data_db: autotrade_data
npc_market_data_db: npc_market_data

// == SQL item, mob, mob skill databases
// =====================================
// Note: the following databases may get out of date at times, or not be
// thoroughly tested (if at all, since they're auto-generated). As such it is
// not advisable to rely on them other than for informative reasons (Control
// Panels, websites, etc.)
// Unless you know what you're doing, please consider using their txt version.
// Note2: It is perfectly legit (and recommended) to use txt databases in
// Hercules, while still loading the SQL tables we provide to be used
// exclusively by your Control Panel or Website.

// Use SQL for item_db? (deprecated)
//use_sql_item_db: no

// Use SQL for mob_db? (deprecated)
//use_sql_mob_db: no

// Use SQL for mob_skill_db? (deprecated)
//use_sql_mob_skill_db: no

import: conf/import/inter_conf.txt
4 changes: 0 additions & 4 deletions src/char/char.c
Expand Up @@ -94,10 +94,6 @@ int save_log = 1;

char db_path[1024] = "db";

int db_use_sql_item_db;
int db_use_sql_mob_db;
int db_use_sql_mob_skill_db;

char wisp_server_name[NAME_LENGTH] = "Server";
char login_ip_str[128];
uint32 login_ip = 0;
Expand Down
4 changes: 0 additions & 4 deletions src/char/char.h
Expand Up @@ -298,10 +298,6 @@ extern char acc_reg_str_db[32];
extern char char_reg_str_db[32];
extern char char_reg_num_db[32];

extern int db_use_sql_item_db;
extern int db_use_sql_mob_db;
extern int db_use_sql_mob_skill_db;

extern int guild_exp_rate;
extern int log_inter;

Expand Down
13 changes: 3 additions & 10 deletions src/map/battle.c
Expand Up @@ -7157,14 +7157,14 @@ void Hercules_report(char* date, char *time_c) {
C_RENEWAL_EDP = 0x0400,
C_RENEWAL_ASPD = 0x0800,
C_SECURE_NPCTIMEOUT = 0x1000,
C_SQL_DB_ITEM = 0x2000,
//C_SQL_DB_ITEM = 0x2000,
C_SQL_LOGS = 0x4000,
C_MEMWATCH = 0x8000,
C_DMALLOC = 0x10000,
C_GCOLLECT = 0x20000,
C_SEND_SHORTLIST = 0x40000,
C_SQL_DB_MOB = 0x80000,
C_SQL_DB_MOBSKILL = 0x100000,
//C_SQL_DB_MOB = 0x80000,
//C_SQL_DB_MOBSKILL = 0x100000,
C_PACKETVER_RE = 0x200000,
};

Expand Down Expand Up @@ -7229,13 +7229,6 @@ void Hercules_report(char* date, char *time_c) {
#endif

/* non-define part */
if( map->db_use_sql_item_db )
config |= C_SQL_DB_ITEM;
if( map->db_use_sql_mob_db )
config |= C_SQL_DB_MOB;
if( map->db_use_sql_mob_skill_db )
config |= C_SQL_DB_MOBSKILL;

if( logs->config.sql_logs )
config |= C_SQL_LOGS;

Expand Down
171 changes: 8 additions & 163 deletions src/map/itemdb.c
Expand Up @@ -1502,112 +1502,8 @@ void itemdb_readdb_additional_fields(int itemid, config_setting_t *it, int n, co
}

/**
* Processes one itemdb entry from the sql backend, loading and inserting it
* into the item database.
*
* @param *handle MySQL connection handle. It is expected to have data
* available (i.e. already queried) and it won't be freed (it
* is care of the caller to do so)
* @param n Ordinal number of the entry, to be displayed in case of
* validation errors.
* @param *source Source of the entry (table name), to be displayed in case of
* validation errors.
* @return Nameid of the validated entry, or 0 in case of failure.
*/
int itemdb_readdb_sql_sub(Sql *handle, int n, const char *source) {
struct item_data id = { 0 };
char *data = NULL;

/*
* `id` smallint(5) unsigned NOT NULL DEFAULT '0'
* `name_english` varchar(50) NOT NULL DEFAULT ''
* `name_japanese` varchar(50) NOT NULL DEFAULT ''
* `type` tinyint(2) unsigned NOT NULL DEFAULT '0'
* `price_buy` mediumint(10) DEFAULT NULL
* `price_sell` mediumint(10) DEFAULT NULL
* `weight` smallint(5) unsigned DEFAULT NULL
* `atk` smallint(5) unsigned DEFAULT NULL
* `matk` smallint(5) unsigned DEFAULT NULL
* `defence` smallint(5) unsigned DEFAULT NULL
* `range` tinyint(2) unsigned DEFAULT NULL
* `slots` tinyint(2) unsigned DEFAULT NULL
* `equip_jobs` int(12) unsigned DEFAULT NULL
* `equip_upper` tinyint(8) unsigned DEFAULT NULL
* `equip_genders` tinyint(2) unsigned DEFAULT NULL
* `equip_locations` smallint(4) unsigned DEFAULT NULL
* `weapon_level` tinyint(2) unsigned DEFAULT NULL
* `equip_level_min` smallint(5) unsigned DEFAULT NULL
* `equip_level_max` smallint(5) unsigned DEFAULT NULL
* `refineable` tinyint(1) unsigned DEFAULT NULL
* `view` smallint(3) unsigned DEFAULT NULL
* `bindonequip` tinyint(1) unsigned DEFAULT NULL
* `buyingstore` tinyint(1) NOT NULL DEFAULT NULL
* `delay` mediumint(9) NOT NULL DEFAULT NULL
* `trade_flag` smallint(4) NOT NULL DEFAULT NULL
* `trade_group` smallint(4) NOT NULL DEFAULT NULL
* `nouse_flag` smallint(4) NOT NULL DEFAULT NULL
* `nouse_group` smallint(4) NOT NULL DEFAULT NULL
* `stack_amount` mediumint(6) NOT NULL DEFAULT NULL
* `stack_flag` smallint(2) NOT NULL DEFAULT NULL
* `sprite` mediumint(6) NOT NULL DEFAULT NULL
* `script` text
* `equip_script` text
* `unequip_script` text
*/
SQL->GetData(handle, 0, &data, NULL); id.nameid = (uint16)atoi(data);
SQL->GetData(handle, 1, &data, NULL); safestrncpy(id.name, data, sizeof(id.name));
SQL->GetData(handle, 2, &data, NULL); safestrncpy(id.jname, data, sizeof(id.jname));
SQL->GetData(handle, 3, &data, NULL); id.type = atoi(data);
SQL->GetData(handle, 4, &data, NULL); id.value_buy = data ? atoi(data) : -1; // Using invalid price -1 when missing, it'll be validated later
SQL->GetData(handle, 5, &data, NULL); id.value_sell = data ? atoi(data) : -1;
SQL->GetData(handle, 6, &data, NULL); id.weight = data ? atoi(data) : 0;
SQL->GetData(handle, 7, &data, NULL); id.atk = data ? atoi(data) : 0;
SQL->GetData(handle, 8, &data, NULL); id.matk = data ? atoi(data) : 0;
SQL->GetData(handle, 9, &data, NULL); id.def = data ? atoi(data) : 0;
SQL->GetData(handle, 10, &data, NULL); id.range = data ? atoi(data) : 0;
SQL->GetData(handle, 11, &data, NULL); id.slot = data ? atoi(data) : 0;
SQL->GetData(handle, 12, &data, NULL); itemdb->jobid2mapid(id.class_base, data ? (unsigned int)strtoul(data,NULL,0) : UINT_MAX);
SQL->GetData(handle, 13, &data, NULL); id.class_upper = data ? (unsigned int)atoi(data) : ITEMUPPER_ALL;
SQL->GetData(handle, 14, &data, NULL); id.sex = data ? atoi(data) : 2;
SQL->GetData(handle, 15, &data, NULL); id.equip = data ? atoi(data) : 0;
SQL->GetData(handle, 16, &data, NULL); id.wlv = data ? atoi(data) : 0;
SQL->GetData(handle, 17, &data, NULL); id.elv = data ? atoi(data) : 0;
SQL->GetData(handle, 18, &data, NULL); id.elvmax = data ? atoi(data) : 0;
SQL->GetData(handle, 19, &data, NULL); id.flag.no_refine = data && atoi(data) ? 0 : 1;
SQL->GetData(handle, 20, &data, NULL); id.look = data ? atoi(data) : 0;
SQL->GetData(handle, 21, &data, NULL); id.flag.bindonequip = data && atoi(data) ? 1 : 0;
SQL->GetData(handle, 22, &data, NULL); id.flag.force_serial = data && atoi(data) ? 1 : 0;
SQL->GetData(handle, 23, &data, NULL); id.flag.buyingstore = data && atoi(data) ? 1 : 0;
SQL->GetData(handle, 24, &data, NULL); id.delay = data ? atoi(data) : 0;
SQL->GetData(handle, 25, &data, NULL); id.flag.trade_restriction = data ? atoi(data) : ITR_NONE;
SQL->GetData(handle, 26, &data, NULL); id.gm_lv_trade_override = data ? atoi(data) : 0;
SQL->GetData(handle, 27, &data, NULL); id.item_usage.flag = data ? atoi(data) : INR_NONE;
SQL->GetData(handle, 28, &data, NULL); id.item_usage.override = data ? atoi(data) : 0;
SQL->GetData(handle, 29, &data, NULL); id.stack.amount = data ? atoi(data) : 0;
SQL->GetData(handle, 30, &data, NULL);
if (data) {
int stack_flag = atoi(data);
id.stack.inventory = (stack_flag&1)!=0;
id.stack.cart = (stack_flag&2)!=0;
id.stack.storage = (stack_flag&4)!=0;
id.stack.guildstorage = (stack_flag&8)!=0;
}
SQL->GetData(handle, 31, &data, NULL);
if (data) {
id.view_id = atoi(data);
if (id.view_id)
id.flag.available = 1;
}
SQL->GetData(handle, 32, &data, NULL); id.script = data && *data ? script->parse(data, source, -id.nameid, SCRIPT_IGNORE_EXTERNAL_BRACKETS, NULL) : NULL;
SQL->GetData(handle, 33, &data, NULL); id.equip_script = data && *data ? script->parse(data, source, -id.nameid, SCRIPT_IGNORE_EXTERNAL_BRACKETS, NULL) : NULL;
SQL->GetData(handle, 34, &data, NULL); id.unequip_script = data && *data ? script->parse(data, source, -id.nameid, SCRIPT_IGNORE_EXTERNAL_BRACKETS, NULL) : NULL;

return itemdb->validate_entry(&id, n, source);
}

/**
* Processes one itemdb entry from the sql backend, loading and inserting it
* into the item database.
* Processes one itemdb entry from the libconfig backend, loading and inserting
* it into the item database.
*
* @param *it Libconfig setting entry. It is expected to be valid and it
* won't be freed (it is care of the caller to do so if
Expand Down Expand Up @@ -1974,45 +1870,6 @@ int itemdb_readdb_libconfig(const char *filename) {
return count;
}

/**
* Reads from a sql itemdb table and inserts the found entries into the item
* database, overwriting duplicate ones (i.e. item_db2 overriding item_db.)
*
* @param *tablename Table name to query.
* @return The number of found entries.
*/
int itemdb_readdb_sql(const char *tablename) {
int i = 0, count = 0;

// retrieve all rows from the item database
if( SQL_ERROR == SQL->Query(map->mysql_handle, "SELECT `id`, `name_english`, `name_japanese`, `type`,"
" `price_buy`, `price_sell`, `weight`, `atk`,"
" `matk`, `defence`, `range`, `slots`,"
" `equip_jobs`, `equip_upper`, `equip_genders`, `equip_locations`,"
" `weapon_level`, `equip_level_min`, `equip_level_max`, `refineable`,"
" `view`, `bindonequip`, `forceserial`, `buyingstore`, `delay`,"
" `trade_flag`, `trade_group`, `nouse_flag`, `nouse_group`,"
" `stack_amount`, `stack_flag`, `sprite`, `script`,"
" `equip_script`, `unequip_script`"
"FROM `%s`", tablename) ) {
Sql_ShowDebug(map->mysql_handle);
return 0;
}

// process rows one by one
while( SQL_SUCCESS == SQL->NextRow(map->mysql_handle) ) {
if( itemdb->readdb_sql_sub(map->mysql_handle, i++, tablename) )
count++;
}

// free the query result
SQL->FreeResult(map->mysql_handle);

ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", count, tablename);

return count;
}

/*==========================================
* Unique item ID function
* Only one operation by once
Expand All @@ -2029,22 +1886,12 @@ void itemdb_read(bool minimal) {
int i;
DBData prev;

if (map->db_use_sql_item_db) {
const char* item_db_name[] = {
map->item_db_db,
map->item_db2_db
};
for(i = 0; i < ARRAYLENGTH(item_db_name); i++)
itemdb->readdb_sql(item_db_name[i]);
} else {
const char* filename[] = {
DBPATH"item_db.conf",
"item_db2.conf",
};

for(i = 0; i < ARRAYLENGTH(filename); i++)
itemdb->readdb_libconfig(filename[i]);
}
const char *filename[] = {
DBPATH"item_db.conf",
"item_db2.conf",
};
for (i = 0; i < ARRAYLENGTH(filename); i++)
itemdb->readdb_libconfig(filename[i]);

for( i = 0; i < ARRAYLENGTH(itemdb->array); ++i ) {
if( itemdb->array[i] ) {
Expand Down Expand Up @@ -2359,10 +2206,8 @@ void itemdb_defaults(void) {
itemdb->gendercheck = itemdb_gendercheck;
itemdb->validate_entry = itemdb_validate_entry;
itemdb->readdb_additional_fields = itemdb_readdb_additional_fields;
itemdb->readdb_sql_sub = itemdb_readdb_sql_sub;
itemdb->readdb_libconfig_sub = itemdb_readdb_libconfig_sub;
itemdb->readdb_libconfig = itemdb_readdb_libconfig;
itemdb->readdb_sql = itemdb_readdb_sql;
itemdb->unique_id = itemdb_unique_id;
itemdb->read = itemdb_read;
itemdb->destroy_item_data = destroy_item_data;
Expand Down
3 changes: 0 additions & 3 deletions src/map/itemdb.h
Expand Up @@ -10,7 +10,6 @@
#include "common/conf.h"
#include "common/db.h"
#include "common/mmo.h" // ITEM_NAME_LENGTH
#include "common/sql.h"

struct script_code;
struct hplugin_data_store;
Expand Down Expand Up @@ -602,10 +601,8 @@ struct itemdb_interface {
int (*gendercheck) (struct item_data *id);
int (*validate_entry) (struct item_data *entry, int n, const char *source);
void (*readdb_additional_fields) (int itemid, config_setting_t *it, int n, const char *source);
int (*readdb_sql_sub) (Sql *handle, int n, const char *source);
int (*readdb_libconfig_sub) (config_setting_t *it, int n, const char *source);
int (*readdb_libconfig) (const char *filename);
int (*readdb_sql) (const char *tablename);
uint64 (*unique_id) (struct map_session_data *sd);
void (*read) (bool minimal);
void (*destroy_item_data) (struct item_data *self, int free_self);
Expand Down
62 changes: 1 addition & 61 deletions src/map/map.c
Expand Up @@ -3702,21 +3702,8 @@ int inter_config_read(char *cfgName) {

if (sscanf(line,"%1023[^:]: %1023[^\r\n]", w1, w2) < 2)
continue;
/* table names */
if(strcmpi(w1,"item_db_db")==0)
safestrncpy(map->item_db_db, w2, sizeof(map->item_db_db));
else if(strcmpi(w1,"mob_db_db")==0)
safestrncpy(map->mob_db_db, w2, sizeof(map->mob_db_db));
else if(strcmpi(w1,"item_db2_db")==0)
safestrncpy(map->item_db2_db, w2, sizeof(map->item_db2_db));
else if(strcmpi(w1,"mob_db2_db")==0)
safestrncpy(map->mob_db2_db, w2, sizeof(map->mob_db2_db));
else if(strcmpi(w1, "mob_skill_db_db") == 0)
safestrncpy(map->mob_skill_db_db, w2, sizeof(map->mob_skill_db_db));
else if(strcmpi(w1,"mob_skill_db2_db")==0)
safestrncpy(map->mob_skill_db2_db, w2, sizeof(map->mob_skill_db2_db));
/* map sql stuff */
else if(strcmpi(w1,"map_server_ip")==0)
if(strcmpi(w1,"map_server_ip")==0)
safestrncpy(map->server_ip, w2, sizeof(map->server_ip));
else if(strcmpi(w1,"map_server_port")==0)
map->server_port=atoi(w2);
Expand All @@ -3728,42 +3715,6 @@ int inter_config_read(char *cfgName) {
safestrncpy(map->server_db, w2, sizeof(map->server_db));
else if(strcmpi(w1,"default_codepage")==0)
safestrncpy(map->default_codepage, w2, sizeof(map->default_codepage));
else if(strcmpi(w1,"use_sql_item_db")==0) {
map->db_use_sql_item_db = config_switch(w2);
ShowStatus ("Using item database as SQL: '%s'\n", w2);
if (map->db_use_sql_item_db) {
// Deprecated 2015-08-09 [Haru]
ShowWarning("Support for the SQL item database is deprecated and it will removed in future versions. "
"Please upgrade to the non-sql version as soon as possible. "
"Bug reports or pull requests concerning the SQL item database are no longer accepted.\n");
ShowInfo("Resuming in 10 seconds...\n");
HSleep(10);
}
}
else if(strcmpi(w1,"use_sql_mob_db")==0) {
map->db_use_sql_mob_db = config_switch(w2);
ShowStatus ("Using monster database as SQL: '%s'\n", w2);
if (map->db_use_sql_mob_db) {
// Deprecated 2015-08-09 [Haru]
ShowWarning("Support for the SQL monster database is deprecated and it will removed in future versions. "
"Please upgrade to the non-sql version as soon as possible. "
"Bug reports or pull requests concerning the SQL monster database are no longer accepted.\n");
ShowInfo("Resuming in 10 seconds...\n");
HSleep(10);
}
}
else if(strcmpi(w1,"use_sql_mob_skill_db")==0) {
map->db_use_sql_mob_skill_db = config_switch(w2);
ShowStatus ("Using monster skill database as SQL: '%s'\n", w2);
if (map->db_use_sql_mob_skill_db) {
// Deprecated 2015-08-09 [Haru]
ShowWarning("Support for the SQL monster skill database is deprecated and it will removed in future versions. "
"Please upgrade to the non-sql version as soon as possible. "
"Bug reports or pull requests concerning the SQL monster skill database are no longer accepted.\n");
ShowInfo("Resuming in 10 seconds...\n");
HSleep(10);
}
}
else if(strcmpi(w1,"autotrade_merchants_db")==0)
safestrncpy(map->autotrade_merchants_db, w2, sizeof(map->autotrade_merchants_db));
else if(strcmpi(w1,"autotrade_data_db")==0)
Expand Down Expand Up @@ -6019,17 +5970,6 @@ void map_defaults(void) {
map->night_flag = 0; // 0=day, 1=night [Yor]
map->enable_spy = 0; //To enable/disable @spy commands, which consume too much cpu time when sending packets. [Skotlex]

map->db_use_sql_item_db = 0;
map->db_use_sql_mob_db = 0;
map->db_use_sql_mob_skill_db = 0;

sprintf(map->item_db_db, "item_db");
sprintf(map->item_db2_db, "item_db2");
sprintf(map->mob_db_db, "mob_db");
sprintf(map->mob_db2_db, "mob_db2");
sprintf(map->mob_skill_db_db, "mob_skill_db");
sprintf(map->mob_skill_db2_db, "mob_skill_db2");

map->INTER_CONF_NAME="conf/inter-server.conf";
map->LOG_CONF_NAME="conf/logs.conf";
map->MAP_CONF_NAME = "conf/map-server.conf";
Expand Down

0 comments on commit 95c3844

Please sign in to comment.