From 5321d32c8d670fbfbfe02f7df5066170aa20ee2e Mon Sep 17 00:00:00 2001 From: shennetsind Date: Fri, 14 Jun 2013 08:50:45 -0300 Subject: Updating .sql item db files Also Introducing the official DB2SQL plugin to quickly update the .sql db files. http://hercules.ws/board/topic/1105-hercules-wpe-free-june-14th-patch Signed-off-by: shennetsind --- src/plugins/db2sql.c | 131 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 src/plugins/db2sql.c (limited to 'src/plugins/db2sql.c') diff --git a/src/plugins/db2sql.c b/src/plugins/db2sql.c new file mode 100644 index 000000000..e5630ee2d --- /dev/null +++ b/src/plugins/db2sql.c @@ -0,0 +1,131 @@ +// Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// See the LICENSE file + +#include +#include +#include +#include "../config/core.h" +#include "../common/HPMi.h" +#include "../common/strlib.h" +#include "../common/SQL.h" +#include "../common/timer.h" +#include "../map/clif.h" +#include "../map/pc.h" +#include "../map/map.h" +#include "../map/itemdb.h" + + +HPExport struct hplugin_info pinfo = { + "DB2SQL", // Plugin name + SERVER_TYPE_MAP,// Which server types this plugin works with? + "0.1", // Plugin version + HPM_VERSION, // HPM Version (don't change, macro is automatically updated) +}; + +SqlStmt* stmt; + +int (*parse_dbrow)(char** str, const char* source, int line, int scriptopt); + +char* trimbraces(char* str) { + size_t start; + size_t end; + + if( str == NULL ) + return str; + + for( start = 0; str[start] && str[start] == '{'; ++start ) + ; + for( end = strlen(str); start < end && str[end-1] && (str[end-1] == '}' || str[end-1] == '\n'); --end ) + ; + if( start == end ) + *str = '\0'; + else { + str[end] = '\0'; + memmove(str,str+start,end-start+1); + trim(str); + } + return str; +} +int db2sql(char** str, const char* source, int line, int scriptopt) { + struct item_data *it = NULL; + unsigned char offset = 0; +#ifdef RENEWAL + if( iMap->db_use_sqldbs ) offset = 1; +#endif + if( (it = itemdb->exists(parse_dbrow(str,source,line,scriptopt))) ) { + /* renewal has the 'matk' and 'equip_level' is now 'equip_level_min', and there is a new 'equip_level_max' field */ +#ifdef RENEWAL + if( SQL_SUCCESS != SQL->StmtPrepare(stmt, "REPLACE INTO `%s` (`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`,`script`,`equip_script`,`unequip_script`) VALUES ('%u',?,?,'%u','%u','%u','%u','%u','%u','%u','%u','%u','%u','%u','%u','%u','%u','%u','%u','%u','%u',?,?,?)",iMap->item_db_re_db, + it->nameid,it->type,it->value_buy,it->value_sell,it->weight,it->atk,it->matk,it->def,it->range,it->slot,(unsigned int)strtoul(str[11+offset],NULL,0),atoi(str[12+offset]),atoi(str[13+offset]),atoi(str[14+offset]),it->wlv,it->elv,it->elvmax,atoi(str[17+offset]),it->look) ) +#else + if( SQL_SUCCESS != SQL->StmtPrepare(stmt, "REPLACE INTO `%s` (`id`,`name_english`,`name_japanese`,`type`,`price_buy`,`price_sell`,`weight`,`atk`,`defence`,`range`,`slots`,`equip_jobs`,`equip_upper`,`equip_genders`,`equip_locations`,`weapon_level`,`equip_level`,`refineable`,`view`,`script`,`equip_script`,`unequip_script`) VALUES ('%u',?,?,'%u','%u','%u','%u','%u','%u','%u','%u','%u','%u','%u','%u','%u','%u','%u','%u',?,?,?)",iMap->item_db_db, + it->nameid,it->type,it->value_buy,it->value_sell,it->weight,it->atk,it->def,it->range,it->slot,(unsigned int)strtoul(str[11],NULL,0),atoi(str[12]),atoi(str[13]),atoi(str[14]),it->wlv,it->elv,atoi(str[17]),it->look) ) +#endif + SqlStmt_ShowDebug(stmt); + else { + if ( SQL_SUCCESS != SQL->StmtBindParam(stmt, 0, SQLDT_STRING, it->name, strlen(it->name)) ) + SqlStmt_ShowDebug(stmt); + else { + if ( SQL_SUCCESS != SQL->StmtBindParam(stmt, 1, SQLDT_STRING, it->jname, strlen(it->jname)) ) + SqlStmt_ShowDebug(stmt); + else { + #ifdef RENEWAL + if( iMap->db_use_sqldbs ) offset += 1; + #endif + if( it->script ) trimbraces(str[19+offset]); + if ( SQL_SUCCESS != SQL->StmtBindParam(stmt, 2, SQLDT_STRING, it->script?str[19+offset]:"", it->script?strlen(str[19+offset]):0) ) + SqlStmt_ShowDebug(stmt); + else { + if( it->equip_script ) trimbraces(str[20+offset]); + if ( SQL_SUCCESS != SQL->StmtBindParam(stmt, 3, SQLDT_STRING, it->equip_script?str[20+offset]:"", it->equip_script?strlen(str[20+offset]):0) ) + SqlStmt_ShowDebug(stmt); + else { + if( it->unequip_script ) trimbraces(str[21+offset]); + if ( SQL_SUCCESS != SQL->StmtBindParam(stmt, 4, SQLDT_STRING, it->unequip_script?str[21+offset]:"", it->unequip_script?strlen(str[21+offset]):0) ) + SqlStmt_ShowDebug(stmt); + else { + if( SQL_SUCCESS != SQL->StmtExecute(stmt) ) + SqlStmt_ShowDebug(stmt); + } + } + } + } + } + } + return it->nameid; + } + return 0; +} + +CPCMD(db2sql) { + + stmt = SQL->StmtMalloc(mysql_handle); + if( stmt == NULL ) { + SqlStmt_ShowDebug(stmt); + return; + } + + /* link */ + parse_dbrow = itemdb->parse_dbrow; + itemdb->parse_dbrow = db2sql; + + /* empty table */ + if ( SQL_ERROR == SQL->Query(mysql_handle, "DELETE FROM `%s`", iMap->item_db_db) ) + Sql_ShowDebug(mysql_handle); + else { + itemdb->reload(); + } + /* unlink */ + itemdb->parse_dbrow = parse_dbrow; + + SQL->StmtFree(stmt); +} + +HPExport void plugin_init (void) { + SQL = GET_SYMBOL("SQL"); + itemdb = GET_SYMBOL("itemdb"); + iMap = GET_SYMBOL("iMap"); + strlib = GET_SYMBOL("strlib"); + + HPMi->addCPCommand("server:tools:db2sql",CPCMD_A(db2sql)); +} \ No newline at end of file -- cgit v1.2.3-70-g09d2 From 1c69264cf2f389e887a398b95454761fcb1bb4b6 Mon Sep 17 00:00:00 2001 From: shennetsind Date: Fri, 14 Jun 2013 13:03:13 -0300 Subject: Fixed system-dependent error don't ask me why. Special Thanks to Takkun~! :D Signed-off-by: shennetsind --- src/plugins/db2sql.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/plugins/db2sql.c') diff --git a/src/plugins/db2sql.c b/src/plugins/db2sql.c index e5630ee2d..d56fd9546 100644 --- a/src/plugins/db2sql.c +++ b/src/plugins/db2sql.c @@ -3,7 +3,6 @@ #include #include -#include #include "../config/core.h" #include "../common/HPMi.h" #include "../common/strlib.h" -- cgit v1.2.3-70-g09d2 From 634bcc63b7adff53d817c19195c4060170eeecfc Mon Sep 17 00:00:00 2001 From: shennetsind Date: Fri, 14 Jun 2013 13:33:02 -0300 Subject: Fixed the '"__USE_GNU" redefined' warnings on selected platforms Special Thanks to Takkun~! Signed-off-by: shennetsind --- src/common/strlib.h | 10 +++++++--- src/plugins/db2sql.c | 12 ++++++------ 2 files changed, 13 insertions(+), 9 deletions(-) (limited to 'src/plugins/db2sql.c') diff --git a/src/common/strlib.h b/src/common/strlib.h index 4a073c3bc..9b1875d45 100644 --- a/src/common/strlib.h +++ b/src/common/strlib.h @@ -8,9 +8,13 @@ #include "../common/cbasetypes.h" #include -#define __USE_GNU // required to enable strnlen on some platforms -#include -#undef __USE_GNU +#ifndef __USE_GNU + #define __USE_GNU // required to enable strnlen on some platforms + #include + #undef __USE_GNU +#else + #include +#endif #ifdef WIN32 #define HAVE_STRTOK_R diff --git a/src/plugins/db2sql.c b/src/plugins/db2sql.c index d56fd9546..723a3cc94 100644 --- a/src/plugins/db2sql.c +++ b/src/plugins/db2sql.c @@ -1,18 +1,18 @@ // Copyright (c) Hercules Dev Team, licensed under GNU GPL. // See the LICENSE file -#include -#include -#include "../config/core.h" -#include "../common/HPMi.h" +#include "../common/cbasetypes.h" #include "../common/strlib.h" -#include "../common/SQL.h" #include "../common/timer.h" +#include "../common/HPMi.h" +#include "../common/mmo.h" +#include "../config/core.h" #include "../map/clif.h" #include "../map/pc.h" #include "../map/map.h" #include "../map/itemdb.h" - +#include +#include HPExport struct hplugin_info pinfo = { "DB2SQL", // Plugin name -- cgit v1.2.3-70-g09d2