From 0aee4fd57f2f4135361f4182a08a98cf52ed9d10 Mon Sep 17 00:00:00 2001 From: shennetsind Date: Wed, 15 May 2013 16:47:08 -0300 Subject: HPM Update Made SQL and strlib functions HPM-friendly, special thanks to Yommy for bringing the issue up. Added partial map.c support, for the all-handy map[] array, beware that soon the whole map.c renewal design will be commit and when that happens your usage of map.c functions in plugins might require some updates. Signed-off-by: shennetsind --- src/char/char.c | 474 +++++++++++++++++++++++------------------------ src/char/int_auction.c | 83 +++++---- src/char/int_elemental.c | 51 ++--- src/char/int_guild.c | 268 +++++++++++++-------------- src/char/int_homun.c | 81 ++++---- src/char/int_mail.c | 161 ++++++++-------- src/char/int_mercenary.c | 59 +++--- src/char/int_party.c | 89 ++++----- src/char/int_pet.c | 40 ++-- src/char/int_quest.c | 11 +- src/char/int_storage.c | 93 +++++----- src/char/inter.c | 149 +++++++-------- src/char/inter.h | 7 +- src/common/HPM.c | 72 ++++--- src/common/HPM.h | 2 +- src/common/HPMi.h | 3 + src/common/core.c | 23 ++- src/common/mmo.h | 2 +- src/common/showmsg.c | 18 +- src/common/sql.c | 134 +++++++------- src/common/sql.h | 236 +++++++++-------------- src/common/strlib.c | 362 +++++++++++++++++------------------- src/common/strlib.h | 244 +++++++++++++----------- src/common/timer.c | 135 +++++++------- src/common/timer.h | 34 ++-- src/login/account_sql.c | 115 ++++++------ src/login/ipban_sql.c | 27 +-- src/login/loginlog_sql.c | 29 +-- src/map/atcommand.c | 182 +++++++++--------- src/map/chrif.c | 4 +- src/map/clif.c | 24 +-- src/map/guild.c | 21 ++- src/map/homunculus.c | 4 +- src/map/itemdb.c | 39 ++-- src/map/log.c | 6 +- src/map/map.c | 79 +++++--- src/map/map.h | 45 +++-- src/map/mapreg_sql.c | 20 +- src/map/mercenary.c | 4 +- src/map/mob.c | 26 +-- src/map/npc.c | 10 +- src/map/pc.c | 8 +- src/map/pc_groups.c | 4 +- src/map/script.c | 166 ++++++++--------- src/map/skill.c | 32 ++-- src/map/status.c | 10 +- 46 files changed, 1860 insertions(+), 1826 deletions(-) (limited to 'src') diff --git a/src/char/char.c b/src/char/char.c index 975b1d77b..f5a75964c 100644 --- a/src/char/char.c +++ b/src/char/char.c @@ -226,7 +226,7 @@ void set_char_online(int map_id, int char_id, int account_id) struct mmo_charstatus *cp; //Update DB - if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `online`='1' WHERE `char_id`='%d' LIMIT 1", char_db, char_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "UPDATE `%s` SET `online`='1' WHERE `char_id`='%d' LIMIT 1", char_db, char_id) ) Sql_ShowDebug(sql_handle); //Check to see for online conflicts @@ -271,7 +271,7 @@ void set_char_offline(int char_id, int account_id) if ( char_id == -1 ) { - if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `online`='0' WHERE `account_id`='%d'", char_db, account_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "UPDATE `%s` SET `online`='0' WHERE `account_id`='%d'", char_db, account_id) ) Sql_ShowDebug(sql_handle); } else @@ -281,7 +281,7 @@ void set_char_offline(int char_id, int account_id) if (cp) idb_remove(char_db_,char_id); - if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `online`='0' WHERE `char_id`='%d' LIMIT 1", char_db, char_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "UPDATE `%s` SET `online`='0' WHERE `char_id`='%d' LIMIT 1", char_db, char_id) ) Sql_ShowDebug(sql_handle); } @@ -376,11 +376,11 @@ void set_all_offline(int id) void set_all_offline_sql(void) { //Set all players to 'OFFLINE' - if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `online` = '0'", char_db) ) + if( SQL_ERROR == SQL->Query(sql_handle, "UPDATE `%s` SET `online` = '0'", char_db) ) Sql_ShowDebug(sql_handle); - if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `online` = '0'", guild_member_db) ) + if( SQL_ERROR == SQL->Query(sql_handle, "UPDATE `%s` SET `online` = '0'", guild_member_db) ) Sql_ShowDebug(sql_handle); - if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `connect_member` = '0'", guild_db) ) + if( SQL_ERROR == SQL->Query(sql_handle, "UPDATE `%s` SET `connect_member` = '0'", guild_db) ) Sql_ShowDebug(sql_handle); } @@ -411,7 +411,7 @@ int mmo_char_tosql(int char_id, struct mmo_charstatus* p) cp = idb_ensure(char_db_, char_id, create_charstatus); - StringBuf_Init(&buf); + StrBuf->Init(&buf); memset(save_status, 0, sizeof(save_status)); //map inventory data @@ -464,7 +464,7 @@ int mmo_char_tosql(int char_id, struct mmo_charstatus* p) if( p->show_equip ) opt |= OPT_SHOW_EQUIP; - if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `base_level`='%d', `job_level`='%d'," + if( SQL_ERROR == SQL->Query(sql_handle, "UPDATE `%s` SET `base_level`='%d', `job_level`='%d'," "`base_exp`='%u', `job_exp`='%u', `zeny`='%d'," "`max_hp`='%d',`hp`='%d',`max_sp`='%d',`sp`='%d',`status_point`='%d',`skill_point`='%d'," "`str`='%d',`agi`='%d',`vit`='%d',`int`='%d',`dex`='%d',`luk`='%d'," @@ -501,7 +501,7 @@ int mmo_char_tosql(int char_id, struct mmo_charstatus* p) (p->fame != cp->fame) ) { - if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `class`='%d'," + if( SQL_ERROR == SQL->Query(sql_handle, "UPDATE `%s` SET `class`='%d'," "`hair`='%d',`hair_color`='%d',`clothes_color`='%d'," "`partner_id`='%d', `father`='%d', `mother`='%d', `child`='%d'," "`karma`='%d',`manner`='%d', `fame`='%d'" @@ -536,29 +536,29 @@ int mmo_char_tosql(int char_id, struct mmo_charstatus* p) char esc_mapname[NAME_LENGTH*2+1]; //`memo` (`memo_id`,`char_id`,`map`,`x`,`y`) - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `char_id`='%d'", memo_db, p->char_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `char_id`='%d'", memo_db, p->char_id) ) { Sql_ShowDebug(sql_handle); errors++; } //insert here. - StringBuf_Clear(&buf); - StringBuf_Printf(&buf, "INSERT INTO `%s`(`char_id`,`map`,`x`,`y`) VALUES ", memo_db); + StrBuf->Clear(&buf); + StrBuf->Printf(&buf, "INSERT INTO `%s`(`char_id`,`map`,`x`,`y`) VALUES ", memo_db); for( i = 0, count = 0; i < MAX_MEMOPOINTS; ++i ) { if( p->memo_point[i].map ) { if( count ) - StringBuf_AppendStr(&buf, ","); - Sql_EscapeString(sql_handle, esc_mapname, mapindex_id2name(p->memo_point[i].map)); - StringBuf_Printf(&buf, "('%d', '%s', '%d', '%d')", char_id, esc_mapname, p->memo_point[i].x, p->memo_point[i].y); + StrBuf->AppendStr(&buf, ","); + SQL->EscapeString(sql_handle, esc_mapname, mapindex_id2name(p->memo_point[i].map)); + StrBuf->Printf(&buf, "('%d', '%s', '%d', '%d')", char_id, esc_mapname, p->memo_point[i].x, p->memo_point[i].y); ++count; } } if( count ) { - if( SQL_ERROR == Sql_QueryStr(sql_handle, StringBuf_Value(&buf)) ) + if( SQL_ERROR == SQL->QueryStr(sql_handle, StrBuf->Value(&buf)) ) { Sql_ShowDebug(sql_handle); errors++; @@ -570,13 +570,13 @@ int mmo_char_tosql(int char_id, struct mmo_charstatus* p) //skills if( memcmp(p->skill, cp->skill, sizeof(p->skill)) ) { //`skill` (`char_id`, `id`, `lv`) - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `char_id`='%d'", skill_db, p->char_id) ) { + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `char_id`='%d'", skill_db, p->char_id) ) { Sql_ShowDebug(sql_handle); errors++; } - StringBuf_Clear(&buf); - StringBuf_Printf(&buf, "INSERT INTO `%s`(`char_id`,`id`,`lv`,`flag`) VALUES ", skill_db); + StrBuf->Clear(&buf); + StrBuf->Printf(&buf, "INSERT INTO `%s`(`char_id`,`id`,`lv`,`flag`) VALUES ", skill_db); //insert here. for( i = 0, count = 0; i < MAX_SKILL; ++i ) { if( p->skill[i].id != 0 && p->skill[i].flag != SKILL_FLAG_TEMPORARY ) { @@ -586,8 +586,8 @@ int mmo_char_tosql(int char_id, struct mmo_charstatus* p) if( p->skill[i].flag != SKILL_FLAG_PERMANENT && p->skill[i].flag != SKILL_FLAG_PERM_GRANTED && (p->skill[i].flag - SKILL_FLAG_REPLACED_LV_0) == 0 ) continue; if( count ) - StringBuf_AppendStr(&buf, ","); - StringBuf_Printf(&buf, "('%d','%d','%d','%d')", char_id, p->skill[i].id, + StrBuf->AppendStr(&buf, ","); + StrBuf->Printf(&buf, "('%d','%d','%d','%d')", char_id, p->skill[i].id, ( (p->skill[i].flag == SKILL_FLAG_PERMANENT || p->skill[i].flag == SKILL_FLAG_PERM_GRANTED) ? p->skill[i].lv : p->skill[i].flag - SKILL_FLAG_REPLACED_LV_0), p->skill[i].flag == SKILL_FLAG_PERM_GRANTED ? p->skill[i].flag : 0);/* other flags do not need to be saved */ ++count; @@ -595,7 +595,7 @@ int mmo_char_tosql(int char_id, struct mmo_charstatus* p) } if( count ) { - if( SQL_ERROR == Sql_QueryStr(sql_handle, StringBuf_Value(&buf)) ) + if( SQL_ERROR == SQL->QueryStr(sql_handle, StrBuf->Value(&buf)) ) { Sql_ShowDebug(sql_handle); errors++; @@ -616,27 +616,27 @@ int mmo_char_tosql(int char_id, struct mmo_charstatus* p) if(diff == 1) { //Save friends - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `char_id`='%d'", friend_db, char_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `char_id`='%d'", friend_db, char_id) ) { Sql_ShowDebug(sql_handle); errors++; } - StringBuf_Clear(&buf); - StringBuf_Printf(&buf, "INSERT INTO `%s` (`char_id`, `friend_account`, `friend_id`) VALUES ", friend_db); + StrBuf->Clear(&buf); + StrBuf->Printf(&buf, "INSERT INTO `%s` (`char_id`, `friend_account`, `friend_id`) VALUES ", friend_db); for( i = 0, count = 0; i < MAX_FRIENDS; ++i ) { if( p->friends[i].char_id > 0 ) { if( count ) - StringBuf_AppendStr(&buf, ","); - StringBuf_Printf(&buf, "('%d','%d','%d')", char_id, p->friends[i].account_id, p->friends[i].char_id); + StrBuf->AppendStr(&buf, ","); + StrBuf->Printf(&buf, "('%d','%d','%d')", char_id, p->friends[i].account_id, p->friends[i].char_id); count++; } } if( count ) { - if( SQL_ERROR == Sql_QueryStr(sql_handle, StringBuf_Value(&buf)) ) + if( SQL_ERROR == SQL->QueryStr(sql_handle, StrBuf->Value(&buf)) ) { Sql_ShowDebug(sql_handle); errors++; @@ -647,20 +647,20 @@ int mmo_char_tosql(int char_id, struct mmo_charstatus* p) #ifdef HOTKEY_SAVING // hotkeys - StringBuf_Clear(&buf); - StringBuf_Printf(&buf, "REPLACE INTO `%s` (`char_id`, `hotkey`, `type`, `itemskill_id`, `skill_lvl`) VALUES ", hotkey_db); + StrBuf->Clear(&buf); + StrBuf->Printf(&buf, "REPLACE INTO `%s` (`char_id`, `hotkey`, `type`, `itemskill_id`, `skill_lvl`) VALUES ", hotkey_db); diff = 0; for(i = 0; i < ARRAYLENGTH(p->hotkeys); i++){ if(memcmp(&p->hotkeys[i], &cp->hotkeys[i], sizeof(struct hotkey))) { if( diff ) - StringBuf_AppendStr(&buf, ",");// not the first hotkey - StringBuf_Printf(&buf, "('%d','%u','%u','%u','%u')", char_id, (unsigned int)i, (unsigned int)p->hotkeys[i].type, p->hotkeys[i].id , (unsigned int)p->hotkeys[i].lv); + StrBuf->AppendStr(&buf, ",");// not the first hotkey + StrBuf->Printf(&buf, "('%d','%u','%u','%u','%u')", char_id, (unsigned int)i, (unsigned int)p->hotkeys[i].type, p->hotkeys[i].id , (unsigned int)p->hotkeys[i].lv); diff = 1; } } if(diff) { - if( SQL_ERROR == Sql_QueryStr(sql_handle, StringBuf_Value(&buf)) ) + if( SQL_ERROR == SQL->QueryStr(sql_handle, StrBuf->Value(&buf)) ) { Sql_ShowDebug(sql_handle); errors++; @@ -668,7 +668,7 @@ int mmo_char_tosql(int char_id, struct mmo_charstatus* p) strcat(save_status, " hotkeys"); } #endif - StringBuf_Destroy(&buf); + StrBuf->Destroy(&buf); if (save_status[0]!='\0' && save_log) ShowInfo("Saved char %d - %s:%s.\n", char_id, p->name, save_status); if (!errors) @@ -706,19 +706,19 @@ int memitemdata_to_sql(const struct item items[], int max, int id, int tableswit // This approach is more complicated than a trivial delete&insert, but // it significantly reduces cpu load on the database server. - StringBuf_Init(&buf); - StringBuf_AppendStr(&buf, "SELECT `id`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `expire_time`"); + StrBuf->Init(&buf); + StrBuf->AppendStr(&buf, "SELECT `id`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `expire_time`"); for( j = 0; j < MAX_SLOTS; ++j ) - StringBuf_Printf(&buf, ", `card%d`", j); - StringBuf_Printf(&buf, " FROM `%s` WHERE `%s`='%d'", tablename, selectoption, id); + StrBuf->Printf(&buf, ", `card%d`", j); + StrBuf->Printf(&buf, " FROM `%s` WHERE `%s`='%d'", tablename, selectoption, id); stmt = SqlStmt_Malloc(sql_handle); - if( SQL_ERROR == SqlStmt_PrepareStr(stmt, StringBuf_Value(&buf)) + if( SQL_ERROR == SqlStmt_PrepareStr(stmt, StrBuf->Value(&buf)) || SQL_ERROR == SqlStmt_Execute(stmt) ) { SqlStmt_ShowDebug(stmt); SqlStmt_Free(stmt); - StringBuf_Destroy(&buf); + StrBuf->Destroy(&buf); return 1; } @@ -763,14 +763,14 @@ int memitemdata_to_sql(const struct item items[], int max, int id, int tableswit else { // update all fields. - StringBuf_Clear(&buf); - StringBuf_Printf(&buf, "UPDATE `%s` SET `amount`='%d', `equip`='%d', `identify`='%d', `refine`='%d',`attribute`='%d', `expire_time`='%u'", + StrBuf->Clear(&buf); + StrBuf->Printf(&buf, "UPDATE `%s` SET `amount`='%d', `equip`='%d', `identify`='%d', `refine`='%d',`attribute`='%d', `expire_time`='%u'", tablename, items[i].amount, items[i].equip, items[i].identify, items[i].refine, items[i].attribute, items[i].expire_time); for( j = 0; j < MAX_SLOTS; ++j ) - StringBuf_Printf(&buf, ", `card%d`=%d", j, items[i].card[j]); - StringBuf_Printf(&buf, " WHERE `id`='%d' LIMIT 1", item.id); + StrBuf->Printf(&buf, ", `card%d`=%d", j, items[i].card[j]); + StrBuf->Printf(&buf, " WHERE `id`='%d' LIMIT 1", item.id); - if( SQL_ERROR == Sql_QueryStr(sql_handle, StringBuf_Value(&buf)) ) + if( SQL_ERROR == SQL->QueryStr(sql_handle, StrBuf->Value(&buf)) ) { Sql_ShowDebug(sql_handle); errors++; @@ -783,7 +783,7 @@ int memitemdata_to_sql(const struct item items[], int max, int id, int tableswit } if( !found ) {// Item not present in inventory, remove it. - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE from `%s` where `id`='%d' LIMIT 1", tablename, item.id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE from `%s` where `id`='%d' LIMIT 1", tablename, item.id) ) { Sql_ShowDebug(sql_handle); errors++; @@ -792,11 +792,11 @@ int memitemdata_to_sql(const struct item items[], int max, int id, int tableswit } SqlStmt_Free(stmt); - StringBuf_Clear(&buf); - StringBuf_Printf(&buf, "INSERT INTO `%s`(`%s`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `expire_time`, `unique_id`", tablename, selectoption); + StrBuf->Clear(&buf); + StrBuf->Printf(&buf, "INSERT INTO `%s`(`%s`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `expire_time`, `unique_id`", tablename, selectoption); for( j = 0; j < MAX_SLOTS; ++j ) - StringBuf_Printf(&buf, ", `card%d`", j); - StringBuf_AppendStr(&buf, ") VALUES "); + StrBuf->Printf(&buf, ", `card%d`", j); + StrBuf->AppendStr(&buf, ") VALUES "); found = false; // insert non-matched items into the db as new items @@ -807,27 +807,27 @@ int memitemdata_to_sql(const struct item items[], int max, int id, int tableswit continue; if( found ) - StringBuf_AppendStr(&buf, ","); + StrBuf->AppendStr(&buf, ","); else found = true; - StringBuf_Printf(&buf, "('%d', '%d', '%d', '%d', '%d', '%d', '%d', '%u', '%"PRIu64"'", + StrBuf->Printf(&buf, "('%d', '%d', '%d', '%d', '%d', '%d', '%d', '%u', '%"PRIu64"'", id, items[i].nameid, items[i].amount, items[i].equip, items[i].identify, items[i].refine, items[i].attribute, items[i].expire_time, items[i].unique_id); for( j = 0; j < MAX_SLOTS; ++j ) - StringBuf_Printf(&buf, ", '%d'", items[i].card[j]); - StringBuf_AppendStr(&buf, ")"); + StrBuf->Printf(&buf, ", '%d'", items[i].card[j]); + StrBuf->AppendStr(&buf, ")"); updateLastUid(items[i].unique_id); // Unique Non Stackable Item ID } dbUpdateUid(sql_handle); // Unique Non Stackable Item ID - if( found && SQL_ERROR == Sql_QueryStr(sql_handle, StringBuf_Value(&buf)) ) + if( found && SQL_ERROR == SQL->QueryStr(sql_handle, StrBuf->Value(&buf)) ) { Sql_ShowDebug(sql_handle); errors++; } - StringBuf_Destroy(&buf); + StrBuf->Destroy(&buf); aFree(flag); return errors; @@ -850,19 +850,19 @@ int inventory_to_sql(const struct item items[], int max, int id) { // This approach is more complicated than a trivial delete&insert, but // it significantly reduces cpu load on the database server. - StringBuf_Init(&buf); - StringBuf_AppendStr(&buf, "SELECT `id`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `expire_time`, `favorite`"); + StrBuf->Init(&buf); + StrBuf->AppendStr(&buf, "SELECT `id`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `expire_time`, `favorite`"); for( j = 0; j < MAX_SLOTS; ++j ) - StringBuf_Printf(&buf, ", `card%d`", j); - StringBuf_Printf(&buf, " FROM `%s` WHERE `char_id`='%d'", inventory_db, id); + StrBuf->Printf(&buf, ", `card%d`", j); + StrBuf->Printf(&buf, " FROM `%s` WHERE `char_id`='%d'", inventory_db, id); stmt = SqlStmt_Malloc(sql_handle); - if( SQL_ERROR == SqlStmt_PrepareStr(stmt, StringBuf_Value(&buf)) + if( SQL_ERROR == SqlStmt_PrepareStr(stmt, StrBuf->Value(&buf)) || SQL_ERROR == SqlStmt_Execute(stmt) ) { SqlStmt_ShowDebug(stmt); SqlStmt_Free(stmt); - StringBuf_Destroy(&buf); + StrBuf->Destroy(&buf); return 1; } @@ -906,14 +906,14 @@ int inventory_to_sql(const struct item items[], int max, int id) { ; //Do nothing. else { // update all fields. - StringBuf_Clear(&buf); - StringBuf_Printf(&buf, "UPDATE `%s` SET `amount`='%d', `equip`='%d', `identify`='%d', `refine`='%d',`attribute`='%d', `expire_time`='%u', `favorite`='%d'", + StrBuf->Clear(&buf); + StrBuf->Printf(&buf, "UPDATE `%s` SET `amount`='%d', `equip`='%d', `identify`='%d', `refine`='%d',`attribute`='%d', `expire_time`='%u', `favorite`='%d'", inventory_db, items[i].amount, items[i].equip, items[i].identify, items[i].refine, items[i].attribute, items[i].expire_time, items[i].favorite); for( j = 0; j < MAX_SLOTS; ++j ) - StringBuf_Printf(&buf, ", `card%d`=%d", j, items[i].card[j]); - StringBuf_Printf(&buf, " WHERE `id`='%d' LIMIT 1", item.id); + StrBuf->Printf(&buf, ", `card%d`=%d", j, items[i].card[j]); + StrBuf->Printf(&buf, " WHERE `id`='%d' LIMIT 1", item.id); - if( SQL_ERROR == Sql_QueryStr(sql_handle, StringBuf_Value(&buf)) ) { + if( SQL_ERROR == SQL->QueryStr(sql_handle, StrBuf->Value(&buf)) ) { Sql_ShowDebug(sql_handle); errors++; } @@ -924,7 +924,7 @@ int inventory_to_sql(const struct item items[], int max, int id) { } } if( !found ) {// Item not present in inventory, remove it. - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE from `%s` where `id`='%d' LIMIT 1", inventory_db, item.id) ) { + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE from `%s` where `id`='%d' LIMIT 1", inventory_db, item.id) ) { Sql_ShowDebug(sql_handle); errors++; } @@ -932,11 +932,11 @@ int inventory_to_sql(const struct item items[], int max, int id) { } SqlStmt_Free(stmt); - StringBuf_Clear(&buf); - StringBuf_Printf(&buf, "INSERT INTO `%s` (`char_id`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `expire_time`, `favorite`, `unique_id`", inventory_db); + StrBuf->Clear(&buf); + StrBuf->Printf(&buf, "INSERT INTO `%s` (`char_id`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `expire_time`, `favorite`, `unique_id`", inventory_db); for( j = 0; j < MAX_SLOTS; ++j ) - StringBuf_Printf(&buf, ", `card%d`", j); - StringBuf_AppendStr(&buf, ") VALUES "); + StrBuf->Printf(&buf, ", `card%d`", j); + StrBuf->AppendStr(&buf, ") VALUES "); found = false; // insert non-matched items into the db as new items @@ -946,26 +946,26 @@ int inventory_to_sql(const struct item items[], int max, int id) { continue; if( found ) - StringBuf_AppendStr(&buf, ","); + StrBuf->AppendStr(&buf, ","); else found = true; - StringBuf_Printf(&buf, "('%d', '%d', '%d', '%d', '%d', '%d', '%d', '%u', '%d', '%"PRIu64"'", + StrBuf->Printf(&buf, "('%d', '%d', '%d', '%d', '%d', '%d', '%d', '%u', '%d', '%"PRIu64"'", id, items[i].nameid, items[i].amount, items[i].equip, items[i].identify, items[i].refine, items[i].attribute, items[i].expire_time, items[i].favorite, items[i].unique_id); for( j = 0; j < MAX_SLOTS; ++j ) - StringBuf_Printf(&buf, ", '%d'", items[i].card[j]); - StringBuf_AppendStr(&buf, ")"); + StrBuf->Printf(&buf, ", '%d'", items[i].card[j]); + StrBuf->AppendStr(&buf, ")"); updateLastUid(items[i].unique_id);// Unique Non Stackable Item ID } dbUpdateUid(sql_handle); - if( found && SQL_ERROR == Sql_QueryStr(sql_handle, StringBuf_Value(&buf)) ) { + if( found && SQL_ERROR == SQL->QueryStr(sql_handle, StrBuf->Value(&buf)) ) { Sql_ShowDebug(sql_handle); errors++; } - StringBuf_Destroy(&buf); + StrBuf->Destroy(&buf); aFree(flag); return errors; @@ -1208,13 +1208,13 @@ int mmo_char_fromsql(int char_id, struct mmo_charstatus* p, bool load_everything //read inventory //`inventory` (`id`,`char_id`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `card0`, `card1`, `card2`, `card3`, `expire_time`, `favorite`, `unique_id`) - StringBuf_Init(&buf); - StringBuf_AppendStr(&buf, "SELECT `id`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `expire_time`, `favorite`, `unique_id`"); + StrBuf->Init(&buf); + StrBuf->AppendStr(&buf, "SELECT `id`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `expire_time`, `favorite`, `unique_id`"); for( i = 0; i < MAX_SLOTS; ++i ) - StringBuf_Printf(&buf, ", `card%d`", i); - StringBuf_Printf(&buf, " FROM `%s` WHERE `char_id`=? LIMIT %d", inventory_db, MAX_INVENTORY); + StrBuf->Printf(&buf, ", `card%d`", i); + StrBuf->Printf(&buf, " FROM `%s` WHERE `char_id`=? LIMIT %d", inventory_db, MAX_INVENTORY); - if( SQL_ERROR == SqlStmt_PrepareStr(stmt, StringBuf_Value(&buf)) + if( SQL_ERROR == SqlStmt_PrepareStr(stmt, StrBuf->Value(&buf)) || SQL_ERROR == SqlStmt_BindParam(stmt, 0, SQLDT_INT, &char_id, 0) || SQL_ERROR == SqlStmt_Execute(stmt) || SQL_ERROR == SqlStmt_BindColumn(stmt, 0, SQLDT_INT, &tmp_item.id, 0, NULL, NULL) @@ -1239,13 +1239,13 @@ int mmo_char_fromsql(int char_id, struct mmo_charstatus* p, bool load_everything //read cart //`cart_inventory` (`id`,`char_id`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `card0`, `card1`, `card2`, `card3`, expire_time`, `unique_id`) - StringBuf_Clear(&buf); - StringBuf_AppendStr(&buf, "SELECT `id`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `expire_time`, `unique_id`"); + StrBuf->Clear(&buf); + StrBuf->AppendStr(&buf, "SELECT `id`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `expire_time`, `unique_id`"); for( j = 0; j < MAX_SLOTS; ++j ) - StringBuf_Printf(&buf, ", `card%d`", j); - StringBuf_Printf(&buf, " FROM `%s` WHERE `char_id`=? LIMIT %d", cart_db, MAX_CART); + StrBuf->Printf(&buf, ", `card%d`", j); + StrBuf->Printf(&buf, " FROM `%s` WHERE `char_id`=? LIMIT %d", cart_db, MAX_CART); - if( SQL_ERROR == SqlStmt_PrepareStr(stmt, StringBuf_Value(&buf)) + if( SQL_ERROR == SqlStmt_PrepareStr(stmt, StrBuf->Value(&buf)) || SQL_ERROR == SqlStmt_BindParam(stmt, 0, SQLDT_INT, &char_id, 0) || SQL_ERROR == SqlStmt_Execute(stmt) || SQL_ERROR == SqlStmt_BindColumn(stmt, 0, SQLDT_INT, &tmp_item.id, 0, NULL, NULL) @@ -1334,7 +1334,7 @@ int mmo_char_fromsql(int char_id, struct mmo_charstatus* p, bool load_everything if (save_log) ShowInfo("Loaded char (%d - %s): %s\n", char_id, p->name, t_msg); //ok. all data load successfuly! SqlStmt_Free(stmt); - StringBuf_Destroy(&buf); + StrBuf->Destroy(&buf); /* load options into proper vars */ if( opt & OPT_ALLOW_PARTY ) @@ -1382,14 +1382,14 @@ bool char_slotchange(struct char_session_data *sd, int fd, unsigned short from, if( sd->found_char[to] > 0 ) {/* moving char to occupied slot */ bool result = false; /* update both at once */ - if( SQL_SUCCESS != Sql_QueryStr(sql_handle, "START TRANSACTION") - || SQL_SUCCESS != Sql_Query(sql_handle, "UPDATE `%s` SET `char_num`='%d' WHERE `char_id`='%d' LIMIT 1", char_db, from, sd->found_char[to]) - || SQL_SUCCESS != Sql_Query(sql_handle, "UPDATE `%s` SET `char_num`='%d' WHERE `char_id`='%d' LIMIT 1", char_db, to, sd->found_char[from]) ) + if( SQL_SUCCESS != SQL->QueryStr(sql_handle, "START TRANSACTION") + || SQL_SUCCESS != SQL->Query(sql_handle, "UPDATE `%s` SET `char_num`='%d' WHERE `char_id`='%d' LIMIT 1", char_db, from, sd->found_char[to]) + || SQL_SUCCESS != SQL->Query(sql_handle, "UPDATE `%s` SET `char_num`='%d' WHERE `char_id`='%d' LIMIT 1", char_db, to, sd->found_char[from]) ) Sql_ShowDebug(sql_handle); else result = true; - if( SQL_ERROR == Sql_QueryStr(sql_handle, (result == true) ? "COMMIT" : "ROLLBACK") ) { + if( SQL_ERROR == SQL->QueryStr(sql_handle, (result == true) ? "COMMIT" : "ROLLBACK") ) { Sql_ShowDebug(sql_handle); result = false; } @@ -1397,14 +1397,14 @@ bool char_slotchange(struct char_session_data *sd, int fd, unsigned short from, return false; } else {/* slot is free. */ - if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `char_num`='%d' WHERE `char_id`='%d' LIMIT 1", char_db, to, sd->found_char[from] ) ) { + if( SQL_ERROR == SQL->Query(sql_handle, "UPDATE `%s` SET `char_num`='%d' WHERE `char_id`='%d' LIMIT 1", char_db, to, sd->found_char[from] ) ) { Sql_ShowDebug(sql_handle); return false; } } /* update count */ - if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `slotchange`=`slotchange`-1 WHERE `char_id`='%d' LIMIT 1", char_db, from_id ) ) { + if( SQL_ERROR == SQL->Query(sql_handle, "UPDATE `%s` SET `slotchange`=`slotchange`-1 WHERE `char_id`='%d' LIMIT 1", char_db, from_id ) ) { Sql_ShowDebug(sql_handle); return false; } @@ -1429,16 +1429,16 @@ int rename_char_sql(struct char_session_data *sd, int char_id) if( char_dat.rename == 0 ) return 1; - Sql_EscapeStringLen(sql_handle, esc_name, sd->new_name, strnlen(sd->new_name, NAME_LENGTH)); + SQL->EscapeStringLen(sql_handle, esc_name, sd->new_name, strnlen(sd->new_name, NAME_LENGTH)); // check if the char exist - if( SQL_ERROR == Sql_Query(sql_handle, "SELECT 1 FROM `%s` WHERE `name` LIKE '%s' LIMIT 1", char_db, esc_name) ) + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT 1 FROM `%s` WHERE `name` LIKE '%s' LIMIT 1", char_db, esc_name) ) { Sql_ShowDebug(sql_handle); return 4; } - if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `name` = '%s', `rename` = '%d' WHERE `char_id` = '%d'", char_db, esc_name, --char_dat.rename, char_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "UPDATE `%s` SET `name` = '%s', `rename` = '%d' WHERE `char_id` = '%d'", char_db, esc_name, --char_dat.rename, char_id) ) { Sql_ShowDebug(sql_handle); return 3; @@ -1454,7 +1454,7 @@ int rename_char_sql(struct char_session_data *sd, int char_id) // log change if( log_char ) { - if( SQL_ERROR == Sql_Query(sql_handle, "INSERT INTO `%s` (`time`, `char_msg`,`account_id`,`char_num`,`name`,`str`,`agi`,`vit`,`int`,`dex`,`luk`,`hair`,`hair_color`)" + if( SQL_ERROR == SQL->Query(sql_handle, "INSERT INTO `%s` (`time`, `char_msg`,`account_id`,`char_num`,`name`,`str`,`agi`,`vit`,`int`,`dex`,`luk`,`hair`,`hair_color`)" "VALUES (NOW(), '%s', '%d', '%d', '%s', '0', '0', '0', '0', '0', '0', '0', '0')", charlog_db, "change char name", sd->account_id, char_dat.slot, esc_name) ) Sql_ShowDebug(sql_handle); @@ -1498,17 +1498,17 @@ int check_char_name(char * name, char * esc_name) return -2; } if( name_ignoring_case ) { - if( SQL_ERROR == Sql_Query(sql_handle, "SELECT 1 FROM `%s` WHERE BINARY `name` = '%s' LIMIT 1", char_db, esc_name) ) { + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT 1 FROM `%s` WHERE BINARY `name` = '%s' LIMIT 1", char_db, esc_name) ) { Sql_ShowDebug(sql_handle); return -2; } } else { - if( SQL_ERROR == Sql_Query(sql_handle, "SELECT 1 FROM `%s` WHERE `name` = '%s' LIMIT 1", char_db, esc_name) ) { + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT 1 FROM `%s` WHERE `name` = '%s' LIMIT 1", char_db, esc_name) ) { Sql_ShowDebug(sql_handle); return -2; } } - if( Sql_NumRows(sql_handle) > 0 ) + if( SQL->NumRows(sql_handle) > 0 ) return -1; // name already exists return 0; @@ -1530,7 +1530,7 @@ int make_new_char_sql(struct char_session_data* sd, char* name_, int str, int ag safestrncpy(name, name_, NAME_LENGTH); normalize_name(name,TRIM_CHARS); - Sql_EscapeStringLen(sql_handle, esc_name, name, strnlen(name, NAME_LENGTH)); + SQL->EscapeStringLen(sql_handle, esc_name, name, strnlen(name, NAME_LENGTH)); flag = check_char_name(name,esc_name); if( flag < 0 ) @@ -1557,14 +1557,14 @@ int make_new_char_sql(struct char_session_data* sd, char* name_, int str, int ag // validation success, log result if (log_char) { - if( SQL_ERROR == Sql_Query(sql_handle, "INSERT INTO `%s` (`time`, `char_msg`,`account_id`,`char_num`,`name`,`str`,`agi`,`vit`,`int`,`dex`,`luk`,`hair`,`hair_color`)" + if( SQL_ERROR == SQL->Query(sql_handle, "INSERT INTO `%s` (`time`, `char_msg`,`account_id`,`char_num`,`name`,`str`,`agi`,`vit`,`int`,`dex`,`luk`,`hair`,`hair_color`)" "VALUES (NOW(), '%s', '%d', '%d', '%s', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d')", charlog_db, "make new char", sd->account_id, slot, esc_name, str, agi, vit, int_, dex, luk, hair_style, hair_color) ) Sql_ShowDebug(sql_handle); } #if PACKETVER >= 20120307 //Insert the new char entry to the database - if( SQL_ERROR == Sql_Query(sql_handle, "INSERT INTO `%s` (`account_id`, `char_num`, `name`, `zeny`, `status_point`,`str`, `agi`, `vit`, `int`, `dex`, `luk`, `max_hp`, `hp`," + if( SQL_ERROR == SQL->Query(sql_handle, "INSERT INTO `%s` (`account_id`, `char_num`, `name`, `zeny`, `status_point`,`str`, `agi`, `vit`, `int`, `dex`, `luk`, `max_hp`, `hp`," "`max_sp`, `sp`, `hair`, `hair_color`, `last_map`, `last_x`, `last_y`, `save_map`, `save_x`, `save_y`) VALUES (" "'%d', '%d', '%s', '%d', '%d','%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d','%d', '%d','%d', '%d', '%s', '%d', '%d', '%s', '%d', '%d')", char_db, sd->account_id , slot, esc_name, start_zeny, 48, str, agi, vit, int_, dex, luk, @@ -1576,7 +1576,7 @@ int make_new_char_sql(struct char_session_data* sd, char* name_, int str, int ag } #else //Insert the new char entry to the database - if( SQL_ERROR == Sql_Query(sql_handle, "INSERT INTO `%s` (`account_id`, `char_num`, `name`, `zeny`, `str`, `agi`, `vit`, `int`, `dex`, `luk`, `max_hp`, `hp`," + if( SQL_ERROR == SQL->Query(sql_handle, "INSERT INTO `%s` (`account_id`, `char_num`, `name`, `zeny`, `str`, `agi`, `vit`, `int`, `dex`, `luk`, `max_hp`, `hp`," "`max_sp`, `sp`, `hair`, `hair_color`, `last_map`, `last_x`, `last_y`, `save_map`, `save_x`, `save_y`) VALUES (" "'%d', '%d', '%s', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d','%d', '%d','%d', '%d', '%s', '%d', '%d', '%s', '%d', '%d')", char_db, sd->account_id , slot, esc_name, start_zeny, str, agi, vit, int_, dex, luk, @@ -1588,11 +1588,11 @@ int make_new_char_sql(struct char_session_data* sd, char* name_, int str, int ag } #endif //Retrieve the newly auto-generated char id - char_id = (int)Sql_LastInsertId(sql_handle); + char_id = (int)SQL->NumRows(sql_handle); //Give the char the default items for (k = 0; k < ARRAYLENGTH(start_items) && start_items[k] != 0; k += 2) { - if( SQL_ERROR == Sql_Query(sql_handle, "INSERT INTO `%s` (`char_id`,`nameid`, `amount`, `identify`) VALUES ('%d', '%d', '%d', '%d')", inventory_db, char_id, start_items[k], start_items[k + 1], 1) ) + if( SQL_ERROR == SQL->Query(sql_handle, "INSERT INTO `%s` (`char_id`,`nameid`, `amount`, `identify`) VALUES ('%d', '%d', '%d', '%d')", inventory_db, char_id, start_items[k], start_items[k + 1], 1) ) Sql_ShowDebug(sql_handle); } @@ -1607,9 +1607,9 @@ int divorce_char_sql(int partner_id1, int partner_id2) { unsigned char buf[64]; - if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `partner_id`='0' WHERE `char_id`='%d' OR `char_id`='%d' LIMIT 2", char_db, partner_id1, partner_id2) ) + if( SQL_ERROR == SQL->Query(sql_handle, "UPDATE `%s` SET `partner_id`='0' WHERE `char_id`='%d' OR `char_id`='%d' LIMIT 2", char_db, partner_id1, partner_id2) ) Sql_ShowDebug(sql_handle); - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE (`nameid`='%d' OR `nameid`='%d') AND (`char_id`='%d' OR `char_id`='%d') LIMIT 2", inventory_db, WEDDING_RING_M, WEDDING_RING_F, partner_id1, partner_id2) ) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE (`nameid`='%d' OR `nameid`='%d') AND (`char_id`='%d' OR `char_id`='%d') LIMIT 2", inventory_db, WEDDING_RING_M, WEDDING_RING_F, partner_id1, partner_id2) ) Sql_ShowDebug(sql_handle); WBUFW(buf,0) = 0x2b12; @@ -1634,30 +1634,30 @@ int delete_char_sql(int char_id) char *data; size_t len; - if (SQL_ERROR == Sql_Query(sql_handle, "SELECT `name`,`account_id`,`party_id`,`guild_id`,`base_level`,`homun_id`,`partner_id`,`father`,`mother`,`elemental_id` FROM `%s` WHERE `char_id`='%d'", char_db, char_id)) + if (SQL_ERROR == SQL->Query(sql_handle, "SELECT `name`,`account_id`,`party_id`,`guild_id`,`base_level`,`homun_id`,`partner_id`,`father`,`mother`,`elemental_id` FROM `%s` WHERE `char_id`='%d'", char_db, char_id)) Sql_ShowDebug(sql_handle); - if( SQL_SUCCESS != Sql_NextRow(sql_handle) ) + if( SQL_SUCCESS != SQL->NextRow(sql_handle) ) { ShowError("delete_char_sql: Unable to fetch character data, deletion aborted.\n"); - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); return -1; } - Sql_GetData(sql_handle, 0, &data, &len); safestrncpy(name, data, NAME_LENGTH); - Sql_GetData(sql_handle, 1, &data, NULL); account_id = atoi(data); - Sql_GetData(sql_handle, 2, &data, NULL); party_id = atoi(data); - Sql_GetData(sql_handle, 3, &data, NULL); guild_id = atoi(data); - Sql_GetData(sql_handle, 4, &data, NULL); base_level = atoi(data); - Sql_GetData(sql_handle, 5, &data, NULL); hom_id = atoi(data); - Sql_GetData(sql_handle, 6, &data, NULL); partner_id = atoi(data); - Sql_GetData(sql_handle, 7, &data, NULL); father_id = atoi(data); - Sql_GetData(sql_handle, 8, &data, NULL); mother_id = atoi(data); - Sql_GetData(sql_handle, 9, &data, NULL); + SQL->GetData(sql_handle, 0, &data, &len); safestrncpy(name, data, NAME_LENGTH); + SQL->GetData(sql_handle, 1, &data, NULL); account_id = atoi(data); + SQL->GetData(sql_handle, 2, &data, NULL); party_id = atoi(data); + SQL->GetData(sql_handle, 3, &data, NULL); guild_id = atoi(data); + SQL->GetData(sql_handle, 4, &data, NULL); base_level = atoi(data); + SQL->GetData(sql_handle, 5, &data, NULL); hom_id = atoi(data); + SQL->GetData(sql_handle, 6, &data, NULL); partner_id = atoi(data); + SQL->GetData(sql_handle, 7, &data, NULL); father_id = atoi(data); + SQL->GetData(sql_handle, 8, &data, NULL); mother_id = atoi(data); + SQL->GetData(sql_handle, 9, &data, NULL); elemental_id = atoi(data); - Sql_EscapeStringLen(sql_handle, esc_name, name, min(len, NAME_LENGTH)); - Sql_FreeResult(sql_handle); + SQL->EscapeStringLen(sql_handle, esc_name, name, min(len, NAME_LENGTH)); + SQL->FreeResult(sql_handle); //check for config char del condition [Lupus] // TODO: Move this out to packet processing (0x68/0x1fb). @@ -1677,9 +1677,9 @@ int delete_char_sql(int char_id) { // Char is Baby unsigned char buf[64]; - if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `child`='0' WHERE `char_id`='%d' OR `char_id`='%d'", char_db, father_id, mother_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "UPDATE `%s` SET `child`='0' WHERE `char_id`='%d' OR `char_id`='%d'", char_db, father_id, mother_id) ) Sql_ShowDebug(sql_handle); - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `id` = '410'AND (`char_id`='%d' OR `char_id`='%d')", skill_db, father_id, mother_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `id` = '410'AND (`char_id`='%d' OR `char_id`='%d')", skill_db, father_id, mother_id) ) Sql_ShowDebug(sql_handle); WBUFW(buf,0) = 0x2b25; @@ -1695,13 +1695,13 @@ int delete_char_sql(int char_id) /* delete char's pet */ //Delete the hatched pet if you have one... - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `char_id`='%d' AND `incuvate` = '0'", pet_db, char_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `char_id`='%d' AND `incuvate` = '0'", pet_db, char_id) ) Sql_ShowDebug(sql_handle); //Delete all pets that are stored in eggs (inventory + cart) - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` USING `%s` JOIN `%s` ON `pet_id` = `card1`|`card2`<<16 WHERE `%s`.char_id = '%d' AND card0 = -256", pet_db, pet_db, inventory_db, inventory_db, char_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` USING `%s` JOIN `%s` ON `pet_id` = `card1`|`card2`<<16 WHERE `%s`.char_id = '%d' AND card0 = -256", pet_db, pet_db, inventory_db, inventory_db, char_id) ) Sql_ShowDebug(sql_handle); - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` USING `%s` JOIN `%s` ON `pet_id` = `card1`|`card2`<<16 WHERE `%s`.char_id = '%d' AND card0 = -256", pet_db, pet_db, cart_db, cart_db, char_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` USING `%s` JOIN `%s` ON `pet_id` = `card1`|`card2`<<16 WHERE `%s`.char_id = '%d' AND card0 = -256", pet_db, pet_db, cart_db, cart_db, char_id) ) Sql_ShowDebug(sql_handle); /* remove homunculus */ @@ -1716,69 +1716,69 @@ int delete_char_sql(int char_id) mercenary_owner_delete(char_id); /* delete char's friends list */ - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `char_id` = '%d'", friend_db, char_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `char_id` = '%d'", friend_db, char_id) ) Sql_ShowDebug(sql_handle); /* delete char from other's friend list */ //NOTE: Won't this cause problems for people who are already online? [Skotlex] - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `friend_id` = '%d'", friend_db, char_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `friend_id` = '%d'", friend_db, char_id) ) Sql_ShowDebug(sql_handle); #ifdef HOTKEY_SAVING /* delete hotkeys */ - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `char_id`='%d'", hotkey_db, char_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `char_id`='%d'", hotkey_db, char_id) ) Sql_ShowDebug(sql_handle); #endif /* delete inventory */ - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `char_id`='%d'", inventory_db, char_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `char_id`='%d'", inventory_db, char_id) ) Sql_ShowDebug(sql_handle); /* delete cart inventory */ - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `char_id`='%d'", cart_db, char_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `char_id`='%d'", cart_db, char_id) ) Sql_ShowDebug(sql_handle); /* delete memo areas */ - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `char_id`='%d'", memo_db, char_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `char_id`='%d'", memo_db, char_id) ) Sql_ShowDebug(sql_handle); /* delete character registry */ - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `type`=3 AND `char_id`='%d'", reg_db, char_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `type`=3 AND `char_id`='%d'", reg_db, char_id) ) Sql_ShowDebug(sql_handle); /* delete skills */ - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `char_id`='%d'", skill_db, char_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `char_id`='%d'", skill_db, char_id) ) Sql_ShowDebug(sql_handle); /* delete mails (only received) */ - if (SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `dest_id`='%d'", mail_db, char_id)) + if (SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `dest_id`='%d'", mail_db, char_id)) Sql_ShowDebug(sql_handle); #ifdef ENABLE_SC_SAVING /* status changes */ - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `account_id` = '%d' AND `char_id`='%d'", scdata_db, account_id, char_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `account_id` = '%d' AND `char_id`='%d'", scdata_db, account_id, char_id) ) Sql_ShowDebug(sql_handle); #endif if (log_char) { - if( SQL_ERROR == Sql_Query(sql_handle, "INSERT INTO `%s`(`time`, `account_id`,`char_num`,`char_msg`,`name`) VALUES (NOW(), '%d', '%d', 'Deleted char (CID %d)', '%s')", + if( SQL_ERROR == SQL->Query(sql_handle, "INSERT INTO `%s`(`time`, `account_id`,`char_num`,`char_msg`,`name`) VALUES (NOW(), '%d', '%d', 'Deleted char (CID %d)', '%s')", charlog_db, account_id, 0, char_id, esc_name) ) Sql_ShowDebug(sql_handle); } /* delete character */ - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `char_id`='%d'", char_db, char_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `char_id`='%d'", char_db, char_id) ) Sql_ShowDebug(sql_handle); /* No need as we used inter_guild_leave [Skotlex] // Also delete info from guildtables. - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `char_id`='%d'", guild_member_db, char_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `char_id`='%d'", guild_member_db, char_id) ) Sql_ShowDebug(sql_handle); */ - if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `guild_id` FROM `%s` WHERE `char_id` = '%d'", guild_db, char_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `guild_id` FROM `%s` WHERE `char_id` = '%d'", guild_db, char_id) ) Sql_ShowDebug(sql_handle); - else if( Sql_NumRows(sql_handle) > 0 ) + else if( SQL->NumRows(sql_handle) > 0 ) mapif_parse_BreakGuild(0,guild_id); else if( guild_id ) inter_guild_leave(guild_id, account_id, char_id);// Leave your guild. @@ -1937,66 +1937,66 @@ int mmo_char_send006b(int fd, struct char_session_data* sd) int char_married(int pl1, int pl2) { - if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `partner_id` FROM `%s` WHERE `char_id` = '%d'", char_db, pl1) ) + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `partner_id` FROM `%s` WHERE `char_id` = '%d'", char_db, pl1) ) Sql_ShowDebug(sql_handle); - else if( SQL_SUCCESS == Sql_NextRow(sql_handle) ) + else if( SQL_SUCCESS == SQL->NextRow(sql_handle) ) { char* data; - Sql_GetData(sql_handle, 0, &data, NULL); + SQL->GetData(sql_handle, 0, &data, NULL); if( pl2 == atoi(data) ) { - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); return 1; } } - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); return 0; } int char_child(int parent_id, int child_id) { - if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `child` FROM `%s` WHERE `char_id` = '%d'", char_db, parent_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `child` FROM `%s` WHERE `char_id` = '%d'", char_db, parent_id) ) Sql_ShowDebug(sql_handle); - else if( SQL_SUCCESS == Sql_NextRow(sql_handle) ) + else if( SQL_SUCCESS == SQL->NextRow(sql_handle) ) { char* data; - Sql_GetData(sql_handle, 0, &data, NULL); + SQL->GetData(sql_handle, 0, &data, NULL); if( child_id == atoi(data) ) { - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); return 1; } } - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); return 0; } int char_family(int cid1, int cid2, int cid3) { - if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `char_id`,`partner_id`,`child` FROM `%s` WHERE `char_id` IN ('%d','%d','%d')", char_db, cid1, cid2, cid3) ) + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `char_id`,`partner_id`,`child` FROM `%s` WHERE `char_id` IN ('%d','%d','%d')", char_db, cid1, cid2, cid3) ) Sql_ShowDebug(sql_handle); - else while( SQL_SUCCESS == Sql_NextRow(sql_handle) ) + else while( SQL_SUCCESS == SQL->NextRow(sql_handle) ) { int charid; int partnerid; int childid; char* data; - Sql_GetData(sql_handle, 0, &data, NULL); charid = atoi(data); - Sql_GetData(sql_handle, 1, &data, NULL); partnerid = atoi(data); - Sql_GetData(sql_handle, 2, &data, NULL); childid = atoi(data); + SQL->GetData(sql_handle, 0, &data, NULL); charid = atoi(data); + SQL->GetData(sql_handle, 1, &data, NULL); partnerid = atoi(data); + SQL->GetData(sql_handle, 2, &data, NULL); childid = atoi(data); if( (cid1 == charid && ((cid2 == partnerid && cid3 == childid ) || (cid2 == childid && cid3 == partnerid))) || (cid1 == partnerid && ((cid2 == charid && cid3 == childid ) || (cid2 == childid && cid3 == charid ))) || (cid1 == childid && ((cid2 == charid && cid3 == partnerid) || (cid2 == partnerid && cid3 == charid ))) ) { - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); return childid; } } - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); return 0; } @@ -2279,13 +2279,13 @@ int parse_fromlogin(int fd) { node->sex = sex; // get characters - if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `char_id`,`class`,`guild_id` FROM `%s` WHERE `account_id` = '%d'", char_db, acc) ) + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `char_id`,`class`,`guild_id` FROM `%s` WHERE `account_id` = '%d'", char_db, acc) ) Sql_ShowDebug(sql_handle); - for( i = 0; i < MAX_CHARS && SQL_SUCCESS == Sql_NextRow(sql_handle); ++i ) + for( i = 0; i < MAX_CHARS && SQL_SUCCESS == SQL->NextRow(sql_handle); ++i ) { - Sql_GetData(sql_handle, 0, &data, NULL); char_id[i] = atoi(data); - Sql_GetData(sql_handle, 1, &data, NULL); class_[i] = atoi(data); - Sql_GetData(sql_handle, 2, &data, NULL); guild_id[i] = atoi(data); + SQL->GetData(sql_handle, 0, &data, NULL); char_id[i] = atoi(data); + SQL->GetData(sql_handle, 1, &data, NULL); class_[i] = atoi(data); + SQL->GetData(sql_handle, 2, &data, NULL); guild_id[i] = atoi(data); } num = i; for( i = 0; i < num; ++i ) @@ -2315,13 +2315,13 @@ int parse_fromlogin(int fd) { class_[i] = (sex ? JOB_KAGEROU : JOB_OBORO); } - if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `class`='%d', `weapon`='0', `shield`='0', `head_top`='0', `head_mid`='0', `head_bottom`='0' WHERE `char_id`='%d'", char_db, class_[i], char_id[i]) ) + if( SQL_ERROR == SQL->Query(sql_handle, "UPDATE `%s` SET `class`='%d', `weapon`='0', `shield`='0', `head_top`='0', `head_mid`='0', `head_bottom`='0' WHERE `char_id`='%d'", char_db, class_[i], char_id[i]) ) Sql_ShowDebug(sql_handle); if( guild_id[i] )// If there is a guild, update the guild_member data [Skotlex] inter_guild_sex_changed(guild_id[i], acc, char_id[i], sex); } - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); // disconnect player if online on char-server disconnect_player(acc); @@ -2506,51 +2506,51 @@ void char_read_fame_list(void) memset(chemist_fame_list, 0, sizeof(chemist_fame_list)); memset(taekwon_fame_list, 0, sizeof(taekwon_fame_list)); // Build Blacksmith ranking list - if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `char_id`,`fame`,`name` FROM `%s` WHERE `fame`>0 AND (`class`='%d' OR `class`='%d' OR `class`='%d' OR `class`='%d' OR `class`='%d' OR `class`='%d') ORDER BY `fame` DESC LIMIT 0,%d", char_db, JOB_BLACKSMITH, JOB_WHITESMITH, JOB_BABY_BLACKSMITH, JOB_MECHANIC, JOB_MECHANIC_T, JOB_BABY_MECHANIC, fame_list_size_smith) ) + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `char_id`,`fame`,`name` FROM `%s` WHERE `fame`>0 AND (`class`='%d' OR `class`='%d' OR `class`='%d' OR `class`='%d' OR `class`='%d' OR `class`='%d') ORDER BY `fame` DESC LIMIT 0,%d", char_db, JOB_BLACKSMITH, JOB_WHITESMITH, JOB_BABY_BLACKSMITH, JOB_MECHANIC, JOB_MECHANIC_T, JOB_BABY_MECHANIC, fame_list_size_smith) ) Sql_ShowDebug(sql_handle); - for( i = 0; i < fame_list_size_smith && SQL_SUCCESS == Sql_NextRow(sql_handle); ++i ) + for( i = 0; i < fame_list_size_smith && SQL_SUCCESS == SQL->NextRow(sql_handle); ++i ) { // char_id - Sql_GetData(sql_handle, 0, &data, NULL); + SQL->GetData(sql_handle, 0, &data, NULL); smith_fame_list[i].id = atoi(data); // fame - Sql_GetData(sql_handle, 1, &data, &len); + SQL->GetData(sql_handle, 1, &data, &len); smith_fame_list[i].fame = atoi(data); // name - Sql_GetData(sql_handle, 2, &data, &len); + SQL->GetData(sql_handle, 2, &data, &len); memcpy(smith_fame_list[i].name, data, min(len, NAME_LENGTH)); } // Build Alchemist ranking list - if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `char_id`,`fame`,`name` FROM `%s` WHERE `fame`>0 AND (`class`='%d' OR `class`='%d' OR `class`='%d' OR `class`='%d' OR `class`='%d' OR `class`='%d') ORDER BY `fame` DESC LIMIT 0,%d", char_db, JOB_ALCHEMIST, JOB_CREATOR, JOB_BABY_ALCHEMIST, JOB_GENETIC, JOB_GENETIC_T, JOB_BABY_GENETIC, fame_list_size_chemist) ) + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `char_id`,`fame`,`name` FROM `%s` WHERE `fame`>0 AND (`class`='%d' OR `class`='%d' OR `class`='%d' OR `class`='%d' OR `class`='%d' OR `class`='%d') ORDER BY `fame` DESC LIMIT 0,%d", char_db, JOB_ALCHEMIST, JOB_CREATOR, JOB_BABY_ALCHEMIST, JOB_GENETIC, JOB_GENETIC_T, JOB_BABY_GENETIC, fame_list_size_chemist) ) Sql_ShowDebug(sql_handle); - for( i = 0; i < fame_list_size_chemist && SQL_SUCCESS == Sql_NextRow(sql_handle); ++i ) + for( i = 0; i < fame_list_size_chemist && SQL_SUCCESS == SQL->NextRow(sql_handle); ++i ) { // char_id - Sql_GetData(sql_handle, 0, &data, NULL); + SQL->GetData(sql_handle, 0, &data, NULL); chemist_fame_list[i].id = atoi(data); // fame - Sql_GetData(sql_handle, 1, &data, &len); + SQL->GetData(sql_handle, 1, &data, &len); chemist_fame_list[i].fame = atoi(data); // name - Sql_GetData(sql_handle, 2, &data, &len); + SQL->GetData(sql_handle, 2, &data, &len); memcpy(chemist_fame_list[i].name, data, min(len, NAME_LENGTH)); } // Build Taekwon ranking list - if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `char_id`,`fame`,`name` FROM `%s` WHERE `fame`>0 AND (`class`='%d') ORDER BY `fame` DESC LIMIT 0,%d", char_db, JOB_TAEKWON, fame_list_size_taekwon) ) + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `char_id`,`fame`,`name` FROM `%s` WHERE `fame`>0 AND (`class`='%d') ORDER BY `fame` DESC LIMIT 0,%d", char_db, JOB_TAEKWON, fame_list_size_taekwon) ) Sql_ShowDebug(sql_handle); - for( i = 0; i < fame_list_size_taekwon && SQL_SUCCESS == Sql_NextRow(sql_handle); ++i ) + for( i = 0; i < fame_list_size_taekwon && SQL_SUCCESS == SQL->NextRow(sql_handle); ++i ) { // char_id - Sql_GetData(sql_handle, 0, &data, NULL); + SQL->GetData(sql_handle, 0, &data, NULL); taekwon_fame_list[i].id = atoi(data); // fame - Sql_GetData(sql_handle, 1, &data, &len); + SQL->GetData(sql_handle, 1, &data, &len); taekwon_fame_list[i].fame = atoi(data); // name - Sql_GetData(sql_handle, 2, &data, &len); + SQL->GetData(sql_handle, 2, &data, &len); memcpy(taekwon_fame_list[i].name, data, min(len, NAME_LENGTH)); } - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); } // Send map-servers the fame ranking lists @@ -2607,11 +2607,11 @@ int char_loadName(int char_id, char* name) char* data; size_t len; - if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `name` FROM `%s` WHERE `char_id`='%d'", char_db, char_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `name` FROM `%s` WHERE `char_id`='%d'", char_db, char_id) ) Sql_ShowDebug(sql_handle); - else if( SQL_SUCCESS == Sql_NextRow(sql_handle) ) + else if( SQL_SUCCESS == SQL->NextRow(sql_handle) ) { - Sql_GetData(sql_handle, 0, &data, &len); + SQL->GetData(sql_handle, 0, &data, &len); safestrncpy(name, data, NAME_LENGTH); return 1; } @@ -2662,7 +2662,7 @@ void mapif_server_reset(int id) WBUFW(buf,2) = j * 4 + 10; mapif_sendallwos(fd, buf, WBUFW(buf,2)); } - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `index`='%d'", ragsrvinfo_db, server[id].fd) ) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `index`='%d'", ragsrvinfo_db, server[id].fd) ) Sql_ShowDebug(sql_handle); online_char_db->foreach(online_char_db,char_db_setoffline,id); //Tag relevant chars as 'in disconnected' server. mapif_server_destroy(id); @@ -2789,13 +2789,13 @@ int parse_frommap(int fd) int aid, cid; aid = RFIFOL(fd,2); cid = RFIFOL(fd,6); - if( SQL_ERROR == Sql_Query(sql_handle, "SELECT type, tick, val1, val2, val3, val4 from `%s` WHERE `account_id` = '%d' AND `char_id`='%d'", + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT type, tick, val1, val2, val3, val4 from `%s` WHERE `account_id` = '%d' AND `char_id`='%d'", scdata_db, aid, cid) ) { Sql_ShowDebug(sql_handle); break; } - if( Sql_NumRows(sql_handle) > 0 ) + if( SQL->NumRows(sql_handle) > 0 ) { struct status_change_data scdata; int count; @@ -2805,14 +2805,14 @@ int parse_frommap(int fd) WFIFOW(fd,0) = 0x2b1d; WFIFOL(fd,4) = aid; WFIFOL(fd,8) = cid; - for( count = 0; count < 50 && SQL_SUCCESS == Sql_NextRow(sql_handle); ++count ) + for( count = 0; count < 50 && SQL_SUCCESS == SQL->NextRow(sql_handle); ++count ) { - Sql_GetData(sql_handle, 0, &data, NULL); scdata.type = atoi(data); - Sql_GetData(sql_handle, 1, &data, NULL); scdata.tick = atoi(data); - Sql_GetData(sql_handle, 2, &data, NULL); scdata.val1 = atoi(data); - Sql_GetData(sql_handle, 3, &data, NULL); scdata.val2 = atoi(data); - Sql_GetData(sql_handle, 4, &data, NULL); scdata.val3 = atoi(data); - Sql_GetData(sql_handle, 5, &data, NULL); scdata.val4 = atoi(data); + SQL->GetData(sql_handle, 0, &data, NULL); scdata.type = atoi(data); + SQL->GetData(sql_handle, 1, &data, NULL); scdata.tick = atoi(data); + SQL->GetData(sql_handle, 2, &data, NULL); scdata.val1 = atoi(data); + SQL->GetData(sql_handle, 3, &data, NULL); scdata.val2 = atoi(data); + SQL->GetData(sql_handle, 4, &data, NULL); scdata.val3 = atoi(data); + SQL->GetData(sql_handle, 5, &data, NULL); scdata.val4 = atoi(data); memcpy(WFIFOP(fd, 14+count*sizeof(struct status_change_data)), &scdata, sizeof(struct status_change_data)); } if (count >= 50) @@ -2824,11 +2824,11 @@ int parse_frommap(int fd) WFIFOSET(fd,WFIFOW(fd,2)); //Clear the data once loaded. - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `account_id` = '%d' AND `char_id`='%d'", scdata_db, aid, cid) ) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `account_id` = '%d' AND `char_id`='%d'", scdata_db, aid, cid) ) Sql_ShowDebug(sql_handle); } } - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); #endif RFIFOSKIP(fd, 10); } @@ -3028,7 +3028,7 @@ int parse_frommap(int fd) int char_id, friend_id; char_id = RFIFOL(fd,2); friend_id = RFIFOL(fd,6); - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `char_id`='%d' AND `friend_id`='%d' LIMIT 1", + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `char_id`='%d' AND `friend_id`='%d' LIMIT 1", friend_db, char_id, friend_id) ) { Sql_ShowDebug(sql_handle); break; @@ -3080,16 +3080,16 @@ int parse_frommap(int fd) short second = RFIFOW(fd,42); RFIFOSKIP(fd,44); - Sql_EscapeStringLen(sql_handle, esc_name, name, strnlen(name, NAME_LENGTH)); - if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `account_id`,`name` FROM `%s` WHERE `name` = '%s'", char_db, esc_name) ) + SQL->EscapeStringLen(sql_handle, esc_name, name, strnlen(name, NAME_LENGTH)); + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `account_id`,`name` FROM `%s` WHERE `name` = '%s'", char_db, esc_name) ) Sql_ShowDebug(sql_handle); else - if( Sql_NumRows(sql_handle) == 0 ) + if( SQL->NumRows(sql_handle) == 0 ) { result = 1; // 1-player not found } else - if( SQL_SUCCESS != Sql_NextRow(sql_handle) ) + if( SQL_SUCCESS != SQL->NextRow(sql_handle) ) Sql_ShowDebug(sql_handle); //FIXME: set proper result value? else @@ -3098,8 +3098,8 @@ int parse_frommap(int fd) int account_id; char* data; - Sql_GetData(sql_handle, 0, &data, NULL); account_id = atoi(data); - Sql_GetData(sql_handle, 1, &data, NULL); safestrncpy(name, data, sizeof(name)); + SQL->GetData(sql_handle, 0, &data, NULL); account_id = atoi(data); + SQL->GetData(sql_handle, 1, &data, NULL); safestrncpy(name, data, sizeof(name)); if( login_fd <= 0 ) result = 3; // 3-login-server offline @@ -3150,7 +3150,7 @@ int parse_frommap(int fd) } } - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); // send answer if a player ask, not if the server ask if( acc != -1 && type != 5) { // Don't send answer for changesex @@ -3233,9 +3233,9 @@ int parse_frommap(int fd) { char esc_server_name[sizeof(server_name)*2+1]; - Sql_EscapeString(sql_handle, esc_server_name, server_name); + SQL->EscapeString(sql_handle, esc_server_name, server_name); - if( SQL_ERROR == Sql_Query(sql_handle, "INSERT INTO `%s` SET `index`='%d',`name`='%s',`exp`='%d',`jexp`='%d',`drop`='%d'", + if( SQL_ERROR == SQL->Query(sql_handle, "INSERT INTO `%s` SET `index`='%d',`name`='%s',`exp`='%d',`jexp`='%d',`drop`='%d'", ragsrvinfo_db, fd, esc_server_name, RFIFOL(fd,2), RFIFOL(fd,6), RFIFOL(fd,10)) ) Sql_ShowDebug(sql_handle); RFIFOSKIP(fd,14); @@ -3286,19 +3286,19 @@ int parse_frommap(int fd) StringBuf buf; int i; - StringBuf_Init(&buf); - StringBuf_Printf(&buf, "INSERT INTO `%s` (`account_id`, `char_id`, `type`, `tick`, `val1`, `val2`, `val3`, `val4`) VALUES ", scdata_db); + StrBuf->Init(&buf); + StrBuf->Printf(&buf, "INSERT INTO `%s` (`account_id`, `char_id`, `type`, `tick`, `val1`, `val2`, `val3`, `val4`) VALUES ", scdata_db); for( i = 0; i < count; ++i ) { memcpy (&data, RFIFOP(fd, 14+i*sizeof(struct status_change_data)), sizeof(struct status_change_data)); if( i > 0 ) - StringBuf_AppendStr(&buf, ", "); - StringBuf_Printf(&buf, "('%d','%d','%hu','%d','%d','%d','%d','%d')", aid, cid, + StrBuf->AppendStr(&buf, ", "); + StrBuf->Printf(&buf, "('%d','%d','%hu','%d','%d','%d','%d','%d')", aid, cid, data.type, data.tick, data.val1, data.val2, data.val3, data.val4); } - if( SQL_ERROR == Sql_QueryStr(sql_handle, StringBuf_Value(&buf)) ) + if( SQL_ERROR == SQL->QueryStr(sql_handle, StrBuf->Value(&buf)) ) Sql_ShowDebug(sql_handle); - StringBuf_Destroy(&buf); + StrBuf->Destroy(&buf); } #endif RFIFOSKIP(fd, RFIFOW(fd, 2)); @@ -3561,14 +3561,14 @@ static void char_delete2_req(int fd, struct char_session_data* sd) return; } - if( SQL_SUCCESS != Sql_Query(sql_handle, "SELECT `delete_date` FROM `%s` WHERE `char_id`='%d'", char_db, char_id) || SQL_SUCCESS != Sql_NextRow(sql_handle) ) + if( SQL_SUCCESS != SQL->Query(sql_handle, "SELECT `delete_date` FROM `%s` WHERE `char_id`='%d'", char_db, char_id) || SQL_SUCCESS != SQL->NextRow(sql_handle) ) { Sql_ShowDebug(sql_handle); char_delete2_ack(fd, char_id, 3, 0); return; } - Sql_GetData(sql_handle, 0, &data, NULL); delete_date = strtoul(data, NULL, 10); + SQL->GetData(sql_handle, 0, &data, NULL); delete_date = strtoul(data, NULL, 10); if( delete_date ) {// character already queued for deletion char_delete2_ack(fd, char_id, 0, 0); @@ -3595,7 +3595,7 @@ static void char_delete2_req(int fd, struct char_session_data* sd) // success delete_date = time(NULL)+char_del_delay; - if( SQL_SUCCESS != Sql_Query(sql_handle, "UPDATE `%s` SET `delete_date`='%lu' WHERE `char_id`='%d'", char_db, (unsigned long)delete_date, char_id) ) + if( SQL_SUCCESS != SQL->Query(sql_handle, "UPDATE `%s` SET `delete_date`='%lu' WHERE `char_id`='%d'", char_db, (unsigned long)delete_date, char_id) ) { Sql_ShowDebug(sql_handle); char_delete2_ack(fd, char_id, 3, 0); @@ -3636,15 +3636,15 @@ static void char_delete2_accept(int fd, struct char_session_data* sd) return; } - if( SQL_SUCCESS != Sql_Query(sql_handle, "SELECT `base_level`,`delete_date` FROM `%s` WHERE `char_id`='%d'", char_db, char_id) || SQL_SUCCESS != Sql_NextRow(sql_handle) ) + if( SQL_SUCCESS != SQL->Query(sql_handle, "SELECT `base_level`,`delete_date` FROM `%s` WHERE `char_id`='%d'", char_db, char_id) || SQL_SUCCESS != SQL->NextRow(sql_handle) ) {// data error Sql_ShowDebug(sql_handle); char_delete2_accept_ack(fd, char_id, 3); return; } - Sql_GetData(sql_handle, 0, &data, NULL); base_level = (unsigned int)strtoul(data, NULL, 10); - Sql_GetData(sql_handle, 1, &data, NULL); delete_date = strtoul(data, NULL, 10); + SQL->GetData(sql_handle, 0, &data, NULL); base_level = (unsigned int)strtoul(data, NULL, 10); + SQL->GetData(sql_handle, 1, &data, NULL); delete_date = strtoul(data, NULL, 10); if( !delete_date || delete_date>time(NULL) ) {// not queued or delay not yet passed @@ -3697,7 +3697,7 @@ static void char_delete2_cancel(int fd, struct char_session_data* sd) // there is no need to check, whether or not the character was // queued for deletion, as the client prints an error message by // itself, if it was not the case (@see char_delete2_cancel_ack) - if( SQL_SUCCESS != Sql_Query(sql_handle, "UPDATE `%s` SET `delete_date`='0' WHERE `char_id`='%d'", char_db, char_id) ) + if( SQL_SUCCESS != SQL->Query(sql_handle, "UPDATE `%s` SET `delete_date`='0' WHERE `char_id`='%d'", char_db, char_id) ) { Sql_ShowDebug(sql_handle); char_delete2_cancel_ack(fd, char_id, 2); @@ -3849,12 +3849,12 @@ int parse_char(int fd) } } #endif - if ( SQL_SUCCESS != Sql_Query(sql_handle, "SELECT `char_id` FROM `%s` WHERE `account_id`='%d' AND `char_num`='%d'", char_db, sd->account_id, slot) - || SQL_SUCCESS != Sql_NextRow(sql_handle) - || SQL_SUCCESS != Sql_GetData(sql_handle, 0, &data, NULL) ) + if ( SQL_SUCCESS != SQL->Query(sql_handle, "SELECT `char_id` FROM `%s` WHERE `account_id`='%d' AND `char_num`='%d'", char_db, sd->account_id, slot) + || SQL_SUCCESS != SQL->NextRow(sql_handle) + || SQL_SUCCESS != SQL->GetData(sql_handle, 0, &data, NULL) ) { //Not found?? May be forged packet. Sql_ShowDebug(sql_handle); - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); WFIFOHEAD(fd,3); WFIFOW(fd,0) = 0x6c; WFIFOB(fd,2) = 0; // rejected from server @@ -3863,7 +3863,7 @@ int parse_char(int fd) } char_id = atoi(data); - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); /* set char as online prior to loading its data so 3rd party applications will realise the sql data is not reliable */ set_char_online(-2,char_id,sd->account_id); @@ -3884,8 +3884,8 @@ int parse_char(int fd) if (log_char) { char esc_name[NAME_LENGTH*2+1]; - Sql_EscapeStringLen(sql_handle, esc_name, char_dat.name, strnlen(char_dat.name, NAME_LENGTH)); - if( SQL_ERROR == Sql_Query(sql_handle, "INSERT INTO `%s`(`time`, `account_id`,`char_num`,`name`) VALUES (NOW(), '%d', '%d', '%s')", + SQL->EscapeStringLen(sql_handle, esc_name, char_dat.name, strnlen(char_dat.name, NAME_LENGTH)); + if( SQL_ERROR == SQL->Query(sql_handle, "INSERT INTO `%s`(`time`, `account_id`,`char_num`,`name`) VALUES (NOW(), '%d', '%d', '%s')", charlog_db, sd->account_id, slot, esc_name) ) Sql_ShowDebug(sql_handle); } @@ -4130,7 +4130,7 @@ int parse_char(int fd) break; normalize_name(name,TRIM_CHARS); - Sql_EscapeStringLen(sql_handle, esc_name, name, strnlen(name, NAME_LENGTH)); + SQL->EscapeStringLen(sql_handle, esc_name, name, strnlen(name, NAME_LENGTH)); if( !check_char_name(name,esc_name) ) { i = 1; safestrncpy(sd->new_name, name, NAME_LENGTH); @@ -4162,7 +4162,7 @@ int parse_char(int fd) break; normalize_name(name,TRIM_CHARS); - Sql_EscapeStringLen(sql_handle, esc_name, name, strnlen(name, NAME_LENGTH)); + SQL->EscapeStringLen(sql_handle, esc_name, name, strnlen(name, NAME_LENGTH)); if( !check_char_name(name,esc_name) ) { i = 1; @@ -4872,7 +4872,7 @@ void do_final(void) do_final_mapif(); do_final_loginif(); - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s`", ragsrvinfo_db) ) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s`", ragsrvinfo_db) ) Sql_ShowDebug(sql_handle); char_db_->destroy(char_db_, NULL); @@ -4885,7 +4885,7 @@ void do_final(void) char_fd = -1; } - Sql_Free(sql_handle); + SQL->Free(sql_handle); mapindex_final(); ShowStatus("Finished.\n"); @@ -4981,15 +4981,15 @@ int do_init(int argc, char **argv) { //Cleaning the tables for NULL entrys @ startup [Sirius] //Chardb clean - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `account_id` = '0'", char_db) ) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `account_id` = '0'", char_db) ) Sql_ShowDebug(sql_handle); //guilddb clean - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `guild_lv` = '0' AND `max_member` = '0' AND `exp` = '0' AND `next_exp` = '0' AND `average_lv` = '0'", guild_db) ) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `guild_lv` = '0' AND `max_member` = '0' AND `exp` = '0' AND `next_exp` = '0' AND `average_lv` = '0'", guild_db) ) Sql_ShowDebug(sql_handle); //guildmemberdb clean - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `guild_id` = '0' AND `account_id` = '0' AND `char_id` = '0'", guild_member_db) ) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `guild_id` = '0' AND `account_id` = '0' AND `char_id` = '0'", guild_member_db) ) Sql_ShowDebug(sql_handle); set_defaultparse(parse_char); diff --git a/src/char/int_auction.c b/src/char/int_auction.c index 06e238667..977638aad 100644 --- a/src/char/int_auction.c +++ b/src/char/int_auction.c @@ -1,5 +1,6 @@ -// Copyright (c) Athena Dev Teams - Licensed under GNU GPL -// For more information, see LICENCE in the main folder +// Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// See the LICENSE file +// Portions Copyright (c) Athena Dev Teams #include "../common/mmo.h" #include "../common/malloc.h" @@ -48,15 +49,15 @@ void auction_save(struct auction_data *auction) if( !auction ) return; - StringBuf_Init(&buf); - StringBuf_Printf(&buf, "UPDATE `%s` SET `seller_id` = '%d', `seller_name` = ?, `buyer_id` = '%d', `buyer_name` = ?, `price` = '%d', `buynow` = '%d', `hours` = '%d', `timestamp` = '%lu', `nameid` = '%d', `item_name` = ?, `type` = '%d', `refine` = '%d', `attribute` = '%d'", + StrBuf->Init(&buf); + StrBuf->Printf(&buf, "UPDATE `%s` SET `seller_id` = '%d', `seller_name` = ?, `buyer_id` = '%d', `buyer_name` = ?, `price` = '%d', `buynow` = '%d', `hours` = '%d', `timestamp` = '%lu', `nameid` = '%d', `item_name` = ?, `type` = '%d', `refine` = '%d', `attribute` = '%d'", auction_db, auction->seller_id, auction->buyer_id, auction->price, auction->buynow, auction->hours, (unsigned long)auction->timestamp, auction->item.nameid, auction->type, auction->item.refine, auction->item.attribute); for( j = 0; j < MAX_SLOTS; j++ ) - StringBuf_Printf(&buf, ", `card%d` = '%d'", j, auction->item.card[j]); - StringBuf_Printf(&buf, " WHERE `auction_id` = '%d'", auction->auction_id); + StrBuf->Printf(&buf, ", `card%d` = '%d'", j, auction->item.card[j]); + StrBuf->Printf(&buf, " WHERE `auction_id` = '%d'", auction->auction_id); stmt = SqlStmt_Malloc(sql_handle); - if( SQL_SUCCESS != SqlStmt_PrepareStr(stmt, StringBuf_Value(&buf)) + if( SQL_SUCCESS != SqlStmt_PrepareStr(stmt, StrBuf->Value(&buf)) || SQL_SUCCESS != SqlStmt_BindParam(stmt, 0, SQLDT_STRING, auction->seller_name, strnlen(auction->seller_name, NAME_LENGTH)) || SQL_SUCCESS != SqlStmt_BindParam(stmt, 1, SQLDT_STRING, auction->buyer_name, strnlen(auction->buyer_name, NAME_LENGTH)) || SQL_SUCCESS != SqlStmt_BindParam(stmt, 2, SQLDT_STRING, auction->item_name, strnlen(auction->item_name, ITEM_NAME_LENGTH)) @@ -66,7 +67,7 @@ void auction_save(struct auction_data *auction) } SqlStmt_Free(stmt); - StringBuf_Destroy(&buf); + StrBuf->Destroy(&buf); } unsigned int auction_create(struct auction_data *auction) @@ -80,22 +81,22 @@ unsigned int auction_create(struct auction_data *auction) auction->timestamp = time(NULL) + (auction->hours * 3600); - StringBuf_Init(&buf); - StringBuf_Printf(&buf, "INSERT INTO `%s` (`seller_id`,`seller_name`,`buyer_id`,`buyer_name`,`price`,`buynow`,`hours`,`timestamp`,`nameid`,`item_name`,`type`,`refine`,`attribute`,`unique_id`", auction_db); + StrBuf->Init(&buf); + StrBuf->Printf(&buf, "INSERT INTO `%s` (`seller_id`,`seller_name`,`buyer_id`,`buyer_name`,`price`,`buynow`,`hours`,`timestamp`,`nameid`,`item_name`,`type`,`refine`,`attribute`,`unique_id`", auction_db); for( j = 0; j < MAX_SLOTS; j++ ) - StringBuf_Printf(&buf, ",`card%d`", j); - StringBuf_Printf(&buf, ") VALUES ('%d',?,'%d',?,'%d','%d','%d','%lu','%d',?,'%d','%d','%d','%"PRIu64"'", + StrBuf->Printf(&buf, ",`card%d`", j); + StrBuf->Printf(&buf, ") VALUES ('%d',?,'%d',?,'%d','%d','%d','%lu','%d',?,'%d','%d','%d','%"PRIu64"'", auction->seller_id, auction->buyer_id, auction->price, auction->buynow, auction->hours, (unsigned long)auction->timestamp, auction->item.nameid, auction->type, auction->item.refine, auction->item.attribute, auction->item.unique_id); for( j = 0; j < MAX_SLOTS; j++ ) - StringBuf_Printf(&buf, ",'%d'", auction->item.card[j]); - StringBuf_AppendStr(&buf, ")"); + StrBuf->Printf(&buf, ",'%d'", auction->item.card[j]); + StrBuf->AppendStr(&buf, ")"); //Unique Non Stackable Item ID updateLastUid(auction->item.unique_id); dbUpdateUid(sql_handle); stmt = SqlStmt_Malloc(sql_handle); - if( SQL_SUCCESS != SqlStmt_PrepareStr(stmt, StringBuf_Value(&buf)) + if( SQL_SUCCESS != SqlStmt_PrepareStr(stmt, StrBuf->Value(&buf)) || SQL_SUCCESS != SqlStmt_BindParam(stmt, 0, SQLDT_STRING, auction->seller_name, strnlen(auction->seller_name, NAME_LENGTH)) || SQL_SUCCESS != SqlStmt_BindParam(stmt, 1, SQLDT_STRING, auction->buyer_name, strnlen(auction->buyer_name, NAME_LENGTH)) || SQL_SUCCESS != SqlStmt_BindParam(stmt, 2, SQLDT_STRING, auction->item_name, strnlen(auction->item_name, ITEM_NAME_LENGTH)) @@ -123,7 +124,7 @@ unsigned int auction_create(struct auction_data *auction) } SqlStmt_Free(stmt); - StringBuf_Destroy(&buf); + StrBuf->Destroy(&buf); return auction->auction_id; } @@ -165,7 +166,7 @@ void auction_delete(struct auction_data *auction) { unsigned int auction_id = auction->auction_id; - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `auction_id` = '%d'", auction_db, auction_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `auction_id` = '%d'", auction_db, auction_id) ) Sql_ShowDebug(sql_handle); if( auction->auction_end_timer != INVALID_TIMER ) @@ -184,39 +185,39 @@ void inter_auctions_fromsql(void) unsigned int tick = gettick(), endtick; time_t now = time(NULL); - StringBuf_Init(&buf); - StringBuf_AppendStr(&buf, "SELECT `auction_id`,`seller_id`,`seller_name`,`buyer_id`,`buyer_name`," + StrBuf->Init(&buf); + StrBuf->AppendStr(&buf, "SELECT `auction_id`,`seller_id`,`seller_name`,`buyer_id`,`buyer_name`," "`price`,`buynow`,`hours`,`timestamp`,`nameid`,`item_name`,`type`,`refine`,`attribute`,`unique_id`"); for( i = 0; i < MAX_SLOTS; i++ ) - StringBuf_Printf(&buf, ",`card%d`", i); - StringBuf_Printf(&buf, " FROM `%s` ORDER BY `auction_id` DESC", auction_db); + StrBuf->Printf(&buf, ",`card%d`", i); + StrBuf->Printf(&buf, " FROM `%s` ORDER BY `auction_id` DESC", auction_db); - if( SQL_ERROR == Sql_Query(sql_handle, StringBuf_Value(&buf)) ) + if( SQL_ERROR == SQL->Query(sql_handle, StrBuf->Value(&buf)) ) Sql_ShowDebug(sql_handle); - StringBuf_Destroy(&buf); + StrBuf->Destroy(&buf); - while( SQL_SUCCESS == Sql_NextRow(sql_handle) ) + while( SQL_SUCCESS == SQL->NextRow(sql_handle) ) { CREATE(auction, struct auction_data, 1); - Sql_GetData(sql_handle, 0, &data, NULL); auction->auction_id = atoi(data); - Sql_GetData(sql_handle, 1, &data, NULL); auction->seller_id = atoi(data); - Sql_GetData(sql_handle, 2, &data, NULL); safestrncpy(auction->seller_name, data, NAME_LENGTH); - Sql_GetData(sql_handle, 3, &data, NULL); auction->buyer_id = atoi(data); - Sql_GetData(sql_handle, 4, &data, NULL); safestrncpy(auction->buyer_name, data, NAME_LENGTH); - Sql_GetData(sql_handle, 5, &data, NULL); auction->price = atoi(data); - Sql_GetData(sql_handle, 6, &data, NULL); auction->buynow = atoi(data); - Sql_GetData(sql_handle, 7, &data, NULL); auction->hours = atoi(data); - Sql_GetData(sql_handle, 8, &data, NULL); auction->timestamp = atoi(data); + SQL->GetData(sql_handle, 0, &data, NULL); auction->auction_id = atoi(data); + SQL->GetData(sql_handle, 1, &data, NULL); auction->seller_id = atoi(data); + SQL->GetData(sql_handle, 2, &data, NULL); safestrncpy(auction->seller_name, data, NAME_LENGTH); + SQL->GetData(sql_handle, 3, &data, NULL); auction->buyer_id = atoi(data); + SQL->GetData(sql_handle, 4, &data, NULL); safestrncpy(auction->buyer_name, data, NAME_LENGTH); + SQL->GetData(sql_handle, 5, &data, NULL); auction->price = atoi(data); + SQL->GetData(sql_handle, 6, &data, NULL); auction->buynow = atoi(data); + SQL->GetData(sql_handle, 7, &data, NULL); auction->hours = atoi(data); + SQL->GetData(sql_handle, 8, &data, NULL); auction->timestamp = atoi(data); item = &auction->item; - Sql_GetData(sql_handle, 9, &data, NULL); item->nameid = atoi(data); - Sql_GetData(sql_handle,10, &data, NULL); safestrncpy(auction->item_name, data, ITEM_NAME_LENGTH); - Sql_GetData(sql_handle,11, &data, NULL); auction->type = atoi(data); + SQL->GetData(sql_handle, 9, &data, NULL); item->nameid = atoi(data); + SQL->GetData(sql_handle,10, &data, NULL); safestrncpy(auction->item_name, data, ITEM_NAME_LENGTH); + SQL->GetData(sql_handle,11, &data, NULL); auction->type = atoi(data); - Sql_GetData(sql_handle,12, &data, NULL); item->refine = atoi(data); - Sql_GetData(sql_handle,13, &data, NULL); item->attribute = atoi(data); - Sql_GetData(sql_handle,14, &data, NULL); item->unique_id = strtoull(data, NULL, 10); + SQL->GetData(sql_handle,12, &data, NULL); item->refine = atoi(data); + SQL->GetData(sql_handle,13, &data, NULL); item->attribute = atoi(data); + SQL->GetData(sql_handle,14, &data, NULL); item->unique_id = strtoull(data, NULL, 10); item->identify = 1; item->amount = 1; @@ -224,7 +225,7 @@ void inter_auctions_fromsql(void) for( i = 0; i < MAX_SLOTS; i++ ) { - Sql_GetData(sql_handle, 15 + i, &data, NULL); + SQL->GetData(sql_handle, 15 + i, &data, NULL); item->card[i] = atoi(data); } @@ -237,7 +238,7 @@ void inter_auctions_fromsql(void) idb_put(auction_db_, auction->auction_id, auction); } - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); } static void mapif_Auction_sendlist(int fd, int char_id, short count, short pages, unsigned char *buf) diff --git a/src/char/int_elemental.c b/src/char/int_elemental.c index 3c2f6672d..807924941 100644 --- a/src/char/int_elemental.c +++ b/src/char/int_elemental.c @@ -1,5 +1,6 @@ -// Copyright (c) Athena Dev Teams - Licensed under GNU GPL -// For more information, see LICENCE in the main folder +// Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// See the LICENSE file +// Portions Copyright (c) Athena Dev Teams #include "../common/mmo.h" #include "../common/malloc.h" @@ -19,7 +20,7 @@ bool mapif_elemental_save(struct s_elemental* ele) { bool flag = true; if( ele->elemental_id == 0 ) { // Create new DB entry - if( SQL_ERROR == Sql_Query(sql_handle, + if( SQL_ERROR == SQL->Query(sql_handle, "INSERT INTO `elemental` (`char_id`,`class`,`mode`,`hp`,`sp`,`max_hp`,`max_sp`,`atk1`,`atk2`,`matk`,`aspd`,`def`,`mdef`,`flee`,`hit`,`life_time`)" "VALUES ('%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%u')", ele->char_id, ele->class_, ele->mode, ele->hp, ele->sp, ele->max_hp, ele->max_sp, ele->atk, ele->atk2, ele->matk, ele->amotion, ele->def, ele->mdef, ele->flee, ele->hit, ele->life_time) ) @@ -28,8 +29,8 @@ bool mapif_elemental_save(struct s_elemental* ele) { flag = false; } else - ele->elemental_id = (int)Sql_LastInsertId(sql_handle); - } else if( SQL_ERROR == Sql_Query(sql_handle, + ele->elemental_id = (int)SQL->NumRows(sql_handle); + } else if( SQL_ERROR == SQL->Query(sql_handle, "UPDATE `elemental` SET `char_id` = '%d', `class` = '%d', `mode` = '%d', `hp` = '%d', `sp` = '%d'," "`max_hp` = '%d', `max_sp` = '%d', `atk1` = '%d', `atk2` = '%d', `matk` = '%d', `aspd` = '%d', `def` = '%d'," "`mdef` = '%d', `flee` = '%d', `hit` = '%d', `life_time` = '%u' WHERE `ele_id` = '%d'", @@ -49,34 +50,34 @@ bool mapif_elemental_load(int ele_id, int char_id, struct s_elemental *ele) { ele->elemental_id = ele_id; ele->char_id = char_id; - if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `class`, `mode`, `hp`, `sp`, `max_hp`, `max_sp`, `atk1`, `atk2`, `matk`, `aspd`," + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `class`, `mode`, `hp`, `sp`, `max_hp`, `max_sp`, `atk1`, `atk2`, `matk`, `aspd`," "`def`, `mdef`, `flee`, `hit`, `life_time` FROM `elemental` WHERE `ele_id` = '%d' AND `char_id` = '%d'", ele_id, char_id) ) { Sql_ShowDebug(sql_handle); return false; } - if( SQL_SUCCESS != Sql_NextRow(sql_handle) ) { - Sql_FreeResult(sql_handle); + if( SQL_SUCCESS != SQL->NextRow(sql_handle) ) { + SQL->FreeResult(sql_handle); return false; } - Sql_GetData(sql_handle, 0, &data, NULL); ele->class_ = atoi(data); - Sql_GetData(sql_handle, 1, &data, NULL); ele->mode = atoi(data); - Sql_GetData(sql_handle, 2, &data, NULL); ele->hp = atoi(data); - Sql_GetData(sql_handle, 3, &data, NULL); ele->sp = atoi(data); - Sql_GetData(sql_handle, 4, &data, NULL); ele->max_hp = atoi(data); - Sql_GetData(sql_handle, 5, &data, NULL); ele->max_sp = atoi(data); - Sql_GetData(sql_handle, 6, &data, NULL); ele->atk = atoi(data); - Sql_GetData(sql_handle, 7, &data, NULL); ele->atk2 = atoi(data); - Sql_GetData(sql_handle, 8, &data, NULL); ele->matk = atoi(data); - Sql_GetData(sql_handle, 9, &data, NULL); ele->amotion = atoi(data); - Sql_GetData(sql_handle, 10, &data, NULL); ele->def = atoi(data); - Sql_GetData(sql_handle, 11, &data, NULL); ele->mdef = atoi(data); - Sql_GetData(sql_handle, 12, &data, NULL); ele->flee = atoi(data); - Sql_GetData(sql_handle, 13, &data, NULL); ele->hit = atoi(data); - Sql_GetData(sql_handle, 14, &data, NULL); ele->life_time = atoi(data); - Sql_FreeResult(sql_handle); + SQL->GetData(sql_handle, 0, &data, NULL); ele->class_ = atoi(data); + SQL->GetData(sql_handle, 1, &data, NULL); ele->mode = atoi(data); + SQL->GetData(sql_handle, 2, &data, NULL); ele->hp = atoi(data); + SQL->GetData(sql_handle, 3, &data, NULL); ele->sp = atoi(data); + SQL->GetData(sql_handle, 4, &data, NULL); ele->max_hp = atoi(data); + SQL->GetData(sql_handle, 5, &data, NULL); ele->max_sp = atoi(data); + SQL->GetData(sql_handle, 6, &data, NULL); ele->atk = atoi(data); + SQL->GetData(sql_handle, 7, &data, NULL); ele->atk2 = atoi(data); + SQL->GetData(sql_handle, 8, &data, NULL); ele->matk = atoi(data); + SQL->GetData(sql_handle, 9, &data, NULL); ele->amotion = atoi(data); + SQL->GetData(sql_handle, 10, &data, NULL); ele->def = atoi(data); + SQL->GetData(sql_handle, 11, &data, NULL); ele->mdef = atoi(data); + SQL->GetData(sql_handle, 12, &data, NULL); ele->flee = atoi(data); + SQL->GetData(sql_handle, 13, &data, NULL); ele->hit = atoi(data); + SQL->GetData(sql_handle, 14, &data, NULL); ele->life_time = atoi(data); + SQL->FreeResult(sql_handle); if( save_log ) ShowInfo("Elemental loaded (%d - %d).\n", ele->elemental_id, ele->char_id); @@ -84,7 +85,7 @@ bool mapif_elemental_load(int ele_id, int char_id, struct s_elemental *ele) { } bool mapif_elemental_delete(int ele_id) { - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `elemental` WHERE `ele_id` = '%d'", ele_id) ) { + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `elemental` WHERE `ele_id` = '%d'", ele_id) ) { Sql_ShowDebug(sql_handle); return false; } diff --git a/src/char/int_guild.c b/src/char/int_guild.c index 46bba63db..d9d89206b 100644 --- a/src/char/int_guild.c +++ b/src/char/int_guild.c @@ -92,9 +92,9 @@ static int guild_save_timer(int tid, unsigned int tick, int id, intptr_t data) int inter_guild_removemember_tosql(int account_id, int char_id) { - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE from `%s` where `account_id` = '%d' and `char_id` = '%d'", guild_member_db, account_id, char_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE from `%s` where `account_id` = '%d' and `char_id` = '%d'", guild_member_db, account_id, char_id) ) Sql_ShowDebug(sql_handle); - if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `guild_id` = '0' WHERE `char_id` = '%d'", char_db, char_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "UPDATE `%s` SET `guild_id` = '0' WHERE `char_id` = '%d'", char_db, char_id) ) Sql_ShowDebug(sql_handle); return 0; } @@ -129,8 +129,8 @@ int inter_guild_tosql(struct guild *g,int flag) ShowInfo("Save guild request ("CL_BOLD"%d"CL_RESET" - flag 0x%x).",g->guild_id, flag); #endif - Sql_EscapeStringLen(sql_handle, esc_name, g->name, strnlen(g->name, NAME_LENGTH)); - Sql_EscapeStringLen(sql_handle, esc_master, g->master, strnlen(g->master, NAME_LENGTH)); + SQL->EscapeStringLen(sql_handle, esc_name, g->name, strnlen(g->name, NAME_LENGTH)); + SQL->EscapeStringLen(sql_handle, esc_master, g->master, strnlen(g->master, NAME_LENGTH)); *t_info = '\0'; // Insert a new guild the guild @@ -139,7 +139,7 @@ int inter_guild_tosql(struct guild *g,int flag) strcat(t_info, " guild_create"); // Create a new guild - if( SQL_ERROR == Sql_Query(sql_handle, "INSERT INTO `%s` " + if( SQL_ERROR == SQL->Query(sql_handle, "INSERT INTO `%s` " "(`name`,`master`,`guild_lv`,`max_member`,`average_lv`,`char_id`) " "VALUES ('%s', '%s', '%d', '%d', '%d', '%d')", guild_db, esc_name, esc_master, g->guild_lv, g->max_member, g->average_lv, g->member[0].char_id) ) @@ -150,7 +150,7 @@ int inter_guild_tosql(struct guild *g,int flag) } else { - g->guild_id = (int)Sql_LastInsertId(sql_handle); + g->guild_id = (int)SQL->NumRows(sql_handle); new_guild = 1; } } @@ -161,8 +161,8 @@ int inter_guild_tosql(struct guild *g,int flag) StringBuf buf; bool add_comma = false; - StringBuf_Init(&buf); - StringBuf_Printf(&buf, "UPDATE `%s` SET ", guild_db); + StrBuf->Init(&buf); + StrBuf->Printf(&buf, "UPDATE `%s` SET ", guild_db); if (flag & GS_EMBLEM) { @@ -177,26 +177,26 @@ int inter_guild_tosql(struct guild *g,int flag) *pData++ = dataToHex[g->emblem_data[i] & 0x0F]; } *pData = 0; - StringBuf_Printf(&buf, "`emblem_len`=%d, `emblem_id`=%d, `emblem_data`='%s'", g->emblem_len, g->emblem_id, emblem_data); + StrBuf->Printf(&buf, "`emblem_len`=%d, `emblem_id`=%d, `emblem_data`='%s'", g->emblem_len, g->emblem_id, emblem_data); add_comma = true; } if (flag & GS_BASIC) { strcat(t_info, " basic"); if( add_comma ) - StringBuf_AppendStr(&buf, ", "); + StrBuf->AppendStr(&buf, ", "); else add_comma = true; - StringBuf_Printf(&buf, "`name`='%s', `master`='%s', `char_id`=%d", esc_name, esc_master, g->member[0].char_id); + StrBuf->Printf(&buf, "`name`='%s', `master`='%s', `char_id`=%d", esc_name, esc_master, g->member[0].char_id); } if (flag & GS_CONNECT) { strcat(t_info, " connect"); if( add_comma ) - StringBuf_AppendStr(&buf, ", "); + StrBuf->AppendStr(&buf, ", "); else add_comma = true; - StringBuf_Printf(&buf, "`connect_member`=%d, `average_lv`=%d", g->connect_member, g->average_lv); + StrBuf->Printf(&buf, "`connect_member`=%d, `average_lv`=%d", g->connect_member, g->average_lv); } if (flag & GS_MES) { @@ -205,26 +205,26 @@ int inter_guild_tosql(struct guild *g,int flag) strcat(t_info, " mes"); if( add_comma ) - StringBuf_AppendStr(&buf, ", "); + StrBuf->AppendStr(&buf, ", "); else add_comma = true; - Sql_EscapeStringLen(sql_handle, esc_mes1, g->mes1, strnlen(g->mes1, sizeof(g->mes1))); - Sql_EscapeStringLen(sql_handle, esc_mes2, g->mes2, strnlen(g->mes2, sizeof(g->mes2))); - StringBuf_Printf(&buf, "`mes1`='%s', `mes2`='%s'", esc_mes1, esc_mes2); + SQL->EscapeStringLen(sql_handle, esc_mes1, g->mes1, strnlen(g->mes1, sizeof(g->mes1))); + SQL->EscapeStringLen(sql_handle, esc_mes2, g->mes2, strnlen(g->mes2, sizeof(g->mes2))); + StrBuf->Printf(&buf, "`mes1`='%s', `mes2`='%s'", esc_mes1, esc_mes2); } if (flag & GS_LEVEL) { strcat(t_info, " level"); if( add_comma ) - StringBuf_AppendStr(&buf, ", "); + StrBuf->AppendStr(&buf, ", "); //else //last condition using add_coma setting // add_comma = true; - StringBuf_Printf(&buf, "`guild_lv`=%d, `skill_point`=%d, `exp`=%"PRIu64", `next_exp`=%u, `max_member`=%d", g->guild_lv, g->skill_point, g->exp, g->next_exp, g->max_member); + StrBuf->Printf(&buf, "`guild_lv`=%d, `skill_point`=%d, `exp`=%"PRIu64", `next_exp`=%u, `max_member`=%d", g->guild_lv, g->skill_point, g->exp, g->next_exp, g->max_member); } - StringBuf_Printf(&buf, " WHERE `guild_id`=%d", g->guild_id); - if( SQL_ERROR == Sql_Query(sql_handle, "%s", StringBuf_Value(&buf)) ) + StrBuf->Printf(&buf, " WHERE `guild_id`=%d", g->guild_id); + if( SQL_ERROR == SQL->Query(sql_handle, "%s", StrBuf->Value(&buf)) ) Sql_ShowDebug(sql_handle); - StringBuf_Destroy(&buf); + StrBuf->Destroy(&buf); } if (flag&GS_MEMBER) @@ -239,8 +239,8 @@ int inter_guild_tosql(struct guild *g,int flag) continue; if(m->account_id) { //Since nothing references guild member table as foreign keys, it's safe to use REPLACE INTO - Sql_EscapeStringLen(sql_handle, esc_name, m->name, strnlen(m->name, NAME_LENGTH)); - if( SQL_ERROR == Sql_Query(sql_handle, "REPLACE INTO `%s` (`guild_id`,`account_id`,`char_id`,`hair`,`hair_color`,`gender`,`class`,`lv`,`exp`,`exp_payper`,`online`,`position`,`name`) " + SQL->EscapeStringLen(sql_handle, esc_name, m->name, strnlen(m->name, NAME_LENGTH)); + if( SQL_ERROR == SQL->Query(sql_handle, "REPLACE INTO `%s` (`guild_id`,`account_id`,`char_id`,`hair`,`hair_color`,`gender`,`class`,`lv`,`exp`,`exp_payper`,`online`,`position`,`name`) " "VALUES ('%d','%d','%d','%d','%d','%d','%d','%d','%"PRIu64"','%d','%d','%d','%s')", guild_member_db, g->guild_id, m->account_id, m->char_id, m->hair, m->hair_color, m->gender, @@ -248,7 +248,7 @@ int inter_guild_tosql(struct guild *g,int flag) Sql_ShowDebug(sql_handle); if (m->modified&GS_MEMBER_NEW || new_guild == 1) { - if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `guild_id` = '%d' WHERE `char_id` = '%d'", + if( SQL_ERROR == SQL->Query(sql_handle, "UPDATE `%s` SET `guild_id` = '%d' WHERE `char_id` = '%d'", char_db, g->guild_id, m->char_id) ) Sql_ShowDebug(sql_handle); } @@ -264,8 +264,8 @@ int inter_guild_tosql(struct guild *g,int flag) struct guild_position *p = &g->position[i]; if (!p->modified) continue; - Sql_EscapeStringLen(sql_handle, esc_name, p->name, strnlen(p->name, NAME_LENGTH)); - if( SQL_ERROR == Sql_Query(sql_handle, "REPLACE INTO `%s` (`guild_id`,`position`,`name`,`mode`,`exp_mode`) VALUES ('%d','%d','%s','%d','%d')", + SQL->EscapeStringLen(sql_handle, esc_name, p->name, strnlen(p->name, NAME_LENGTH)); + if( SQL_ERROR == SQL->Query(sql_handle, "REPLACE INTO `%s` (`guild_id`,`position`,`name`,`mode`,`exp_mode`) VALUES ('%d','%d','%s','%d','%d')", guild_position_db, g->guild_id, i, esc_name, p->mode, p->exp_mode) ) Sql_ShowDebug(sql_handle); p->modified = GS_POSITION_UNMODIFIED; @@ -278,8 +278,8 @@ int inter_guild_tosql(struct guild *g,int flag) // NOTE: no need to do it on both sides since both guilds in memory had // their info changed, not to mention this would also mess up oppositions! // [Skotlex] - //if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `guild_id`='%d' OR `alliance_id`='%d'", guild_alliance_db, g->guild_id, g->guild_id) ) - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `guild_id`='%d'", guild_alliance_db, g->guild_id) ) + //if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `guild_id`='%d' OR `alliance_id`='%d'", guild_alliance_db, g->guild_id, g->guild_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `guild_id`='%d'", guild_alliance_db, g->guild_id) ) { Sql_ShowDebug(sql_handle); } @@ -291,8 +291,8 @@ int inter_guild_tosql(struct guild *g,int flag) struct guild_alliance *a=&g->alliance[i]; if(a->guild_id>0) { - Sql_EscapeStringLen(sql_handle, esc_name, a->name, strnlen(a->name, NAME_LENGTH)); - if( SQL_ERROR == Sql_Query(sql_handle, "REPLACE INTO `%s` (`guild_id`,`opposition`,`alliance_id`,`name`) " + SQL->EscapeStringLen(sql_handle, esc_name, a->name, strnlen(a->name, NAME_LENGTH)); + if( SQL_ERROR == SQL->Query(sql_handle, "REPLACE INTO `%s` (`guild_id`,`opposition`,`alliance_id`,`name`) " "VALUES ('%d','%d','%d','%s')", guild_alliance_db, g->guild_id, a->opposition, a->guild_id, esc_name) ) Sql_ShowDebug(sql_handle); @@ -309,9 +309,9 @@ int inter_guild_tosql(struct guild *g,int flag) if(e->account_id>0){ char esc_mes[sizeof(e->mes)*2+1]; - Sql_EscapeStringLen(sql_handle, esc_name, e->name, strnlen(e->name, NAME_LENGTH)); - Sql_EscapeStringLen(sql_handle, esc_mes, e->mes, strnlen(e->mes, sizeof(e->mes))); - if( SQL_ERROR == Sql_Query(sql_handle, "REPLACE INTO `%s` (`guild_id`,`account_id`,`name`,`mes`) " + SQL->EscapeStringLen(sql_handle, esc_name, e->name, strnlen(e->name, NAME_LENGTH)); + SQL->EscapeStringLen(sql_handle, esc_mes, e->mes, strnlen(e->mes, sizeof(e->mes))); + if( SQL_ERROR == SQL->Query(sql_handle, "REPLACE INTO `%s` (`guild_id`,`account_id`,`name`,`mes`) " "VALUES ('%d','%d','%s','%s')", guild_expulsion_db, g->guild_id, e->account_id, esc_name, esc_mes) ) Sql_ShowDebug(sql_handle); } @@ -323,7 +323,7 @@ int inter_guild_tosql(struct guild *g,int flag) //printf("- Insert guild %d to guild_skill\n",g->guild_id); for(i=0;iskill[i].id>0 && g->skill[i].lv>0){ - if( SQL_ERROR == Sql_Query(sql_handle, "REPLACE INTO `%s` (`guild_id`,`id`,`lv`) VALUES ('%d','%d','%d')", + if( SQL_ERROR == SQL->Query(sql_handle, "REPLACE INTO `%s` (`guild_id`,`id`,`lv`) VALUES ('%d','%d','%d')", guild_skill_db, g->guild_id, g->skill[i].id, g->skill[i].lv) ) Sql_ShowDebug(sql_handle); } @@ -355,38 +355,38 @@ struct guild * inter_guild_fromsql(int guild_id) ShowInfo("Guild load request (%d)...\n", guild_id); #endif - if( SQL_ERROR == Sql_Query(sql_handle, "SELECT g.`name`,c.`name`,g.`guild_lv`,g.`connect_member`,g.`max_member`,g.`average_lv`,g.`exp`,g.`next_exp`,g.`skill_point`,g.`mes1`,g.`mes2`,g.`emblem_len`,g.`emblem_id`,g.`emblem_data` " + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT g.`name`,c.`name`,g.`guild_lv`,g.`connect_member`,g.`max_member`,g.`average_lv`,g.`exp`,g.`next_exp`,g.`skill_point`,g.`mes1`,g.`mes2`,g.`emblem_len`,g.`emblem_id`,g.`emblem_data` " "FROM `%s` g LEFT JOIN `%s` c ON c.`char_id` = g.`char_id` WHERE g.`guild_id`='%d'", guild_db, char_db, guild_id) ) { Sql_ShowDebug(sql_handle); return NULL; } - if( SQL_SUCCESS != Sql_NextRow(sql_handle) ) + if( SQL_SUCCESS != SQL->NextRow(sql_handle) ) return NULL;// Guild does not exists. CREATE(g, struct guild, 1); g->guild_id = guild_id; - Sql_GetData(sql_handle, 0, &data, &len); memcpy(g->name, data, min(len, NAME_LENGTH)); - Sql_GetData(sql_handle, 1, &data, &len); memcpy(g->master, data, min(len, NAME_LENGTH)); - Sql_GetData(sql_handle, 2, &data, NULL); g->guild_lv = atoi(data); - Sql_GetData(sql_handle, 3, &data, NULL); g->connect_member = atoi(data); - Sql_GetData(sql_handle, 4, &data, NULL); g->max_member = atoi(data); + SQL->GetData(sql_handle, 0, &data, &len); memcpy(g->name, data, min(len, NAME_LENGTH)); + SQL->GetData(sql_handle, 1, &data, &len); memcpy(g->master, data, min(len, NAME_LENGTH)); + SQL->GetData(sql_handle, 2, &data, NULL); g->guild_lv = atoi(data); + SQL->GetData(sql_handle, 3, &data, NULL); g->connect_member = atoi(data); + SQL->GetData(sql_handle, 4, &data, NULL); g->max_member = atoi(data); if( g->max_member > MAX_GUILD ) { // Fix reduction of MAX_GUILD [PoW] ShowWarning("Guild %d:%s specifies higher capacity (%d) than MAX_GUILD (%d)\n", guild_id, g->name, g->max_member, MAX_GUILD); g->max_member = MAX_GUILD; } - Sql_GetData(sql_handle, 5, &data, NULL); g->average_lv = atoi(data); - Sql_GetData(sql_handle, 6, &data, NULL); g->exp = strtoull(data, NULL, 10); - Sql_GetData(sql_handle, 7, &data, NULL); g->next_exp = (unsigned int)strtoul(data, NULL, 10); - Sql_GetData(sql_handle, 8, &data, NULL); g->skill_point = atoi(data); - Sql_GetData(sql_handle, 9, &data, &len); memcpy(g->mes1, data, min(len, sizeof(g->mes1))); - Sql_GetData(sql_handle, 10, &data, &len); memcpy(g->mes2, data, min(len, sizeof(g->mes2))); - Sql_GetData(sql_handle, 11, &data, &len); g->emblem_len = atoi(data); - Sql_GetData(sql_handle, 12, &data, &len); g->emblem_id = atoi(data); - Sql_GetData(sql_handle, 13, &data, &len); + SQL->GetData(sql_handle, 5, &data, NULL); g->average_lv = atoi(data); + SQL->GetData(sql_handle, 6, &data, NULL); g->exp = strtoull(data, NULL, 10); + SQL->GetData(sql_handle, 7, &data, NULL); g->next_exp = (unsigned int)strtoul(data, NULL, 10); + SQL->GetData(sql_handle, 8, &data, NULL); g->skill_point = atoi(data); + SQL->GetData(sql_handle, 9, &data, &len); memcpy(g->mes1, data, min(len, sizeof(g->mes1))); + SQL->GetData(sql_handle, 10, &data, &len); memcpy(g->mes2, data, min(len, sizeof(g->mes2))); + SQL->GetData(sql_handle, 11, &data, &len); g->emblem_len = atoi(data); + SQL->GetData(sql_handle, 12, &data, &len); g->emblem_id = atoi(data); + SQL->GetData(sql_handle, 13, &data, &len); // convert emblem data from hexadecimal to binary //TODO: why not store it in the db as binary directly? [ultramage] for( i = 0, p = g->emblem_data; i < g->emblem_len; ++i, ++p ) @@ -410,90 +410,90 @@ struct guild * inter_guild_fromsql(int guild_id) } // load guild member info - if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `account_id`,`char_id`,`hair`,`hair_color`,`gender`,`class`,`lv`,`exp`,`exp_payper`,`online`,`position`,`name` " + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `account_id`,`char_id`,`hair`,`hair_color`,`gender`,`class`,`lv`,`exp`,`exp_payper`,`online`,`position`,`name` " "FROM `%s` WHERE `guild_id`='%d' ORDER BY `position`", guild_member_db, guild_id) ) { Sql_ShowDebug(sql_handle); aFree(g); return NULL; } - for( i = 0; i < g->max_member && SQL_SUCCESS == Sql_NextRow(sql_handle); ++i ) + for( i = 0; i < g->max_member && SQL_SUCCESS == SQL->NextRow(sql_handle); ++i ) { struct guild_member* m = &g->member[i]; - Sql_GetData(sql_handle, 0, &data, NULL); m->account_id = atoi(data); - Sql_GetData(sql_handle, 1, &data, NULL); m->char_id = atoi(data); - Sql_GetData(sql_handle, 2, &data, NULL); m->hair = atoi(data); - Sql_GetData(sql_handle, 3, &data, NULL); m->hair_color = atoi(data); - Sql_GetData(sql_handle, 4, &data, NULL); m->gender = atoi(data); - Sql_GetData(sql_handle, 5, &data, NULL); m->class_ = atoi(data); - Sql_GetData(sql_handle, 6, &data, NULL); m->lv = atoi(data); - Sql_GetData(sql_handle, 7, &data, NULL); m->exp = strtoull(data, NULL, 10); - Sql_GetData(sql_handle, 8, &data, NULL); m->exp_payper = (unsigned int)atoi(data); - Sql_GetData(sql_handle, 9, &data, NULL); m->online = atoi(data); - Sql_GetData(sql_handle, 10, &data, NULL); m->position = atoi(data); + SQL->GetData(sql_handle, 0, &data, NULL); m->account_id = atoi(data); + SQL->GetData(sql_handle, 1, &data, NULL); m->char_id = atoi(data); + SQL->GetData(sql_handle, 2, &data, NULL); m->hair = atoi(data); + SQL->GetData(sql_handle, 3, &data, NULL); m->hair_color = atoi(data); + SQL->GetData(sql_handle, 4, &data, NULL); m->gender = atoi(data); + SQL->GetData(sql_handle, 5, &data, NULL); m->class_ = atoi(data); + SQL->GetData(sql_handle, 6, &data, NULL); m->lv = atoi(data); + SQL->GetData(sql_handle, 7, &data, NULL); m->exp = strtoull(data, NULL, 10); + SQL->GetData(sql_handle, 8, &data, NULL); m->exp_payper = (unsigned int)atoi(data); + SQL->GetData(sql_handle, 9, &data, NULL); m->online = atoi(data); + SQL->GetData(sql_handle, 10, &data, NULL); m->position = atoi(data); if( m->position >= MAX_GUILDPOSITION ) // Fix reduction of MAX_GUILDPOSITION [PoW] m->position = MAX_GUILDPOSITION - 1; - Sql_GetData(sql_handle, 11, &data, &len); memcpy(m->name, data, min(len, NAME_LENGTH)); + SQL->GetData(sql_handle, 11, &data, &len); memcpy(m->name, data, min(len, NAME_LENGTH)); m->modified = GS_MEMBER_UNMODIFIED; } //printf("- Read guild_position %d from sql \n",guild_id); - if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `position`,`name`,`mode`,`exp_mode` FROM `%s` WHERE `guild_id`='%d'", guild_position_db, guild_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `position`,`name`,`mode`,`exp_mode` FROM `%s` WHERE `guild_id`='%d'", guild_position_db, guild_id) ) { Sql_ShowDebug(sql_handle); aFree(g); return NULL; } - while( SQL_SUCCESS == Sql_NextRow(sql_handle) ) + while( SQL_SUCCESS == SQL->NextRow(sql_handle) ) { int position; struct guild_position* p; - Sql_GetData(sql_handle, 0, &data, NULL); position = atoi(data); + SQL->GetData(sql_handle, 0, &data, NULL); position = atoi(data); if( position < 0 || position >= MAX_GUILDPOSITION ) continue;// invalid position p = &g->position[position]; - Sql_GetData(sql_handle, 1, &data, &len); memcpy(p->name, data, min(len, NAME_LENGTH)); - Sql_GetData(sql_handle, 2, &data, NULL); p->mode = atoi(data); - Sql_GetData(sql_handle, 3, &data, NULL); p->exp_mode = atoi(data); + SQL->GetData(sql_handle, 1, &data, &len); memcpy(p->name, data, min(len, NAME_LENGTH)); + SQL->GetData(sql_handle, 2, &data, NULL); p->mode = atoi(data); + SQL->GetData(sql_handle, 3, &data, NULL); p->exp_mode = atoi(data); p->modified = GS_POSITION_UNMODIFIED; } //printf("- Read guild_alliance %d from sql \n",guild_id); - if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `opposition`,`alliance_id`,`name` FROM `%s` WHERE `guild_id`='%d'", guild_alliance_db, guild_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `opposition`,`alliance_id`,`name` FROM `%s` WHERE `guild_id`='%d'", guild_alliance_db, guild_id) ) { Sql_ShowDebug(sql_handle); aFree(g); return NULL; } - for( i = 0; i < MAX_GUILDALLIANCE && SQL_SUCCESS == Sql_NextRow(sql_handle); ++i ) + for( i = 0; i < MAX_GUILDALLIANCE && SQL_SUCCESS == SQL->NextRow(sql_handle); ++i ) { struct guild_alliance* a = &g->alliance[i]; - Sql_GetData(sql_handle, 0, &data, NULL); a->opposition = atoi(data); - Sql_GetData(sql_handle, 1, &data, NULL); a->guild_id = atoi(data); - Sql_GetData(sql_handle, 2, &data, &len); memcpy(a->name, data, min(len, NAME_LENGTH)); + SQL->GetData(sql_handle, 0, &data, NULL); a->opposition = atoi(data); + SQL->GetData(sql_handle, 1, &data, NULL); a->guild_id = atoi(data); + SQL->GetData(sql_handle, 2, &data, &len); memcpy(a->name, data, min(len, NAME_LENGTH)); } //printf("- Read guild_expulsion %d from sql \n",guild_id); - if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `account_id`,`name`,`mes` FROM `%s` WHERE `guild_id`='%d'", guild_expulsion_db, guild_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `account_id`,`name`,`mes` FROM `%s` WHERE `guild_id`='%d'", guild_expulsion_db, guild_id) ) { Sql_ShowDebug(sql_handle); aFree(g); return NULL; } - for( i = 0; i < MAX_GUILDEXPULSION && SQL_SUCCESS == Sql_NextRow(sql_handle); ++i ) + for( i = 0; i < MAX_GUILDEXPULSION && SQL_SUCCESS == SQL->NextRow(sql_handle); ++i ) { struct guild_expulsion *e = &g->expulsion[i]; - Sql_GetData(sql_handle, 0, &data, NULL); e->account_id = atoi(data); - Sql_GetData(sql_handle, 1, &data, &len); memcpy(e->name, data, min(len, NAME_LENGTH)); - Sql_GetData(sql_handle, 2, &data, &len); memcpy(e->mes, data, min(len, sizeof(e->mes))); + SQL->GetData(sql_handle, 0, &data, NULL); e->account_id = atoi(data); + SQL->GetData(sql_handle, 1, &data, &len); memcpy(e->name, data, min(len, NAME_LENGTH)); + SQL->GetData(sql_handle, 2, &data, &len); memcpy(e->mes, data, min(len, sizeof(e->mes))); } //printf("- Read guild_skill %d from sql \n",guild_id); - if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `id`,`lv` FROM `%s` WHERE `guild_id`='%d' ORDER BY `id`", guild_skill_db, guild_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `id`,`lv` FROM `%s` WHERE `guild_id`='%d' ORDER BY `id`", guild_skill_db, guild_id) ) { Sql_ShowDebug(sql_handle); aFree(g); @@ -505,15 +505,15 @@ struct guild * inter_guild_fromsql(int guild_id) g->skill[i].id = i + GD_SKILLBASE; } - while( SQL_SUCCESS == Sql_NextRow(sql_handle) ) + while( SQL_SUCCESS == SQL->NextRow(sql_handle) ) { int id; - Sql_GetData(sql_handle, 0, &data, NULL); id = atoi(data) - GD_SKILLBASE; + SQL->GetData(sql_handle, 0, &data, NULL); id = atoi(data) - GD_SKILLBASE; if( id < 0 || id >= MAX_GUILDSKILL ) continue;// invalid guild skill - Sql_GetData(sql_handle, 1, &data, NULL); g->skill[id].lv = atoi(data); + SQL->GetData(sql_handle, 1, &data, NULL); g->skill[id].lv = atoi(data); } - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); idb_put(guild_db_, guild_id, g); //Add to cache g->save_flag |= GS_REMOVE; //But set it to be removed, in case it is not needed for long. @@ -530,20 +530,20 @@ int inter_guildcastle_tosql(struct guild_castle *gc) StringBuf buf; int i; - StringBuf_Init(&buf); - StringBuf_Printf(&buf, "REPLACE INTO `%s` SET `castle_id`='%d', `guild_id`='%d', `economy`='%d', `defense`='%d', " + StrBuf->Init(&buf); + StrBuf->Printf(&buf, "REPLACE INTO `%s` SET `castle_id`='%d', `guild_id`='%d', `economy`='%d', `defense`='%d', " "`triggerE`='%d', `triggerD`='%d', `nextTime`='%d', `payTime`='%d', `createTime`='%d', `visibleC`='%d'", guild_castle_db, gc->castle_id, gc->guild_id, gc->economy, gc->defense, gc->triggerE, gc->triggerD, gc->nextTime, gc->payTime, gc->createTime, gc->visibleC); for (i = 0; i < MAX_GUARDIANS; ++i) - StringBuf_Printf(&buf, ", `visibleG%d`='%d'", i, gc->guardian[i].visible); + StrBuf->Printf(&buf, ", `visibleG%d`='%d'", i, gc->guardian[i].visible); - if (SQL_ERROR == Sql_Query(sql_handle, StringBuf_Value(&buf))) + if (SQL_ERROR == SQL->Query(sql_handle, StrBuf->Value(&buf))) Sql_ShowDebug(sql_handle); else if(save_log) ShowInfo("Saved guild castle (%d)\n", gc->castle_id); - StringBuf_Destroy(&buf); + StrBuf->Destroy(&buf); return 0; } @@ -558,37 +558,37 @@ static struct guild_castle* inter_guildcastle_fromsql(int castle_id) if (gc != NULL) return gc; - StringBuf_Init(&buf); - StringBuf_AppendStr(&buf, "SELECT `castle_id`, `guild_id`, `economy`, `defense`, `triggerE`, " + StrBuf->Init(&buf); + StrBuf->AppendStr(&buf, "SELECT `castle_id`, `guild_id`, `economy`, `defense`, `triggerE`, " "`triggerD`, `nextTime`, `payTime`, `createTime`, `visibleC`"); for (i = 0; i < MAX_GUARDIANS; ++i) - StringBuf_Printf(&buf, ", `visibleG%d`", i); - StringBuf_Printf(&buf, " FROM `%s` WHERE `castle_id`='%d'", guild_castle_db, castle_id); - if (SQL_ERROR == Sql_Query(sql_handle, StringBuf_Value(&buf))) { + StrBuf->Printf(&buf, ", `visibleG%d`", i); + StrBuf->Printf(&buf, " FROM `%s` WHERE `castle_id`='%d'", guild_castle_db, castle_id); + if (SQL_ERROR == SQL->Query(sql_handle, StrBuf->Value(&buf))) { Sql_ShowDebug(sql_handle); - StringBuf_Destroy(&buf); + StrBuf->Destroy(&buf); return NULL; } - StringBuf_Destroy(&buf); + StrBuf->Destroy(&buf); CREATE(gc, struct guild_castle, 1); gc->castle_id = castle_id; - if (SQL_SUCCESS == Sql_NextRow(sql_handle)) { - Sql_GetData(sql_handle, 1, &data, NULL); gc->guild_id = atoi(data); - Sql_GetData(sql_handle, 2, &data, NULL); gc->economy = atoi(data); - Sql_GetData(sql_handle, 3, &data, NULL); gc->defense = atoi(data); - Sql_GetData(sql_handle, 4, &data, NULL); gc->triggerE = atoi(data); - Sql_GetData(sql_handle, 5, &data, NULL); gc->triggerD = atoi(data); - Sql_GetData(sql_handle, 6, &data, NULL); gc->nextTime = atoi(data); - Sql_GetData(sql_handle, 7, &data, NULL); gc->payTime = atoi(data); - Sql_GetData(sql_handle, 8, &data, NULL); gc->createTime = atoi(data); - Sql_GetData(sql_handle, 9, &data, NULL); gc->visibleC = atoi(data); + if (SQL_SUCCESS == SQL->NextRow(sql_handle)) { + SQL->GetData(sql_handle, 1, &data, NULL); gc->guild_id = atoi(data); + SQL->GetData(sql_handle, 2, &data, NULL); gc->economy = atoi(data); + SQL->GetData(sql_handle, 3, &data, NULL); gc->defense = atoi(data); + SQL->GetData(sql_handle, 4, &data, NULL); gc->triggerE = atoi(data); + SQL->GetData(sql_handle, 5, &data, NULL); gc->triggerD = atoi(data); + SQL->GetData(sql_handle, 6, &data, NULL); gc->nextTime = atoi(data); + SQL->GetData(sql_handle, 7, &data, NULL); gc->payTime = atoi(data); + SQL->GetData(sql_handle, 8, &data, NULL); gc->createTime = atoi(data); + SQL->GetData(sql_handle, 9, &data, NULL); gc->visibleC = atoi(data); for (i = 10; i < 10+MAX_GUARDIANS; i++) { - Sql_GetData(sql_handle, i, &data, NULL); gc->guardian[i-10].visible = atoi(data); + SQL->GetData(sql_handle, i, &data, NULL); gc->guardian[i-10].visible = atoi(data); } } - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); idb_put(castle_db, castle_id, gc); @@ -621,24 +621,24 @@ int inter_guild_CharOnline(int char_id, int guild_id) if (guild_id == -1) { //Get guild_id from the database - if( SQL_ERROR == Sql_Query(sql_handle, "SELECT guild_id FROM `%s` WHERE char_id='%d'", char_db, char_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT guild_id FROM `%s` WHERE char_id='%d'", char_db, char_id) ) { Sql_ShowDebug(sql_handle); return 0; } - if( SQL_SUCCESS == Sql_NextRow(sql_handle) ) + if( SQL_SUCCESS == SQL->NextRow(sql_handle) ) { char* data; - Sql_GetData(sql_handle, 0, &data, NULL); + SQL->GetData(sql_handle, 0, &data, NULL); guild_id = atoi(data); } else { guild_id = 0; } - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); } if (guild_id == 0) return 0; //No guild... @@ -672,24 +672,24 @@ int inter_guild_CharOffline(int char_id, int guild_id) if (guild_id == -1) { //Get guild_id from the database - if( SQL_ERROR == Sql_Query(sql_handle, "SELECT guild_id FROM `%s` WHERE char_id='%d'", char_db, char_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT guild_id FROM `%s` WHERE char_id='%d'", char_db, char_id) ) { Sql_ShowDebug(sql_handle); return 0; } - if( SQL_SUCCESS == Sql_NextRow(sql_handle) ) + if( SQL_SUCCESS == SQL->NextRow(sql_handle) ) { char* data; - Sql_GetData(sql_handle, 0, &data, NULL); + SQL->GetData(sql_handle, 0, &data, NULL); guild_id = atoi(data); } else { guild_id = 0; } - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); } if (guild_id == 0) return 0; //No guild... @@ -727,7 +727,7 @@ int inter_guild_sql_init(void) castle_db = idb_alloc(DB_OPT_RELEASE_DATA); //Read exp file - sv_readdb("db", DBPATH"exp_guild.txt", ',', 1, 1, 100, exp_guild_parse_row); + sv->readdb("db", DBPATH"exp_guild.txt", ',', 1, 1, 100, exp_guild_parse_row); add_timer_func_list(guild_save_timer, "guild_save_timer"); add_timer(gettick() + 10000, guild_save_timer, 0, 0); @@ -760,26 +760,26 @@ int search_guildname(char *str) int guild_id; char esc_name[NAME_LENGTH*2+1]; - Sql_EscapeStringLen(sql_handle, esc_name, str, safestrnlen(str, NAME_LENGTH)); + SQL->EscapeStringLen(sql_handle, esc_name, str, safestrnlen(str, NAME_LENGTH)); //Lookup guilds with the same name - if( SQL_ERROR == Sql_Query(sql_handle, "SELECT guild_id FROM `%s` WHERE name='%s'", guild_db, esc_name) ) + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT guild_id FROM `%s` WHERE name='%s'", guild_db, esc_name) ) { Sql_ShowDebug(sql_handle); return -1; } - if( SQL_SUCCESS == Sql_NextRow(sql_handle) ) + if( SQL_SUCCESS == SQL->NextRow(sql_handle) ) { char* data; - Sql_GetData(sql_handle, 0, &data, NULL); + SQL->GetData(sql_handle, 0, &data, NULL); guild_id = atoi(data); } else { guild_id = 0; } - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); return guild_id; } @@ -1268,7 +1268,7 @@ int mapif_parse_GuildLeave(int fd, int guild_id, int account_id, int char_id, in if( g == NULL ) { // Unknown guild, just update the player - if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `guild_id`='0' WHERE `account_id`='%d' AND `char_id`='%d'", char_db, account_id, char_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "UPDATE `%s` SET `guild_id`='0' WHERE `account_id`='%d' AND `char_id`='%d'", char_db, account_id, char_id) ) Sql_ShowDebug(sql_handle); // mapif_guild_withdraw(guild_id,account_id,char_id,flag,g->member[i].name,mes); return 0; @@ -1381,32 +1381,32 @@ int mapif_parse_BreakGuild(int fd,int guild_id) // Delete guild from sql //printf("- Delete guild %d from guild\n",guild_id); - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `guild_id` = '%d'", guild_db, guild_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `guild_id` = '%d'", guild_db, guild_id) ) Sql_ShowDebug(sql_handle); - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `guild_id` = '%d'", guild_member_db, guild_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `guild_id` = '%d'", guild_member_db, guild_id) ) Sql_ShowDebug(sql_handle); - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `guild_id` = '%d'", guild_castle_db, guild_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `guild_id` = '%d'", guild_castle_db, guild_id) ) Sql_ShowDebug(sql_handle); - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `guild_id` = '%d'", guild_storage_db, guild_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `guild_id` = '%d'", guild_storage_db, guild_id) ) Sql_ShowDebug(sql_handle); - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `guild_id` = '%d' OR `alliance_id` = '%d'", guild_alliance_db, guild_id, guild_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `guild_id` = '%d' OR `alliance_id` = '%d'", guild_alliance_db, guild_id, guild_id) ) Sql_ShowDebug(sql_handle); - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `guild_id` = '%d'", guild_position_db, guild_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `guild_id` = '%d'", guild_position_db, guild_id) ) Sql_ShowDebug(sql_handle); - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `guild_id` = '%d'", guild_skill_db, guild_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `guild_id` = '%d'", guild_skill_db, guild_id) ) Sql_ShowDebug(sql_handle); - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `guild_id` = '%d'", guild_expulsion_db, guild_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `guild_id` = '%d'", guild_expulsion_db, guild_id) ) Sql_ShowDebug(sql_handle); //printf("- Update guild %d of char\n",guild_id); - if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `guild_id`='0' WHERE `guild_id`='%d'", char_db, guild_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "UPDATE `%s` SET `guild_id`='0' WHERE `guild_id`='%d'", char_db, guild_id) ) Sql_ShowDebug(sql_handle); mapif_guild_broken(guild_id,0); diff --git a/src/char/int_homun.c b/src/char/int_homun.c index 933661954..f06ace0b2 100644 --- a/src/char/int_homun.c +++ b/src/char/int_homun.c @@ -1,5 +1,6 @@ -// Copyright (c) Athena Dev Teams - Licensed under GNU GPL -// For more information, see LICENCE in the main folder +// Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// See the LICENSE file +// Portions Copyright (c) Athena Dev Teams #include "../common/mmo.h" #include "../common/malloc.h" @@ -88,11 +89,11 @@ bool mapif_homunculus_save(struct s_homunculus* hd) bool flag = true; char esc_name[NAME_LENGTH*2+1]; - Sql_EscapeStringLen(sql_handle, esc_name, hd->name, strnlen(hd->name, NAME_LENGTH)); + SQL->EscapeStringLen(sql_handle, esc_name, hd->name, strnlen(hd->name, NAME_LENGTH)); if( hd->hom_id == 0 ) {// new homunculus - if( SQL_ERROR == Sql_Query(sql_handle, "INSERT INTO `%s` " + if( SQL_ERROR == SQL->Query(sql_handle, "INSERT INTO `%s` " "(`char_id`, `class`,`prev_class`,`name`,`level`,`exp`,`intimacy`,`hunger`, `str`, `agi`, `vit`, `int`, `dex`, `luk`, `hp`,`max_hp`,`sp`,`max_sp`,`skill_point`, `rename_flag`, `vaporize`) " "VALUES ('%d', '%d', '%d', '%s', '%d', '%u', '%u', '%d', '%d', %d, '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d')", homunculus_db, hd->char_id, hd->class_, hd->prev_class, esc_name, hd->level, hd->exp, hd->intimacy, hd->hunger, hd->str, hd->agi, hd->vit, hd->int_, hd->dex, hd->luk, @@ -103,12 +104,12 @@ bool mapif_homunculus_save(struct s_homunculus* hd) } else { - hd->hom_id = (int)Sql_LastInsertId(sql_handle); + hd->hom_id = (int)SQL->NumRows(sql_handle); } } else { - if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `char_id`='%d', `class`='%d',`prev_class`='%d',`name`='%s',`level`='%d',`exp`='%u',`intimacy`='%u',`hunger`='%d', `str`='%d', `agi`='%d', `vit`='%d', `int`='%d', `dex`='%d', `luk`='%d', `hp`='%d',`max_hp`='%d',`sp`='%d',`max_sp`='%d',`skill_point`='%d', `rename_flag`='%d', `vaporize`='%d' WHERE `homun_id`='%d'", + if( SQL_ERROR == SQL->Query(sql_handle, "UPDATE `%s` SET `char_id`='%d', `class`='%d',`prev_class`='%d',`name`='%s',`level`='%d',`exp`='%u',`intimacy`='%u',`hunger`='%d', `str`='%d', `agi`='%d', `vit`='%d', `int`='%d', `dex`='%d', `luk`='%d', `hp`='%d',`max_hp`='%d',`sp`='%d',`max_sp`='%d',`skill_point`='%d', `rename_flag`='%d', `vaporize`='%d' WHERE `homun_id`='%d'", homunculus_db, hd->char_id, hd->class_, hd->prev_class, esc_name, hd->level, hd->exp, hd->intimacy, hd->hunger, hd->str, hd->agi, hd->vit, hd->int_, hd->dex, hd->luk, hd->hp, hd->max_hp, hd->sp, hd->max_sp, hd->skillpts, hd->rename_flag, hd->vaporize, hd->hom_id) ) { @@ -156,61 +157,61 @@ bool mapif_homunculus_load(int homun_id, struct s_homunculus* hd) memset(hd, 0, sizeof(*hd)); - if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `homun_id`,`char_id`,`class`,`prev_class`,`name`,`level`,`exp`,`intimacy`,`hunger`, `str`, `agi`, `vit`, `int`, `dex`, `luk`, `hp`,`max_hp`,`sp`,`max_sp`,`skill_point`,`rename_flag`, `vaporize` FROM `%s` WHERE `homun_id`='%u'", homunculus_db, homun_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `homun_id`,`char_id`,`class`,`prev_class`,`name`,`level`,`exp`,`intimacy`,`hunger`, `str`, `agi`, `vit`, `int`, `dex`, `luk`, `hp`,`max_hp`,`sp`,`max_sp`,`skill_point`,`rename_flag`, `vaporize` FROM `%s` WHERE `homun_id`='%u'", homunculus_db, homun_id) ) { Sql_ShowDebug(sql_handle); return false; } - if( !Sql_NumRows(sql_handle) ) + if( !SQL->NumRows(sql_handle) ) { //No homunculus found. - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); return false; } - if( SQL_SUCCESS != Sql_NextRow(sql_handle) ) + if( SQL_SUCCESS != SQL->NextRow(sql_handle) ) { Sql_ShowDebug(sql_handle); - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); return false; } hd->hom_id = homun_id; - Sql_GetData(sql_handle, 1, &data, NULL); hd->char_id = atoi(data); - Sql_GetData(sql_handle, 2, &data, NULL); hd->class_ = atoi(data); - Sql_GetData(sql_handle, 3, &data, NULL); hd->prev_class = atoi(data); - Sql_GetData(sql_handle, 4, &data, &len); safestrncpy(hd->name, data, sizeof(hd->name)); - Sql_GetData(sql_handle, 5, &data, NULL); hd->level = atoi(data); - Sql_GetData(sql_handle, 6, &data, NULL); hd->exp = atoi(data); - Sql_GetData(sql_handle, 7, &data, NULL); hd->intimacy = (unsigned int)strtoul(data, NULL, 10); - Sql_GetData(sql_handle, 8, &data, NULL); hd->hunger = atoi(data); - Sql_GetData(sql_handle, 9, &data, NULL); hd->str = atoi(data); - Sql_GetData(sql_handle, 10, &data, NULL); hd->agi = atoi(data); - Sql_GetData(sql_handle, 11, &data, NULL); hd->vit = atoi(data); - Sql_GetData(sql_handle, 12, &data, NULL); hd->int_ = atoi(data); - Sql_GetData(sql_handle, 13, &data, NULL); hd->dex = atoi(data); - Sql_GetData(sql_handle, 14, &data, NULL); hd->luk = atoi(data); - Sql_GetData(sql_handle, 15, &data, NULL); hd->hp = atoi(data); - Sql_GetData(sql_handle, 16, &data, NULL); hd->max_hp = atoi(data); - Sql_GetData(sql_handle, 17, &data, NULL); hd->sp = atoi(data); - Sql_GetData(sql_handle, 18, &data, NULL); hd->max_sp = atoi(data); - Sql_GetData(sql_handle, 19, &data, NULL); hd->skillpts = atoi(data); - Sql_GetData(sql_handle, 20, &data, NULL); hd->rename_flag = atoi(data); - Sql_GetData(sql_handle, 21, &data, NULL); hd->vaporize = atoi(data); - Sql_FreeResult(sql_handle); + SQL->GetData(sql_handle, 1, &data, NULL); hd->char_id = atoi(data); + SQL->GetData(sql_handle, 2, &data, NULL); hd->class_ = atoi(data); + SQL->GetData(sql_handle, 3, &data, NULL); hd->prev_class = atoi(data); + SQL->GetData(sql_handle, 4, &data, &len); safestrncpy(hd->name, data, sizeof(hd->name)); + SQL->GetData(sql_handle, 5, &data, NULL); hd->level = atoi(data); + SQL->GetData(sql_handle, 6, &data, NULL); hd->exp = atoi(data); + SQL->GetData(sql_handle, 7, &data, NULL); hd->intimacy = (unsigned int)strtoul(data, NULL, 10); + SQL->GetData(sql_handle, 8, &data, NULL); hd->hunger = atoi(data); + SQL->GetData(sql_handle, 9, &data, NULL); hd->str = atoi(data); + SQL->GetData(sql_handle, 10, &data, NULL); hd->agi = atoi(data); + SQL->GetData(sql_handle, 11, &data, NULL); hd->vit = atoi(data); + SQL->GetData(sql_handle, 12, &data, NULL); hd->int_ = atoi(data); + SQL->GetData(sql_handle, 13, &data, NULL); hd->dex = atoi(data); + SQL->GetData(sql_handle, 14, &data, NULL); hd->luk = atoi(data); + SQL->GetData(sql_handle, 15, &data, NULL); hd->hp = atoi(data); + SQL->GetData(sql_handle, 16, &data, NULL); hd->max_hp = atoi(data); + SQL->GetData(sql_handle, 17, &data, NULL); hd->sp = atoi(data); + SQL->GetData(sql_handle, 18, &data, NULL); hd->max_sp = atoi(data); + SQL->GetData(sql_handle, 19, &data, NULL); hd->skillpts = atoi(data); + SQL->GetData(sql_handle, 20, &data, NULL); hd->rename_flag = atoi(data); + SQL->GetData(sql_handle, 21, &data, NULL); hd->vaporize = atoi(data); + SQL->FreeResult(sql_handle); hd->intimacy = cap_value(hd->intimacy, 0, 100000); hd->hunger = cap_value(hd->hunger, 0, 100); // Load Homunculus Skill - if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `id`,`lv` FROM `%s` WHERE `homun_id`=%d", skill_homunculus_db, homun_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `id`,`lv` FROM `%s` WHERE `homun_id`=%d", skill_homunculus_db, homun_id) ) { Sql_ShowDebug(sql_handle); return false; } - while( SQL_SUCCESS == Sql_NextRow(sql_handle) ) + while( SQL_SUCCESS == SQL->NextRow(sql_handle) ) { // id - Sql_GetData(sql_handle, 0, &data, NULL); + SQL->GetData(sql_handle, 0, &data, NULL); i = atoi(data); if( i < HM_SKILLBASE || i >= HM_SKILLBASE + MAX_HOMUNSKILL ) continue;// invalid skill id @@ -218,10 +219,10 @@ bool mapif_homunculus_load(int homun_id, struct s_homunculus* hd) hd->hskill[i].id = (unsigned short)atoi(data); // lv - Sql_GetData(sql_handle, 1, &data, NULL); + SQL->GetData(sql_handle, 1, &data, NULL); hd->hskill[i].lv = (unsigned char)atoi(data); } - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); if( save_log ) ShowInfo("Homunculus loaded (%d - %s).\n", hd->hom_id, hd->name); @@ -231,8 +232,8 @@ bool mapif_homunculus_load(int homun_id, struct s_homunculus* hd) bool mapif_homunculus_delete(int homun_id) { - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `homun_id` = '%u'", homunculus_db, homun_id) - || SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `homun_id` = '%u'", skill_homunculus_db, homun_id) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `homun_id` = '%u'", homunculus_db, homun_id) + || SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `homun_id` = '%u'", skill_homunculus_db, homun_id) ) { Sql_ShowDebug(sql_handle); return false; diff --git a/src/char/int_mail.c b/src/char/int_mail.c index 8d50c713f..9181b7db6 100644 --- a/src/char/int_mail.c +++ b/src/char/int_mail.c @@ -1,5 +1,6 @@ -// Copyright (c) Athena Dev Teams - Licensed under GNU GPL -// For more information, see LICENCE in the main folder +// Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// See the LICENSE file +// Portions Copyright (c) Athena Dev Teams #include "../common/mmo.h" #include "../common/malloc.h" @@ -27,54 +28,54 @@ static int mail_fromsql(int char_id, struct mail_data* md) md->amount = 0; md->full = false; - StringBuf_Init(&buf); - StringBuf_AppendStr(&buf, "SELECT `id`,`send_name`,`send_id`,`dest_name`,`dest_id`,`title`,`message`,`time`,`status`," + StrBuf->Init(&buf); + StrBuf->AppendStr(&buf, "SELECT `id`,`send_name`,`send_id`,`dest_name`,`dest_id`,`title`,`message`,`time`,`status`," "`zeny`,`amount`,`nameid`,`refine`,`attribute`,`identify`,`unique_id`"); for (i = 0; i < MAX_SLOTS; i++) - StringBuf_Printf(&buf, ",`card%d`", i); + StrBuf->Printf(&buf, ",`card%d`", i); // I keep the `status` < 3 just in case someone forget to apply the sqlfix - StringBuf_Printf(&buf, " FROM `%s` WHERE `dest_id`='%d' AND `status` < 3 ORDER BY `id` LIMIT %d", + StrBuf->Printf(&buf, " FROM `%s` WHERE `dest_id`='%d' AND `status` < 3 ORDER BY `id` LIMIT %d", mail_db, char_id, MAIL_MAX_INBOX + 1); - if( SQL_ERROR == Sql_Query(sql_handle, StringBuf_Value(&buf)) ) + if( SQL_ERROR == SQL->Query(sql_handle, StrBuf->Value(&buf)) ) Sql_ShowDebug(sql_handle); - StringBuf_Destroy(&buf); + StrBuf->Destroy(&buf); - for (i = 0; i < MAIL_MAX_INBOX && SQL_SUCCESS == Sql_NextRow(sql_handle); ++i ) + for (i = 0; i < MAIL_MAX_INBOX && SQL_SUCCESS == SQL->NextRow(sql_handle); ++i ) { msg = &md->msg[i]; - Sql_GetData(sql_handle, 0, &data, NULL); msg->id = atoi(data); - Sql_GetData(sql_handle, 1, &data, NULL); safestrncpy(msg->send_name, data, NAME_LENGTH); - Sql_GetData(sql_handle, 2, &data, NULL); msg->send_id = atoi(data); - Sql_GetData(sql_handle, 3, &data, NULL); safestrncpy(msg->dest_name, data, NAME_LENGTH); - Sql_GetData(sql_handle, 4, &data, NULL); msg->dest_id = atoi(data); - Sql_GetData(sql_handle, 5, &data, NULL); safestrncpy(msg->title, data, MAIL_TITLE_LENGTH); - Sql_GetData(sql_handle, 6, &data, NULL); safestrncpy(msg->body, data, MAIL_BODY_LENGTH); - Sql_GetData(sql_handle, 7, &data, NULL); msg->timestamp = atoi(data); - Sql_GetData(sql_handle, 8, &data, NULL); msg->status = (mail_status)atoi(data); - Sql_GetData(sql_handle, 9, &data, NULL); msg->zeny = atoi(data); + SQL->GetData(sql_handle, 0, &data, NULL); msg->id = atoi(data); + SQL->GetData(sql_handle, 1, &data, NULL); safestrncpy(msg->send_name, data, NAME_LENGTH); + SQL->GetData(sql_handle, 2, &data, NULL); msg->send_id = atoi(data); + SQL->GetData(sql_handle, 3, &data, NULL); safestrncpy(msg->dest_name, data, NAME_LENGTH); + SQL->GetData(sql_handle, 4, &data, NULL); msg->dest_id = atoi(data); + SQL->GetData(sql_handle, 5, &data, NULL); safestrncpy(msg->title, data, MAIL_TITLE_LENGTH); + SQL->GetData(sql_handle, 6, &data, NULL); safestrncpy(msg->body, data, MAIL_BODY_LENGTH); + SQL->GetData(sql_handle, 7, &data, NULL); msg->timestamp = atoi(data); + SQL->GetData(sql_handle, 8, &data, NULL); msg->status = (mail_status)atoi(data); + SQL->GetData(sql_handle, 9, &data, NULL); msg->zeny = atoi(data); item = &msg->item; - Sql_GetData(sql_handle,10, &data, NULL); item->amount = (short)atoi(data); - Sql_GetData(sql_handle,11, &data, NULL); item->nameid = atoi(data); - Sql_GetData(sql_handle,12, &data, NULL); item->refine = atoi(data); - Sql_GetData(sql_handle,13, &data, NULL); item->attribute = atoi(data); - Sql_GetData(sql_handle,14, &data, NULL); item->identify = atoi(data); - Sql_GetData(sql_handle,15, &data, NULL); item->unique_id = strtoull(data, NULL, 10); + SQL->GetData(sql_handle,10, &data, NULL); item->amount = (short)atoi(data); + SQL->GetData(sql_handle,11, &data, NULL); item->nameid = atoi(data); + SQL->GetData(sql_handle,12, &data, NULL); item->refine = atoi(data); + SQL->GetData(sql_handle,13, &data, NULL); item->attribute = atoi(data); + SQL->GetData(sql_handle,14, &data, NULL); item->identify = atoi(data); + SQL->GetData(sql_handle,15, &data, NULL); item->unique_id = strtoull(data, NULL, 10); item->expire_time = 0; for (j = 0; j < MAX_SLOTS; j++) { - Sql_GetData(sql_handle, 16 + j, &data, NULL); + SQL->GetData(sql_handle, 16 + j, &data, NULL); item->card[j] = atoi(data); } } - md->full = ( Sql_NumRows(sql_handle) > MAIL_MAX_INBOX ); + md->full = ( SQL->NumRows(sql_handle) > MAIL_MAX_INBOX ); md->amount = i; - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); md->unchecked = 0; md->unread = 0; @@ -83,7 +84,7 @@ static int mail_fromsql(int char_id, struct mail_data* md) msg = &md->msg[i]; if( msg->status == MAIL_NEW ) { - if ( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `status` = '%d' WHERE `id` = '%d'", mail_db, MAIL_UNREAD, msg->id) ) + if ( SQL_ERROR == SQL->Query(sql_handle, "UPDATE `%s` SET `status` = '%d' WHERE `id` = '%d'", mail_db, MAIL_UNREAD, msg->id) ) Sql_ShowDebug(sql_handle); msg->status = MAIL_UNREAD; @@ -106,15 +107,15 @@ int mail_savemessage(struct mail_message* msg) int j; // build message save query - StringBuf_Init(&buf); - StringBuf_Printf(&buf, "INSERT INTO `%s` (`send_name`, `send_id`, `dest_name`, `dest_id`, `title`, `message`, `time`, `status`, `zeny`, `amount`, `nameid`, `refine`, `attribute`, `identify`, `unique_id`", mail_db); + StrBuf->Init(&buf); + StrBuf->Printf(&buf, "INSERT INTO `%s` (`send_name`, `send_id`, `dest_name`, `dest_id`, `title`, `message`, `time`, `status`, `zeny`, `amount`, `nameid`, `refine`, `attribute`, `identify`, `unique_id`", mail_db); for (j = 0; j < MAX_SLOTS; j++) - StringBuf_Printf(&buf, ", `card%d`", j); - StringBuf_Printf(&buf, ") VALUES (?, '%d', ?, '%d', ?, ?, '%lu', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%"PRIu64"'", + StrBuf->Printf(&buf, ", `card%d`", j); + StrBuf->Printf(&buf, ") VALUES (?, '%d', ?, '%d', ?, ?, '%lu', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%"PRIu64"'", msg->send_id, msg->dest_id, (unsigned long)msg->timestamp, msg->status, msg->zeny, msg->item.amount, msg->item.nameid, msg->item.refine, msg->item.attribute, msg->item.identify, msg->item.unique_id); for (j = 0; j < MAX_SLOTS; j++) - StringBuf_Printf(&buf, ", '%d'", msg->item.card[j]); - StringBuf_AppendStr(&buf, ")"); + StrBuf->Printf(&buf, ", '%d'", msg->item.card[j]); + StrBuf->AppendStr(&buf, ")"); //Unique Non Stackable Item ID updateLastUid(msg->item.unique_id); @@ -122,7 +123,7 @@ int mail_savemessage(struct mail_message* msg) // prepare and execute query stmt = SqlStmt_Malloc(sql_handle); - if( SQL_SUCCESS != SqlStmt_PrepareStr(stmt, StringBuf_Value(&buf)) + if( SQL_SUCCESS != SqlStmt_PrepareStr(stmt, StrBuf->Value(&buf)) || SQL_SUCCESS != SqlStmt_BindParam(stmt, 0, SQLDT_STRING, msg->send_name, strnlen(msg->send_name, NAME_LENGTH)) || SQL_SUCCESS != SqlStmt_BindParam(stmt, 1, SQLDT_STRING, msg->dest_name, strnlen(msg->dest_name, NAME_LENGTH)) || SQL_SUCCESS != SqlStmt_BindParam(stmt, 2, SQLDT_STRING, msg->title, strnlen(msg->title, MAIL_TITLE_LENGTH)) @@ -135,7 +136,7 @@ int mail_savemessage(struct mail_message* msg) msg->id = (int)SqlStmt_LastInsertId(stmt); SqlStmt_Free(stmt); - StringBuf_Destroy(&buf); + StrBuf->Destroy(&buf); return msg->id; } @@ -147,52 +148,52 @@ static bool mail_loadmessage(int mail_id, struct mail_message* msg) int j; StringBuf buf; - StringBuf_Init(&buf); - StringBuf_AppendStr(&buf, "SELECT `id`,`send_name`,`send_id`,`dest_name`,`dest_id`,`title`,`message`,`time`,`status`," + StrBuf->Init(&buf); + StrBuf->AppendStr(&buf, "SELECT `id`,`send_name`,`send_id`,`dest_name`,`dest_id`,`title`,`message`,`time`,`status`," "`zeny`,`amount`,`nameid`,`refine`,`attribute`,`identify`,`unique_id`"); for( j = 0; j < MAX_SLOTS; j++ ) - StringBuf_Printf(&buf, ",`card%d`", j); - StringBuf_Printf(&buf, " FROM `%s` WHERE `id` = '%d'", mail_db, mail_id); + StrBuf->Printf(&buf, ",`card%d`", j); + StrBuf->Printf(&buf, " FROM `%s` WHERE `id` = '%d'", mail_db, mail_id); - if( SQL_ERROR == Sql_Query(sql_handle, StringBuf_Value(&buf)) - || SQL_SUCCESS != Sql_NextRow(sql_handle) ) + if( SQL_ERROR == SQL->Query(sql_handle, StrBuf->Value(&buf)) + || SQL_SUCCESS != SQL->NextRow(sql_handle) ) { Sql_ShowDebug(sql_handle); - Sql_FreeResult(sql_handle); - StringBuf_Destroy(&buf); + SQL->FreeResult(sql_handle); + StrBuf->Destroy(&buf); return false; } else { char* data; - Sql_GetData(sql_handle, 0, &data, NULL); msg->id = atoi(data); - Sql_GetData(sql_handle, 1, &data, NULL); safestrncpy(msg->send_name, data, NAME_LENGTH); - Sql_GetData(sql_handle, 2, &data, NULL); msg->send_id = atoi(data); - Sql_GetData(sql_handle, 3, &data, NULL); safestrncpy(msg->dest_name, data, NAME_LENGTH); - Sql_GetData(sql_handle, 4, &data, NULL); msg->dest_id = atoi(data); - Sql_GetData(sql_handle, 5, &data, NULL); safestrncpy(msg->title, data, MAIL_TITLE_LENGTH); - Sql_GetData(sql_handle, 6, &data, NULL); safestrncpy(msg->body, data, MAIL_BODY_LENGTH); - Sql_GetData(sql_handle, 7, &data, NULL); msg->timestamp = atoi(data); - Sql_GetData(sql_handle, 8, &data, NULL); msg->status = (mail_status)atoi(data); - Sql_GetData(sql_handle, 9, &data, NULL); msg->zeny = atoi(data); - Sql_GetData(sql_handle,10, &data, NULL); msg->item.amount = (short)atoi(data); - Sql_GetData(sql_handle,11, &data, NULL); msg->item.nameid = atoi(data); - Sql_GetData(sql_handle,12, &data, NULL); msg->item.refine = atoi(data); - Sql_GetData(sql_handle,13, &data, NULL); msg->item.attribute = atoi(data); - Sql_GetData(sql_handle,14, &data, NULL); msg->item.identify = atoi(data); - Sql_GetData(sql_handle,15, &data, NULL); msg->item.unique_id = strtoull(data, NULL, 10); + SQL->GetData(sql_handle, 0, &data, NULL); msg->id = atoi(data); + SQL->GetData(sql_handle, 1, &data, NULL); safestrncpy(msg->send_name, data, NAME_LENGTH); + SQL->GetData(sql_handle, 2, &data, NULL); msg->send_id = atoi(data); + SQL->GetData(sql_handle, 3, &data, NULL); safestrncpy(msg->dest_name, data, NAME_LENGTH); + SQL->GetData(sql_handle, 4, &data, NULL); msg->dest_id = atoi(data); + SQL->GetData(sql_handle, 5, &data, NULL); safestrncpy(msg->title, data, MAIL_TITLE_LENGTH); + SQL->GetData(sql_handle, 6, &data, NULL); safestrncpy(msg->body, data, MAIL_BODY_LENGTH); + SQL->GetData(sql_handle, 7, &data, NULL); msg->timestamp = atoi(data); + SQL->GetData(sql_handle, 8, &data, NULL); msg->status = (mail_status)atoi(data); + SQL->GetData(sql_handle, 9, &data, NULL); msg->zeny = atoi(data); + SQL->GetData(sql_handle,10, &data, NULL); msg->item.amount = (short)atoi(data); + SQL->GetData(sql_handle,11, &data, NULL); msg->item.nameid = atoi(data); + SQL->GetData(sql_handle,12, &data, NULL); msg->item.refine = atoi(data); + SQL->GetData(sql_handle,13, &data, NULL); msg->item.attribute = atoi(data); + SQL->GetData(sql_handle,14, &data, NULL); msg->item.identify = atoi(data); + SQL->GetData(sql_handle,15, &data, NULL); msg->item.unique_id = strtoull(data, NULL, 10); msg->item.expire_time = 0; for( j = 0; j < MAX_SLOTS; j++ ) { - Sql_GetData(sql_handle,16 + j, &data, NULL); + SQL->GetData(sql_handle,16 + j, &data, NULL); msg->item.card[j] = atoi(data); } } - StringBuf_Destroy(&buf); - Sql_FreeResult(sql_handle); + StrBuf->Destroy(&buf); + SQL->FreeResult(sql_handle); return true; } @@ -226,7 +227,7 @@ static void mapif_parse_Mail_requestinbox(int fd) static void mapif_parse_Mail_read(int fd) { int mail_id = RFIFOL(fd,2); - if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `status` = '%d' WHERE `id` = '%d'", mail_db, MAIL_READ, mail_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "UPDATE `%s` SET `status` = '%d' WHERE `id` = '%d'", mail_db, MAIL_READ, mail_id) ) Sql_ShowDebug(sql_handle); } @@ -238,21 +239,21 @@ static bool mail_DeleteAttach(int mail_id) StringBuf buf; int i; - StringBuf_Init(&buf); - StringBuf_Printf(&buf, "UPDATE `%s` SET `zeny` = '0', `nameid` = '0', `amount` = '0', `refine` = '0', `attribute` = '0', `identify` = '0'", mail_db); + StrBuf->Init(&buf); + StrBuf->Printf(&buf, "UPDATE `%s` SET `zeny` = '0', `nameid` = '0', `amount` = '0', `refine` = '0', `attribute` = '0', `identify` = '0'", mail_db); for (i = 0; i < MAX_SLOTS; i++) - StringBuf_Printf(&buf, ", `card%d` = '0'", i); - StringBuf_Printf(&buf, " WHERE `id` = '%d'", mail_id); + StrBuf->Printf(&buf, ", `card%d` = '0'", i); + StrBuf->Printf(&buf, " WHERE `id` = '%d'", mail_id); - if( SQL_ERROR == Sql_Query(sql_handle, StringBuf_Value(&buf)) ) + if( SQL_ERROR == SQL->Query(sql_handle, StrBuf->Value(&buf)) ) { Sql_ShowDebug(sql_handle); - StringBuf_Destroy(&buf); + StrBuf->Destroy(&buf); return false; } - StringBuf_Destroy(&buf); + StrBuf->Destroy(&buf); return true; } @@ -295,7 +296,7 @@ static void mapif_parse_Mail_getattach(int fd) static void mapif_Mail_delete(int fd, int char_id, int mail_id) { bool failed = false; - if ( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `id` = '%d'", mail_db, mail_id) ) + if ( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `id` = '%d'", mail_db, mail_id) ) { Sql_ShowDebug(sql_handle); failed = true; @@ -344,7 +345,7 @@ static void mapif_Mail_return(int fd, int char_id, int mail_id) { if( msg.dest_id != char_id) return; - else if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `id` = '%d'", mail_db, mail_id) ) + else if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `id` = '%d'", mail_db, mail_id) ) Sql_ShowDebug(sql_handle); else { @@ -408,21 +409,21 @@ static void mapif_parse_Mail_send(int fd) memcpy(&msg, RFIFOP(fd,8), sizeof(struct mail_message)); // Try to find the Dest Char by Name - Sql_EscapeStringLen(sql_handle, esc_name, msg.dest_name, strnlen(msg.dest_name, NAME_LENGTH)); - if ( SQL_ERROR == Sql_Query(sql_handle, "SELECT `account_id`, `char_id` FROM `%s` WHERE `name` = '%s'", char_db, esc_name) ) + SQL->EscapeStringLen(sql_handle, esc_name, msg.dest_name, strnlen(msg.dest_name, NAME_LENGTH)); + if ( SQL_ERROR == SQL->Query(sql_handle, "SELECT `account_id`, `char_id` FROM `%s` WHERE `name` = '%s'", char_db, esc_name) ) Sql_ShowDebug(sql_handle); else - if ( SQL_SUCCESS == Sql_NextRow(sql_handle) ) + if ( SQL_SUCCESS == SQL->NextRow(sql_handle) ) { char *data; - Sql_GetData(sql_handle, 0, &data, NULL); + SQL->GetData(sql_handle, 0, &data, NULL); if (atoi(data) != account_id) { // Cannot send mail to char in the same account - Sql_GetData(sql_handle, 1, &data, NULL); + SQL->GetData(sql_handle, 1, &data, NULL); msg.dest_id = atoi(data); } } - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); msg.status = MAIL_NEW; if( msg.dest_id > 0 ) diff --git a/src/char/int_mercenary.c b/src/char/int_mercenary.c index 3b3714416..11cc47062 100644 --- a/src/char/int_mercenary.c +++ b/src/char/int_mercenary.c @@ -1,5 +1,6 @@ -// Copyright (c) Athena Dev Teams - Licensed under GNU GPL -// For more information, see LICENCE in the main folder +// Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// See the LICENSE file +// Portions Copyright (c) Athena Dev Teams #include "../common/mmo.h" #include "../common/malloc.h" @@ -19,33 +20,33 @@ bool mercenary_owner_fromsql(int char_id, struct mmo_charstatus *status) { char* data; - if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `merc_id`, `arch_calls`, `arch_faith`, `spear_calls`, `spear_faith`, `sword_calls`, `sword_faith` FROM `%s` WHERE `char_id` = '%d'", mercenary_owner_db, char_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `merc_id`, `arch_calls`, `arch_faith`, `spear_calls`, `spear_faith`, `sword_calls`, `sword_faith` FROM `%s` WHERE `char_id` = '%d'", mercenary_owner_db, char_id) ) { Sql_ShowDebug(sql_handle); return false; } - if( SQL_SUCCESS != Sql_NextRow(sql_handle) ) + if( SQL_SUCCESS != SQL->NextRow(sql_handle) ) { - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); return false; } - Sql_GetData(sql_handle, 0, &data, NULL); status->mer_id = atoi(data); - Sql_GetData(sql_handle, 1, &data, NULL); status->arch_calls = atoi(data); - Sql_GetData(sql_handle, 2, &data, NULL); status->arch_faith = atoi(data); - Sql_GetData(sql_handle, 3, &data, NULL); status->spear_calls = atoi(data); - Sql_GetData(sql_handle, 4, &data, NULL); status->spear_faith = atoi(data); - Sql_GetData(sql_handle, 5, &data, NULL); status->sword_calls = atoi(data); - Sql_GetData(sql_handle, 6, &data, NULL); status->sword_faith = atoi(data); - Sql_FreeResult(sql_handle); + SQL->GetData(sql_handle, 0, &data, NULL); status->mer_id = atoi(data); + SQL->GetData(sql_handle, 1, &data, NULL); status->arch_calls = atoi(data); + SQL->GetData(sql_handle, 2, &data, NULL); status->arch_faith = atoi(data); + SQL->GetData(sql_handle, 3, &data, NULL); status->spear_calls = atoi(data); + SQL->GetData(sql_handle, 4, &data, NULL); status->spear_faith = atoi(data); + SQL->GetData(sql_handle, 5, &data, NULL); status->sword_calls = atoi(data); + SQL->GetData(sql_handle, 6, &data, NULL); status->sword_faith = atoi(data); + SQL->FreeResult(sql_handle); return true; } bool mercenary_owner_tosql(int char_id, struct mmo_charstatus *status) { - if( SQL_ERROR == Sql_Query(sql_handle, "REPLACE INTO `%s` (`char_id`, `merc_id`, `arch_calls`, `arch_faith`, `spear_calls`, `spear_faith`, `sword_calls`, `sword_faith`) VALUES ('%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d')", + if( SQL_ERROR == SQL->Query(sql_handle, "REPLACE INTO `%s` (`char_id`, `merc_id`, `arch_calls`, `arch_faith`, `spear_calls`, `spear_faith`, `sword_calls`, `sword_faith`) VALUES ('%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d')", mercenary_owner_db, char_id, status->mer_id, status->arch_calls, status->arch_faith, status->spear_calls, status->spear_faith, status->sword_calls, status->sword_faith) ) { Sql_ShowDebug(sql_handle); @@ -57,10 +58,10 @@ bool mercenary_owner_tosql(int char_id, struct mmo_charstatus *status) bool mercenary_owner_delete(int char_id) { - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `char_id` = '%d'", mercenary_owner_db, char_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `char_id` = '%d'", mercenary_owner_db, char_id) ) Sql_ShowDebug(sql_handle); - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `char_id` = '%d'", mercenary_db, char_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `char_id` = '%d'", mercenary_db, char_id) ) Sql_ShowDebug(sql_handle); return true; @@ -72,7 +73,7 @@ bool mapif_mercenary_save(struct s_mercenary* merc) if( merc->mercenary_id == 0 ) { // Create new DB entry - if( SQL_ERROR == Sql_Query(sql_handle, + if( SQL_ERROR == SQL->Query(sql_handle, "INSERT INTO `%s` (`char_id`,`class`,`hp`,`sp`,`kill_counter`,`life_time`) VALUES ('%d','%d','%d','%d','%u','%u')", mercenary_db, merc->char_id, merc->class_, merc->hp, merc->sp, merc->kill_count, merc->life_time) ) { @@ -80,9 +81,9 @@ bool mapif_mercenary_save(struct s_mercenary* merc) flag = false; } else - merc->mercenary_id = (int)Sql_LastInsertId(sql_handle); + merc->mercenary_id = (int)SQL->NumRows(sql_handle); } - else if( SQL_ERROR == Sql_Query(sql_handle, + else if( SQL_ERROR == SQL->Query(sql_handle, "UPDATE `%s` SET `char_id` = '%d', `class` = '%d', `hp` = '%d', `sp` = '%d', `kill_counter` = '%u', `life_time` = '%u' WHERE `mer_id` = '%d'", mercenary_db, merc->char_id, merc->class_, merc->hp, merc->sp, merc->kill_count, merc->life_time, merc->mercenary_id) ) { // Update DB entry @@ -101,24 +102,24 @@ bool mapif_mercenary_load(int merc_id, int char_id, struct s_mercenary *merc) merc->mercenary_id = merc_id; merc->char_id = char_id; - if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `class`, `hp`, `sp`, `kill_counter`, `life_time` FROM `%s` WHERE `mer_id` = '%d' AND `char_id` = '%d'", mercenary_db, merc_id, char_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `class`, `hp`, `sp`, `kill_counter`, `life_time` FROM `%s` WHERE `mer_id` = '%d' AND `char_id` = '%d'", mercenary_db, merc_id, char_id) ) { Sql_ShowDebug(sql_handle); return false; } - if( SQL_SUCCESS != Sql_NextRow(sql_handle) ) + if( SQL_SUCCESS != SQL->NextRow(sql_handle) ) { - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); return false; } - Sql_GetData(sql_handle, 0, &data, NULL); merc->class_ = atoi(data); - Sql_GetData(sql_handle, 1, &data, NULL); merc->hp = atoi(data); - Sql_GetData(sql_handle, 2, &data, NULL); merc->sp = atoi(data); - Sql_GetData(sql_handle, 3, &data, NULL); merc->kill_count = atoi(data); - Sql_GetData(sql_handle, 4, &data, NULL); merc->life_time = atoi(data); - Sql_FreeResult(sql_handle); + SQL->GetData(sql_handle, 0, &data, NULL); merc->class_ = atoi(data); + SQL->GetData(sql_handle, 1, &data, NULL); merc->hp = atoi(data); + SQL->GetData(sql_handle, 2, &data, NULL); merc->sp = atoi(data); + SQL->GetData(sql_handle, 3, &data, NULL); merc->kill_count = atoi(data); + SQL->GetData(sql_handle, 4, &data, NULL); merc->life_time = atoi(data); + SQL->FreeResult(sql_handle); if( save_log ) ShowInfo("Mercenary loaded (%d - %d).\n", merc->mercenary_id, merc->char_id); @@ -127,7 +128,7 @@ bool mapif_mercenary_load(int merc_id, int char_id, struct s_mercenary *merc) bool mapif_mercenary_delete(int merc_id) { - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `mer_id` = '%d'", mercenary_db, merc_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `mer_id` = '%d'", mercenary_db, merc_id) ) { Sql_ShowDebug(sql_handle); return false; diff --git a/src/char/int_party.c b/src/char/int_party.c index a88e5c586..7f99590ab 100644 --- a/src/char/int_party.c +++ b/src/char/int_party.c @@ -1,5 +1,6 @@ -// Copyright (c) Athena Dev Teams - Licensed under GNU GPL -// For more information, see LICENCE in the main folder +// Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// See the LICENSE file +// Portions Copyright (c) Athena Dev Teams #include "../common/cbasetypes.h" #include "../common/mmo.h" @@ -125,14 +126,14 @@ int inter_party_tosql(struct party *p, int flag, int index) #ifdef NOISY ShowInfo("Save party request ("CL_BOLD"%d"CL_RESET" - %s).\n", party_id, p->name); #endif - Sql_EscapeStringLen(sql_handle, esc_name, p->name, strnlen(p->name, NAME_LENGTH)); + SQL->EscapeStringLen(sql_handle, esc_name, p->name, strnlen(p->name, NAME_LENGTH)); if( flag & PS_BREAK ) {// Break the party // we'll skip name-checking and just reset everyone with the same party id [celest] - if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `party_id`='0' WHERE `party_id`='%d'", char_db, party_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "UPDATE `%s` SET `party_id`='0' WHERE `party_id`='%d'", char_db, party_id) ) Sql_ShowDebug(sql_handle); - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `party_id`='%d'", party_db, party_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `party_id`='%d'", party_db, party_id) ) Sql_ShowDebug(sql_handle); //Remove from memory idb_remove(party_db_, party_id); @@ -141,7 +142,7 @@ int inter_party_tosql(struct party *p, int flag, int index) if( flag & PS_CREATE ) {// Create party - if( SQL_ERROR == Sql_Query(sql_handle, "INSERT INTO `%s` " + if( SQL_ERROR == SQL->Query(sql_handle, "INSERT INTO `%s` " "(`name`, `exp`, `item`, `leader_id`, `leader_char`) " "VALUES ('%s', '%d', '%d', '%d', '%d')", party_db, esc_name, p->exp, p->item, p->member[index].account_id, p->member[index].char_id) ) @@ -149,33 +150,33 @@ int inter_party_tosql(struct party *p, int flag, int index) Sql_ShowDebug(sql_handle); return 0; } - party_id = p->party_id = (int)Sql_LastInsertId(sql_handle); + party_id = p->party_id = (int)SQL->NumRows(sql_handle); } if( flag & PS_BASIC ) {// Update party info. - if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `name`='%s', `exp`='%d', `item`='%d' WHERE `party_id`='%d'", + if( SQL_ERROR == SQL->Query(sql_handle, "UPDATE `%s` SET `name`='%s', `exp`='%d', `item`='%d' WHERE `party_id`='%d'", party_db, esc_name, p->exp, p->item, party_id) ) Sql_ShowDebug(sql_handle); } if( flag & PS_LEADER ) {// Update leader - if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `leader_id`='%d', `leader_char`='%d' WHERE `party_id`='%d'", + if( SQL_ERROR == SQL->Query(sql_handle, "UPDATE `%s` SET `leader_id`='%d', `leader_char`='%d' WHERE `party_id`='%d'", party_db, p->member[index].account_id, p->member[index].char_id, party_id) ) Sql_ShowDebug(sql_handle); } if( flag & PS_ADDMEMBER ) {// Add one party member. - if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `party_id`='%d' WHERE `account_id`='%d' AND `char_id`='%d'", + if( SQL_ERROR == SQL->Query(sql_handle, "UPDATE `%s` SET `party_id`='%d' WHERE `account_id`='%d' AND `char_id`='%d'", char_db, party_id, p->member[index].account_id, p->member[index].char_id) ) Sql_ShowDebug(sql_handle); } if( flag & PS_DELMEMBER ) {// Remove one party member. - if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `party_id`='0' WHERE `party_id`='%d' AND `account_id`='%d' AND `char_id`='%d'", + if( SQL_ERROR == SQL->Query(sql_handle, "UPDATE `%s` SET `party_id`='0' WHERE `party_id`='%d' AND `account_id`='%d' AND `char_id`='%d'", char_db, party_id, p->member[index].account_id, p->member[index].char_id) ) Sql_ShowDebug(sql_handle); } @@ -210,42 +211,42 @@ struct party_data *inter_party_fromsql(int party_id) p = party_pt; memset(p, 0, sizeof(struct party_data)); - if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `party_id`, `name`,`exp`,`item`, `leader_id`, `leader_char` FROM `%s` WHERE `party_id`='%d'", party_db, party_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `party_id`, `name`,`exp`,`item`, `leader_id`, `leader_char` FROM `%s` WHERE `party_id`='%d'", party_db, party_id) ) { Sql_ShowDebug(sql_handle); return NULL; } - if( SQL_SUCCESS != Sql_NextRow(sql_handle) ) + if( SQL_SUCCESS != SQL->NextRow(sql_handle) ) return NULL; p->party.party_id = party_id; - Sql_GetData(sql_handle, 1, &data, &len); memcpy(p->party.name, data, min(len, NAME_LENGTH)); - Sql_GetData(sql_handle, 2, &data, NULL); p->party.exp = (atoi(data) ? 1 : 0); - Sql_GetData(sql_handle, 3, &data, NULL); p->party.item = atoi(data); - Sql_GetData(sql_handle, 4, &data, NULL); leader_id = atoi(data); - Sql_GetData(sql_handle, 5, &data, NULL); leader_char = atoi(data); - Sql_FreeResult(sql_handle); + SQL->GetData(sql_handle, 1, &data, &len); memcpy(p->party.name, data, min(len, NAME_LENGTH)); + SQL->GetData(sql_handle, 2, &data, NULL); p->party.exp = (atoi(data) ? 1 : 0); + SQL->GetData(sql_handle, 3, &data, NULL); p->party.item = atoi(data); + SQL->GetData(sql_handle, 4, &data, NULL); leader_id = atoi(data); + SQL->GetData(sql_handle, 5, &data, NULL); leader_char = atoi(data); + SQL->FreeResult(sql_handle); // Load members - if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `account_id`,`char_id`,`name`,`base_level`,`last_map`,`online`,`class` FROM `%s` WHERE `party_id`='%d'", char_db, party_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `account_id`,`char_id`,`name`,`base_level`,`last_map`,`online`,`class` FROM `%s` WHERE `party_id`='%d'", char_db, party_id) ) { Sql_ShowDebug(sql_handle); return NULL; } - for( i = 0; i < MAX_PARTY && SQL_SUCCESS == Sql_NextRow(sql_handle); ++i ) + for( i = 0; i < MAX_PARTY && SQL_SUCCESS == SQL->NextRow(sql_handle); ++i ) { m = &p->party.member[i]; - Sql_GetData(sql_handle, 0, &data, NULL); m->account_id = atoi(data); - Sql_GetData(sql_handle, 1, &data, NULL); m->char_id = atoi(data); - Sql_GetData(sql_handle, 2, &data, &len); memcpy(m->name, data, min(len, NAME_LENGTH)); - Sql_GetData(sql_handle, 3, &data, NULL); m->lv = atoi(data); - Sql_GetData(sql_handle, 4, &data, NULL); m->map = mapindex_name2id(data); - Sql_GetData(sql_handle, 5, &data, NULL); m->online = (atoi(data) ? 1 : 0); - Sql_GetData(sql_handle, 6, &data, NULL); m->class_ = atoi(data); + SQL->GetData(sql_handle, 0, &data, NULL); m->account_id = atoi(data); + SQL->GetData(sql_handle, 1, &data, NULL); m->char_id = atoi(data); + SQL->GetData(sql_handle, 2, &data, &len); memcpy(m->name, data, min(len, NAME_LENGTH)); + SQL->GetData(sql_handle, 3, &data, NULL); m->lv = atoi(data); + SQL->GetData(sql_handle, 4, &data, NULL); m->map = mapindex_name2id(data); + SQL->GetData(sql_handle, 5, &data, NULL); m->online = (atoi(data) ? 1 : 0); + SQL->GetData(sql_handle, 6, &data, NULL); m->class_ = atoi(data); m->leader = (m->account_id == leader_id && m->char_id == leader_char ? 1 : 0); } - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); if( save_log ) ShowInfo("Party loaded (%d - %s).\n", party_id, p->party.name); @@ -270,7 +271,7 @@ int inter_party_sql_init(void) /* Uncomment the following if you want to do a party_db cleanup (remove parties with no members) on startup.[Skotlex] ShowStatus("cleaning party table...\n"); - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` USING `%s` LEFT JOIN `%s` ON `%s`.leader_id =`%s`.account_id AND `%s`.leader_char = `%s`.char_id WHERE `%s`.account_id IS NULL", + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` USING `%s` LEFT JOIN `%s` ON `%s`.leader_id =`%s`.account_id AND `%s`.leader_char = `%s`.char_id WHERE `%s`.account_id IS NULL", party_db, party_db, char_db, party_db, char_db, party_db, char_db, char_db) ) Sql_ShowDebug(sql_handle); */ @@ -291,15 +292,15 @@ struct party_data* search_partyname(char* str) char* data; struct party_data* p = NULL; - Sql_EscapeStringLen(sql_handle, esc_name, str, safestrnlen(str, NAME_LENGTH)); - if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `party_id` FROM `%s` WHERE `name`='%s'", party_db, esc_name) ) + SQL->EscapeStringLen(sql_handle, esc_name, str, safestrnlen(str, NAME_LENGTH)); + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `party_id` FROM `%s` WHERE `name`='%s'", party_db, esc_name) ) Sql_ShowDebug(sql_handle); - else if( SQL_SUCCESS == Sql_NextRow(sql_handle) ) + else if( SQL_SUCCESS == SQL->NextRow(sql_handle) ) { - Sql_GetData(sql_handle, 0, &data, NULL); + SQL->GetData(sql_handle, 0, &data, NULL); p = inter_party_fromsql(atoi(data)); } - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); return p; } @@ -592,7 +593,7 @@ int mapif_parse_PartyLeave(int fd, int party_id, int account_id, int char_id) p = inter_party_fromsql(party_id); if( p == NULL ) {// Party does not exists? - if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `party_id`='0' WHERE `party_id`='%d'", char_db, party_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "UPDATE `%s` SET `party_id`='0' WHERE `party_id`='%d'", char_db, party_id) ) Sql_ShowDebug(sql_handle); return 0; } @@ -777,18 +778,18 @@ int inter_party_CharOnline(int char_id, int party_id) {// Get party_id from the database char* data; - if( SQL_ERROR == Sql_Query(sql_handle, "SELECT party_id FROM `%s` WHERE char_id='%d'", char_db, char_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT party_id FROM `%s` WHERE char_id='%d'", char_db, char_id) ) { Sql_ShowDebug(sql_handle); return 0; } - if( SQL_SUCCESS != Sql_NextRow(sql_handle) ) + if( SQL_SUCCESS != SQL->NextRow(sql_handle) ) return 0; //Eh? No party? - Sql_GetData(sql_handle, 0, &data, NULL); + SQL->GetData(sql_handle, 0, &data, NULL); party_id = atoi(data); - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); } if (party_id == 0) return 0; //No party... @@ -823,18 +824,18 @@ int inter_party_CharOffline(int char_id, int party_id) { {// Get guild_id from the database char* data; - if( SQL_ERROR == Sql_Query(sql_handle, "SELECT party_id FROM `%s` WHERE char_id='%d'", char_db, char_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT party_id FROM `%s` WHERE char_id='%d'", char_db, char_id) ) { Sql_ShowDebug(sql_handle); return 0; } - if( SQL_SUCCESS != Sql_NextRow(sql_handle) ) + if( SQL_SUCCESS != SQL->NextRow(sql_handle) ) return 0; //Eh? No party? - Sql_GetData(sql_handle, 0, &data, NULL); + SQL->GetData(sql_handle, 0, &data, NULL); party_id = atoi(data); - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); } if (party_id == 0) return 0; //No party... diff --git a/src/char/int_pet.c b/src/char/int_pet.c index 311ccd4be..8d523a133 100644 --- a/src/char/int_pet.c +++ b/src/char/int_pet.c @@ -24,13 +24,13 @@ int inter_pet_tosql(int pet_id, struct s_pet* p) //`pet` (`pet_id`, `class`,`name`,`account_id`,`char_id`,`level`,`egg_id`,`equip`,`intimate`,`hungry`,`rename_flag`,`incuvate`) char esc_name[NAME_LENGTH*2+1];// escaped pet name - Sql_EscapeStringLen(sql_handle, esc_name, p->name, strnlen(p->name, NAME_LENGTH)); + SQL->EscapeStringLen(sql_handle, esc_name, p->name, strnlen(p->name, NAME_LENGTH)); p->hungry = cap_value(p->hungry, 0, 100); p->intimate = cap_value(p->intimate, 0, 1000); if( pet_id == -1 ) {// New pet. - if( SQL_ERROR == Sql_Query(sql_handle, "INSERT INTO `%s` " + if( SQL_ERROR == SQL->Query(sql_handle, "INSERT INTO `%s` " "(`class`,`name`,`account_id`,`char_id`,`level`,`egg_id`,`equip`,`intimate`,`hungry`,`rename_flag`,`incuvate`) " "VALUES ('%d', '%s', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d')", pet_db, p->class_, esc_name, p->account_id, p->char_id, p->level, p->egg_id, @@ -39,11 +39,11 @@ int inter_pet_tosql(int pet_id, struct s_pet* p) Sql_ShowDebug(sql_handle); return 0; } - p->pet_id = (int)Sql_LastInsertId(sql_handle); + p->pet_id = (int)SQL->NumRows(sql_handle); } else {// Update pet. - if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `class`='%d',`name`='%s',`account_id`='%d',`char_id`='%d',`level`='%d',`egg_id`='%d',`equip`='%d',`intimate`='%d',`hungry`='%d',`rename_flag`='%d',`incuvate`='%d' WHERE `pet_id`='%d'", + if( SQL_ERROR == SQL->Query(sql_handle, "UPDATE `%s` SET `class`='%d',`name`='%s',`account_id`='%d',`char_id`='%d',`level`='%d',`egg_id`='%d',`equip`='%d',`intimate`='%d',`hungry`='%d',`rename_flag`='%d',`incuvate`='%d' WHERE `pet_id`='%d'", pet_db, p->class_, esc_name, p->account_id, p->char_id, p->level, p->egg_id, p->equip, p->intimate, p->hungry, p->rename_flag, p->incuvate, p->pet_id) ) { @@ -69,28 +69,28 @@ int inter_pet_fromsql(int pet_id, struct s_pet* p) //`pet` (`pet_id`, `class`,`name`,`account_id`,`char_id`,`level`,`egg_id`,`equip`,`intimate`,`hungry`,`rename_flag`,`incuvate`) - if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `pet_id`, `class`,`name`,`account_id`,`char_id`,`level`,`egg_id`,`equip`,`intimate`,`hungry`,`rename_flag`,`incuvate` FROM `%s` WHERE `pet_id`='%d'", pet_db, pet_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `pet_id`, `class`,`name`,`account_id`,`char_id`,`level`,`egg_id`,`equip`,`intimate`,`hungry`,`rename_flag`,`incuvate` FROM `%s` WHERE `pet_id`='%d'", pet_db, pet_id) ) { Sql_ShowDebug(sql_handle); return 0; } - if( SQL_SUCCESS == Sql_NextRow(sql_handle) ) + if( SQL_SUCCESS == SQL->NextRow(sql_handle) ) { p->pet_id = pet_id; - Sql_GetData(sql_handle, 1, &data, NULL); p->class_ = atoi(data); - Sql_GetData(sql_handle, 2, &data, &len); memcpy(p->name, data, min(len, NAME_LENGTH)); - Sql_GetData(sql_handle, 3, &data, NULL); p->account_id = atoi(data); - Sql_GetData(sql_handle, 4, &data, NULL); p->char_id = atoi(data); - Sql_GetData(sql_handle, 5, &data, NULL); p->level = atoi(data); - Sql_GetData(sql_handle, 6, &data, NULL); p->egg_id = atoi(data); - Sql_GetData(sql_handle, 7, &data, NULL); p->equip = atoi(data); - Sql_GetData(sql_handle, 8, &data, NULL); p->intimate = atoi(data); - Sql_GetData(sql_handle, 9, &data, NULL); p->hungry = atoi(data); - Sql_GetData(sql_handle, 10, &data, NULL); p->rename_flag = atoi(data); - Sql_GetData(sql_handle, 11, &data, NULL); p->incuvate = atoi(data); - - Sql_FreeResult(sql_handle); + SQL->GetData(sql_handle, 1, &data, NULL); p->class_ = atoi(data); + SQL->GetData(sql_handle, 2, &data, &len); memcpy(p->name, data, min(len, NAME_LENGTH)); + SQL->GetData(sql_handle, 3, &data, NULL); p->account_id = atoi(data); + SQL->GetData(sql_handle, 4, &data, NULL); p->char_id = atoi(data); + SQL->GetData(sql_handle, 5, &data, NULL); p->level = atoi(data); + SQL->GetData(sql_handle, 6, &data, NULL); p->egg_id = atoi(data); + SQL->GetData(sql_handle, 7, &data, NULL); p->equip = atoi(data); + SQL->GetData(sql_handle, 8, &data, NULL); p->intimate = atoi(data); + SQL->GetData(sql_handle, 9, &data, NULL); p->hungry = atoi(data); + SQL->GetData(sql_handle, 10, &data, NULL); p->rename_flag = atoi(data); + SQL->GetData(sql_handle, 11, &data, NULL); p->incuvate = atoi(data); + + SQL->FreeResult(sql_handle); p->hungry = cap_value(p->hungry, 0, 100); p->intimate = cap_value(p->intimate, 0, 1000); @@ -115,7 +115,7 @@ void inter_pet_sql_final(void){ int inter_pet_delete(int pet_id){ ShowInfo("delete pet request: %d...\n",pet_id); - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `pet_id`='%d'", pet_db, pet_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `pet_id`='%d'", pet_db, pet_id) ) Sql_ShowDebug(sql_handle); return 0; } diff --git a/src/char/int_quest.c b/src/char/int_quest.c index 224205412..d771543cc 100644 --- a/src/char/int_quest.c +++ b/src/char/int_quest.c @@ -1,5 +1,6 @@ -// Copyright (c) Athena Dev Teams - Licensed under GNU GPL -// For more information, see LICENCE in the main folder +// Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// See the LICENSE file +// Portions Copyright (c) Athena Dev Teams #include "../common/mmo.h" #include "../common/db.h" @@ -55,7 +56,7 @@ int mapif_quests_fromsql(int char_id, struct quest questlog[]) //Delete a quest bool mapif_quest_delete(int char_id, int quest_id) { - if ( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `quest_id` = '%d' AND `char_id` = '%d'", quest_db, quest_id, char_id) ) + if ( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `quest_id` = '%d' AND `char_id` = '%d'", quest_db, quest_id, char_id) ) { Sql_ShowDebug(sql_handle); return false; @@ -67,7 +68,7 @@ bool mapif_quest_delete(int char_id, int quest_id) //Add a quest to a questlog bool mapif_quest_add(int char_id, struct quest qd) { - if ( SQL_ERROR == Sql_Query(sql_handle, "INSERT INTO `%s`(`quest_id`, `char_id`, `state`, `time`, `count1`, `count2`, `count3`) VALUES ('%d', '%d', '%d','%d', '%d', '%d', '%d')", quest_db, qd.quest_id, char_id, qd.state, qd.time, qd.count[0], qd.count[1], qd.count[2]) ) + if ( SQL_ERROR == SQL->Query(sql_handle, "INSERT INTO `%s`(`quest_id`, `char_id`, `state`, `time`, `count1`, `count2`, `count3`) VALUES ('%d', '%d', '%d','%d', '%d', '%d', '%d')", quest_db, qd.quest_id, char_id, qd.state, qd.time, qd.count[0], qd.count[1], qd.count[2]) ) { Sql_ShowDebug(sql_handle); return false; @@ -79,7 +80,7 @@ bool mapif_quest_add(int char_id, struct quest qd) //Update a questlog bool mapif_quest_update(int char_id, struct quest qd) { - if ( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `state`='%d', `count1`='%d', `count2`='%d', `count3`='%d' WHERE `quest_id` = '%d' AND `char_id` = '%d'", quest_db, qd.state, qd.count[0], qd.count[1], qd.count[2], qd.quest_id, char_id) ) + if ( SQL_ERROR == SQL->Query(sql_handle, "UPDATE `%s` SET `state`='%d', `count1`='%d', `count2`='%d', `count3`='%d' WHERE `quest_id` = '%d' AND `char_id` = '%d'", quest_db, qd.state, qd.count[0], qd.count[1], qd.count[2], qd.quest_id, char_id) ) { Sql_ShowDebug(sql_handle); return false; diff --git a/src/char/int_storage.c b/src/char/int_storage.c index 68b588087..429b80105 100644 --- a/src/char/int_storage.c +++ b/src/char/int_storage.c @@ -1,5 +1,6 @@ -// Copyright (c) Athena Dev Teams - Licensed under GNU GPL -// For more information, see LICENCE in the main folder +// Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// See the LICENSE file +// Portions Copyright (c) Athena Dev Teams #include "../common/mmo.h" #include "../common/malloc.h" @@ -37,36 +38,36 @@ int storage_fromsql(int account_id, struct storage_data* p) p->storage_amount = 0; // storage {`account_id`/`id`/`nameid`/`amount`/`equip`/`identify`/`refine`/`attribute`/`card0`/`card1`/`card2`/`card3`} - StringBuf_Init(&buf); - StringBuf_AppendStr(&buf, "SELECT `id`,`nameid`,`amount`,`equip`,`identify`,`refine`,`attribute`,`expire_time`,`unique_id`"); + StrBuf->Init(&buf); + StrBuf->AppendStr(&buf, "SELECT `id`,`nameid`,`amount`,`equip`,`identify`,`refine`,`attribute`,`expire_time`,`unique_id`"); for( j = 0; j < MAX_SLOTS; ++j ) - StringBuf_Printf(&buf, ",`card%d`", j); - StringBuf_Printf(&buf, " FROM `%s` WHERE `account_id`='%d' ORDER BY `nameid`", storage_db, account_id); + StrBuf->Printf(&buf, ",`card%d`", j); + StrBuf->Printf(&buf, " FROM `%s` WHERE `account_id`='%d' ORDER BY `nameid`", storage_db, account_id); - if( SQL_ERROR == Sql_Query(sql_handle, StringBuf_Value(&buf)) ) + if( SQL_ERROR == SQL->Query(sql_handle, StrBuf->Value(&buf)) ) Sql_ShowDebug(sql_handle); - StringBuf_Destroy(&buf); + StrBuf->Destroy(&buf); - for( i = 0; i < MAX_STORAGE && SQL_SUCCESS == Sql_NextRow(sql_handle); ++i ) + for( i = 0; i < MAX_STORAGE && SQL_SUCCESS == SQL->NextRow(sql_handle); ++i ) { item = &p->items[i]; - Sql_GetData(sql_handle, 0, &data, NULL); item->id = atoi(data); - Sql_GetData(sql_handle, 1, &data, NULL); item->nameid = atoi(data); - Sql_GetData(sql_handle, 2, &data, NULL); item->amount = atoi(data); - Sql_GetData(sql_handle, 3, &data, NULL); item->equip = atoi(data); - Sql_GetData(sql_handle, 4, &data, NULL); item->identify = atoi(data); - Sql_GetData(sql_handle, 5, &data, NULL); item->refine = atoi(data); - Sql_GetData(sql_handle, 6, &data, NULL); item->attribute = atoi(data); - Sql_GetData(sql_handle, 7, &data, NULL); item->expire_time = (unsigned int)atoi(data); - Sql_GetData(sql_handle, 8, &data, NULL); item->unique_id = strtoull(data, NULL, 10); + SQL->GetData(sql_handle, 0, &data, NULL); item->id = atoi(data); + SQL->GetData(sql_handle, 1, &data, NULL); item->nameid = atoi(data); + SQL->GetData(sql_handle, 2, &data, NULL); item->amount = atoi(data); + SQL->GetData(sql_handle, 3, &data, NULL); item->equip = atoi(data); + SQL->GetData(sql_handle, 4, &data, NULL); item->identify = atoi(data); + SQL->GetData(sql_handle, 5, &data, NULL); item->refine = atoi(data); + SQL->GetData(sql_handle, 6, &data, NULL); item->attribute = atoi(data); + SQL->GetData(sql_handle, 7, &data, NULL); item->expire_time = (unsigned int)atoi(data); + SQL->GetData(sql_handle, 8, &data, NULL); item->unique_id = strtoull(data, NULL, 10); for( j = 0; j < MAX_SLOTS; ++j ) { - Sql_GetData(sql_handle, 9+j, &data, NULL); item->card[j] = atoi(data); + SQL->GetData(sql_handle, 9+j, &data, NULL); item->card[j] = atoi(data); } } p->storage_amount = i; - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); ShowInfo("storage load complete from DB - id: %d (total: %d)\n", account_id, p->storage_amount); return 1; @@ -94,36 +95,36 @@ int guild_storage_fromsql(int guild_id, struct guild_storage* p) p->guild_id = guild_id; // storage {`guild_id`/`id`/`nameid`/`amount`/`equip`/`identify`/`refine`/`attribute`/`card0`/`card1`/`card2`/`card3`} - StringBuf_Init(&buf); - StringBuf_AppendStr(&buf, "SELECT `id`,`nameid`,`amount`,`equip`,`identify`,`refine`,`attribute`,`unique_id`"); + StrBuf->Init(&buf); + StrBuf->AppendStr(&buf, "SELECT `id`,`nameid`,`amount`,`equip`,`identify`,`refine`,`attribute`,`unique_id`"); for( j = 0; j < MAX_SLOTS; ++j ) - StringBuf_Printf(&buf, ",`card%d`", j); - StringBuf_Printf(&buf, " FROM `%s` WHERE `guild_id`='%d' ORDER BY `nameid`", guild_storage_db, guild_id); + StrBuf->Printf(&buf, ",`card%d`", j); + StrBuf->Printf(&buf, " FROM `%s` WHERE `guild_id`='%d' ORDER BY `nameid`", guild_storage_db, guild_id); - if( SQL_ERROR == Sql_Query(sql_handle, StringBuf_Value(&buf)) ) + if( SQL_ERROR == SQL->Query(sql_handle, StrBuf->Value(&buf)) ) Sql_ShowDebug(sql_handle); - StringBuf_Destroy(&buf); + StrBuf->Destroy(&buf); - for( i = 0; i < MAX_GUILD_STORAGE && SQL_SUCCESS == Sql_NextRow(sql_handle); ++i ) + for( i = 0; i < MAX_GUILD_STORAGE && SQL_SUCCESS == SQL->NextRow(sql_handle); ++i ) { item = &p->items[i]; - Sql_GetData(sql_handle, 0, &data, NULL); item->id = atoi(data); - Sql_GetData(sql_handle, 1, &data, NULL); item->nameid = atoi(data); - Sql_GetData(sql_handle, 2, &data, NULL); item->amount = atoi(data); - Sql_GetData(sql_handle, 3, &data, NULL); item->equip = atoi(data); - Sql_GetData(sql_handle, 4, &data, NULL); item->identify = atoi(data); - Sql_GetData(sql_handle, 5, &data, NULL); item->refine = atoi(data); - Sql_GetData(sql_handle, 6, &data, NULL); item->attribute = atoi(data); - Sql_GetData(sql_handle, 7, &data, NULL); item->unique_id = strtoull(data, NULL, 10); + SQL->GetData(sql_handle, 0, &data, NULL); item->id = atoi(data); + SQL->GetData(sql_handle, 1, &data, NULL); item->nameid = atoi(data); + SQL->GetData(sql_handle, 2, &data, NULL); item->amount = atoi(data); + SQL->GetData(sql_handle, 3, &data, NULL); item->equip = atoi(data); + SQL->GetData(sql_handle, 4, &data, NULL); item->identify = atoi(data); + SQL->GetData(sql_handle, 5, &data, NULL); item->refine = atoi(data); + SQL->GetData(sql_handle, 6, &data, NULL); item->attribute = atoi(data); + SQL->GetData(sql_handle, 7, &data, NULL); item->unique_id = strtoull(data, NULL, 10); item->expire_time = 0; for( j = 0; j < MAX_SLOTS; ++j ) { - Sql_GetData(sql_handle, 8+j, &data, NULL); item->card[j] = atoi(data); + SQL->GetData(sql_handle, 8+j, &data, NULL); item->card[j] = atoi(data); } } p->storage_amount = i; - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); ShowInfo("guild storage load complete from DB - id: %d (total: %d)\n", guild_id, p->storage_amount); return 0; @@ -144,13 +145,13 @@ void inter_storage_sql_final(void) // q?f[^? int inter_storage_delete(int account_id) { - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `account_id`='%d'", storage_db, account_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `account_id`='%d'", storage_db, account_id) ) Sql_ShowDebug(sql_handle); return 0; } int inter_guild_storage_delete(int guild_id) { - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `guild_id`='%d'", guild_storage_db, guild_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `guild_id`='%d'", guild_storage_db, guild_id) ) Sql_ShowDebug(sql_handle); return 0; } @@ -160,9 +161,9 @@ int inter_guild_storage_delete(int guild_id) int mapif_load_guild_storage(int fd,int account_id,int guild_id) { - if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `guild_id` FROM `%s` WHERE `guild_id`='%d'", guild_db, guild_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `guild_id` FROM `%s` WHERE `guild_id`='%d'", guild_db, guild_id) ) Sql_ShowDebug(sql_handle); - else if( Sql_NumRows(sql_handle) > 0 ) + else if( SQL->NumRows(sql_handle) > 0 ) {// guild exists WFIFOHEAD(fd, sizeof(struct guild_storage)+12); WFIFOW(fd,0) = 0x3818; @@ -174,7 +175,7 @@ int mapif_load_guild_storage(int fd,int account_id,int guild_id) return 0; } // guild does not exist - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); WFIFOHEAD(fd, 12); WFIFOW(fd,0) = 0x3818; WFIFOW(fd,2) = 12; @@ -219,16 +220,16 @@ int mapif_parse_SaveGuildStorage(int fd) } else { - if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `guild_id` FROM `%s` WHERE `guild_id`='%d'", guild_db, guild_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `guild_id` FROM `%s` WHERE `guild_id`='%d'", guild_db, guild_id) ) Sql_ShowDebug(sql_handle); - else if( Sql_NumRows(sql_handle) > 0 ) + else if( SQL->NumRows(sql_handle) > 0 ) {// guild exists - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); guild_storage_tosql(guild_id, (struct guild_storage*)RFIFOP(fd,12)); mapif_save_guild_storage_ack(fd, RFIFOL(fd,4), guild_id, 0); return 0; } - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); } mapif_save_guild_storage_ack(fd, RFIFOL(fd,4), guild_id, 1); return 0; diff --git a/src/char/inter.c b/src/char/inter.c index 7fd1e089a..83989271e 100644 --- a/src/char/inter.c +++ b/src/char/inter.c @@ -1,5 +1,6 @@ -// Copyright (c) Athena Dev Teams - Licensed under GNU GPL -// For more information, see LICENCE in the main folder +// Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// See the LICENSE file +// Portions Copyright (c) Athena Dev Teams #include "../common/mmo.h" #include "../common/db.h" @@ -445,43 +446,43 @@ void mapif_parse_accinfo(int fd) { safestrncpy(query, (char*) RFIFOP(fd,14), NAME_LENGTH); - Sql_EscapeString(sql_handle, query_esq, query); + SQL->EscapeString(sql_handle, query_esq, query); account_id = atoi(query); if (account_id < START_ACCOUNT_NUM) { // is string - if ( SQL_ERROR == Sql_Query(sql_handle, "SELECT `account_id`,`name`,`class`,`base_level`,`job_level`,`online` FROM `char` WHERE `name` LIKE '%s' LIMIT 10", query_esq) - || Sql_NumRows(sql_handle) == 0 ) { - if( Sql_NumRows(sql_handle) == 0 ) { + if ( SQL_ERROR == SQL->Query(sql_handle, "SELECT `account_id`,`name`,`class`,`base_level`,`job_level`,`online` FROM `char` WHERE `name` LIKE '%s' LIMIT 10", query_esq) + || SQL->NumRows(sql_handle) == 0 ) { + if( SQL->NumRows(sql_handle) == 0 ) { inter_to_fd(fd, u_fd, aid, "No matches were found for your criteria, '%s'",query); } else { Sql_ShowDebug(sql_handle); inter_to_fd(fd, u_fd, aid, "An error occured, bother your admin about it."); } - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); return; } else { - if( Sql_NumRows(sql_handle) == 1 ) {//we found a perfect match - Sql_NextRow(sql_handle); - Sql_GetData(sql_handle, 0, &data, NULL); account_id = atoi(data); - Sql_FreeResult(sql_handle); + if( SQL->NumRows(sql_handle) == 1 ) {//we found a perfect match + SQL->NextRow(sql_handle); + SQL->GetData(sql_handle, 0, &data, NULL); account_id = atoi(data); + SQL->FreeResult(sql_handle); } else {// more than one, listing... [Dekamaster/Nightroad] - inter_to_fd(fd, u_fd, aid, "Your query returned the following %d results, please be more specific...",(int)Sql_NumRows(sql_handle)); - while ( SQL_SUCCESS == Sql_NextRow(sql_handle) ) { + inter_to_fd(fd, u_fd, aid, "Your query returned the following %d results, please be more specific...",(int)SQL->NumRows(sql_handle)); + while ( SQL_SUCCESS == SQL->NextRow(sql_handle) ) { int class_; short base_level, job_level, online; char name[NAME_LENGTH]; - Sql_GetData(sql_handle, 0, &data, NULL); account_id = atoi(data); - Sql_GetData(sql_handle, 1, &data, NULL); safestrncpy(name, data, sizeof(name)); - Sql_GetData(sql_handle, 2, &data, NULL); class_ = atoi(data); - Sql_GetData(sql_handle, 3, &data, NULL); base_level = atoi(data); - Sql_GetData(sql_handle, 4, &data, NULL); job_level = atoi(data); - Sql_GetData(sql_handle, 5, &data, NULL); online = atoi(data); + SQL->GetData(sql_handle, 0, &data, NULL); account_id = atoi(data); + SQL->GetData(sql_handle, 1, &data, NULL); safestrncpy(name, data, sizeof(name)); + SQL->GetData(sql_handle, 2, &data, NULL); class_ = atoi(data); + SQL->GetData(sql_handle, 3, &data, NULL); base_level = atoi(data); + SQL->GetData(sql_handle, 4, &data, NULL); job_level = atoi(data); + SQL->GetData(sql_handle, 5, &data, NULL); online = atoi(data); inter_to_fd(fd, u_fd, aid, "[AID: %d] %s | %s | Level: %d/%d | %s", account_id, name, job_name(class_), base_level, job_level, online?"Online":"Offline"); } - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); return; } } @@ -492,29 +493,29 @@ void mapif_parse_accinfo(int fd) { char userid[NAME_LENGTH], user_pass[NAME_LENGTH], email[40], last_ip[20], lastlogin[30], pincode[5], birthdate[11]; short level = -1; int logincount = 0,state = 0; - if ( SQL_ERROR == Sql_Query(sql_handle, "SELECT `userid`, `user_pass`, `email`, `last_ip`, `group_id`, `lastlogin`, `logincount`, `state`,`pincode`,`birthdate` FROM `login` WHERE `account_id` = '%d' LIMIT 1", account_id) - || Sql_NumRows(sql_handle) == 0 ) { - if( Sql_NumRows(sql_handle) == 0 ) { + if ( SQL_ERROR == SQL->Query(sql_handle, "SELECT `userid`, `user_pass`, `email`, `last_ip`, `group_id`, `lastlogin`, `logincount`, `state`,`pincode`,`birthdate` FROM `login` WHERE `account_id` = '%d' LIMIT 1", account_id) + || SQL->NumRows(sql_handle) == 0 ) { + if( SQL->NumRows(sql_handle) == 0 ) { inter_to_fd(fd, u_fd, aid, "No account with ID '%d' was found.", account_id ); } else { inter_to_fd(fd, u_fd, aid, "An error occured, bother your admin about it."); Sql_ShowDebug(sql_handle); } } else { - Sql_NextRow(sql_handle); - Sql_GetData(sql_handle, 0, &data, NULL); safestrncpy(userid, data, sizeof(userid)); - Sql_GetData(sql_handle, 1, &data, NULL); safestrncpy(user_pass, data, sizeof(user_pass)); - Sql_GetData(sql_handle, 2, &data, NULL); safestrncpy(email, data, sizeof(email)); - Sql_GetData(sql_handle, 3, &data, NULL); safestrncpy(last_ip, data, sizeof(last_ip)); - Sql_GetData(sql_handle, 4, &data, NULL); level = atoi(data); - Sql_GetData(sql_handle, 5, &data, NULL); safestrncpy(lastlogin, data, sizeof(lastlogin)); - Sql_GetData(sql_handle, 6, &data, NULL); logincount = atoi(data); - Sql_GetData(sql_handle, 7, &data, NULL); state = atoi(data); - Sql_GetData(sql_handle, 8, &data, NULL); safestrncpy(pincode, data, sizeof(pincode)); - Sql_GetData(sql_handle, 9, &data, NULL); safestrncpy(birthdate, data, sizeof(birthdate)); + SQL->NextRow(sql_handle); + SQL->GetData(sql_handle, 0, &data, NULL); safestrncpy(userid, data, sizeof(userid)); + SQL->GetData(sql_handle, 1, &data, NULL); safestrncpy(user_pass, data, sizeof(user_pass)); + SQL->GetData(sql_handle, 2, &data, NULL); safestrncpy(email, data, sizeof(email)); + SQL->GetData(sql_handle, 3, &data, NULL); safestrncpy(last_ip, data, sizeof(last_ip)); + SQL->GetData(sql_handle, 4, &data, NULL); level = atoi(data); + SQL->GetData(sql_handle, 5, &data, NULL); safestrncpy(lastlogin, data, sizeof(lastlogin)); + SQL->GetData(sql_handle, 6, &data, NULL); logincount = atoi(data); + SQL->GetData(sql_handle, 7, &data, NULL); state = atoi(data); + SQL->GetData(sql_handle, 8, &data, NULL); safestrncpy(pincode, data, sizeof(pincode)); + SQL->GetData(sql_handle, 9, &data, NULL); safestrncpy(birthdate, data, sizeof(birthdate)); } - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); if (level == -1) return; @@ -535,10 +536,10 @@ void mapif_parse_accinfo(int fd) { inter_to_fd(fd, u_fd, aid, "-- Character Details --" ); - if ( SQL_ERROR == Sql_Query(sql_handle, "SELECT `char_id`, `name`, `char_num`, `class`, `base_level`, `job_level`, `online` FROM `char` WHERE `account_id` = '%d' ORDER BY `char_num` LIMIT %d", account_id, MAX_CHARS) - || Sql_NumRows(sql_handle) == 0 ) { + if ( SQL_ERROR == SQL->Query(sql_handle, "SELECT `char_id`, `name`, `char_num`, `class`, `base_level`, `job_level`, `online` FROM `char` WHERE `account_id` = '%d' ORDER BY `char_num` LIMIT %d", account_id, MAX_CHARS) + || SQL->NumRows(sql_handle) == 0 ) { - if( Sql_NumRows(sql_handle) == 0 ) + if( SQL->NumRows(sql_handle) == 0 ) inter_to_fd(fd, u_fd, aid,"This account doesn't have characters."); else { inter_to_fd(fd, u_fd, aid,"An error occured, bother your admin about it."); @@ -546,23 +547,23 @@ void mapif_parse_accinfo(int fd) { } } else { - while ( SQL_SUCCESS == Sql_NextRow(sql_handle) ) { + while ( SQL_SUCCESS == SQL->NextRow(sql_handle) ) { int char_id, class_; short char_num, base_level, job_level, online; char name[NAME_LENGTH]; - Sql_GetData(sql_handle, 0, &data, NULL); char_id = atoi(data); - Sql_GetData(sql_handle, 1, &data, NULL); safestrncpy(name, data, sizeof(name)); - Sql_GetData(sql_handle, 2, &data, NULL); char_num = atoi(data); - Sql_GetData(sql_handle, 3, &data, NULL); class_ = atoi(data); - Sql_GetData(sql_handle, 4, &data, NULL); base_level = atoi(data); - Sql_GetData(sql_handle, 5, &data, NULL); job_level = atoi(data); - Sql_GetData(sql_handle, 6, &data, NULL); online = atoi(data); + SQL->GetData(sql_handle, 0, &data, NULL); char_id = atoi(data); + SQL->GetData(sql_handle, 1, &data, NULL); safestrncpy(name, data, sizeof(name)); + SQL->GetData(sql_handle, 2, &data, NULL); char_num = atoi(data); + SQL->GetData(sql_handle, 3, &data, NULL); class_ = atoi(data); + SQL->GetData(sql_handle, 4, &data, NULL); base_level = atoi(data); + SQL->GetData(sql_handle, 5, &data, NULL); job_level = atoi(data); + SQL->GetData(sql_handle, 6, &data, NULL); online = atoi(data); inter_to_fd(fd, u_fd, aid, "[Slot/CID: %d/%d] %s | %s | Level: %d/%d | %s", char_num, char_id, name, job_name(class_), base_level, job_level, online?"On":"Off"); } } - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); } return; @@ -584,12 +585,12 @@ int inter_accreg_tosql(int account_id, int char_id, struct accreg* reg, int type switch( type ) { case 3: //Char Reg - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `type`=3 AND `char_id`='%d'", reg_db, char_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `type`=3 AND `char_id`='%d'", reg_db, char_id) ) Sql_ShowDebug(sql_handle); account_id = 0; break; case 2: //Account Reg - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `type`=2 AND `account_id`='%d'", reg_db, account_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `type`=2 AND `account_id`='%d'", reg_db, account_id) ) Sql_ShowDebug(sql_handle); char_id = 0; break; @@ -604,8 +605,8 @@ int inter_accreg_tosql(int account_id, int char_id, struct accreg* reg, int type if( reg->reg_num <= 0 ) return 0; - StringBuf_Init(&buf); - StringBuf_Printf(&buf, "INSERT INTO `%s` (`type`,`account_id`,`char_id`,`str`,`value`) VALUES ", reg_db); + StrBuf->Init(&buf); + StrBuf->Printf(&buf, "INSERT INTO `%s` (`type`,`account_id`,`char_id`,`str`,`value`) VALUES ", reg_db); for( i = 0; i < reg->reg_num; ++i ) { r = ®->reg[i]; @@ -614,20 +615,20 @@ int inter_accreg_tosql(int account_id, int char_id, struct accreg* reg, int type char val[256]; if( i > 0 ) - StringBuf_AppendStr(&buf, ","); + StrBuf->AppendStr(&buf, ","); - Sql_EscapeString(sql_handle, str, r->str); - Sql_EscapeString(sql_handle, val, r->value); + SQL->EscapeString(sql_handle, str, r->str); + SQL->EscapeString(sql_handle, val, r->value); - StringBuf_Printf(&buf, "('%d','%d','%d','%s','%s')", type, account_id, char_id, str, val); + StrBuf->Printf(&buf, "('%d','%d','%d','%s','%s')", type, account_id, char_id, str, val); } } - if( SQL_ERROR == Sql_QueryStr(sql_handle, StringBuf_Value(&buf)) ) { + if( SQL_ERROR == SQL->QueryStr(sql_handle, StrBuf->Value(&buf)) ) { Sql_ShowDebug(sql_handle); } - StringBuf_Destroy(&buf); + StrBuf->Destroy(&buf); return 1; } @@ -651,11 +652,11 @@ int inter_accreg_fromsql(int account_id,int char_id, struct accreg *reg, int typ switch( type ) { case 3: //char reg - if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `str`, `value` FROM `%s` WHERE `type`=3 AND `char_id`='%d'", reg_db, char_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `str`, `value` FROM `%s` WHERE `type`=3 AND `char_id`='%d'", reg_db, char_id) ) Sql_ShowDebug(sql_handle); break; case 2: //account reg - if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `str`, `value` FROM `%s` WHERE `type`=2 AND `account_id`='%d'", reg_db, account_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `str`, `value` FROM `%s` WHERE `type`=2 AND `account_id`='%d'", reg_db, account_id) ) Sql_ShowDebug(sql_handle); break; case 1: //account2 reg @@ -665,18 +666,18 @@ int inter_accreg_fromsql(int account_id,int char_id, struct accreg *reg, int typ ShowError("inter_accreg_fromsql: Invalid type %d\n", type); return 0; } - for( i = 0; i < MAX_REG_NUM && SQL_SUCCESS == Sql_NextRow(sql_handle); ++i ) + for( i = 0; i < MAX_REG_NUM && SQL_SUCCESS == SQL->NextRow(sql_handle); ++i ) { r = ®->reg[i]; // str - Sql_GetData(sql_handle, 0, &data, &len); + SQL->GetData(sql_handle, 0, &data, &len); memcpy(r->str, data, min(len, sizeof(r->str))); // value - Sql_GetData(sql_handle, 1, &data, &len); + SQL->GetData(sql_handle, 1, &data, &len); memcpy(r->value, data, min(len, sizeof(r->value))); } reg->reg_num = i; - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); return 1; } @@ -752,8 +753,8 @@ int inter_log(char* fmt, ...) vsnprintf(str, sizeof(str), fmt, ap); va_end(ap); - Sql_EscapeStringLen(sql_handle, esc_str, str, strnlen(str, sizeof(str))); - if( SQL_ERROR == Sql_Query(sql_handle, "INSERT INTO `%s` (`time`, `log`) VALUES (NOW(), '%s')", interlog_db, esc_str) ) + SQL->EscapeStringLen(sql_handle, esc_str, str, strnlen(str, sizeof(str))); + if( SQL_ERROR == SQL->Query(sql_handle, "INSERT INTO `%s` (`time`, `log`) VALUES (NOW(), '%s')", interlog_db, esc_str) ) Sql_ShowDebug(sql_handle); return 0; @@ -767,17 +768,17 @@ int inter_init_sql(const char *file) inter_config_read(file); //DB connection initialized - sql_handle = Sql_Malloc(); + sql_handle = SQL->Malloc(); ShowInfo("Connect Character DB server.... (Character Server)\n"); - if( SQL_ERROR == Sql_Connect(sql_handle, char_server_id, char_server_pw, char_server_ip, (uint16)char_server_port, char_server_db) ) + if( SQL_ERROR == SQL->Connect(sql_handle, char_server_id, char_server_pw, char_server_ip, (uint16)char_server_port, char_server_db) ) { Sql_ShowDebug(sql_handle); - Sql_Free(sql_handle); + SQL->Free(sql_handle); exit(EXIT_FAILURE); } if( *default_codepage ) { - if( SQL_ERROR == Sql_SetEncoding(sql_handle, default_codepage) ) + if( SQL_ERROR == SQL->SetEncoding(sql_handle, default_codepage) ) Sql_ShowDebug(sql_handle); } @@ -996,12 +997,12 @@ int mapif_parse_WisRequest(int fd) safestrncpy(name, (char*)RFIFOP(fd,28), NAME_LENGTH); //Received name may be too large and not contain \0! [Skotlex] - Sql_EscapeStringLen(sql_handle, esc_name, name, strnlen(name, NAME_LENGTH)); - if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `name` FROM `%s` WHERE `name`='%s'", char_db, esc_name) ) + SQL->EscapeStringLen(sql_handle, esc_name, name, strnlen(name, NAME_LENGTH)); + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `name` FROM `%s` WHERE `name`='%s'", char_db, esc_name) ) Sql_ShowDebug(sql_handle); // search if character exists before to ask all map-servers - if( SQL_SUCCESS != Sql_NextRow(sql_handle) ) + if( SQL_SUCCESS != SQL->NextRow(sql_handle) ) { unsigned char buf[27]; WBUFW(buf, 0) = 0x3802; @@ -1012,7 +1013,7 @@ int mapif_parse_WisRequest(int fd) else {// Character exists. So, ask all map-servers // to be sure of the correct name, rewrite it - Sql_GetData(sql_handle, 0, &data, &len); + SQL->GetData(sql_handle, 0, &data, &len); memset(name, 0, NAME_LENGTH); memcpy(name, data, min(len, NAME_LENGTH)); // if source is destination, don't ask other servers. @@ -1044,7 +1045,7 @@ int mapif_parse_WisRequest(int fd) } } - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); return 0; } diff --git a/src/char/inter.h b/src/char/inter.h index e34c54c16..de27b0473 100644 --- a/src/char/inter.h +++ b/src/char/inter.h @@ -1,5 +1,6 @@ -// Copyright (c) Athena Dev Teams - Licensed under GNU GPL -// For more information, see LICENCE in the main folder +// Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// See the LICENSE file +// Portions Copyright (c) Athena Dev Teams #ifndef _INTER_SQL_H_ #define _INTER_SQL_H_ @@ -31,7 +32,7 @@ uint64 inter_chk_lastuid(int8 flag, uint64 value); #define dbUpdateUid(handler_)\ { \ uint64 unique_id_ = inter_chk_lastuid(0, 0); \ - if (unique_id_ && SQL_ERROR == Sql_Query(handler_, "UPDATE `interreg` SET `value`='%"PRIu64"' WHERE `varname`='unique_id'", unique_id_)) \ + if (unique_id_ && SQL_ERROR == SQL->Query(handler_, "UPDATE `interreg` SET `value`='%"PRIu64"' WHERE `varname`='unique_id'", unique_id_)) \ Sql_ShowDebug(handler_);\ } #else diff --git a/src/common/HPM.c b/src/common/HPM.c index 2df559c82..af06811a5 100644 --- a/src/common/HPM.c +++ b/src/common/HPM.c @@ -11,6 +11,8 @@ #include "../common/conf.h" #include "../common/utils.h" #include "../common/console.h" +#include "../common/strlib.h" +#include "../common/sql.h" #include "HPM.h" #include @@ -73,39 +75,34 @@ struct hplugin *hplugin_create(void) { HPM->plugins[HPM->plugin_count - 1]->filename = NULL; return HPM->plugins[HPM->plugin_count - 1]; } -bool hplugin_showmsg_populate(struct hplugin *plugin, const char *filename) { - void **ShowSub; - const char* ShowSubNames[9] = { - "ShowMessage", - "ShowStatus", - "ShowSQL", - "ShowInfo", - "ShowNotice", - "ShowWarning", - "ShowDebug", - "ShowError", - "ShowFatalError", +#define HPM_POP(x) { #x , x } +bool hplugin_populate(struct hplugin *plugin, const char *filename) { + void **Link; + struct { + const char* name; + void *Ref; + } ToLink[] = { + HPM_POP(ShowMessage), + HPM_POP(ShowStatus), + HPM_POP(ShowSQL), + HPM_POP(ShowInfo), + HPM_POP(ShowNotice), + HPM_POP(ShowWarning), + HPM_POP(ShowDebug), + HPM_POP(ShowError), + HPM_POP(ShowFatalError), }; - void* ShowSubRef[9] = { - ShowMessage, - ShowStatus, - ShowSQL, - ShowInfo, - ShowNotice, - ShowWarning, - ShowDebug, - ShowError, - ShowFatalError, - }; - int i; - for(i = 0; i < 9; i++) { - if( !( ShowSub = plugin_import(plugin->dll, ShowSubNames[i],void **) ) ) { - ShowWarning("HPM:plugin_load: failed to retrieve '%s' for '"CL_WHITE"%s"CL_RESET"', skipping...\n", ShowSubNames[i], filename); + int i, length = ARRAYLENGTH(ToLink); + + for(i = 0; i < length; i++) { + if( !( Link = plugin_import(plugin->dll, ToLink[i].name,void **) ) ) { + ShowWarning("HPM:plugin_load: failed to retrieve '%s' for '"CL_WHITE"%s"CL_RESET"', skipping...\n", ToLink[i].name, filename); HPM->unload(plugin); return false; } - *ShowSub = ShowSubRef[i]; + *Link = ToLink[i].Ref; } + return true; } void hplugin_load(const char* filename) { @@ -114,6 +111,7 @@ void hplugin_load(const char* filename) { struct HPMi_interface **HPMi; bool anyEvent = false; void **import_symbol_ref; + Sql **sql_handle; if( HPM->exists(filename) ) { ShowWarning("HPM:plugin_load: attempting to load duplicate '"CL_WHITE"%s"CL_RESET"', skipping...\n", filename); @@ -153,6 +151,14 @@ void hplugin_load(const char* filename) { *import_symbol_ref = HPM->import_symbol; + if( !( sql_handle = plugin_import(plugin->dll, "mysql_handle",Sql **) ) ) { + ShowWarning("HPM:plugin_load: failed to retrieve 'mysql_handle' for '"CL_WHITE"%s"CL_RESET"', skipping...\n", filename); + HPM->unload(plugin); + return; + } + + *sql_handle = HPM->import_symbol("sql_handle"); + if( !( HPMi = plugin_import(plugin->dll, "HPMi",struct HPMi_interface **) ) ) { ShowWarning("HPM:plugin_load: failed to retrieve 'HPMi' for '"CL_WHITE"%s"CL_RESET"', skipping...\n", filename); HPM->unload(plugin); @@ -181,7 +187,7 @@ void hplugin_load(const char* filename) { return; } - if( !HPM->showmsg_pop(plugin,filename) ) + if( !HPM->populate(plugin,filename) ) return; if( SERVER_TYPE == SERVER_TYPE_MAP ) { @@ -266,6 +272,12 @@ void hplugins_share_defaults(void) { HPM->share(session,"session"); HPM->share(&fd_max,"fd_max"); HPM->share(addr_,"addr"); + /* strlib */ + HPM->share(strlib,"strlib"); + HPM->share(sv,"sv"); + HPM->share(StrBuf,"StrBuf"); + /* sql */ + HPM->share(SQL,"SQL"); /* timer */ HPM->share(gettick,"gettick"); HPM->share(add_timer,"add_timer"); @@ -343,6 +355,6 @@ void hpm_defaults(void) { HPM->share = hplugin_export_symbol; HPM->symbol_defaults = hplugins_share_defaults; HPM->config_read = hplugins_config_read; - HPM->showmsg_pop = hplugin_showmsg_populate; + HPM->populate = hplugin_populate; HPM->symbol_defaults_sub = NULL; } diff --git a/src/common/HPM.h b/src/common/HPM.h index 87d7bdac6..10b1f0e79 100644 --- a/src/common/HPM.h +++ b/src/common/HPM.h @@ -72,7 +72,7 @@ struct HPM_interface { void (*share) (void *, char *); void (*symbol_defaults) (void); void (*config_read) (void); - bool (*showmsg_pop) (struct hplugin *plugin,const char *filename); + bool (*populate) (struct hplugin *plugin,const char *filename); void (*symbol_defaults_sub) (void); } HPM_s; diff --git a/src/common/HPMi.h b/src/common/HPMi.h index f7832d0ec..a58eeed38 100644 --- a/src/common/HPMi.h +++ b/src/common/HPMi.h @@ -7,6 +7,7 @@ #include "../common/cbasetypes.h" #include "../common/core.h" #include "../common/console.h" +#include "../common/sql.h" struct script_state; struct AtCommandInfo; @@ -42,6 +43,8 @@ struct hplugin_info { }; HPExport void *(*import_symbol) (char *name); +HPExport Sql *mysql_handle; + #define GET_SYMBOL(n) import_symbol(n) #define SERVER_TYPE_ALL SERVER_TYPE_LOGIN|SERVER_TYPE_CHAR|SERVER_TYPE_MAP diff --git a/src/common/core.c b/src/common/core.c index 9fd9747aa..8ed0b5801 100644 --- a/src/common/core.c +++ b/src/common/core.c @@ -278,27 +278,32 @@ void usercheck(void) { } #endif } - +void core_defaults(void) { +#ifndef MINICORE + hpm_defaults(); +#endif + console_defaults(); +#ifndef MINICORE + strlib_defaults(); + sql_defaults(); + timer_defaults(); +#endif +} /*====================================== * CORE : MAINROUTINE *--------------------------------------*/ -int main (int argc, char **argv) -{ +int main (int argc, char **argv) { {// initialize program arguments char *p1 = SERVER_NAME = argv[0]; char *p2 = p1; - while ((p1 = strchr(p2, '/')) != NULL || (p1 = strchr(p2, '\\')) != NULL) - { + while ((p1 = strchr(p2, '/')) != NULL || (p1 = strchr(p2, '\\')) != NULL) { SERVER_NAME = ++p1; p2 = p1; } arg_c = argc; arg_v = argv; } -#ifndef MINICORE - hpm_defaults(); -#endif - console_defaults(); + core_defaults(); malloc_init();// needed for Show* in display_title() [FlavioJS] diff --git a/src/common/mmo.h b/src/common/mmo.h index 257a3b42d..581a7a357 100644 --- a/src/common/mmo.h +++ b/src/common/mmo.h @@ -47,7 +47,7 @@ // 20120307 - 2012-03-07aRagexeRE+ - 0x970 #ifndef PACKETVER - #define PACKETVER 20120418 + #define PACKETVER 20130320 #endif //Remove/Comment this line to disable sc_data saving. [Skotlex] diff --git a/src/common/showmsg.c b/src/common/showmsg.c index 50fa972f0..2a3146d35 100644 --- a/src/common/showmsg.c +++ b/src/common/showmsg.c @@ -78,9 +78,9 @@ int console_msg_log = 0;//[Ind] msg error logging } \ else \ {/* dynamic buffer */ \ - buf.d_ = StringBuf_Malloc(); \ - buf.l_ = StringBuf_Vprintf(buf.d_, fmt, args); \ - buf.v_ = StringBuf_Value(buf.d_); \ + buf.d_ = StrBuf->Malloc(); \ + buf.l_ = StrBuf->Vprintf(buf.d_, fmt, args); \ + buf.v_ = StrBuf->Value(buf.d_); \ ShowDebug("showmsg: dynamic buffer used, increase the static buffer size to %d or more.\n", buf.l_+1);\ } \ //define BUFVPRINTF @@ -91,7 +91,7 @@ int console_msg_log = 0;//[Ind] msg error logging #define FREEBUF(buf) \ if( buf.d_ ) \ { \ - StringBuf_Free(buf.d_); \ + StrBuf->Free(buf.d_); \ buf.d_ = NULL; \ } \ buf.v_ = NULL; \ @@ -855,13 +855,13 @@ void ShowConfigWarning(config_setting_t *config, const char *string, ...) { StringBuf buf; va_list ap; - StringBuf_Init(&buf); - StringBuf_AppendStr(&buf, string); - StringBuf_Printf(&buf, " (%s:%d)\n", config_setting_source_file(config), config_setting_source_line(config)); + StrBuf->Init(&buf); + StrBuf->AppendStr(&buf, string); + StrBuf->Printf(&buf, " (%s:%d)\n", config_setting_source_file(config), config_setting_source_line(config)); va_start(ap, string); - _vShowMessage(MSG_WARNING, StringBuf_Value(&buf), ap); + _vShowMessage(MSG_WARNING, StrBuf->Value(&buf), ap); va_end(ap); - StringBuf_Destroy(&buf); + StrBuf->Destroy(&buf); } void ShowDebug(const char *string, ...) { va_list ap; diff --git a/src/common/sql.c b/src/common/sql.c index 3df9bc1c5..391211183 100644 --- a/src/common/sql.c +++ b/src/common/sql.c @@ -22,8 +22,7 @@ int mysql_reconnect_type; unsigned int mysql_reconnect_count; /// Sql handle -struct Sql -{ +struct Sql { StringBuf buf; MYSQL handle; MYSQL_RES* result; @@ -36,8 +35,7 @@ struct Sql // Column length receiver. // Takes care of the possible size missmatch between uint32 and unsigned long. -struct s_column_length -{ +struct s_column_length { uint32* out_length; unsigned long length; }; @@ -46,8 +44,7 @@ typedef struct s_column_length s_column_length; /// Sql statement -struct SqlStmt -{ +struct SqlStmt { StringBuf buf; MYSQL_STMT* stmt; MYSQL_BIND* params; @@ -74,7 +71,7 @@ Sql* Sql_Malloc(void) CREATE(self, Sql, 1); mysql_init(&self->handle); - StringBuf_Init(&self->buf); + StrBuf->Init(&self->buf); self->lengths = NULL; self->result = NULL; self->keepalive = INVALID_TIMER; @@ -92,7 +89,7 @@ int Sql_Connect(Sql* self, const char* user, const char* passwd, const char* hos if( self == NULL ) return SQL_ERROR; - StringBuf_Clear(&self->buf); + StrBuf->Clear(&self->buf); if( !mysql_real_connect(&self->handle, host, user, passwd, db, (unsigned int)port, NULL/*unix_socket*/, 0/*clientflag*/) ) { ShowSQL("%s\n", mysql_error(&self->handle)); @@ -114,18 +111,16 @@ int Sql_Connect(Sql* self, const char* user, const char* passwd, const char* hos /// Retrieves the timeout of the connection. int Sql_GetTimeout(Sql* self, uint32* out_timeout) { - if( self && out_timeout && SQL_SUCCESS == Sql_Query(self, "SHOW VARIABLES LIKE 'wait_timeout'") ) - { + if( self && out_timeout && SQL_SUCCESS == SQL->Query(self, "SHOW VARIABLES LIKE 'wait_timeout'") ) { char* data; size_t len; - if( SQL_SUCCESS == Sql_NextRow(self) && - SQL_SUCCESS == Sql_GetData(self, 1, &data, &len) ) - { + if( SQL_SUCCESS == SQL->NextRow(self) && + SQL_SUCCESS == SQL->GetData(self, 1, &data, &len) ) { *out_timeout = (uint32)strtoul(data, NULL, 10); - Sql_FreeResult(self); + SQL->FreeResult(self); return SQL_SUCCESS; } - Sql_FreeResult(self); + SQL->FreeResult(self); } return SQL_ERROR; } @@ -139,12 +134,11 @@ int Sql_GetColumnNames(Sql* self, const char* table, char* out_buf, size_t buf_l size_t len; size_t off = 0; - if( self == NULL || SQL_ERROR == Sql_Query(self, "EXPLAIN `%s`", table) ) + if( self == NULL || SQL_ERROR == SQL->Query(self, "EXPLAIN `%s`", table) ) return SQL_ERROR; out_buf[off] = '\0'; - while( SQL_SUCCESS == Sql_NextRow(self) && SQL_SUCCESS == Sql_GetData(self, 0, &data, &len) ) - { + while( SQL_SUCCESS == SQL->NextRow(self) && SQL_SUCCESS == SQL->GetData(self, 0, &data, &len) ) { len = strnlen(data, len); if( off + len + 2 > buf_len ) { @@ -157,7 +151,7 @@ int Sql_GetColumnNames(Sql* self, const char* table, char* out_buf, size_t buf_l out_buf[off++] = sep; } out_buf[off] = '\0'; - Sql_FreeResult(self); + SQL->FreeResult(self); return SQL_SUCCESS; } @@ -250,7 +244,7 @@ int Sql_Query(Sql* self, const char* query, ...) va_list args; va_start(args, query); - res = Sql_QueryV(self, query, args); + res = SQL->QueryV(self, query, args); va_end(args); return res; @@ -264,10 +258,10 @@ int Sql_QueryV(Sql* self, const char* query, va_list args) if( self == NULL ) return SQL_ERROR; - Sql_FreeResult(self); - StringBuf_Clear(&self->buf); - StringBuf_Vprintf(&self->buf, query, args); - if( mysql_real_query(&self->handle, StringBuf_Value(&self->buf), (unsigned long)StringBuf_Length(&self->buf)) ) + SQL->FreeResult(self); + StrBuf->Clear(&self->buf); + StrBuf->Vprintf(&self->buf, query, args); + if( mysql_real_query(&self->handle, StrBuf->Value(&self->buf), (unsigned long)StrBuf->Length(&self->buf)) ) { ShowSQL("DB error - %s\n", mysql_error(&self->handle)); hercules_mysql_error_handler(mysql_errno(&self->handle)); @@ -291,10 +285,10 @@ int Sql_QueryStr(Sql* self, const char* query) if( self == NULL ) return SQL_ERROR; - Sql_FreeResult(self); - StringBuf_Clear(&self->buf); - StringBuf_AppendStr(&self->buf, query); - if( mysql_real_query(&self->handle, StringBuf_Value(&self->buf), (unsigned long)StringBuf_Length(&self->buf)) ) + SQL->FreeResult(self); + StrBuf->Clear(&self->buf); + StrBuf->AppendStr(&self->buf, query); + if( mysql_real_query(&self->handle, StrBuf->Value(&self->buf), (unsigned long)StrBuf->Length(&self->buf)) ) { ShowSQL("DB error - %s\n", mysql_error(&self->handle)); hercules_mysql_error_handler(mysql_errno(&self->handle)); @@ -344,13 +338,10 @@ uint64 Sql_NumRows(Sql* self) /// Fetches the next row. -int Sql_NextRow(Sql* self) -{ - if( self && self->result ) - { +int Sql_NextRow(Sql* self) { + if( self && self->result ) { self->row = mysql_fetch_row(self->result); - if( self->row ) - { + if( self->row ) { self->lengths = mysql_fetch_lengths(self->result); return SQL_SUCCESS; } @@ -366,15 +357,11 @@ int Sql_NextRow(Sql* self) /// Gets the data of a column. int Sql_GetData(Sql* self, size_t col, char** out_buf, size_t* out_len) { - if( self && self->row ) - { - if( col < Sql_NumColumns(self) ) - { + if( self && self->row ) { + if( col < SQL->NumColumns(self) ) { if( out_buf ) *out_buf = self->row[col]; if( out_len ) *out_len = (size_t)self->lengths[col]; - } - else - {// out of range - ignore + } else {// out of range - ignore if( out_buf ) *out_buf = NULL; if( out_len ) *out_len = 0; } @@ -386,10 +373,8 @@ int Sql_GetData(Sql* self, size_t col, char** out_buf, size_t* out_len) /// Frees the result of the query. -void Sql_FreeResult(Sql* self) -{ - if( self && self->result ) - { +void Sql_FreeResult(Sql* self) { + if( self && self->result ) { mysql_free_result(self->result); self->result = NULL; self->row = NULL; @@ -404,8 +389,8 @@ void Sql_ShowDebug_(Sql* self, const char* debug_file, const unsigned long debug { if( self == NULL ) ShowDebug("at %s:%lu - self is NULL\n", debug_file, debug_line); - else if( StringBuf_Length(&self->buf) > 0 ) - ShowDebug("at %s:%lu - %s\n", debug_file, debug_line, StringBuf_Value(&self->buf)); + else if( StrBuf->Length(&self->buf) > 0 ) + ShowDebug("at %s:%lu - %s\n", debug_file, debug_line, StrBuf->Value(&self->buf)); else ShowDebug("at %s:%lu\n", debug_file, debug_line); } @@ -417,8 +402,8 @@ void Sql_Free(Sql* self) { if( self ) { - Sql_FreeResult(self); - StringBuf_Destroy(&self->buf); + SQL->FreeResult(self); + StrBuf->Destroy(&self->buf); if( self->keepalive != INVALID_TIMER ) delete_timer(self->keepalive, Sql_P_KeepaliveTimer); aFree(self); } @@ -590,8 +575,7 @@ static void SqlStmt_P_ShowDebugTruncatedColumn(SqlStmt* self, size_t i) /// Allocates and initializes a new SqlStmt handle. -SqlStmt* SqlStmt_Malloc(Sql* sql) -{ +SqlStmt* SqlStmt_Malloc(Sql* sql) { SqlStmt* self; MYSQL_STMT* stmt; @@ -599,13 +583,12 @@ SqlStmt* SqlStmt_Malloc(Sql* sql) return NULL; stmt = mysql_stmt_init(&sql->handle); - if( stmt == NULL ) - { + if( stmt == NULL ) { ShowSQL("DB error - %s\n", mysql_error(&sql->handle)); return NULL; } CREATE(self, SqlStmt, 1); - StringBuf_Init(&self->buf); + StrBuf->Init(&self->buf); self->stmt = stmt; self->params = NULL; self->columns = NULL; @@ -642,9 +625,9 @@ int SqlStmt_PrepareV(SqlStmt* self, const char* query, va_list args) return SQL_ERROR; SqlStmt_FreeResult(self); - StringBuf_Clear(&self->buf); - StringBuf_Vprintf(&self->buf, query, args); - if( mysql_stmt_prepare(self->stmt, StringBuf_Value(&self->buf), (unsigned long)StringBuf_Length(&self->buf)) ) + StrBuf->Clear(&self->buf); + StrBuf->Vprintf(&self->buf, query, args); + if( mysql_stmt_prepare(self->stmt, StrBuf->Value(&self->buf), (unsigned long)StrBuf->Length(&self->buf)) ) { ShowSQL("DB error - %s\n", mysql_stmt_error(self->stmt)); hercules_mysql_error_handler(mysql_stmt_errno(self->stmt)); @@ -664,9 +647,9 @@ int SqlStmt_PrepareStr(SqlStmt* self, const char* query) return SQL_ERROR; SqlStmt_FreeResult(self); - StringBuf_Clear(&self->buf); - StringBuf_AppendStr(&self->buf, query); - if( mysql_stmt_prepare(self->stmt, StringBuf_Value(&self->buf), (unsigned long)StringBuf_Length(&self->buf)) ) + StrBuf->Clear(&self->buf); + StrBuf->AppendStr(&self->buf, query); + if( mysql_stmt_prepare(self->stmt, StrBuf->Value(&self->buf), (unsigned long)StrBuf->Length(&self->buf)) ) { ShowSQL("DB error - %s\n", mysql_stmt_error(self->stmt)); hercules_mysql_error_handler(mysql_stmt_errno(self->stmt)); @@ -933,8 +916,8 @@ void SqlStmt_ShowDebug_(SqlStmt* self, const char* debug_file, const unsigned lo { if( self == NULL ) ShowDebug("at %s:%lu - self is NULL\n", debug_file, debug_line); - else if( StringBuf_Length(&self->buf) > 0 ) - ShowDebug("at %s:%lu - %s\n", debug_file, debug_line, StringBuf_Value(&self->buf)); + else if( StrBuf->Length(&self->buf) > 0 ) + ShowDebug("at %s:%lu - %s\n", debug_file, debug_line, StrBuf->Value(&self->buf)); else ShowDebug("at %s:%lu\n", debug_file, debug_line); } @@ -947,7 +930,7 @@ void SqlStmt_Free(SqlStmt* self) if( self ) { SqlStmt_FreeResult(self); - StringBuf_Destroy(&self->buf); + StrBuf->Destroy(&self->buf); mysql_stmt_close(self->stmt); if( self->params ) aFree(self->params); @@ -1048,7 +1031,7 @@ void Sql_HerculesUpdateCheck(Sql* self) { if( fgets(timestamp,sizeof(timestamp),ufp) ) { unsigned int timestampui = atol(timestamp); - if( SQL_ERROR == Sql_Query(self, "SELECT 1 FROM `sql_updates` WHERE `timestamp` = '%u' LIMIT 1", timestampui) ) + if( SQL_ERROR == SQL->Query(self, "SELECT 1 FROM `sql_updates` WHERE `timestamp` = '%u' LIMIT 1", timestampui) ) Sql_ShowDebug(self); if( Sql_NumRows(self) != 1 ) { ShowSQL("'"CL_WHITE"%s"CL_RESET"' wasn't applied to the database\n",path); @@ -1069,3 +1052,26 @@ void Sql_HerculesUpdateCheck(Sql* self) { void Sql_Init(void) { Sql_inter_server_read("conf/inter-server.conf",true); } +void sql_defaults(void) { + SQL = &sql_s; + + SQL->Connect = Sql_Connect; + SQL->GetTimeout = Sql_GetTimeout; + SQL->GetColumnNames = Sql_GetColumnNames; + SQL->SetEncoding = Sql_SetEncoding; + SQL->Ping = Sql_Ping; + SQL->EscapeString = Sql_EscapeString; + SQL->EscapeStringLen = Sql_EscapeStringLen; + SQL->Query = Sql_Query; + SQL->QueryV = Sql_QueryV; + SQL->QueryStr = Sql_QueryStr; + SQL->LastInsertId = Sql_LastInsertId; + SQL->NumColumns = Sql_NumColumns; + SQL->NumRows = Sql_NumRows; + SQL->NextRow = Sql_NextRow; + SQL->GetData = Sql_GetData; + SQL->FreeResult = Sql_FreeResult; + SQL->ShowDebug_ = Sql_ShowDebug_; + SQL->Free = Sql_Free; + SQL->Malloc = Sql_Malloc; +} diff --git a/src/common/sql.h b/src/common/sql.h index 319581504..d5a0eda2c 100644 --- a/src/common/sql.h +++ b/src/common/sql.h @@ -22,8 +22,7 @@ /// Data type identifier. /// String, enum and blob data types need the buffer length specified. -enum SqlDataType -{ +enum SqlDataType { SQLDT_NULL, // fixed size SQLDT_INT8, @@ -64,149 +63,96 @@ typedef enum SqlDataType SqlDataType; typedef struct Sql Sql; typedef struct SqlStmt SqlStmt; - -/// Allocates and initializes a new Sql handle. -struct Sql* Sql_Malloc(void); - - - -/// Establishes a connection. -/// -/// @return SQL_SUCCESS or SQL_ERROR -int Sql_Connect(Sql* self, const char* user, const char* passwd, const char* host, uint16 port, const char* db); - - - - -/// Retrieves the timeout of the connection. -/// -/// @return SQL_SUCCESS or SQL_ERROR -int Sql_GetTimeout(Sql* self, uint32* out_timeout); - - - - -/// Retrieves the name of the columns of a table into out_buf, with the separator after each name. -/// -/// @return SQL_SUCCESS or SQL_ERROR -int Sql_GetColumnNames(Sql* self, const char* table, char* out_buf, size_t buf_len, char sep); - - - - -/// Changes the encoding of the connection. -/// -/// @return SQL_SUCCESS or SQL_ERROR -int Sql_SetEncoding(Sql* self, const char* encoding); - - - -/// Pings the connection. -/// -/// @return SQL_SUCCESS or SQL_ERROR -int Sql_Ping(Sql* self); - - - -/// Escapes a string. -/// The output buffer must be at least strlen(from)*2+1 in size. -/// -/// @return The size of the escaped string -size_t Sql_EscapeString(Sql* self, char* out_to, const char* from); - - - -/// Escapes a string. -/// The output buffer must be at least from_len*2+1 in size. -/// -/// @return The size of the escaped string -size_t Sql_EscapeStringLen(Sql* self, char* out_to, const char* from, size_t from_len); - - - -/// Executes a query. -/// Any previous result is freed. -/// The query is constructed as if it was sprintf. -/// -/// @return SQL_SUCCESS or SQL_ERROR -int Sql_Query(Sql* self, const char* query, ...); - - - -/// Executes a query. -/// Any previous result is freed. -/// The query is constructed as if it was svprintf. -/// -/// @return SQL_SUCCESS or SQL_ERROR -int Sql_QueryV(Sql* self, const char* query, va_list args); - - - -/// Executes a query. -/// Any previous result is freed. -/// The query is used directly. -/// -/// @return SQL_SUCCESS or SQL_ERROR -int Sql_QueryStr(Sql* self, const char* query); - - - -/// Returns the number of the AUTO_INCREMENT column of the last INSERT/UPDATE query. -/// -/// @return Value of the auto-increment column -uint64 Sql_LastInsertId(Sql* self); - - - -/// Returns the number of columns in each row of the result. -/// -/// @return Number of columns -uint32 Sql_NumColumns(Sql* self); - - - -/// Returns the number of rows in the result. -/// -/// @return Number of rows -uint64 Sql_NumRows(Sql* self); - - - -/// Fetches the next row. -/// The data of the previous row is no longer valid. -/// -/// @return SQL_SUCCESS, SQL_ERROR or SQL_NO_DATA -int Sql_NextRow(Sql* self); - - - -/// Gets the data of a column. -/// The data remains valid until the next row is fetched or the result is freed. -/// -/// @return SQL_SUCCESS or SQL_ERROR -int Sql_GetData(Sql* self, size_t col, char** out_buf, size_t* out_len); - - - -/// Frees the result of the query. -void Sql_FreeResult(Sql* self); - - +struct sql_interface { + /// Establishes a connection. + /// + /// @return SQL_SUCCESS or SQL_ERROR + int (*Connect) (Sql* self, const char* user, const char* passwd, const char* host, uint16 port, const char* db); + /// Retrieves the timeout of the connection. + /// + /// @return SQL_SUCCESS or SQL_ERROR + int (*GetTimeout) (Sql* self, uint32* out_timeout); + /// Retrieves the name of the columns of a table into out_buf, with the separator after each name. + /// + /// @return SQL_SUCCESS or SQL_ERROR + int (*GetColumnNames) (Sql* self, const char* table, char* out_buf, size_t buf_len, char sep); + /// Changes the encoding of the connection. + /// + /// @return SQL_SUCCESS or SQL_ERROR + int (*SetEncoding) (Sql* self, const char* encoding); + /// Pings the connection. + /// + /// @return SQL_SUCCESS or SQL_ERROR + int (*Ping) (Sql* self); + /// Escapes a string. + /// The output buffer must be at least strlen(from)*2+1 in size. + /// + /// @return The size of the escaped string + size_t (*EscapeString) (Sql* self, char* out_to, const char* from); + /// Escapes a string. + /// The output buffer must be at least from_len*2+1 in size. + /// + /// @return The size of the escaped string + size_t (*EscapeStringLen) (Sql* self, char* out_to, const char* from, size_t from_len); + /// Executes a query. + /// Any previous result is freed. + /// The query is constructed as if it was sprintf. + /// + /// @return SQL_SUCCESS or SQL_ERROR + int (*Query) (Sql* self, const char* query, ...); + /// Executes a query. + /// Any previous result is freed. + /// The query is constructed as if it was svprintf. + /// + /// @return SQL_SUCCESS or SQL_ERROR + int (*QueryV) (Sql* self, const char* query, va_list args); + /// Executes a query. + /// Any previous result is freed. + /// The query is used directly. + /// + /// @return SQL_SUCCESS or SQL_ERROR + int (*QueryStr) (Sql* self, const char* query); + /// Returns the number of the AUTO_INCREMENT column of the last INSERT/UPDATE query. + /// + /// @return Value of the auto-increment column + uint64 (*LastInsertId) (Sql* self); + /// Returns the number of columns in each row of the result. + /// + /// @return Number of columns + uint32 (*NumColumns) (Sql* self); + /// Returns the number of rows in the result. + /// + /// @return Number of rows + uint64 (*NumRows) (Sql* self); + /// Fetches the next row. + /// The data of the previous row is no longer valid. + /// + /// @return SQL_SUCCESS, SQL_ERROR or SQL_NO_DATA + int (*NextRow) (Sql* self); + /// Gets the data of a column. + /// The data remains valid until the next row is fetched or the result is freed. + /// + /// @return SQL_SUCCESS or SQL_ERROR + int (*GetData) (Sql* self, size_t col, char** out_buf, size_t* out_len); + /// Frees the result of the query. + void (*FreeResult) (Sql* self); + /// Shows debug information (last query). + void (*ShowDebug_) (Sql* self, const char* debug_file, const unsigned long debug_line); + /// Frees a Sql handle returned by Sql_Malloc. + void (*Free) (Sql* self); + /// Allocates and initializes a new Sql handle. + struct Sql *(*Malloc) (void); +} sql_s; + +struct sql_interface *SQL; + +void sql_defaults(void); #if defined(SQL_REMOVE_SHOWDEBUG) -#define Sql_ShowDebug(self) (void)0 + #define Sql_ShowDebug(self) (void)0 #else -#define Sql_ShowDebug(self) Sql_ShowDebug_(self, __FILE__, __LINE__) + #define Sql_ShowDebug(self) SQL->ShowDebug_(self, __FILE__, __LINE__) #endif -/// Shows debug information (last query). -void Sql_ShowDebug_(Sql* self, const char* debug_file, const unsigned long debug_line); - - - -/// Frees a Sql handle returned by Sql_Malloc. -void Sql_Free(Sql* self); - - /////////////////////////////////////////////////////////////////////////////// // Prepared Statements @@ -221,8 +167,6 @@ void Sql_Free(Sql* self); // 1) SELECT col FROM table WHERE id=? // 2) INSERT INTO table(col1,col2) VALUES(?,?) - - /// Allocates and initializes a new SqlStmt handle. /// It uses the connection of the parent Sql handle. /// Queries in Sql and SqlStmt are independent and don't affect each other. @@ -239,8 +183,6 @@ struct SqlStmt* SqlStmt_Malloc(Sql* sql); /// @return SQL_SUCCESS or SQL_ERROR int SqlStmt_Prepare(SqlStmt* self, const char* query, ...); - - /// Prepares the statement. /// Any previous result is freed and all parameter bindings are removed. /// The query is constructed as if it was svprintf. @@ -328,9 +270,9 @@ void SqlStmt_FreeResult(SqlStmt* self); void Sql_HerculesUpdateCheck(Sql* self); #if defined(SQL_REMOVE_SHOWDEBUG) -#define SqlStmt_ShowDebug(self) (void)0 + #define SqlStmt_ShowDebug(self) (void)0 #else -#define SqlStmt_ShowDebug(self) SqlStmt_ShowDebug_(self, __FILE__, __LINE__) + #define SqlStmt_ShowDebug(self) SqlStmt_ShowDebug_(self, __FILE__, __LINE__) #endif /// Shows debug information (with statement). void SqlStmt_ShowDebug_(SqlStmt* self, const char* debug_file, const unsigned long debug_line); diff --git a/src/common/strlib.c b/src/common/strlib.c index dfacbf136..278542a24 100644 --- a/src/common/strlib.c +++ b/src/common/strlib.c @@ -1,9 +1,11 @@ -// Copyright (c) Athena Dev Teams - Licensed under GNU GPL -// For more information, see LICENCE in the main folder +// Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// See the LICENSE file +// Portions Copyright (c) Athena Dev Teams #include "../common/cbasetypes.h" #include "../common/malloc.h" #include "../common/showmsg.h" +#define STRLIB_C #include "strlib.h" #include @@ -14,8 +16,7 @@ #define J_MAX_MALLOC_SIZE 65535 // escapes a string in-place (' -> \' , \ -> \\ , % -> _) -char* jstrescape (char* pt) -{ +char* jstrescape (char* pt) { //copy from here char *ptr; int i = 0, j = 0; @@ -220,8 +221,7 @@ const char* stristr(const char* haystack, const char* needle) } #ifdef __WIN32 -char* _strtok_r(char *s1, const char *s2, char **lasts) -{ +char* _strtok_r(char *s1, const char *s2, char **lasts) { char *ret; if (s1 == NULL) @@ -618,8 +618,7 @@ int sv_parse_next(struct s_svstate* sv) /// @param npos Size of the pos array /// @param opt Options that determine the parsing behaviour /// @return Number of fields found in the string or -1 if an error occured -int sv_parse(const char* str, int len, int startoff, char delim, int* out_pos, int npos, enum e_svopt opt) -{ +int sv_parse(const char* str, int len, int startoff, char delim, int* out_pos, int npos, enum e_svopt opt) { struct s_svstate sv; int count; @@ -637,8 +636,7 @@ int sv_parse(const char* str, int len, int startoff, char delim, int* out_pos, i // parse count = 0; if( npos > 0 ) out_pos[0] = startoff; - while( !sv.done ) - { + while( !sv.done ) { ++count; if( sv_parse_next(&sv) <= 0 ) return -1;// error @@ -668,8 +666,7 @@ int sv_parse(const char* str, int len, int startoff, char delim, int* out_pos, i /// @param nfields Size of the field array /// @param opt Options that determine the parsing behaviour /// @return Number of fields found in the string or -1 if an error occured -int sv_split(char* str, int len, int startoff, char delim, char** out_fields, int nfields, enum e_svopt opt) -{ +int sv_split(char* str, int len, int startoff, char delim, char** out_fields, int nfields, enum e_svopt opt) { int pos[1024]; int i; int done; @@ -681,30 +678,21 @@ int sv_split(char* str, int len, int startoff, char delim, char** out_fields, in // next line end = str + pos[1]; - if( end[0] == '\0' ) - { + if( end[0] == '\0' ) { *out_fields = end; - } - else if( (opt&SV_TERMINATE_LF) && end[0] == '\n' ) - { + } else if( (opt&SV_TERMINATE_LF) && end[0] == '\n' ) { if( !(opt&SV_KEEP_TERMINATOR) ) end[0] = '\0'; *out_fields = end + 1; - } - else if( (opt&SV_TERMINATE_CRLF) && end[0] == '\r' && end[1] == '\n' ) - { + } else if( (opt&SV_TERMINATE_CRLF) && end[0] == '\r' && end[1] == '\n' ) { if( !(opt&SV_KEEP_TERMINATOR) ) end[0] = end[1] = '\0'; *out_fields = end + 2; - } - else if( (opt&SV_TERMINATE_CR) && end[0] == '\r' ) - { + } else if( (opt&SV_TERMINATE_CR) && end[0] == '\r' ) { if( !(opt&SV_KEEP_TERMINATOR) ) end[0] = '\0'; *out_fields = end + 1; - } - else - { + } else { ShowError("sv_split: unknown line delimiter 0x02%x.\n", (unsigned char)end[0]); return -1;// error } @@ -714,10 +702,8 @@ int sv_split(char* str, int len, int startoff, char delim, char** out_fields, in // fields i = 2; done = 0; - while( done < ret && nfields > 0 ) - { - if( i < ARRAYLENGTH(pos) ) - {// split field + while( done < ret && nfields > 0 ) { + if( i < ARRAYLENGTH(pos) ) { // split field *out_fields = str + pos[i]; end = str + pos[i+1]; *end = '\0'; @@ -726,9 +712,7 @@ int sv_split(char* str, int len, int startoff, char delim, char** out_fields, in ++done; ++out_fields; --nfields; - } - else - {// get more fields + } else { // get more fields sv_parse(str, len, pos[i-1] + 1, delim, pos, ARRAYLENGTH(pos), opt); i = 2; } @@ -748,65 +732,59 @@ int sv_split(char* str, int len, int startoff, char delim, char** out_fields, in /// @param len Length of the source string /// @param escapes Extra characters to be escaped /// @return Length of the escaped string -size_t sv_escape_c(char* out_dest, const char* src, size_t len, const char* escapes) -{ +size_t sv_escape_c(char* out_dest, const char* src, size_t len, const char* escapes) { size_t i; size_t j; if( out_dest == NULL ) return 0;// nothing to do - if( src == NULL ) - {// nothing to escape + if( src == NULL ) { // nothing to escape *out_dest = 0; return 0; } if( escapes == NULL ) escapes = ""; - for( i = 0, j = 0; i < len; ++i ) - { - switch( src[i] ) - { - case '\0':// octal 0 - out_dest[j++] = '\\'; - out_dest[j++] = '0'; - out_dest[j++] = '0'; - out_dest[j++] = '0'; - break; - case '\r':// carriage return - out_dest[j++] = '\\'; - out_dest[j++] = 'r'; - break; - case '\n':// line feed - out_dest[j++] = '\\'; - out_dest[j++] = 'n'; - break; - case '\\':// escape character - out_dest[j++] = '\\'; - out_dest[j++] = '\\'; - break; - default: - if( strchr(escapes,src[i]) ) - {// escape + for( i = 0, j = 0; i < len; ++i ) { + switch( src[i] ) { + case '\0':// octal 0 out_dest[j++] = '\\'; - switch( src[i] ) - { - case '\a': out_dest[j++] = 'a'; break; - case '\b': out_dest[j++] = 'b'; break; - case '\t': out_dest[j++] = 't'; break; - case '\v': out_dest[j++] = 'v'; break; - case '\f': out_dest[j++] = 'f'; break; - case '\?': out_dest[j++] = '?'; break; - default:// to octal - out_dest[j++] = '0'+((char)(((unsigned char)src[i]&0700)>>6)); - out_dest[j++] = '0'+((char)(((unsigned char)src[i]&0070)>>3)); - out_dest[j++] = '0'+((char)(((unsigned char)src[i]&0007) )); - break; + out_dest[j++] = '0'; + out_dest[j++] = '0'; + out_dest[j++] = '0'; + break; + case '\r':// carriage return + out_dest[j++] = '\\'; + out_dest[j++] = 'r'; + break; + case '\n':// line feed + out_dest[j++] = '\\'; + out_dest[j++] = 'n'; + break; + case '\\':// escape character + out_dest[j++] = '\\'; + out_dest[j++] = '\\'; + break; + default: + if( strchr(escapes,src[i]) ) {// escape + out_dest[j++] = '\\'; + switch( src[i] ) { + case '\a': out_dest[j++] = 'a'; break; + case '\b': out_dest[j++] = 'b'; break; + case '\t': out_dest[j++] = 't'; break; + case '\v': out_dest[j++] = 'v'; break; + case '\f': out_dest[j++] = 'f'; break; + case '\?': out_dest[j++] = '?'; break; + default:// to octal + out_dest[j++] = '0'+((char)(((unsigned char)src[i]&0700)>>6)); + out_dest[j++] = '0'+((char)(((unsigned char)src[i]&0070)>>3)); + out_dest[j++] = '0'+((char)(((unsigned char)src[i]&0007) )); + break; + } } - } - else - out_dest[j++] = src[i]; - break; + else + out_dest[j++] = src[i]; + break; } } out_dest[j] = 0; @@ -821,8 +799,7 @@ size_t sv_escape_c(char* out_dest, const char* src, size_t len, const char* esca /// @param src Source string /// @param len Length of the source string /// @return Length of the escaped string -size_t sv_unescape_c(char* out_dest, const char* src, size_t len) -{ +size_t sv_unescape_c(char* out_dest, const char* src, size_t len) { static unsigned char low2hex[256] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,// 0x0? 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,// 0x1? @@ -844,71 +821,58 @@ size_t sv_unescape_c(char* out_dest, const char* src, size_t len) size_t i; size_t j; - for( i = 0, j = 0; i < len; ) - { - if( src[i] == '\\' ) - { + for( i = 0, j = 0; i < len; ) { + if( src[i] == '\\' ) { ++i;// '\\' if( i >= len ) ShowWarning("sv_unescape_c: empty escape sequence\n"); - else if( src[i] == 'x' ) - {// hex escape sequence + else if( src[i] == 'x' ) {// hex escape sequence unsigned char c = 0; unsigned char inrange = 1; ++i;// 'x' - if( i >= len || !ISXDIGIT(src[i]) ) - { + if( i >= len || !ISXDIGIT(src[i]) ) { ShowWarning("sv_unescape_c: \\x with no following hex digits\n"); continue; } - do{ - if( c > 0x0F && inrange ) - { + do { + if( c > 0x0F && inrange ) { ShowWarning("sv_unescape_c: hex escape sequence out of range\n"); inrange = 0; } c = (c<<4)|low2hex[(unsigned char)src[i]];// hex digit ++i; - }while( i < len && ISXDIGIT(src[i]) ); + } while( i < len && ISXDIGIT(src[i]) ); out_dest[j++] = (char)c; - } - else if( src[i] == '0' || src[i] == '1' || src[i] == '2' || src[i] == '3' ) - {// octal escape sequence (255=0377) + } else if( src[i] == '0' || src[i] == '1' || src[i] == '2' || src[i] == '3' ) {// octal escape sequence (255=0377) unsigned char c = src[i]-'0'; ++i;// '0', '1', '2' or '3' - if( i < len && src[i] >= '0' && src[i] <= '7' ) - { + if( i < len && src[i] >= '0' && src[i] <= '7' ) { c = (c<<3)|(src[i]-'0'); ++i;// octal digit } - if( i < len && src[i] >= '0' && src[i] <= '7' ) - { + if( i < len && src[i] >= '0' && src[i] <= '7' ) { c = (c<<3)|(src[i]-'0'); ++i;// octal digit } out_dest[j++] = (char)c; - } - else - {// other escape sequence + } else { // other escape sequence if( strchr(SV_ESCAPE_C_SUPPORTED, src[i]) == NULL ) ShowWarning("sv_unescape_c: unknown escape sequence \\%c\n", src[i]); - switch( src[i] ) - { - case 'a': out_dest[j++] = '\a'; break; - case 'b': out_dest[j++] = '\b'; break; - case 't': out_dest[j++] = '\t'; break; - case 'n': out_dest[j++] = '\n'; break; - case 'v': out_dest[j++] = '\v'; break; - case 'f': out_dest[j++] = '\f'; break; - case 'r': out_dest[j++] = '\r'; break; - case '?': out_dest[j++] = '\?'; break; - default: out_dest[j++] = src[i]; break; + switch( src[i] ) { + case 'a': out_dest[j++] = '\a'; break; + case 'b': out_dest[j++] = '\b'; break; + case 't': out_dest[j++] = '\t'; break; + case 'n': out_dest[j++] = '\n'; break; + case 'v': out_dest[j++] = '\v'; break; + case 'f': out_dest[j++] = '\f'; break; + case 'r': out_dest[j++] = '\r'; break; + case '?': out_dest[j++] = '\?'; break; + default: out_dest[j++] = src[i]; break; } ++i;// escaped character } - } - else + } else out_dest[j++] = src[i++];// normal character } out_dest[j] = 0; @@ -916,31 +880,28 @@ size_t sv_unescape_c(char* out_dest, const char* src, size_t len) } /// Skips a C escape sequence (starting with '\\'). -const char* skip_escaped_c(const char* p) -{ - if( p && *p == '\\' ) - { +const char* skip_escaped_c(const char* p) { + if( p && *p == '\\' ) { ++p; - switch( *p ) - { - case 'x':// hexadecimal - ++p; - while( ISXDIGIT(*p) ) - ++p; - break; - case '0': - case '1': - case '2': - case '3':// octal - ++p; - if( *p >= '0' && *p <= '7' ) + switch( *p ) { + case 'x':// hexadecimal ++p; - if( *p >= '0' && *p <= '7' ) - ++p; - break; - default: - if( *p && strchr(SV_ESCAPE_C_SUPPORTED, *p) ) + while( ISXDIGIT(*p) ) + ++p; + break; + case '0': + case '1': + case '2': + case '3':// octal ++p; + if( *p >= '0' && *p <= '7' ) + ++p; + if( *p >= '0' && *p <= '7' ) + ++p; + break; + default: + if( *p && strchr(SV_ESCAPE_C_SUPPORTED, *p) ) + ++p; } } return p; @@ -958,8 +919,7 @@ const char* skip_escaped_c(const char* p) /// @param maxcols Maximum number of columns of a valid row /// @param parseproc User-supplied row processing function /// @return true on success, false if file could not be opened -bool sv_readdb(const char* directory, const char* filename, char delim, int mincols, int maxcols, int maxrows, bool (*parseproc)(char* fields[], int columns, int current)) -{ +bool sv_readdb(const char* directory, const char* filename, char delim, int mincols, int maxcols, int maxrows, bool (*parseproc)(char* fields[], int columns, int current)) { FILE* fp; int lines = 0; int entries = 0; @@ -971,9 +931,7 @@ bool sv_readdb(const char* directory, const char* filename, char delim, int minc snprintf(path, sizeof(path), "%s/%s", directory, filename); // open file - fp = fopen(path, "r"); - if( fp == NULL ) - { + if( (fp = fopen(path, "r")) == NULL ) { ShowError("sv_readdb: can't read %s\n", path); return false; } @@ -983,12 +941,10 @@ bool sv_readdb(const char* directory, const char* filename, char delim, int minc fields = (char**)aMalloc(fields_length*sizeof(char*)); // process rows one by one - while( fgets(line, sizeof(line), fp) ) - { + while( fgets(line, sizeof(line), fp) ) { lines++; - if( ( match = strstr(line, "//") ) != NULL ) - {// strip comments + if( ( match = strstr(line, "//") ) != NULL ) {// strip comments match[0] = 0; } @@ -998,25 +954,21 @@ bool sv_readdb(const char* directory, const char* filename, char delim, int minc columns = sv_split(line, strlen(line), 0, delim, fields, fields_length, (e_svopt)(SV_TERMINATE_LF|SV_TERMINATE_CRLF)); - if( columns < mincols ) - { + if( columns < mincols ) { ShowError("sv_readdb: Insufficient columns in line %d of \"%s\" (found %d, need at least %d).\n", lines, path, columns, mincols); continue; // not enough columns } - if( columns > maxcols ) - { + if( columns > maxcols ) { ShowError("sv_readdb: Too many columns in line %d of \"%s\" (found %d, maximum is %d).\n", lines, path, columns, maxcols ); continue; // too many columns } - if( entries == maxrows ) - { + if( entries == maxrows ) { ShowError("sv_readdb: Reached the maximum allowed number of entries (%d) when parsing file \"%s\".\n", maxrows, path); break; } // parse this row - if( !parseproc(fields+1, columns, entries) ) - { + if( !parseproc(fields+1, columns, entries) ) { ShowError("sv_readdb: Could not process contents of line %d of \"%s\".\n", lines, path); continue; // invalid row contents } @@ -1039,41 +991,36 @@ bool sv_readdb(const char* directory, const char* filename, char delim, int minc // @author MouseJstr (original) /// Allocates a StringBuf -StringBuf* StringBuf_Malloc() -{ +StringBuf* StringBuf_Malloc() { StringBuf* self; CREATE(self, StringBuf, 1); - StringBuf_Init(self); + StrBuf->Init(self); return self; } /// Initializes a previously allocated StringBuf -void StringBuf_Init(StringBuf* self) -{ +void StringBuf_Init(StringBuf* self) { self->max_ = 1024; self->ptr_ = self->buf_ = (char*)aMalloc(self->max_ + 1); } /// Appends the result of printf to the StringBuf -int StringBuf_Printf(StringBuf* self, const char* fmt, ...) -{ +int StringBuf_Printf(StringBuf* self, const char* fmt, ...) { int len; va_list ap; va_start(ap, fmt); - len = StringBuf_Vprintf(self, fmt, ap); + len = StrBuf->Vprintf(self, fmt, ap); va_end(ap); return len; } /// Appends the result of vprintf to the StringBuf -int StringBuf_Vprintf(StringBuf* self, const char* fmt, va_list ap) -{ +int StringBuf_Vprintf(StringBuf* self, const char* fmt, va_list ap) { int n, size, off; - for(;;) - { + for(;;) { va_list apcopy; /* Try to print in the allocated space. */ size = self->max_ - (self->ptr_ - self->buf_); @@ -1081,8 +1028,7 @@ int StringBuf_Vprintf(StringBuf* self, const char* fmt, va_list ap) n = vsnprintf(self->ptr_, size, fmt, apcopy); va_end(apcopy); /* If that worked, return the length. */ - if( n > -1 && n < size ) - { + if( n > -1 && n < size ) { self->ptr_ += n; return (int)(self->ptr_ - self->buf_); } @@ -1095,13 +1041,11 @@ int StringBuf_Vprintf(StringBuf* self, const char* fmt, va_list ap) } /// Appends the contents of another StringBuf to the StringBuf -int StringBuf_Append(StringBuf* self, const StringBuf* sbuf) -{ +int StringBuf_Append(StringBuf* self, const StringBuf* sbuf) { int available = self->max_ - (self->ptr_ - self->buf_); int needed = (int)(sbuf->ptr_ - sbuf->buf_); - if( needed >= available ) - { + if( needed >= available ) { int off = (int)(self->ptr_ - self->buf_); self->max_ += needed; self->buf_ = (char*)aRealloc(self->buf_, self->max_ + 1); @@ -1114,13 +1058,12 @@ int StringBuf_Append(StringBuf* self, const StringBuf* sbuf) } // Appends str to the StringBuf -int StringBuf_AppendStr(StringBuf* self, const char* str) -{ +int StringBuf_AppendStr(StringBuf* self, const char* str) { int available = self->max_ - (self->ptr_ - self->buf_); int needed = (int)strlen(str); - if( needed >= available ) - {// not enough space, expand the buffer (minimum expansion = 1024) + if( needed >= available ) { + // not enough space, expand the buffer (minimum expansion = 1024) int off = (int)(self->ptr_ - self->buf_); self->max_ += max(needed, 1024); self->buf_ = (char*)aRealloc(self->buf_, self->max_ + 1); @@ -1133,35 +1076,78 @@ int StringBuf_AppendStr(StringBuf* self, const char* str) } // Returns the length of the data in the Stringbuf -int StringBuf_Length(StringBuf* self) -{ +int StringBuf_Length(StringBuf* self) { return (int)(self->ptr_ - self->buf_); } /// Returns the data in the StringBuf -char* StringBuf_Value(StringBuf* self) -{ +char* StringBuf_Value(StringBuf* self) { *self->ptr_ = '\0'; return self->buf_; } /// Clears the contents of the StringBuf -void StringBuf_Clear(StringBuf* self) -{ +void StringBuf_Clear(StringBuf* self) { self->ptr_ = self->buf_; } /// Destroys the StringBuf -void StringBuf_Destroy(StringBuf* self) -{ +void StringBuf_Destroy(StringBuf* self) { aFree(self->buf_); self->ptr_ = self->buf_ = 0; self->max_ = 0; } // Frees a StringBuf returned by StringBuf_Malloc -void StringBuf_Free(StringBuf* self) -{ - StringBuf_Destroy(self); +void StringBuf_Free(StringBuf* self) { + StrBuf->Destroy(self); aFree(self); } +void strlib_defaults(void) { + /* connect */ + strlib = &strlib_s; + StrBuf = &stringbuf_s; + sv = &sv_s; + /* link~u! */ + strlib->jstrescape = jstrescape; + strlib->jmemescapecpy = jmemescapecpy; + strlib->remove_control_chars = remove_control_chars; + strlib->trim = trim; + strlib->normalize_name = normalize_name; + strlib->stristr = stristr; + +#if !(defined(WIN32) && defined(_MSC_VER) && _MSC_VER >= 1400) && !defined(HAVE_STRNLEN) + strlib->strnlen = strnlen; +#endif + +#if defined(WIN32) && defined(_MSC_VER) && _MSC_VER <= 1200 + strlib->strtoull = strtoull; +#endif + strlib->e_mail_check = e_mail_check; + strlib->config_switch = config_switch; + strlib->safestrncpy = safestrncpy; + strlib->safestrnlen = safestrnlen; + strlib->safesnprintf = safesnprintf; + strlib->strline = strline; + strlib->bin2hex = bin2hex; + + StrBuf->Malloc = StringBuf_Malloc; + StrBuf->Init = StringBuf_Init; + StrBuf->Printf = StringBuf_Printf; + StrBuf->Vprintf = StringBuf_Vprintf; + StrBuf->Append = StringBuf_Append; + StrBuf->AppendStr = StringBuf_AppendStr; + StrBuf->Length = StringBuf_Length; + StrBuf->Value = StringBuf_Value; + StrBuf->Clear = StringBuf_Clear; + StrBuf->Destroy = StringBuf_Destroy; + StrBuf->Free = StringBuf_Free; + + sv->parse_next = sv_parse_next; + sv->parse = sv_parse; + sv->split = sv_split; + sv->escape_c = sv_escape_c; + sv->unescape_c = sv_unescape_c; + sv->skip_escaped_c = skip_escaped_c; + sv->readdb = sv_readdb; +} diff --git a/src/common/strlib.h b/src/common/strlib.h index bbc2c6105..af0fb2764 100644 --- a/src/common/strlib.h +++ b/src/common/strlib.h @@ -1,5 +1,6 @@ -// Copyright (c) Athena Dev Teams - Licensed under GNU GPL -// For more information, see LICENCE in the main folder +// Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// See the LICENSE file +// Portions Copyright (c) Athena Dev Teams #ifndef _STRLIB_H_ #define _STRLIB_H_ @@ -11,56 +12,14 @@ #include #undef __USE_GNU -char* jstrescape (char* pt); -char* jstrescapecpy (char* pt, const char* spt); -int jmemescapecpy (char* pt, const char* spt, int size); - -int remove_control_chars(char* str); -char* trim(char* str); -char* normalize_name(char* str,const char* delims); -const char *stristr(const char *haystack, const char *needle); - #ifdef WIN32 -#define HAVE_STRTOK_R -#define strtok_r(s,delim,save_ptr) _strtok_r((s),(delim),(save_ptr)) -char* _strtok_r(char* s1, const char* s2, char** lasts); -#endif - -#if !(defined(WIN32) && defined(_MSC_VER) && _MSC_VER >= 1400) && !defined(HAVE_STRNLEN) -size_t strnlen (const char* string, size_t maxlen); + #define HAVE_STRTOK_R + #define strtok_r(s,delim,save_ptr) _strtok_r((s),(delim),(save_ptr)) + char _strtok_r(char* s1, const char* s2, char** lasts); #endif -#if defined(WIN32) && defined(_MSC_VER) && _MSC_VER <= 1200 -uint64 strtoull(const char* str, char** endptr, int base); -#endif - -int e_mail_check(char* email); -int config_switch(const char* str); - -/// strncpy that always nul-terminates the string -char* safestrncpy(char* dst, const char* src, size_t n); - -/// doesn't crash on null pointer -size_t safestrnlen(const char* string, size_t maxlen); - -/// Works like snprintf, but always nul-terminates the buffer. -/// Returns the size of the string (without nul-terminator) -/// or -1 if the buffer is too small. -int safesnprintf(char* buf, size_t sz, const char* fmt, ...); - -/// Returns the line of the target position in the string. -/// Lines start at 1. -int strline(const char* str, size_t pos); - -/// Produces the hexadecimal representation of the given input. -/// The output buffer must be at least count*2+1 in size. -/// Returns true on success, false on failure. -bool bin2hex(char* output, unsigned char* input, size_t count); - - /// Bitfield determining the behaviour of sv_parse and sv_split. -typedef enum e_svopt -{ +typedef enum e_svopt { // default: no escapes and no line terminator SV_NOESCAPE_NOTERMINATE = 0, // Escapes according to the C compiler. @@ -78,8 +37,7 @@ typedef enum e_svopt /// Parse state. /// The field is [start,end[ -struct s_svstate -{ +struct s_svstate { const char* str; //< string to parse int len; //< string length int off; //< current offset in the string @@ -90,66 +48,144 @@ struct s_svstate bool done; //< if all the text has been parsed }; -/// Parses a single field in a delim-separated string. -/// The delimiter after the field is skipped. -/// -/// @param sv Parse state -/// @return 1 if a field was parsed, 0 if done, -1 on error. -int sv_parse_next(struct s_svstate* sv); - -/// Parses a delim-separated string. -/// Starts parsing at startoff and fills the pos array with position pairs. -/// out_pos[0] and out_pos[1] are the start and end of line. -/// Other position pairs are the start and end of fields. -/// Returns the number of fields found or -1 if an error occurs. -int sv_parse(const char* str, int len, int startoff, char delim, int* out_pos, int npos, enum e_svopt opt); - -/// Splits a delim-separated string. -/// WARNING: this function modifies the input string -/// Starts splitting at startoff and fills the out_fields array. -/// out_fields[0] is the start of the next line. -/// Other entries are the start of fields (nul-teminated). -/// Returns the number of fields found or -1 if an error occurs. -int sv_split(char* str, int len, int startoff, char delim, char** out_fields, int nfields, enum e_svopt opt); - -/// Escapes src to out_dest according to the format of the C compiler. -/// Returns the length of the escaped string. -/// out_dest should be len*4+1 in size. -size_t sv_escape_c(char* out_dest, const char* src, size_t len, const char* escapes); - -/// Unescapes src to out_dest according to the format of the C compiler. -/// Returns the length of the unescaped string. -/// out_dest should be len+1 in size and can be the same buffer as src. -size_t sv_unescape_c(char* out_dest, const char* src, size_t len); - -/// Skips a C escape sequence (starting with '\\'). -const char* skip_escaped_c(const char* p); - -/// Opens and parses a file containing delim-separated columns, feeding them to the specified callback function row by row. -/// Tracks the progress of the operation (current line number, number of successfully processed rows). -/// Returns 'true' if it was able to process the specified file, or 'false' if it could not be read. -bool sv_readdb(const char* directory, const char* filename, char delim, int mincols, int maxcols, int maxrows, bool (*parseproc)(char* fields[], int columns, int current)); - /// StringBuf - dynamic string -struct StringBuf -{ +struct StringBuf { char *buf_; char *ptr_; unsigned int max_; }; typedef struct StringBuf StringBuf; -StringBuf* StringBuf_Malloc(void); -void StringBuf_Init(StringBuf* self); -int StringBuf_Printf(StringBuf* self, const char* fmt, ...); -int StringBuf_Vprintf(StringBuf* self, const char* fmt, va_list args); -int StringBuf_Append(StringBuf* self, const StringBuf *sbuf); -int StringBuf_AppendStr(StringBuf* self, const char* str); -int StringBuf_Length(StringBuf* self); -char* StringBuf_Value(StringBuf* self); -void StringBuf_Clear(StringBuf* self); -void StringBuf_Destroy(StringBuf* self); -void StringBuf_Free(StringBuf* self); - +struct strlib_interface { + char *(*jstrescape) (char* pt); + char *(*jstrescapecpy) (char* pt, const char* spt); + int (*jmemescapecpy) (char* pt, const char* spt, int size); + int (*remove_control_chars) (char* str); + char *(*trim) (char* str); + char *(*normalize_name) (char* str,const char* delims); + const char *(*stristr) (const char *haystack, const char *needle); + +#if !(defined(WIN32) && defined(_MSC_VER) && _MSC_VER >= 1400) && !defined(HAVE_STRNLEN) + size_t (*strnlen) (const char* string, size_t maxlen); +#endif + +#if defined(WIN32) && defined(_MSC_VER) && _MSC_VER <= 1200 + uint64 (*strtoull) (const char* str, char** endptr, int base); +#endif + + int (*e_mail_check) (char* email); + int (*config_switch) (const char* str); + + /// strncpy that always nul-terminates the string + char *(*safestrncpy) (char* dst, const char* src, size_t n); + + /// doesn't crash on null pointer + size_t (*safestrnlen) (const char* string, size_t maxlen); + + /// Works like snprintf, but always nul-terminates the buffer. + /// Returns the size of the string (without nul-terminator) + /// or -1 if the buffer is too small. + int (*safesnprintf) (char* buf, size_t sz, const char* fmt, ...); + + /// Returns the line of the target position in the string. + /// Lines start at 1. + int (*strline) (const char* str, size_t pos); + + /// Produces the hexadecimal representation of the given input. + /// The output buffer must be at least count*2+1 in size. + /// Returns true on success, false on failure. + bool (*bin2hex) (char* output, unsigned char* input, size_t count); +} strlib_s; + +struct strlib_interface *strlib; + +struct stringbuf_interface { + StringBuf* (*Malloc) (void); + void (*Init) (StringBuf* self); + int (*Printf) (StringBuf* self, const char* fmt, ...); + int (*Vprintf) (StringBuf* self, const char* fmt, va_list args); + int (*Append) (StringBuf* self, const StringBuf *sbuf); + int (*AppendStr) (StringBuf* self, const char* str); + int (*Length) (StringBuf* self); + char* (*Value) (StringBuf* self); + void (*Clear) (StringBuf* self); + void (*Destroy) (StringBuf* self); + void (*Free) (StringBuf* self); +} stringbuf_s; + +struct stringbuf_interface *StrBuf; + +struct sv_interface { + /// Parses a single field in a delim-separated string. + /// The delimiter after the field is skipped. + /// + /// @param sv Parse state + /// @return 1 if a field was parsed, 0 if done, -1 on error. + int (*parse_next) (struct s_svstate* sv); + + /// Parses a delim-separated string. + /// Starts parsing at startoff and fills the pos array with position pairs. + /// out_pos[0] and out_pos[1] are the start and end of line. + /// Other position pairs are the start and end of fields. + /// Returns the number of fields found or -1 if an error occurs. + int (*parse) (const char* str, int len, int startoff, char delim, int* out_pos, int npos, enum e_svopt opt); + + /// Splits a delim-separated string. + /// WARNING: this function modifies the input string + /// Starts splitting at startoff and fills the out_fields array. + /// out_fields[0] is the start of the next line. + /// Other entries are the start of fields (nul-teminated). + /// Returns the number of fields found or -1 if an error occurs. + int (*split) (char* str, int len, int startoff, char delim, char** out_fields, int nfields, enum e_svopt opt); + + /// Escapes src to out_dest according to the format of the C compiler. + /// Returns the length of the escaped string. + /// out_dest should be len*4+1 in size. + size_t (*escape_c) (char* out_dest, const char* src, size_t len, const char* escapes); + + /// Unescapes src to out_dest according to the format of the C compiler. + /// Returns the length of the unescaped string. + /// out_dest should be len+1 in size and can be the same buffer as src. + size_t (*unescape_c) (char* out_dest, const char* src, size_t len); + + /// Skips a C escape sequence (starting with '\\'). + const char* (*skip_escaped_c) (const char* p); + + /// Opens and parses a file containing delim-separated columns, feeding them to the specified callback function row by row. + /// Tracks the progress of the operation (current line number, number of successfully processed rows). + /// Returns 'true' if it was able to process the specified file, or 'false' if it could not be read. + bool (*readdb) (const char* directory, const char* filename, char delim, int mincols, int maxcols, int maxrows, bool (*parseproc)(char* fields[], int columns, int current)); +} sv_s; + +struct sv_interface *sv; + +void strlib_defaults(void); + +/* the purpose of these macros is simply to not make calling them be an annoyance */ +#ifndef STRLIB_C + #define jstrescape(pt) strlib->jstrescape(pt) + #define jstrescapecpy(pt,spt) strlib->jstrescapecpy(pt,spt) + #define jmemescapecpy(pt,spt,size) strlib->jmemescapecpy(pt,spt,size) + #define remove_control_chars(str) strlib->remove_control_chars(str) + #define trim(str) strlib->trim(str) + #define normalize_name(str,delims) strlib->normalize_name(str,delims) + #define stristr(haystack,needle) strlib->stristr(haystack,needle) + + #if !(defined(WIN32) && defined(_MSC_VER) && _MSC_VER >= 1400) && !defined(HAVE_STRNLEN) + #define strnln(string,maxlen) strlib->strnlen(string,maxlen) + #endif + + #if defined(WIN32) && defined(_MSC_VER) && _MSC_VER <= 1200 + #define strtoull(str,endptr,base) strlib->strtoull(str,endptr,base) + #endif + + #define e_mail_check(email) strlib->e_mail_check(email) + #define config_switch(str) strlib->config_switch(str) + #define safestrncpy(dst,src,n) strlib->safestrncpy(dst,src,n) + #define safestrnlen(string,maxlen) strlib->safestrnlen(string,maxlen) + #define safesnprintf(buf,sz,fmt,...) strlib->safesnprintf(buf,sz,fmt,##__VA_ARGS__) + #define strline(str,pos) strlib->strline(str,pos) + #define bin2hex(output,input,count) strlib->bin2hex(output,input,count) +#endif /* STRLIB_C */ #endif /* _STRLIB_H_ */ diff --git a/src/common/timer.c b/src/common/timer.c index c239a9d70..1ea1a0d1c 100644 --- a/src/common/timer.c +++ b/src/common/timer.c @@ -1,5 +1,6 @@ -// Copyright (c) Athena Dev Teams - Licensed under GNU GPL -// For more information, see LICENCE in the main folder +// Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// See the LICENSE file +// Portions Copyright (c) Athena Dev Teams #include "../common/cbasetypes.h" #include "../common/db.h" @@ -62,7 +63,7 @@ struct timer_func_list { } *tfl_root = NULL; /// Sets the name of a timer function. -int add_timer_func_list(TimerFunc func, char* name) +int timer_add_func_list(TimerFunc func, char* name) { struct timer_func_list* tfl; @@ -70,9 +71,9 @@ int add_timer_func_list(TimerFunc func, char* name) for( tfl=tfl_root; tfl != NULL; tfl=tfl->next ) {// check suspicious cases if( func == tfl->func ) - ShowWarning("add_timer_func_list: duplicating function %p(%s) as %s.\n",tfl->func,tfl->name,name); + ShowWarning("timer_add_func_list: duplicating function %p(%s) as %s.\n",tfl->func,tfl->name,name); else if( strcmp(name,tfl->name) == 0 ) - ShowWarning("add_timer_func_list: function %p has the same name as %p(%s)\n",func,tfl->func,tfl->name); + ShowWarning("timer_add_func_list: function %p has the same name as %p(%s)\n",func,tfl->func,tfl->name); } CREATE(tfl,struct timer_func_list,1); tfl->next = tfl_root; @@ -137,8 +138,7 @@ static void rdtsc_calibrate(){ #endif /// platform-abstracted tick retrieval -static unsigned int tick(void) -{ +static unsigned int tick(void) { #if defined(WIN32) return GetTickCount(); #elif defined(ENABLE_RDTSC) @@ -163,28 +163,25 @@ static unsigned int tick(void) static unsigned int gettick_cache; static int gettick_count = 1; -unsigned int gettick_nocache(void) -{ +unsigned int timer_gettick_nocache(void) { gettick_count = TICK_CACHE; gettick_cache = tick(); return gettick_cache; } -unsigned int gettick(void) -{ +unsigned int timer_gettick(void) { return ( --gettick_count == 0 ) ? gettick_nocache() : gettick_cache; } ////////////////////////////// #else ////////////////////////////// // tick doesn't get cached -unsigned int gettick_nocache(void) +unsigned int timer_gettick_nocache(void) { return tick(); } -unsigned int gettick(void) -{ +unsigned int timer_gettick(void) { return tick(); } ////////////////////////////////////////////////////////////////////////// @@ -196,8 +193,7 @@ unsigned int gettick(void) *--------------------------------------*/ /// Adds a timer to the timer_heap -static void push_timer_heap(int tid) -{ +static void push_timer_heap(int tid) { BHEAP_ENSURE(timer_heap, 1, 256); BHEAP_PUSH(timer_heap, tid, DIFFTICK_MINTOPCMP); } @@ -207,8 +203,7 @@ static void push_timer_heap(int tid) *--------------------------*/ /// Returns a free timer id. -static int acquire_timer(void) -{ +static int acquire_timer(void) { int tid; // select a free timer @@ -240,8 +235,7 @@ static int acquire_timer(void) /// Starts a new timer that is deleted once it expires (single-use). /// Returns the timer's id. -int add_timer(unsigned int tick, TimerFunc func, int id, intptr_t data) -{ +int timer_add(unsigned int tick, TimerFunc func, int id, intptr_t data) { int tid; tid = acquire_timer(); @@ -258,13 +252,12 @@ int add_timer(unsigned int tick, TimerFunc func, int id, intptr_t data) /// Starts a new timer that automatically restarts itself (infinite loop until manually removed). /// Returns the timer's id, or INVALID_TIMER if it fails. -int add_timer_interval(unsigned int tick, TimerFunc func, int id, intptr_t data, int interval) +int timer_add_interval(unsigned int tick, TimerFunc func, int id, intptr_t data, int interval) { int tid; - if( interval < 1 ) - { - ShowError("add_timer_interval: invalid interval (tick=%u %p[%s] id=%d data=%d diff_tick=%d)\n", tick, func, search_timer_func_list(func), id, data, DIFF_TICK(tick, gettick())); + if( interval < 1 ) { + ShowError("timer_add_interval: invalid interval (tick=%u %p[%s] id=%d data=%d diff_tick=%d)\n", tick, func, search_timer_func_list(func), id, data, DIFF_TICK(tick, gettick())); return INVALID_TIMER; } @@ -281,24 +274,20 @@ int add_timer_interval(unsigned int tick, TimerFunc func, int id, intptr_t data, } /// Retrieves internal timer data -const struct TimerData* get_timer(int tid) -{ +const struct TimerData* timer_get(int tid) { return ( tid >= 0 && tid < timer_data_num ) ? &timer_data[tid] : NULL; } /// Marks a timer specified by 'id' for immediate deletion once it expires. /// Param 'func' is used for debug/verification purposes. /// Returns 0 on success, < 0 on failure. -int delete_timer(int tid, TimerFunc func) -{ - if( tid < 0 || tid >= timer_data_num ) - { - ShowError("delete_timer error : no such timer %d (%p(%s))\n", tid, func, search_timer_func_list(func)); +int timer_delete(int tid, TimerFunc func) { + if( tid < 0 || tid >= timer_data_num ) { + ShowError("timer_delete error : no such timer %d (%p(%s))\n", tid, func, search_timer_func_list(func)); return -1; } - if( timer_data[tid].func != func ) - { - ShowError("delete_timer error : function mismatch %p(%s) != %p(%s)\n", timer_data[tid].func, search_timer_func_list(timer_data[tid].func), func, search_timer_func_list(func)); + if( timer_data[tid].func != func ) { + ShowError("timer_delete error : function mismatch %p(%s) != %p(%s)\n", timer_data[tid].func, search_timer_func_list(timer_data[tid].func), func, search_timer_func_list(func)); return -2; } @@ -310,22 +299,19 @@ int delete_timer(int tid, TimerFunc func) /// Adjusts a timer's expiration time. /// Returns the new tick value, or -1 if it fails. -int addtick_timer(int tid, unsigned int tick) -{ +int timer_addtick(int tid, unsigned int tick) { return settick_timer(tid, timer_data[tid].tick+tick); } /// Modifies a timer's expiration time (an alternative to deleting a timer and starting a new one). /// Returns the new tick value, or -1 if it fails. -int settick_timer(int tid, unsigned int tick) -{ +int timer_settick(int tid, unsigned int tick) { size_t i; // search timer position ARR_FIND(0, BHEAP_LENGTH(timer_heap), i, BHEAP_DATA(timer_heap)[i] == tid); - if( i == BHEAP_LENGTH(timer_heap) ) - { - ShowError("settick_timer: no such timer %d (%p(%s))\n", tid, timer_data[tid].func, search_timer_func_list(timer_data[tid].func)); + if( i == BHEAP_LENGTH(timer_heap) ) { + ShowError("timer_settick: no such timer %d (%p(%s))\n", tid, timer_data[tid].func, search_timer_func_list(timer_data[tid].func)); return -1; } @@ -344,13 +330,11 @@ int settick_timer(int tid, unsigned int tick) /// Executes all expired timers. /// Returns the value of the smallest non-expired timer (or 1 second if there aren't any). -int do_timer(unsigned int tick) -{ +int do_timer(unsigned int tick) { int diff = TIMER_MAX_INTERVAL; // return value // process all timers one by one - while( BHEAP_LENGTH(timer_heap) ) - { + while( BHEAP_LENGTH(timer_heap) ) { int tid = BHEAP_PEEK(timer_heap);// top element in heap (smallest tick) diff = DIFF_TICK(timer_data[tid].tick, tick); @@ -361,8 +345,7 @@ int do_timer(unsigned int tick) BHEAP_POP(timer_heap, DIFFTICK_MINTOPCMP); timer_data[tid].type |= TIMER_REMOVE_HEAP; - if( timer_data[tid].func ) - { + if( timer_data[tid].func ) { if( diff < -1000 ) // timer was delayed for more than 1 second, use current tick instead timer_data[tid].func(tid, tick, timer_data[tid].id, timer_data[tid].data); @@ -371,29 +354,27 @@ int do_timer(unsigned int tick) } // in the case the function didn't change anything... - if( timer_data[tid].type & TIMER_REMOVE_HEAP ) - { + if( timer_data[tid].type & TIMER_REMOVE_HEAP ) { timer_data[tid].type &= ~TIMER_REMOVE_HEAP; - switch( timer_data[tid].type ) - { - default: - case TIMER_ONCE_AUTODEL: - timer_data[tid].type = 0; - if (free_timer_list_pos >= free_timer_list_max) { - free_timer_list_max += 256; - RECREATE(free_timer_list,int,free_timer_list_max); - memset(free_timer_list + (free_timer_list_max - 256), 0, 256 * sizeof(int)); - } - free_timer_list[free_timer_list_pos++] = tid; - break; - case TIMER_INTERVAL: - if( DIFF_TICK(timer_data[tid].tick, tick) < -1000 ) - timer_data[tid].tick = tick + timer_data[tid].interval; - else - timer_data[tid].tick += timer_data[tid].interval; - push_timer_heap(tid); - break; + switch( timer_data[tid].type ) { + default: + case TIMER_ONCE_AUTODEL: + timer_data[tid].type = 0; + if (free_timer_list_pos >= free_timer_list_max) { + free_timer_list_max += 256; + RECREATE(free_timer_list,int,free_timer_list_max); + memset(free_timer_list + (free_timer_list_max - 256), 0, 256 * sizeof(int)); + } + free_timer_list[free_timer_list_pos++] = tid; + break; + case TIMER_INTERVAL: + if( DIFF_TICK(timer_data[tid].tick, tick) < -1000 ) + timer_data[tid].tick = tick + timer_data[tid].interval; + else + timer_data[tid].tick += timer_data[tid].interval; + push_timer_heap(tid); + break; } } } @@ -401,8 +382,7 @@ int do_timer(unsigned int tick) return cap_value(diff, TIMER_MIN_INTERVAL, TIMER_MAX_INTERVAL); } -unsigned long get_uptime(void) -{ +unsigned long timer_get_uptime(void) { return (unsigned long)difftime(time(NULL), start_time); } @@ -415,8 +395,7 @@ void timer_init(void) time(&start_time); } -void timer_final(void) -{ +void timer_final(void) { struct timer_func_list *tfl; struct timer_func_list *next; @@ -430,3 +409,15 @@ void timer_final(void) BHEAP_CLEAR(timer_heap); if (free_timer_list) aFree(free_timer_list); } +void timer_defaults(void) { + gettick = timer_gettick; + gettick_nocache = timer_gettick_nocache; + add_timer = timer_add; + add_timer_interval = timer_add_interval; + add_timer_func_list = timer_add_func_list; + get_timer = timer_get; + delete_timer = timer_delete; + addtick_timer = timer_addtick; + settick_timer = timer_settick; + get_uptime = timer_get_uptime; +} diff --git a/src/common/timer.h b/src/common/timer.h index d45c73d12..902679f51 100644 --- a/src/common/timer.h +++ b/src/common/timer.h @@ -1,5 +1,6 @@ -// Copyright (c) Athena Dev Teams - Licensed under GNU GPL -// For more information, see LICENCE in the main folder +// Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// See the LICENSE file +// Portions Copyright (c) Athena Dev Teams #ifndef _TIMER_H_ #define _TIMER_H_ @@ -35,23 +36,26 @@ struct TimerData { // Function prototype declaration -unsigned int gettick(void); -unsigned int gettick_nocache(void); +int do_timer(unsigned int tick); +void timer_init(void); +void timer_final(void); -int add_timer(unsigned int tick, TimerFunc func, int id, intptr_t data); -int add_timer_interval(unsigned int tick, TimerFunc func, int id, intptr_t data, int interval); -const struct TimerData* get_timer(int tid); -int delete_timer(int tid, TimerFunc func); +/* Hercules Renewal Phase One */ +unsigned int (*gettick) (void); +unsigned int (*gettick_nocache) (void); -int addtick_timer(int tid, unsigned int tick); -int settick_timer(int tid, unsigned int tick); +int (*add_timer) (unsigned int tick, TimerFunc func, int id, intptr_t data); +int (*add_timer_interval) (unsigned int tick, TimerFunc func, int id, intptr_t data, int interval); +const struct TimerData *(*get_timer) (int tid); +int (*delete_timer) (int tid, TimerFunc func); -int add_timer_func_list(TimerFunc func, char* name); +int (*addtick_timer) (int tid, unsigned int tick); +int (*settick_timer) (int tid, unsigned int tick); -unsigned long get_uptime(void); +int (*add_timer_func_list) (TimerFunc func, char* name); -int do_timer(unsigned int tick); -void timer_init(void); -void timer_final(void); +unsigned long (*get_uptime) (void); + +void timer_defaults(void); #endif /* _TIMER_H_ */ diff --git a/src/login/account_sql.c b/src/login/account_sql.c index 1d77f1975..565dd0460 100644 --- a/src/login/account_sql.c +++ b/src/login/account_sql.c @@ -1,5 +1,6 @@ -// Copyright (c) Athena Dev Teams - Licensed under GNU GPL -// For more information, see LICENCE in the main folder +// Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// See the LICENSE file +// Portions Copyright (c) Athena Dev Teams #include "../common/malloc.h" #include "../common/mmo.h" @@ -125,7 +126,7 @@ static bool account_db_sql_init(AccountDB* self) const char* database; const char* codepage; - db->accounts = Sql_Malloc(); + db->accounts = SQL->Malloc(); sql_handle = db->accounts; if( db->db_hostname[0] != '\0' ) @@ -147,15 +148,15 @@ static bool account_db_sql_init(AccountDB* self) codepage = db->global_codepage; } - if( SQL_ERROR == Sql_Connect(sql_handle, username, password, hostname, port, database) ) + if( SQL_ERROR == SQL->Connect(sql_handle, username, password, hostname, port, database) ) { Sql_ShowDebug(sql_handle); - Sql_Free(db->accounts); + SQL->Free(db->accounts); db->accounts = NULL; return false; } - if( codepage[0] != '\0' && SQL_ERROR == Sql_SetEncoding(sql_handle, codepage) ) + if( codepage[0] != '\0' && SQL_ERROR == SQL->SetEncoding(sql_handle, codepage) ) Sql_ShowDebug(sql_handle); return true; @@ -166,7 +167,7 @@ static void account_db_sql_destroy(AccountDB* self) { AccountDB_SQL* db = (AccountDB_SQL*)self; - Sql_Free(db->accounts); + SQL->Free(db->accounts); db->accounts = NULL; aFree(db); } @@ -348,21 +349,21 @@ static bool account_db_sql_create(AccountDB* self, struct mmo_account* acc) char* data; size_t len; - if( SQL_SUCCESS != Sql_Query(sql_handle, "SELECT MAX(`account_id`)+1 FROM `%s`", db->account_db) ) + if( SQL_SUCCESS != SQL->Query(sql_handle, "SELECT MAX(`account_id`)+1 FROM `%s`", db->account_db) ) { Sql_ShowDebug(sql_handle); return false; } - if( SQL_SUCCESS != Sql_NextRow(sql_handle) ) + if( SQL_SUCCESS != SQL->NextRow(sql_handle) ) { Sql_ShowDebug(sql_handle); - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); return false; } - Sql_GetData(sql_handle, 0, &data, &len); + SQL->GetData(sql_handle, 0, &data, &len); account_id = ( data != NULL ) ? atoi(data) : 0; - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); if( account_id < START_ACCOUNT_NUM ) account_id = START_ACCOUNT_NUM; @@ -389,14 +390,14 @@ static bool account_db_sql_remove(AccountDB* self, const int account_id) Sql* sql_handle = db->accounts; bool result = false; - if( SQL_SUCCESS != Sql_QueryStr(sql_handle, "START TRANSACTION") - || SQL_SUCCESS != Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `account_id` = %d", db->account_db, account_id) - || SQL_SUCCESS != Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `account_id` = %d", db->accreg_db, account_id) ) + if( SQL_SUCCESS != SQL->QueryStr(sql_handle, "START TRANSACTION") + || SQL_SUCCESS != SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `account_id` = %d", db->account_db, account_id) + || SQL_SUCCESS != SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `account_id` = %d", db->accreg_db, account_id) ) Sql_ShowDebug(sql_handle); else result = true; - result &= ( SQL_SUCCESS == Sql_QueryStr(sql_handle, (result == true) ? "COMMIT" : "ROLLBACK") ); + result &= ( SQL_SUCCESS == SQL->QueryStr(sql_handle, (result == true) ? "COMMIT" : "ROLLBACK") ); return result; } @@ -424,30 +425,30 @@ static bool account_db_sql_load_str(AccountDB* self, struct mmo_account* acc, co int account_id; char* data; - Sql_EscapeString(sql_handle, esc_userid, userid); + SQL->EscapeString(sql_handle, esc_userid, userid); // get the list of account IDs for this user ID - if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `account_id` FROM `%s` WHERE `userid`= %s '%s'", + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `account_id` FROM `%s` WHERE `userid`= %s '%s'", db->account_db, (db->case_sensitive ? "BINARY" : ""), esc_userid) ) { Sql_ShowDebug(sql_handle); return false; } - if( Sql_NumRows(sql_handle) > 1 ) + if( SQL->NumRows(sql_handle) > 1 ) {// serious problem - duplicit account ShowError("account_db_sql_load_str: multiple accounts found when retrieving data for account '%s'!\n", userid); - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); return false; } - if( SQL_SUCCESS != Sql_NextRow(sql_handle) ) + if( SQL_SUCCESS != SQL->NextRow(sql_handle) ) {// no such entry - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); return false; } - Sql_GetData(sql_handle, 0, &data, NULL); + SQL->GetData(sql_handle, 0, &data, NULL); account_id = atoi(data); return account_db_sql_load_num(self, acc, account_id); @@ -489,15 +490,15 @@ static bool account_db_sql_iter_next(AccountDBIterator* self, struct mmo_account char* data; // get next account ID - if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `account_id` FROM `%s` WHERE `account_id` > '%d' ORDER BY `account_id` ASC LIMIT 1", + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `account_id` FROM `%s` WHERE `account_id` > '%d' ORDER BY `account_id` ASC LIMIT 1", db->account_db, iter->last_account_id) ) { Sql_ShowDebug(sql_handle); return false; } - if( SQL_SUCCESS == Sql_NextRow(sql_handle) && - SQL_SUCCESS == Sql_GetData(sql_handle, 0, &data, NULL) && + if( SQL_SUCCESS == SQL->NextRow(sql_handle) && + SQL_SUCCESS == SQL->GetData(sql_handle, 0, &data, NULL) && data != NULL ) {// get account data int account_id; @@ -505,11 +506,11 @@ static bool account_db_sql_iter_next(AccountDBIterator* self, struct mmo_account if( mmo_auth_fromsql(db, acc, account_id) ) { iter->last_account_id = account_id; - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); return true; } } - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); return false; } @@ -521,7 +522,7 @@ static bool mmo_auth_fromsql(AccountDB_SQL* db, struct mmo_account* acc, int acc int i = 0; // retrieve login entry for the specified account - if( SQL_ERROR == Sql_Query(sql_handle, + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `account_id`,`userid`,`user_pass`,`sex`,`email`,`group_id`,`state`,`unban_time`,`expiration_time`,`logincount`,`lastlogin`,`last_ip`,`birthdate`,`character_slots`,`pincode`,`pincode_change` FROM `%s` WHERE `account_id` = %d", db->account_db, account_id ) ) { @@ -529,49 +530,49 @@ static bool mmo_auth_fromsql(AccountDB_SQL* db, struct mmo_account* acc, int acc return false; } - if( SQL_SUCCESS != Sql_NextRow(sql_handle) ) + if( SQL_SUCCESS != SQL->NextRow(sql_handle) ) {// no such entry - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); return false; } - Sql_GetData(sql_handle, 0, &data, NULL); acc->account_id = atoi(data); - Sql_GetData(sql_handle, 1, &data, NULL); safestrncpy(acc->userid, data, sizeof(acc->userid)); - Sql_GetData(sql_handle, 2, &data, NULL); safestrncpy(acc->pass, data, sizeof(acc->pass)); - Sql_GetData(sql_handle, 3, &data, NULL); acc->sex = data[0]; - Sql_GetData(sql_handle, 4, &data, NULL); safestrncpy(acc->email, data, sizeof(acc->email)); - Sql_GetData(sql_handle, 5, &data, NULL); acc->group_id = atoi(data); - Sql_GetData(sql_handle, 6, &data, NULL); acc->state = strtoul(data, NULL, 10); - Sql_GetData(sql_handle, 7, &data, NULL); acc->unban_time = atol(data); - Sql_GetData(sql_handle, 8, &data, NULL); acc->expiration_time = atol(data); - Sql_GetData(sql_handle, 9, &data, NULL); acc->logincount = strtoul(data, NULL, 10); - Sql_GetData(sql_handle, 10, &data, NULL); safestrncpy(acc->lastlogin, data, sizeof(acc->lastlogin)); - Sql_GetData(sql_handle, 11, &data, NULL); safestrncpy(acc->last_ip, data, sizeof(acc->last_ip)); - Sql_GetData(sql_handle, 12, &data, NULL); safestrncpy(acc->birthdate, data, sizeof(acc->birthdate)); - Sql_GetData(sql_handle, 13, &data, NULL); acc->char_slots = atoi(data); - Sql_GetData(sql_handle, 14, &data, NULL); safestrncpy(acc->pincode, data, sizeof(acc->pincode)); - Sql_GetData(sql_handle, 15, &data, NULL); acc->pincode_change = atol(data); + SQL->GetData(sql_handle, 0, &data, NULL); acc->account_id = atoi(data); + SQL->GetData(sql_handle, 1, &data, NULL); safestrncpy(acc->userid, data, sizeof(acc->userid)); + SQL->GetData(sql_handle, 2, &data, NULL); safestrncpy(acc->pass, data, sizeof(acc->pass)); + SQL->GetData(sql_handle, 3, &data, NULL); acc->sex = data[0]; + SQL->GetData(sql_handle, 4, &data, NULL); safestrncpy(acc->email, data, sizeof(acc->email)); + SQL->GetData(sql_handle, 5, &data, NULL); acc->group_id = atoi(data); + SQL->GetData(sql_handle, 6, &data, NULL); acc->state = strtoul(data, NULL, 10); + SQL->GetData(sql_handle, 7, &data, NULL); acc->unban_time = atol(data); + SQL->GetData(sql_handle, 8, &data, NULL); acc->expiration_time = atol(data); + SQL->GetData(sql_handle, 9, &data, NULL); acc->logincount = strtoul(data, NULL, 10); + SQL->GetData(sql_handle, 10, &data, NULL); safestrncpy(acc->lastlogin, data, sizeof(acc->lastlogin)); + SQL->GetData(sql_handle, 11, &data, NULL); safestrncpy(acc->last_ip, data, sizeof(acc->last_ip)); + SQL->GetData(sql_handle, 12, &data, NULL); safestrncpy(acc->birthdate, data, sizeof(acc->birthdate)); + SQL->GetData(sql_handle, 13, &data, NULL); acc->char_slots = atoi(data); + SQL->GetData(sql_handle, 14, &data, NULL); safestrncpy(acc->pincode, data, sizeof(acc->pincode)); + SQL->GetData(sql_handle, 15, &data, NULL); acc->pincode_change = atol(data); - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); // retrieve account regs for the specified user - if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `str`,`value` FROM `%s` WHERE `type`='1' AND `account_id`='%d'", db->accreg_db, acc->account_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `str`,`value` FROM `%s` WHERE `type`='1' AND `account_id`='%d'", db->accreg_db, acc->account_id) ) { Sql_ShowDebug(sql_handle); return false; } - acc->account_reg2_num = (int)Sql_NumRows(sql_handle); + acc->account_reg2_num = (int)SQL->NumRows(sql_handle); - while( SQL_SUCCESS == Sql_NextRow(sql_handle) ) + while( SQL_SUCCESS == SQL->NextRow(sql_handle) ) { char* data; - Sql_GetData(sql_handle, 0, &data, NULL); safestrncpy(acc->account_reg2[i].str, data, sizeof(acc->account_reg2[i].str)); - Sql_GetData(sql_handle, 1, &data, NULL); safestrncpy(acc->account_reg2[i].value, data, sizeof(acc->account_reg2[i].value)); + SQL->GetData(sql_handle, 0, &data, NULL); safestrncpy(acc->account_reg2[i].str, data, sizeof(acc->account_reg2[i].str)); + SQL->GetData(sql_handle, 1, &data, NULL); safestrncpy(acc->account_reg2[i].value, data, sizeof(acc->account_reg2[i].value)); ++i; } - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); if( i != acc->account_reg2_num ) return false; @@ -590,7 +591,7 @@ static bool mmo_auth_tosql(AccountDB_SQL* db, const struct mmo_account* acc, boo do { - if( SQL_SUCCESS != Sql_QueryStr(sql_handle, "START TRANSACTION") ) + if( SQL_SUCCESS != SQL->QueryStr(sql_handle, "START TRANSACTION") ) { Sql_ShowDebug(sql_handle); break; @@ -647,7 +648,7 @@ static bool mmo_auth_tosql(AccountDB_SQL* db, const struct mmo_account* acc, boo } // remove old account regs - if( SQL_SUCCESS != Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `type`='1' AND `account_id`='%d'", db->accreg_db, acc->account_id) ) + if( SQL_SUCCESS != SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `type`='1' AND `account_id`='%d'", db->accreg_db, acc->account_id) ) { Sql_ShowDebug(sql_handle); break; @@ -680,7 +681,7 @@ static bool mmo_auth_tosql(AccountDB_SQL* db, const struct mmo_account* acc, boo } while(0); // finally - result &= ( SQL_SUCCESS == Sql_QueryStr(sql_handle, (result == true) ? "COMMIT" : "ROLLBACK") ); + result &= ( SQL_SUCCESS == SQL->QueryStr(sql_handle, (result == true) ? "COMMIT" : "ROLLBACK") ); SqlStmt_Free(stmt); return result; diff --git a/src/login/ipban_sql.c b/src/login/ipban_sql.c index c75a1f956..701d3bc1d 100644 --- a/src/login/ipban_sql.c +++ b/src/login/ipban_sql.c @@ -1,5 +1,6 @@ -// Copyright (c) Athena Dev Teams - Licensed under GNU GPL -// For more information, see LICENCE in the main folder +// Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// See the LICENSE file +// Portions Copyright (c) Athena Dev Teams #include "../common/cbasetypes.h" #include "../common/db.h" @@ -73,14 +74,14 @@ void ipban_init(void) } // establish connections - sql_handle = Sql_Malloc(); - if( SQL_ERROR == Sql_Connect(sql_handle, username, password, hostname, port, database) ) + sql_handle = SQL->Malloc(); + if( SQL_ERROR == SQL->Connect(sql_handle, username, password, hostname, port, database) ) { Sql_ShowDebug(sql_handle); - Sql_Free(sql_handle); + SQL->Free(sql_handle); exit(EXIT_FAILURE); } - if( codepage[0] != '\0' && SQL_ERROR == Sql_SetEncoding(sql_handle, codepage) ) + if( codepage[0] != '\0' && SQL_ERROR == SQL->SetEncoding(sql_handle, codepage) ) Sql_ShowDebug(sql_handle); if( login_config.ipban_cleanup_interval > 0 ) @@ -104,7 +105,7 @@ void ipban_final(void) ipban_cleanup(0,0,0,0); // always clean up on login-server stop // close connections - Sql_Free(sql_handle); + SQL->Free(sql_handle); sql_handle = NULL; } @@ -207,7 +208,7 @@ bool ipban_check(uint32 ip) if( !login_config.ipban ) return false;// ipban disabled - if( SQL_ERROR == Sql_Query(sql_handle, "SELECT count(*) FROM `%s` WHERE `rtime` > NOW() AND (`list` = '%u.*.*.*' OR `list` = '%u.%u.*.*' OR `list` = '%u.%u.%u.*' OR `list` = '%u.%u.%u.%u')", + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT count(*) FROM `%s` WHERE `rtime` > NOW() AND (`list` = '%u.*.*.*' OR `list` = '%u.%u.*.*' OR `list` = '%u.%u.%u.*' OR `list` = '%u.%u.%u.%u')", ipban_table, p[3], p[3], p[2], p[3], p[2], p[1], p[3], p[2], p[1], p[0]) ) { Sql_ShowDebug(sql_handle); @@ -215,12 +216,12 @@ bool ipban_check(uint32 ip) return true; } - if( SQL_ERROR == Sql_NextRow(sql_handle) ) + if( SQL_ERROR == SQL->NextRow(sql_handle) ) return true;// Shouldn't happen, but just in case... - Sql_GetData(sql_handle, 0, &data, NULL); + SQL->GetData(sql_handle, 0, &data, NULL); matches = atoi(data); - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); return( matches > 0 ); } @@ -239,7 +240,7 @@ void ipban_log(uint32 ip) if( failures >= login_config.dynamic_pass_failure_ban_limit ) { uint8* p = (uint8*)&ip; - if( SQL_ERROR == Sql_Query(sql_handle, "INSERT INTO `%s`(`list`,`btime`,`rtime`,`reason`) VALUES ('%u.%u.%u.*', NOW() , NOW() + INTERVAL %d MINUTE ,'Password error ban')", + if( SQL_ERROR == SQL->Query(sql_handle, "INSERT INTO `%s`(`list`,`btime`,`rtime`,`reason`) VALUES ('%u.%u.%u.*', NOW() , NOW() + INTERVAL %d MINUTE ,'Password error ban')", ipban_table, p[3], p[2], p[1], login_config.dynamic_pass_failure_ban_duration) ) Sql_ShowDebug(sql_handle); } @@ -251,7 +252,7 @@ int ipban_cleanup(int tid, unsigned int tick, int id, intptr_t data) if( !login_config.ipban ) return 0;// ipban disabled - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `ipbanlist` WHERE `rtime` <= NOW()") ) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `ipbanlist` WHERE `rtime` <= NOW()") ) Sql_ShowDebug(sql_handle); return 0; diff --git a/src/login/loginlog_sql.c b/src/login/loginlog_sql.c index d61172697..231ac783b 100644 --- a/src/login/loginlog_sql.c +++ b/src/login/loginlog_sql.c @@ -1,5 +1,6 @@ -// Copyright (c) Athena Dev Teams - Licensed under GNU GPL -// For more information, see LICENCE in the main folder +// Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// See the LICENSE file +// Portions Copyright (c) Athena Dev Teams #include "../common/cbasetypes.h" #include "../common/mmo.h" @@ -37,16 +38,16 @@ unsigned long loginlog_failedattempts(uint32 ip, unsigned int minutes) if( !enabled ) return 0; - if( SQL_ERROR == Sql_Query(sql_handle, "SELECT count(*) FROM `%s` WHERE `ip` = '%s' AND `rcode` = '1' AND `time` > NOW() - INTERVAL %d MINUTE", + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT count(*) FROM `%s` WHERE `ip` = '%s' AND `rcode` = '1' AND `time` > NOW() - INTERVAL %d MINUTE", log_login_db, ip2str(ip,NULL), minutes) )// how many times failed account? in one ip. Sql_ShowDebug(sql_handle); - if( SQL_SUCCESS == Sql_NextRow(sql_handle) ) + if( SQL_SUCCESS == SQL->NextRow(sql_handle) ) { char* data; - Sql_GetData(sql_handle, 0, &data, NULL); + SQL->GetData(sql_handle, 0, &data, NULL); failures = strtoul(data, NULL, 10); - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); } return failures; } @@ -64,10 +65,10 @@ void login_log(uint32 ip, const char* username, int rcode, const char* message) if( !enabled ) return; - Sql_EscapeStringLen(sql_handle, esc_username, username, strnlen(username, NAME_LENGTH)); - Sql_EscapeStringLen(sql_handle, esc_message, message, strnlen(message, 255)); + SQL->EscapeStringLen(sql_handle, esc_username, username, strnlen(username, NAME_LENGTH)); + SQL->EscapeStringLen(sql_handle, esc_message, message, strnlen(message, 255)); - retcode = Sql_Query(sql_handle, + retcode = SQL->Query(sql_handle, "INSERT INTO `%s`(`time`,`ip`,`user`,`rcode`,`log`) VALUES (NOW(), '%s', '%s', '%d', '%s')", log_login_db, ip2str(ip,NULL), esc_username, rcode, esc_message); @@ -103,16 +104,16 @@ bool loginlog_init(void) codepage = global_codepage; } - sql_handle = Sql_Malloc(); + sql_handle = SQL->Malloc(); - if( SQL_ERROR == Sql_Connect(sql_handle, username, password, hostname, port, database) ) + if( SQL_ERROR == SQL->Connect(sql_handle, username, password, hostname, port, database) ) { Sql_ShowDebug(sql_handle); - Sql_Free(sql_handle); + SQL->Free(sql_handle); exit(EXIT_FAILURE); } - if( codepage[0] != '\0' && SQL_ERROR == Sql_SetEncoding(sql_handle, codepage) ) + if( codepage[0] != '\0' && SQL_ERROR == SQL->SetEncoding(sql_handle, codepage) ) Sql_ShowDebug(sql_handle); enabled = true; @@ -122,7 +123,7 @@ bool loginlog_init(void) bool loginlog_final(void) { - Sql_Free(sql_handle); + SQL->Free(sql_handle); sql_handle = NULL; return true; } diff --git a/src/map/atcommand.c b/src/map/atcommand.c index 6ffceac8e..428113c68 100644 --- a/src/map/atcommand.c +++ b/src/map/atcommand.c @@ -581,70 +581,70 @@ ACMD(who) display_type = 3; level = pc_get_group_level(sd); - StringBuf_Init(&buf); + StrBuf->Init(&buf); iter = mapit_getallusers(); - for (pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter)) { + for (pl_sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); pl_sd = (TBL_PC*)mapit->next(iter)) { if (!((pc_has_permission(pl_sd, PC_PERM_HIDE_SESSION) || (pl_sd->sc.option & OPTION_INVISIBLE)) && pc_get_group_level(pl_sd) > level)) { // you can look only lower or same level if (stristr(pl_sd->status.name, player_name) == NULL // search with no case sensitive || (map_id >= 0 && pl_sd->bl.m != map_id)) continue; switch (display_type) { case 2: { - StringBuf_Printf(&buf, msg_txt(343), pl_sd->status.name); // "Name: %s " + StrBuf->Printf(&buf, msg_txt(343), pl_sd->status.name); // "Name: %s " if (pc_get_group_id(pl_sd) > 0) // Player title, if exists - StringBuf_Printf(&buf, msg_txt(344), pc_group_id2name(pc_get_group_id(pl_sd))); // "(%s) " - StringBuf_Printf(&buf, msg_txt(347), pl_sd->status.base_level, pl_sd->status.job_level, + StrBuf->Printf(&buf, msg_txt(344), pc_group_id2name(pc_get_group_id(pl_sd))); // "(%s) " + StrBuf->Printf(&buf, msg_txt(347), pl_sd->status.base_level, pl_sd->status.job_level, job_name(pl_sd->status.class_)); // "| Lv:%d/%d | Job: %s" break; } case 3: { if (pc_has_permission(sd, PC_PERM_WHO_DISPLAY_AID)) - StringBuf_Printf(&buf, msg_txt(912), pl_sd->status.char_id, pl_sd->status.account_id); // "(CID:%d/AID:%d) " - StringBuf_Printf(&buf, msg_txt(343), pl_sd->status.name); // "Name: %s " + StrBuf->Printf(&buf, msg_txt(912), pl_sd->status.char_id, pl_sd->status.account_id); // "(CID:%d/AID:%d) " + StrBuf->Printf(&buf, msg_txt(343), pl_sd->status.name); // "Name: %s " if (pc_get_group_id(pl_sd) > 0) // Player title, if exists - StringBuf_Printf(&buf, msg_txt(344), pc_group_id2name(pc_get_group_id(pl_sd))); // "(%s) " - StringBuf_Printf(&buf, msg_txt(348), mapindex_id2name(pl_sd->mapindex), pl_sd->bl.x, pl_sd->bl.y); // "| Location: %s %d %d" + StrBuf->Printf(&buf, msg_txt(344), pc_group_id2name(pc_get_group_id(pl_sd))); // "(%s) " + StrBuf->Printf(&buf, msg_txt(348), mapindex_id2name(pl_sd->mapindex), pl_sd->bl.x, pl_sd->bl.y); // "| Location: %s %d %d" break; } default: { struct party_data *p = party_search(pl_sd->status.party_id); struct guild *g = pl_sd->guild; - StringBuf_Printf(&buf, msg_txt(343), pl_sd->status.name); // "Name: %s " + StrBuf->Printf(&buf, msg_txt(343), pl_sd->status.name); // "Name: %s " if (pc_get_group_id(pl_sd) > 0) // Player title, if exists - StringBuf_Printf(&buf, msg_txt(344), pc_group_id2name(pc_get_group_id(pl_sd))); // "(%s) " + StrBuf->Printf(&buf, msg_txt(344), pc_group_id2name(pc_get_group_id(pl_sd))); // "(%s) " if (p != NULL) - StringBuf_Printf(&buf, msg_txt(345), p->party.name); // " | Party: '%s'" + StrBuf->Printf(&buf, msg_txt(345), p->party.name); // " | Party: '%s'" if (g != NULL) - StringBuf_Printf(&buf, msg_txt(346), g->name); // " | Guild: '%s'" + StrBuf->Printf(&buf, msg_txt(346), g->name); // " | Guild: '%s'" break; } } - clif->message(fd, StringBuf_Value(&buf)); - StringBuf_Clear(&buf); + clif->message(fd, StrBuf->Value(&buf)); + StrBuf->Clear(&buf); count++; } } - mapit_free(iter); + mapit->free(iter); if (map_id < 0) { if (count == 0) - StringBuf_Printf(&buf, msg_txt(28)); // No player found. + StrBuf->Printf(&buf, msg_txt(28)); // No player found. else if (count == 1) - StringBuf_Printf(&buf, msg_txt(29)); // 1 player found. + StrBuf->Printf(&buf, msg_txt(29)); // 1 player found. else - StringBuf_Printf(&buf, msg_txt(30), count); // %d players found. + StrBuf->Printf(&buf, msg_txt(30), count); // %d players found. } else { if (count == 0) - StringBuf_Printf(&buf, msg_txt(54), map[map_id].name); // No player found in map '%s'. + StrBuf->Printf(&buf, msg_txt(54), map[map_id].name); // No player found in map '%s'. else if (count == 1) - StringBuf_Printf(&buf, msg_txt(55), map[map_id].name); // 1 player found in map '%s'. + StrBuf->Printf(&buf, msg_txt(55), map[map_id].name); // 1 player found in map '%s'. else - StringBuf_Printf(&buf, msg_txt(56), count, map[map_id].name); // %d players found in map '%s'. + StrBuf->Printf(&buf, msg_txt(56), count, map[map_id].name); // %d players found in map '%s'. } - clif->message(fd, StringBuf_Value(&buf)); - StringBuf_Destroy(&buf); + clif->message(fd, StrBuf->Value(&buf)); + StrBuf->Destroy(&buf); return true; } @@ -677,7 +677,7 @@ ACMD(whogm) level = pc_get_group_level(sd); iter = mapit_getallusers(); - for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) ) + for( pl_sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); pl_sd = (TBL_PC*)mapit->next(iter) ) { pl_level = pc_get_group_level(pl_sd); if (!pl_level) @@ -720,7 +720,7 @@ ACMD(whogm) clif->message(fd, atcmd_output); count++; } - mapit_free(iter); + mapit->free(iter); if (count == 0) clif->message(fd, msg_txt(150)); // No GM found. @@ -1427,20 +1427,20 @@ ACMD(help) { StringBuf buf; bool has_aliases = false; - StringBuf_Init(&buf); - StringBuf_AppendStr(&buf, msg_txt(990)); // Available aliases: + StrBuf->Init(&buf); + StrBuf->AppendStr(&buf, msg_txt(990)); // Available aliases: command_info = get_atcommandinfo_byname(command_name); iter = db_iterator(atcommand->alias_db); for (alias_info = dbi_first(iter); dbi_exists(iter); alias_info = dbi_next(iter)) { if (alias_info->command == command_info) { - StringBuf_Printf(&buf, " %s", alias_info->alias); + StrBuf->Printf(&buf, " %s", alias_info->alias); has_aliases = true; } } dbi_destroy(iter); if (has_aliases) - clif->message(fd, StringBuf_Value(&buf)); - StringBuf_Destroy(&buf); + clif->message(fd, StrBuf->Value(&buf)); + StrBuf->Destroy(&buf); } // Display help contents @@ -2936,7 +2936,7 @@ ACMD(doom) nullpo_retr(-1, sd); iter = mapit_getallusers(); - for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) ) + for( pl_sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); pl_sd = (TBL_PC*)mapit->next(iter) ) { if (pl_sd->fd != fd && pc_get_group_level(sd) >= pc_get_group_level(pl_sd)) { @@ -2945,7 +2945,7 @@ ACMD(doom) clif->message(pl_sd->fd, msg_txt(61)); // The holy messenger has given judgement. } } - mapit_free(iter); + mapit->free(iter); clif->message(fd, msg_txt(62)); // Judgement was made. @@ -2963,7 +2963,7 @@ ACMD(doommap) nullpo_retr(-1, sd); iter = mapit_getallusers(); - for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) ) + for( pl_sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); pl_sd = (TBL_PC*)mapit->next(iter) ) { if (pl_sd->fd != fd && sd->bl.m == pl_sd->bl.m && pc_get_group_level(sd) >= pc_get_group_level(pl_sd)) { @@ -2972,7 +2972,7 @@ ACMD(doommap) clif->message(pl_sd->fd, msg_txt(61)); // The holy messenger has given judgement. } } - mapit_free(iter); + mapit->free(iter); clif->message(fd, msg_txt(62)); // Judgement was made. @@ -3001,10 +3001,10 @@ ACMD(raise) nullpo_retr(-1, sd); iter = mapit_getallusers(); - for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) ) + for( pl_sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); pl_sd = (TBL_PC*)mapit->next(iter) ) if( pc_isdead(pl_sd) ) atcommand_raise_sub(pl_sd); - mapit_free(iter); + mapit->free(iter); clif->message(fd, msg_txt(64)); // Mercy has been granted. @@ -3022,10 +3022,10 @@ ACMD(raisemap) nullpo_retr(-1, sd); iter = mapit_getallusers(); - for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) ) + for( pl_sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); pl_sd = (TBL_PC*)mapit->next(iter) ) if (sd->bl.m == pl_sd->bl.m && pc_isdead(pl_sd) ) atcommand_raise_sub(pl_sd); - mapit_free(iter); + mapit->free(iter); clif->message(fd, msg_txt(64)); // Mercy has been granted. @@ -3074,14 +3074,14 @@ ACMD(kickall) nullpo_retr(-1, sd); iter = mapit_getallusers(); - for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) ) + for( pl_sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); pl_sd = (TBL_PC*)mapit->next(iter) ) { if (pc_get_group_level(sd) >= pc_get_group_level(pl_sd)) { // you can kick only lower or same gm level if (sd->status.account_id != pl_sd->status.account_id) clif->GM_kick(NULL, pl_sd); } } - mapit_free(iter); + mapit->free(iter); clif->message(fd, msg_txt(195)); // All players have been kicked! @@ -3431,7 +3431,7 @@ ACMD(recallall) count = 0; iter = mapit_getallusers(); - for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) ) + for( pl_sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); pl_sd = (TBL_PC*)mapit->next(iter) ) { if (sd->status.account_id != pl_sd->status.account_id && pc_get_group_level(sd) >= pc_get_group_level(pl_sd)) { @@ -3448,7 +3448,7 @@ ACMD(recallall) } } } - mapit_free(iter); + mapit->free(iter); clif->message(fd, msg_txt(92)); // All characters recalled! if (count) { @@ -3494,7 +3494,7 @@ ACMD(guildrecall) count = 0; iter = mapit_getallusers(); - for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) ) + for( pl_sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); pl_sd = (TBL_PC*)mapit->next(iter) ) { if (sd->status.account_id != pl_sd->status.account_id && pl_sd->status.guild_id == g->guild_id) { @@ -3506,7 +3506,7 @@ ACMD(guildrecall) pc_setpos(pl_sd, sd->mapindex, sd->bl.x, sd->bl.y, CLR_RESPAWN); } } - mapit_free(iter); + mapit->free(iter); sprintf(atcmd_output, msg_txt(93), g->name); // All online characters of the %s guild have been recalled to your position. clif->message(fd, atcmd_output); @@ -3553,7 +3553,7 @@ ACMD(partyrecall) count = 0; iter = mapit_getallusers(); - for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) ) + for( pl_sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); pl_sd = (TBL_PC*)mapit->next(iter) ) { if (sd->status.account_id != pl_sd->status.account_id && pl_sd->status.party_id == p->party.party_id) { @@ -3565,7 +3565,7 @@ ACMD(partyrecall) pc_setpos(pl_sd, sd->mapindex, sd->bl.x, sd->bl.y, CLR_RESPAWN); } } - mapit_free(iter); + mapit->free(iter); sprintf(atcmd_output, msg_txt(95), p->party.name); // All online characters of the %s party have been recalled to your position. clif->message(fd, atcmd_output); @@ -3792,7 +3792,7 @@ ACMD(mapinfo) { // count chats (for initial message) chat_num = 0; iter = mapit_getallusers(); - for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) ) { + for( pl_sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); pl_sd = (TBL_PC*)mapit->next(iter) ) { if( pl_sd->mapindex == m_index ) { if( pl_sd->state.vending ) vend_num++; @@ -3800,7 +3800,7 @@ ACMD(mapinfo) { chat_num++; } } - mapit_free(iter); + mapit->free(iter); sprintf(atcmd_output, msg_txt(1040), mapname, map[m_id].zone->name, map[m_id].users, map[m_id].npc_num, chat_num, vend_num); // Map: %s (Zone:%s) | Players: %d | NPCs: %d | Chats: %d | Vendings: %d clif->message(fd, atcmd_output); @@ -3935,7 +3935,7 @@ ACMD(mapinfo) { case 1: clif->message(fd, msg_txt(1098)); // ----- Players in Map ----- iter = mapit_getallusers(); - for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) ) + for( pl_sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); pl_sd = (TBL_PC*)mapit->next(iter) ) { if (pl_sd->mapindex == m_index) { sprintf(atcmd_output, msg_txt(1099), // Player '%s' (session #%d) | Location: %d,%d @@ -3943,7 +3943,7 @@ ACMD(mapinfo) { clif->message(fd, atcmd_output); } } - mapit_free(iter); + mapit->free(iter); break; case 2: clif->message(fd, msg_txt(1100)); // ----- NPCs in Map ----- @@ -3974,7 +3974,7 @@ ACMD(mapinfo) { case 3: clif->message(fd, msg_txt(1113)); // ----- Chats in Map ----- iter = mapit_getallusers(); - for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) ) + for( pl_sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); pl_sd = (TBL_PC*)mapit->next(iter) ) { if ((cd = (struct chat_data*)map_id2bl(pl_sd->chatID)) != NULL && pl_sd->mapindex == m_index && @@ -3988,7 +3988,7 @@ ACMD(mapinfo) { clif->message(fd, atcmd_output); } } - mapit_free(iter); + mapit->free(iter); break; default: // normally impossible to arrive here clif->message(fd, msg_txt(1118)); // Please enter at least one valid list number (usage: @mapinfo <0-3> ). @@ -4778,9 +4778,9 @@ ACMD(disguiseall) } iter = mapit_getallusers(); - for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) ) + for( pl_sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); pl_sd = (TBL_PC*)mapit->next(iter) ) pc_disguise(pl_sd, mob_id); - mapit_free(iter); + mapit->free(iter); clif->message(fd, msg_txt(122)); // Disguise applied. return true; @@ -4860,10 +4860,10 @@ ACMD(undisguiseall) { nullpo_retr(-1, sd); iter = mapit_getallusers(); - for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) ) + for( pl_sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); pl_sd = (TBL_PC*)mapit->next(iter) ) if( pl_sd->disguise != -1 ) pc_disguise(pl_sd, -1); - mapit_free(iter); + mapit->free(iter); clif->message(fd, msg_txt(124)); // Undisguise applied. @@ -6088,7 +6088,7 @@ ACMD(mobsearch) it = mapit_geteachmob(); for(;;) { - TBL_MOB* md = (TBL_MOB*)mapit_next(it); + TBL_MOB* md = (TBL_MOB*)mapit->next(it); if( md == NULL ) break;// no more mobs @@ -6104,7 +6104,7 @@ ACMD(mobsearch) snprintf(atcmd_output, sizeof(atcmd_output), "%2d[%s] %s", number, "dead", md->name); clif->message(fd, atcmd_output); } - mapit_free(it); + mapit->free(it); return true; } @@ -6270,7 +6270,7 @@ ACMD(users) iter = mapit_getallusers(); for(;;) { - struct map_session_data* sd2 = (struct map_session_data*)mapit_next(iter); + struct map_session_data* sd2 = (struct map_session_data*)mapit->next(iter); if( sd2 == NULL ) break;// no more users @@ -6280,7 +6280,7 @@ ACMD(users) if( users[sd2->mapindex] < INT_MAX ) ++users[sd2->mapindex]; if( users_all < INT_MAX ) ++users_all; } - mapit_free(iter); + mapit->free(iter); // display results for each map for( i = 0; i < MAX_MAPINDEX; ++i ) @@ -6564,9 +6564,9 @@ ACMD(refreshall) nullpo_retr(-1, sd); iter = mapit_getallusers(); - for (iter_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); iter_sd = (TBL_PC*)mapit_next(iter)) + for (iter_sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); iter_sd = (TBL_PC*)mapit->next(iter)) clif->refresh(iter_sd); - mapit_free(iter); + mapit->free(iter); return true; } @@ -6808,7 +6808,7 @@ ACMD(showmobs) it = mapit_geteachmob(); for(;;) { - TBL_MOB* md = (TBL_MOB*)mapit_next(it); + TBL_MOB* md = (TBL_MOB*)mapit->next(it); if( md == NULL ) break;// no more mobs @@ -6824,7 +6824,7 @@ ACMD(showmobs) ++number; clif->viewpoint(sd, 1, 0, md->bl.x, md->bl.y, number, 0xFFFFFF); } - mapit_free(it); + mapit->free(it); return true; } @@ -7444,7 +7444,7 @@ ACMD(sizeall) size = cap_value(size,0,2); iter = mapit_getallusers(); - for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) ) { + for( pl_sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); pl_sd = (TBL_PC*)mapit->next(iter) ) { if( pl_sd->state.size != size ) { if( pl_sd->state.size ) { pl_sd->state.size = SZ_SMALL; @@ -7458,7 +7458,7 @@ ACMD(sizeall) clif->specialeffect(&pl_sd->bl,422,AREA); } } - mapit_free(iter); + mapit->free(iter); clif->message(fd, msg_txt(1303)); // Size change applied. return true; @@ -8124,7 +8124,7 @@ ACMD(itemlist) else return 1; - StringBuf_Init(&buf); + StrBuf->Init(&buf); count = 0; // total slots occupied counter = 0; // total items found @@ -8141,15 +8141,15 @@ ACMD(itemlist) if( count == 1 ) { - StringBuf_Printf(&buf, msg_txt(1332), location, sd->status.name); // ------ %s items list of '%s' ------ - clif->message(fd, StringBuf_Value(&buf)); - StringBuf_Clear(&buf); + StrBuf->Printf(&buf, msg_txt(1332), location, sd->status.name); // ------ %s items list of '%s' ------ + clif->message(fd, StrBuf->Value(&buf)); + StrBuf->Clear(&buf); } if( it->refine ) - StringBuf_Printf(&buf, "%d %s %+d (%s, id: %d)", it->amount, itd->jname, it->refine, itd->name, it->nameid); + StrBuf->Printf(&buf, "%d %s %+d (%s, id: %d)", it->amount, itd->jname, it->refine, itd->name, it->nameid); else - StringBuf_Printf(&buf, "%d %s (%s, id: %d)", it->amount, itd->jname, itd->name, it->nameid); + StrBuf->Printf(&buf, "%d %s (%s, id: %d)", it->amount, itd->jname, itd->name, it->nameid); if( it->equip ) { @@ -8185,28 +8185,28 @@ ACMD(itemlist) strcat(equipstr, msg_txt(1347)); // lower/mid/top head, // remove final ', ' equipstr[strlen(equipstr) - 2] = '\0'; - StringBuf_AppendStr(&buf, equipstr); + StrBuf->AppendStr(&buf, equipstr); } - clif->message(fd, StringBuf_Value(&buf)); - StringBuf_Clear(&buf); + clif->message(fd, StrBuf->Value(&buf)); + StrBuf->Clear(&buf); if( it->card[0] == CARD0_PET ) {// pet egg if (it->card[3]) - StringBuf_Printf(&buf, msg_txt(1348), (unsigned int)MakeDWord(it->card[1], it->card[2])); // -> (pet egg, pet id: %u, named) + StrBuf->Printf(&buf, msg_txt(1348), (unsigned int)MakeDWord(it->card[1], it->card[2])); // -> (pet egg, pet id: %u, named) else - StringBuf_Printf(&buf, msg_txt(1349), (unsigned int)MakeDWord(it->card[1], it->card[2])); // -> (pet egg, pet id: %u, unnamed) + StrBuf->Printf(&buf, msg_txt(1349), (unsigned int)MakeDWord(it->card[1], it->card[2])); // -> (pet egg, pet id: %u, unnamed) } else if(it->card[0] == CARD0_FORGE) {// forged item - StringBuf_Printf(&buf, msg_txt(1350), (unsigned int)MakeDWord(it->card[2], it->card[3]), it->card[1]>>8, it->card[1]&0x0f); // -> (crafted item, creator id: %u, star crumbs %d, element %d) + StrBuf->Printf(&buf, msg_txt(1350), (unsigned int)MakeDWord(it->card[2], it->card[3]), it->card[1]>>8, it->card[1]&0x0f); // -> (crafted item, creator id: %u, star crumbs %d, element %d) } else if(it->card[0] == CARD0_CREATE) {// created item - StringBuf_Printf(&buf, msg_txt(1351), (unsigned int)MakeDWord(it->card[2], it->card[3])); // -> (produced item, creator id: %u) + StrBuf->Printf(&buf, msg_txt(1351), (unsigned int)MakeDWord(it->card[2], it->card[3])); // -> (produced item, creator id: %u) } else {// normal item @@ -8222,32 +8222,32 @@ ACMD(itemlist) counter2++; if( counter2 == 1 ) - StringBuf_AppendStr(&buf, msg_txt(1352)); // -> (card(s): + StrBuf->AppendStr(&buf, msg_txt(1352)); // -> (card(s): if( counter2 != 1 ) - StringBuf_AppendStr(&buf, ", "); + StrBuf->AppendStr(&buf, ", "); - StringBuf_Printf(&buf, "#%d %s (id: %d)", counter2, card->jname, card->nameid); + StrBuf->Printf(&buf, "#%d %s (id: %d)", counter2, card->jname, card->nameid); } if( counter2 > 0 ) - StringBuf_AppendStr(&buf, ")"); + StrBuf->AppendStr(&buf, ")"); } - if( StringBuf_Length(&buf) > 0 ) - clif->message(fd, StringBuf_Value(&buf)); + if( StrBuf->Length(&buf) > 0 ) + clif->message(fd, StrBuf->Value(&buf)); - StringBuf_Clear(&buf); + StrBuf->Clear(&buf); } if( count == 0 ) - StringBuf_Printf(&buf, msg_txt(1353), location); // No item found in this player's %s. + StrBuf->Printf(&buf, msg_txt(1353), location); // No item found in this player's %s. else - StringBuf_Printf(&buf, msg_txt(1354), counter, count, location); // %d item(s) found in %d %s slots. + StrBuf->Printf(&buf, msg_txt(1354), counter, count, location); // %d item(s) found in %d %s slots. - clif->message(fd, StringBuf_Value(&buf)); + clif->message(fd, StrBuf->Value(&buf)); - StringBuf_Destroy(&buf); + StrBuf->Destroy(&buf); return true; } diff --git a/src/map/chrif.c b/src/map/chrif.c index eed7ba2a6..c5ff16713 100644 --- a/src/map/chrif.c +++ b/src/map/chrif.c @@ -1509,13 +1509,13 @@ int send_users_tochar(void) { iter = mapit_getallusers(); - for( sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); sd = (TBL_PC*)mapit_next(iter) ) { + for( sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); sd = (TBL_PC*)mapit->next(iter) ) { WFIFOL(char_fd,6+8*i) = sd->status.account_id; WFIFOL(char_fd,6+8*i+4) = sd->status.char_id; i++; } - mapit_free(iter); + mapit->free(iter); WFIFOW(char_fd,2) = 6 + 8*users; WFIFOW(char_fd,4) = users; diff --git a/src/map/clif.c b/src/map/clif.c index 4edb1541d..06f180a35 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -336,24 +336,24 @@ int clif_send(const void* buf, int len, struct block_list* bl, enum send_target case ALL_CLIENT: //All player clients. iter = mapit_getallusers(); - while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL ) { + while( (tsd = (TBL_PC*)mapit->next(iter)) != NULL ) { WFIFOHEAD(tsd->fd, len); memcpy(WFIFOP(tsd->fd,0), buf, len); WFIFOSET(tsd->fd,len); } - mapit_free(iter); + mapit->free(iter); break; case ALL_SAMEMAP: //All players on the same map iter = mapit_getallusers(); - while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL ) { + while( (tsd = (TBL_PC*)mapit->next(iter)) != NULL ) { if( bl->m == tsd->bl.m ) { WFIFOHEAD(tsd->fd, len); memcpy(WFIFOP(tsd->fd,0), buf, len); WFIFOSET(tsd->fd,len); } } - mapit_free(iter); + mapit->free(iter); break; case AREA: @@ -431,14 +431,14 @@ int clif_send(const void* buf, int len, struct block_list* bl, enum send_target break; iter = mapit_getallusers(); - while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL ) { + while( (tsd = (TBL_PC*)mapit->next(iter)) != NULL ) { if( tsd->partyspy == p->party.party_id ) { WFIFOHEAD(tsd->fd, len); memcpy(WFIFOP(tsd->fd,0), buf, len); WFIFOSET(tsd->fd,len); } } - mapit_free(iter); + mapit->free(iter); } break; @@ -447,7 +447,7 @@ int clif_send(const void* buf, int len, struct block_list* bl, enum send_target if (!sd || !sd->duel_group) break; //Invalid usage. iter = mapit_getallusers(); - while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL ) { + while( (tsd = (TBL_PC*)mapit->next(iter)) != NULL ) { if( type == DUEL_WOS && bl->id == tsd->bl.id ) continue; if( sd->duel_group == tsd->duel_group ) { @@ -456,7 +456,7 @@ int clif_send(const void* buf, int len, struct block_list* bl, enum send_target WFIFOSET(tsd->fd,len); } } - mapit_free(iter); + mapit->free(iter); break; case SELF: @@ -508,14 +508,14 @@ int clif_send(const void* buf, int len, struct block_list* bl, enum send_target break; iter = mapit_getallusers(); - while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL ) { + while( (tsd = (TBL_PC*)mapit->next(iter)) != NULL ) { if( tsd->guildspy == g->guild_id ) { WFIFOHEAD(tsd->fd, len); memcpy(WFIFOP(tsd->fd,0), buf, len); WFIFOSET(tsd->fd,len); } } - mapit_free(iter); + mapit->free(iter); } break; @@ -1311,12 +1311,12 @@ void clif_weather(int16 m) struct map_session_data *sd=NULL; iter = mapit_getallusers(); - for( sd = (struct map_session_data*)mapit_first(iter); mapit_exists(iter); sd = (struct map_session_data*)mapit_next(iter) ) + for( sd = (struct map_session_data*)mapit->first(iter); mapit->exists(iter); sd = (struct map_session_data*)mapit->next(iter) ) { if( sd->bl.m == m ) clif_weather_check(sd); } - mapit_free(iter); + mapit->free(iter); } /** * Main function to spawn a unit on the client (player/mob/pet/etc) diff --git a/src/map/guild.c b/src/map/guild.c index 5e8a5897a..a028cb201 100644 --- a/src/map/guild.c +++ b/src/map/guild.c @@ -1,5 +1,6 @@ -// Copyright (c) Athena Dev Teams - Licensed under GNU GPL -// For more information, see LICENCE in the main folder +// Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// See the LICENSE file +// Portions Copyright (c) Athena Dev Teams #include "../common/cbasetypes.h" #include "../common/timer.h" @@ -457,7 +458,7 @@ int guild_check_member(struct guild *g) nullpo_ret(g); iter = mapit_getallusers(); - for( sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); sd = (TBL_PC*)mapit_next(iter) ) + for( sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); sd = (TBL_PC*)mapit->next(iter) ) { if( sd->status.guild_id != g->guild_id ) continue; @@ -469,7 +470,7 @@ int guild_check_member(struct guild *g) ShowWarning("guild: check_member %d[%s] is not member\n",sd->status.account_id,sd->status.name); } } - mapit_free(iter); + mapit->free(iter); return 0; } @@ -481,11 +482,11 @@ int guild_recv_noinfo(int guild_id) struct s_mapiterator* iter; iter = mapit_getallusers(); - for( sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); sd = (TBL_PC*)mapit_next(iter) ) { + for( sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); sd = (TBL_PC*)mapit->next(iter) ) { if( sd->status.guild_id == guild_id ) sd->status.guild_id = 0; // erase guild } - mapit_free(iter); + mapit->free(iter); return 0; } @@ -523,7 +524,7 @@ int guild_recv_info(struct guild *sg) { tg[i] = guild_search(sg->alliance[i].guild_id); } - for( sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); sd = (TBL_PC*)mapit_next(iter) ) { + for( sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); sd = (TBL_PC*)mapit->next(iter) ) { if( sd->status.guild_id ) { if( sd->status.guild_id == sg->guild_id ) { clif->chsys_join(channel,sd); @@ -543,7 +544,7 @@ int guild_recv_info(struct guild *sg) { } } - mapit_free(iter); + mapit->free(iter); } @@ -2197,10 +2198,10 @@ void do_init_guild(void) { guild_flags_count = 0; - sv_readdb(db_path, "castle_db.txt", ',', 4, 5, -1, &guild_read_castledb); + sv->readdb(db_path, "castle_db.txt", ',', 4, 5, -1, &guild_read_castledb); memset(guild_skill_tree,0,sizeof(guild_skill_tree)); - sv_readdb(db_path, "guild_skill_tree.txt", ',', 2+MAX_GUILD_SKILL_REQUIRE*2, 2+MAX_GUILD_SKILL_REQUIRE*2, -1, &guild_read_guildskill_tree_db); //guild skill tree [Komurka] + sv->readdb(db_path, "guild_skill_tree.txt", ',', 2+MAX_GUILD_SKILL_REQUIRE*2, 2+MAX_GUILD_SKILL_REQUIRE*2, -1, &guild_read_guildskill_tree_db); //guild skill tree [Komurka] add_timer_func_list(guild_payexp_timer,"guild_payexp_timer"); add_timer_func_list(guild_send_xy_timer, "guild_send_xy_timer"); diff --git a/src/map/homunculus.c b/src/map/homunculus.c index 026b9a86c..e306e7f60 100644 --- a/src/map/homunculus.c +++ b/src/map/homunculus.c @@ -1134,7 +1134,7 @@ void homunculus_read_db(void) { } } - sv_readdb(db_path, filename[i], ',', 50, 50, MAX_HOMUNCULUS_CLASS, homun->read_db_sub); + sv->readdb(db_path, filename[i], ',', 50, 50, MAX_HOMUNCULUS_CLASS, homun->read_db_sub); } } @@ -1180,7 +1180,7 @@ bool homunculus_read_skill_db_sub(char* split[], int columns, int current) { void homunculus_skill_db_read(void) { memset(homun->skill_tree,0,sizeof(homun->skill_tree)); - sv_readdb(db_path, "homun_skill_tree.txt", ',', 13, 15, -1, homun->read_skill_db_sub); + sv->readdb(db_path, "homun_skill_tree.txt", ',', 13, 15, -1, homun->read_skill_db_sub); } diff --git a/src/map/itemdb.c b/src/map/itemdb.c index 0b4419e0c..590a0cf57 100644 --- a/src/map/itemdb.c +++ b/src/map/itemdb.c @@ -1,5 +1,6 @@ -// Copyright (c) Athena Dev Teams - Licensed under GNU GPL -// For more information, see LICENCE in the main folder +// Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// See the LICENSE file +// Portions Copyright (c) Athena Dev Teams #include "../common/nullpo.h" #include "../common/malloc.h" @@ -1236,19 +1237,19 @@ static int itemdb_read_sqldb(void) { uint32 lines = 0, count = 0; // retrieve all rows from the item database - if( SQL_ERROR == Sql_Query(mmysql_handle, "SELECT * FROM `%s`", item_db_name[fi]) ) { + if( SQL_ERROR == SQL->Query(mmysql_handle, "SELECT * FROM `%s`", item_db_name[fi]) ) { Sql_ShowDebug(mmysql_handle); continue; } // process rows one by one - while( SQL_SUCCESS == Sql_NextRow(mmysql_handle) ) {// wrap the result into a TXT-compatible format + while( SQL_SUCCESS == SQL->NextRow(mmysql_handle) ) {// wrap the result into a TXT-compatible format char* str[22]; char* dummy = ""; int i; ++lines; for( i = 0; i < 22; ++i ) { - Sql_GetData(mmysql_handle, i, &str[i], NULL); + SQL->GetData(mmysql_handle, i, &str[i], NULL); if( str[i] == NULL ) str[i] = dummy; // get rid of NULL columns } @@ -1259,7 +1260,7 @@ static int itemdb_read_sqldb(void) { } // free the query result - Sql_FreeResult(mmysql_handle); + SQL->FreeResult(mmysql_handle); ShowStatus("Done reading '"CL_WHITE"%lu"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", count, item_db_name[fi]); } @@ -1295,19 +1296,19 @@ uint64 itemdb_unique_id(int8 flag, int64 value) { int itemdb_uid_load(){ char * uid; - if (SQL_ERROR == Sql_Query(mmysql_handle, "SELECT `value` FROM `interreg` WHERE `varname`='unique_id'")) + if (SQL_ERROR == SQL->Query(mmysql_handle, "SELECT `value` FROM `interreg` WHERE `varname`='unique_id'")) Sql_ShowDebug(mmysql_handle); - if( SQL_SUCCESS != Sql_NextRow(mmysql_handle) ) + if( SQL_SUCCESS != SQL->NextRow(mmysql_handle) ) { ShowError("itemdb_uid_load: Unable to fetch unique_id data\n"); - Sql_FreeResult(mmysql_handle); + SQL->FreeResult(mmysql_handle); return -1; } - Sql_GetData(mmysql_handle, 0, &uid, NULL); + SQL->GetData(mmysql_handle, 0, &uid, NULL); itemdb_unique_id(1, (uint64)strtoull(uid, NULL, 10)); - Sql_FreeResult(mmysql_handle); + SQL->FreeResult(mmysql_handle); return 0; } @@ -1324,12 +1325,12 @@ static void itemdb_read(void) { itemdb_read_combos(); itemdb_read_itemgroup(); - sv_readdb(db_path, "item_avail.txt", ',', 2, 2, -1, &itemdb_read_itemavail); - sv_readdb(db_path, DBPATH"item_trade.txt", ',', 3, 3, -1, &itemdb_read_itemtrade); - sv_readdb(db_path, "item_delay.txt", ',', 2, 2, -1, &itemdb_read_itemdelay); - sv_readdb(db_path, "item_stack.txt", ',', 3, 3, -1, &itemdb_read_stack); - sv_readdb(db_path, DBPATH"item_buyingstore.txt", ',', 1, 1, -1, &itemdb_read_buyingstore); - sv_readdb(db_path, "item_nouse.txt", ',', 3, 3, -1, &itemdb_read_nouse); + sv->readdb(db_path, "item_avail.txt", ',', 2, 2, -1, &itemdb_read_itemavail); + sv->readdb(db_path, DBPATH"item_trade.txt", ',', 3, 3, -1, &itemdb_read_itemtrade); + sv->readdb(db_path, "item_delay.txt", ',', 2, 2, -1, &itemdb_read_itemdelay); + sv->readdb(db_path, "item_stack.txt", ',', 3, 3, -1, &itemdb_read_stack); + sv->readdb(db_path, DBPATH"item_buyingstore.txt", ',', 1, 1, -1, &itemdb_read_buyingstore); + sv->readdb(db_path, "item_nouse.txt", ',', 3, 3, -1, &itemdb_read_nouse); itemdb_uid_load(); } @@ -1432,7 +1433,7 @@ void itemdb_reload(void) // readjust itemdb pointer cache for each player iter = mapit_geteachpc(); - for( sd = (struct map_session_data*)mapit_first(iter); mapit_exists(iter); sd = (struct map_session_data*)mapit_next(iter) ) { + for( sd = (struct map_session_data*)mapit->first(iter); mapit->exists(iter); sd = (struct map_session_data*)mapit->next(iter) ) { memset(sd->item_delay, 0, sizeof(sd->item_delay)); // reset item delays pc_setinventorydata(sd); /* clear combo bonuses */ @@ -1447,7 +1448,7 @@ void itemdb_reload(void) } } - mapit_free(iter); + mapit->free(iter); } void do_final_itemdb(void) diff --git a/src/map/log.c b/src/map/log.c index 1cca0a098..f57b91a2a 100644 --- a/src/map/log.c +++ b/src/map/log.c @@ -152,7 +152,7 @@ void log_branch(struct map_session_data* sd) { logs->branch_sub(sd); } void log_pick_sub_sql(int id, int16 m, e_log_pick_type type, int amount, struct item* itm, struct item_data *data) { - if( SQL_ERROR == Sql_Query(logmysql_handle, LOG_QUERY " INTO `%s` (`time`, `char_id`, `type`, `nameid`, `amount`, `refine`, `card0`, `card1`, `card2`, `card3`, `map`, `unique_id`) VALUES (NOW(), '%d', '%c', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%s', '%"PRIu64"')", + if( SQL_ERROR == SQL->Query(logmysql_handle, LOG_QUERY " INTO `%s` (`time`, `char_id`, `type`, `nameid`, `amount`, `refine`, `card0`, `card1`, `card2`, `card3`, `map`, `unique_id`) VALUES (NOW(), '%d', '%c', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%s', '%"PRIu64"')", logs->config.log_pick, id, log_picktype2char(type), itm->nameid, amount, itm->refine, itm->card[0], itm->card[1], itm->card[2], itm->card[3], map[m].name?map[m].name:"", itm->unique_id) ) { Sql_ShowDebug(logmysql_handle); @@ -197,7 +197,7 @@ void log_pick_mob(struct mob_data* md, e_log_pick_type type, int amount, struct log_pick(md->class_, md->bl.m, type, amount, itm, data ? data : itemdb_exists(itm->nameid)); } void log_zeny_sub_sql(struct map_session_data* sd, e_log_pick_type type, struct map_session_data* src_sd, int amount) { - if( SQL_ERROR == Sql_Query(logmysql_handle, LOG_QUERY " INTO `%s` (`time`, `char_id`, `src_id`, `type`, `amount`, `map`) VALUES (NOW(), '%d', '%d', '%c', '%d', '%s')", + if( SQL_ERROR == SQL->Query(logmysql_handle, LOG_QUERY " INTO `%s` (`time`, `char_id`, `src_id`, `type`, `amount`, `map`) VALUES (NOW(), '%d', '%d', '%c', '%d', '%s')", logs->config.log_zeny, sd->status.char_id, src_sd->status.char_id, log_picktype2char(type), amount, mapindex_id2name(sd->mapindex)) ) { Sql_ShowDebug(logmysql_handle); @@ -227,7 +227,7 @@ void log_zeny(struct map_session_data* sd, e_log_pick_type type, struct map_sess logs->zeny_sub(sd,type,src_sd,amount); } void log_mvpdrop_sub_sql(struct map_session_data* sd, int monster_id, int* log_mvp) { - if( SQL_ERROR == Sql_Query(logmysql_handle, LOG_QUERY " INTO `%s` (`mvp_date`, `kill_char_id`, `monster_id`, `prize`, `mvpexp`, `map`) VALUES (NOW(), '%d', '%d', '%d', '%d', '%s') ", + if( SQL_ERROR == SQL->Query(logmysql_handle, LOG_QUERY " INTO `%s` (`mvp_date`, `kill_char_id`, `monster_id`, `prize`, `mvpexp`, `map`) VALUES (NOW(), '%d', '%d', '%d', '%d', '%s') ", logs->config.log_mvpdrop, sd->status.char_id, monster_id, log_mvp[0], log_mvp[1], mapindex_id2name(sd->mapindex)) ) { Sql_ShowDebug(logmysql_handle); diff --git a/src/map/map.c b/src/map/map.c index 313abb2c6..5b0a4ed27 100644 --- a/src/map/map.c +++ b/src/map/map.c @@ -117,7 +117,6 @@ static int block_free_count = 0, block_free_lock = 0; static struct block_list *bl_list[BL_LIST_MAX]; static int bl_list_count = 0; -struct map_data map[MAX_MAP_PER_SERVER]; int map_num = 0; int map_port=0; @@ -1826,7 +1825,7 @@ struct map_session_data * map_nick2sd(const char *nick) iter = mapit_getallusers(); found_sd = NULL; - for( sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); sd = (TBL_PC*)mapit_next(iter) ) + for( sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); sd = (TBL_PC*)mapit->next(iter) ) { if( battle_config.partial_name_scan ) {// partial name search @@ -1849,7 +1848,7 @@ struct map_session_data * map_nick2sd(const char *nick) break; } } - mapit_free(iter); + mapit->free(iter); if( battle_config.partial_name_scan && qty != 1 ) found_sd = NULL; @@ -1902,8 +1901,7 @@ struct mob_data * map_id2boss(int id) /// Applies func to all the players in the db. /// Stops iterating if func returns -1. -void map_foreachpc(int (*func)(struct map_session_data* sd, va_list args), ...) -{ +void map_map_foreachpc(int (*func)(struct map_session_data* sd, va_list args), ...) { DBIterator* iter; struct map_session_data* sd; @@ -1924,7 +1922,7 @@ void map_foreachpc(int (*func)(struct map_session_data* sd, va_list args), ...) /// Applies func to all the mobs in the db. /// Stops iterating if func returns -1. -void map_foreachmob(int (*func)(struct mob_data* md, va_list args), ...) +void map_map_foreachmob(int (*func)(struct mob_data* md, va_list args), ...) { DBIterator* iter; struct mob_data* md; @@ -1946,7 +1944,7 @@ void map_foreachmob(int (*func)(struct mob_data* md, va_list args), ...) /// Applies func to all the npcs in the db. /// Stops iterating if func returns -1. -void map_foreachnpc(int (*func)(struct npc_data* nd, va_list args), ...) +void map_map_foreachnpc(int (*func)(struct npc_data* nd, va_list args), ...) { DBIterator* iter; struct block_list* bl; @@ -1972,7 +1970,7 @@ void map_foreachnpc(int (*func)(struct npc_data* nd, va_list args), ...) /// Applies func to everything in the db. /// Stops iteratin gif func returns -1. -void map_foreachregen(int (*func)(struct block_list* bl, va_list args), ...) +void map_map_foreachregen(int (*func)(struct block_list* bl, va_list args), ...) { DBIterator* iter; struct block_list* bl; @@ -1994,7 +1992,7 @@ void map_foreachregen(int (*func)(struct block_list* bl, va_list args), ...) /// Applies func to everything in the db. /// Stops iterating if func returns -1. -void map_foreachiddb(int (*func)(struct block_list* bl, va_list args), ...) +void map_map_foreachiddb(int (*func)(struct block_list* bl, va_list args), ...) { DBIterator* iter; struct block_list* bl; @@ -3169,14 +3167,13 @@ void map_removemapdb(struct map_data *m) /*====================================== * Initiate maps loading stage *--------------------------------------*/ -int map_readallmaps (void) -{ +int map_readallmaps (void) { int i; FILE* fp=NULL; int maps_removed = 0; char *map_cache_buffer = NULL; // Has the uncompressed gat data of all maps, so just one allocation has to be made char map_cache_decode_buffer[MAX_MAP_SIZE]; - + if( enable_grf ) ShowStatus("Loading maps (using GRF files)...\n"); else { @@ -3509,15 +3506,15 @@ int inter_config_read(char *cfgName) int map_sql_init(void) { // main db connection - mmysql_handle = Sql_Malloc(); + mmysql_handle = SQL->Malloc(); ShowInfo("Connecting to the Map DB Server....\n"); - if( SQL_ERROR == Sql_Connect(mmysql_handle, map_server_id, map_server_pw, map_server_ip, map_server_port, map_server_db) ) + if( SQL_ERROR == SQL->Connect(mmysql_handle, map_server_id, map_server_pw, map_server_ip, map_server_port, map_server_db) ) exit(EXIT_FAILURE); ShowStatus("connect success! (Map Server Connection)\n"); if( strlen(default_codepage) > 0 ) - if ( SQL_ERROR == Sql_SetEncoding(mmysql_handle, default_codepage) ) + if ( SQL_ERROR == SQL->SetEncoding(mmysql_handle, default_codepage) ) Sql_ShowDebug(mmysql_handle); return 0; @@ -3526,11 +3523,11 @@ int map_sql_init(void) int map_sql_close(void) { ShowStatus("Close Map DB Connection....\n"); - Sql_Free(mmysql_handle); + SQL->Free(mmysql_handle); mmysql_handle = NULL; if (logs->config.sql_logs) { ShowStatus("Close Log DB Connection....\n"); - Sql_Free(logmysql_handle); + SQL->Free(logmysql_handle); logmysql_handle = NULL; } return 0; @@ -3539,15 +3536,15 @@ int map_sql_close(void) int log_sql_init(void) { // log db connection - logmysql_handle = Sql_Malloc(); + logmysql_handle = SQL->Malloc(); ShowInfo(""CL_WHITE"[SQL]"CL_RESET": Connecting to the Log Database "CL_WHITE"%s"CL_RESET" At "CL_WHITE"%s"CL_RESET"...\n",log_db_db,log_db_ip); - if ( SQL_ERROR == Sql_Connect(logmysql_handle, log_db_id, log_db_pw, log_db_ip, log_db_port, log_db_db) ) + if ( SQL_ERROR == SQL->Connect(logmysql_handle, log_db_id, log_db_pw, log_db_ip, log_db_port, log_db_db) ) exit(EXIT_FAILURE); ShowStatus(""CL_WHITE"[SQL]"CL_RESET": Successfully '"CL_GREEN"connected"CL_RESET"' to Database '"CL_WHITE"%s"CL_RESET"'.\n", log_db_db); if( strlen(default_codepage) > 0 ) - if ( SQL_ERROR == Sql_SetEncoding(logmysql_handle, default_codepage) ) + if ( SQL_ERROR == SQL->SetEncoding(logmysql_handle, default_codepage) ) Sql_ShowDebug(logmysql_handle); return 0; } @@ -4934,9 +4931,9 @@ void do_final(void) //Ladies and babies first. iter = mapit_getallusers(); - for( sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); sd = (TBL_PC*)mapit_next(iter) ) + for( sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); sd = (TBL_PC*)mapit->next(iter) ) map_quit(sd); - mapit_free(iter); + mapit->free(iter); /* prepares npcs for a faster shutdown process */ do_clear_npc(); @@ -4996,6 +4993,8 @@ void do_final(void) map_sql_close(); ers_destroy(map_iterator_ers); + + aFree(map); ShowStatus("Finished.\n"); } @@ -5083,9 +5082,9 @@ void do_shutdown(void) { struct map_session_data* sd; struct s_mapiterator* iter = mapit_getallusers(); - for( sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); sd = (TBL_PC*)mapit_next(iter) ) + for( sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); sd = (TBL_PC*)mapit->next(iter) ) clif->GM_kick(NULL, sd); - mapit_free(iter); + mapit->free(iter); flush_fifos(); } chrif_check_shutdown(); @@ -5164,9 +5163,38 @@ void map_hp_symbols(void) { HPM->share(searchstore,"searchstore"); HPM->share(skill,"skill"); HPM->share(vending,"vending"); + /* partial */ + HPM->share(mapit,"mapit"); + HPM->share(map_foreachpc,"map_foreachpc"); + HPM->share(map_foreachmob,"map_foreachmob"); + HPM->share(map_foreachnpc,"map_foreachnpc"); + HPM->share(map_foreachregen,"map_foreachregen"); + HPM->share(map_foreachiddb,"map_foreachiddb"); + /* sql link */ + HPM->share(mmysql_handle,"sql_handle"); /* specific */ HPM->share(atcommand->create,"addCommand"); HPM->share(script->addScript,"addScript"); + /* vars */ + HPM->share(map,"map"); +} +/* temporary until the map.c "Hercules Renewal Phase One" design is complete. */ +void map_defaults(void) { + mapit = &mapit_s; + + mapit->alloc = mapit_alloc; + mapit->free = mapit_free; + mapit->first = mapit_first; + mapit->last = mapit_last; + mapit->next = mapit_next; + mapit->prev = mapit_prev; + mapit->exists = mapit_exists; + + map_foreachpc = map_map_foreachpc; + map_foreachmob = map_map_foreachmob; + map_foreachnpc = map_map_foreachnpc; + map_foreachregen = map_map_foreachregen; + map_foreachiddb = map_map_foreachiddb; } void load_defaults(void) { atcommand_defaults(); @@ -5176,6 +5204,7 @@ void load_defaults(void) { homunculus_defaults(); ircbot_defaults(); log_defaults(); + map_defaults(); script_defaults(); searchstore_defaults(); skill_defaults(); @@ -5286,6 +5315,8 @@ int do_init(int argc, char *argv[]) } } + CREATE(map,struct map_data,MAX_MAP_PER_SERVER); + load_defaults(); map_config_read(MAP_CONF_NAME); diff --git a/src/map/map.h b/src/map/map.h index a8ce19713..a7bcb08db 100644 --- a/src/map/map.h +++ b/src/map/map.h @@ -693,7 +693,7 @@ int map_getcellp(struct map_data* m,int16 x,int16 y,cell_chk cellchk); void map_setcell(int16 m, int16 x, int16 y, cell_t cell, bool flag); void map_setgatcell(int16 m, int16 x, int16 y, int gat); -extern struct map_data map[]; +struct map_data *map; extern int map_num; extern int autosave_interval; @@ -776,11 +776,13 @@ int map_eraseipport(unsigned short map, uint32 ip, uint16 port); int map_eraseallipport(void); void map_addiddb(struct block_list *); void map_deliddb(struct block_list *bl); -void map_foreachpc(int (*func)(struct map_session_data* sd, va_list args), ...); -void map_foreachmob(int (*func)(struct mob_data* md, va_list args), ...); -void map_foreachnpc(int (*func)(struct npc_data* nd, va_list args), ...); -void map_foreachregen(int (*func)(struct block_list* bl, va_list args), ...); -void map_foreachiddb(int (*func)(struct block_list* bl, va_list args), ...); +/* temporary until the map.c "Hercules Renewal Phase One" design is complete. */ +void (*map_foreachpc) (int (*func)(struct map_session_data* sd, va_list args), ...); +void (*map_foreachmob) (int (*func)(struct mob_data* md, va_list args), ...); +void (*map_foreachnpc) (int (*func)(struct npc_data* nd, va_list args), ...); +void (*map_foreachregen) (int (*func)(struct block_list* bl, va_list args), ...); +void (*map_foreachiddb) (int (*func)(struct block_list* bl, va_list args), ...); +/* */ struct map_session_data * map_nick2sd(const char*); struct mob_data * map_getmob_boss(int16 m); struct mob_data * map_id2boss(int id); @@ -789,24 +791,27 @@ struct mob_data * map_id2boss(int id); void map_reloadnpc(bool clear); /// Bitfield of flags for the iterator. -enum e_mapitflags -{ +enum e_mapitflags { MAPIT_NORMAL = 0, // MAPIT_PCISPLAYING = 1,// Unneeded as pc_db/id_db will only hold auth'ed, active players. }; struct s_mapiterator; -struct s_mapiterator* mapit_alloc(enum e_mapitflags flags, enum bl_type types); -void mapit_free(struct s_mapiterator* mapit); -struct block_list* mapit_first(struct s_mapiterator* mapit); -struct block_list* mapit_last(struct s_mapiterator* mapit); -struct block_list* mapit_next(struct s_mapiterator* mapit); -struct block_list* mapit_prev(struct s_mapiterator* mapit); -bool mapit_exists(struct s_mapiterator* mapit); -#define mapit_getallusers() mapit_alloc(MAPIT_NORMAL,BL_PC) -#define mapit_geteachpc() mapit_alloc(MAPIT_NORMAL,BL_PC) -#define mapit_geteachmob() mapit_alloc(MAPIT_NORMAL,BL_MOB) -#define mapit_geteachnpc() mapit_alloc(MAPIT_NORMAL,BL_NPC) -#define mapit_geteachiddb() mapit_alloc(MAPIT_NORMAL,BL_ALL) +/* temporary until the map.c "Hercules Renewal Phase One" design is complete. */ +struct mapit_interface { + struct s_mapiterator* (*alloc) (enum e_mapitflags flags, enum bl_type types); + void (*free) (struct s_mapiterator* mapit); + struct block_list* (*first) (struct s_mapiterator* mapit); + struct block_list* (*last) (struct s_mapiterator* mapit); + struct block_list* (*next) (struct s_mapiterator* mapit); + struct block_list* (*prev) (struct s_mapiterator* mapit); + bool (*exists) (struct s_mapiterator* mapit); +} mapit_s; +struct mapit_interface *mapit; +#define mapit_getallusers() mapit->alloc(MAPIT_NORMAL,BL_PC) +#define mapit_geteachpc() mapit->alloc(MAPIT_NORMAL,BL_PC) +#define mapit_geteachmob() mapit->alloc(MAPIT_NORMAL,BL_MOB) +#define mapit_geteachnpc() mapit->alloc(MAPIT_NORMAL,BL_NPC) +#define mapit_geteachiddb() mapit->alloc(MAPIT_NORMAL,BL_ALL) int map_check_dir(int s_dir,int t_dir); uint8 map_calc_dir( struct block_list *src,int16 x,int16 y); diff --git a/src/map/mapreg_sql.c b/src/map/mapreg_sql.c index bac3cea13..484da5641 100644 --- a/src/map/mapreg_sql.c +++ b/src/map/mapreg_sql.c @@ -62,8 +62,8 @@ bool mapreg_setreg(int uid, int val) { if(name[1] != '@') {// write new variable to database char tmp_str[32*2+1]; - Sql_EscapeStringLen(mmysql_handle, tmp_str, name, strnlen(name, 32)); - if( SQL_ERROR == Sql_Query(mmysql_handle, "INSERT INTO `%s`(`varname`,`index`,`value`) VALUES ('%s','%d','%d')", mapreg_table, tmp_str, i, val) ) + SQL->EscapeStringLen(mmysql_handle, tmp_str, name, strnlen(name, 32)); + if( SQL_ERROR == SQL->Query(mmysql_handle, "INSERT INTO `%s`(`varname`,`index`,`value`) VALUES ('%s','%d','%d')", mapreg_table, tmp_str, i, val) ) Sql_ShowDebug(mmysql_handle); } idb_put(mapreg_db, uid, m); @@ -75,7 +75,7 @@ bool mapreg_setreg(int uid, int val) { idb_remove(mapreg_db,uid); if( name[1] != '@' ) {// Remove from database because it is unused. - if( SQL_ERROR == Sql_Query(mmysql_handle, "DELETE FROM `%s` WHERE `varname`='%s' AND `index`='%d'", mapreg_table, name, i) ) + if( SQL_ERROR == SQL->Query(mmysql_handle, "DELETE FROM `%s` WHERE `varname`='%s' AND `index`='%d'", mapreg_table, name, i) ) Sql_ShowDebug(mmysql_handle); } } @@ -92,7 +92,7 @@ bool mapreg_setregstr(int uid, const char* str) { if( str == NULL || *str == 0 ) { if(name[1] != '@') { - if( SQL_ERROR == Sql_Query(mmysql_handle, "DELETE FROM `%s` WHERE `varname`='%s' AND `index`='%d'", mapreg_table, name, i) ) + if( SQL_ERROR == SQL->Query(mmysql_handle, "DELETE FROM `%s` WHERE `varname`='%s' AND `index`='%d'", mapreg_table, name, i) ) Sql_ShowDebug(mmysql_handle); } if( (m = idb_get(mapregstr_db,uid)) ) { @@ -120,9 +120,9 @@ bool mapreg_setregstr(int uid, const char* str) { if(name[1] != '@') { //put returned null, so we must insert. char tmp_str[32*2+1]; char tmp_str2[255*2+1]; - Sql_EscapeStringLen(mmysql_handle, tmp_str, name, strnlen(name, 32)); - Sql_EscapeStringLen(mmysql_handle, tmp_str2, str, strnlen(str, 255)); - if( SQL_ERROR == Sql_Query(mmysql_handle, "INSERT INTO `%s`(`varname`,`index`,`value`) VALUES ('%s','%d','%s')", mapreg_table, tmp_str, i, tmp_str2) ) + SQL->EscapeStringLen(mmysql_handle, tmp_str, name, strnlen(name, 32)); + SQL->EscapeStringLen(mmysql_handle, tmp_str2, str, strnlen(str, 255)); + if( SQL_ERROR == SQL->Query(mmysql_handle, "INSERT INTO `%s`(`varname`,`index`,`value`) VALUES ('%s','%d','%s')", mapreg_table, tmp_str, i, tmp_str2) ) Sql_ShowDebug(mmysql_handle); } idb_put(mapregstr_db, uid, m); @@ -206,7 +206,7 @@ static void script_save_mapreg(void) { int i = (m->uid & 0xff000000) >> 24; const char* name = get_str(num); - if( SQL_ERROR == Sql_Query(mmysql_handle, "UPDATE `%s` SET `value`='%d' WHERE `varname`='%s' AND `index`='%d' LIMIT 1", mapreg_table, m->u.i, name, i) ) + if( SQL_ERROR == SQL->Query(mmysql_handle, "UPDATE `%s` SET `value`='%d' WHERE `varname`='%s' AND `index`='%d' LIMIT 1", mapreg_table, m->u.i, name, i) ) Sql_ShowDebug(mmysql_handle); m->save = false; } @@ -224,8 +224,8 @@ static void script_save_mapreg(void) { const char* name = get_str(num); char tmp_str2[2*255+1]; - Sql_EscapeStringLen(mmysql_handle, tmp_str2, m->u.str, safestrnlen(m->u.str, 255)); - if( SQL_ERROR == Sql_Query(mmysql_handle, "UPDATE `%s` SET `value`='%s' WHERE `varname`='%s' AND `index`='%d' LIMIT 1", mapreg_table, tmp_str2, name, i) ) + SQL->EscapeStringLen(mmysql_handle, tmp_str2, m->u.str, safestrnlen(m->u.str, 255)); + if( SQL_ERROR == SQL->Query(mmysql_handle, "UPDATE `%s` SET `value`='%s' WHERE `varname`='%s' AND `index`='%d' LIMIT 1", mapreg_table, tmp_str2, name, i) ) Sql_ShowDebug(mmysql_handle); m->save = false; } diff --git a/src/map/mercenary.c b/src/map/mercenary.c index f673ae5de..02fcea891 100644 --- a/src/map/mercenary.c +++ b/src/map/mercenary.c @@ -456,7 +456,7 @@ static bool read_mercenarydb_sub(char* str[], int columns, int current) int read_mercenarydb(void) { memset(mercenary_db,0,sizeof(mercenary_db)); - sv_readdb(db_path, "mercenary_db.txt", ',', 26, 26, MAX_MERCENARY_CLASS, &read_mercenarydb_sub); + sv->readdb(db_path, "mercenary_db.txt", ',', 26, 26, MAX_MERCENARY_CLASS, &read_mercenarydb_sub); return 0; } @@ -494,7 +494,7 @@ static bool read_mercenary_skilldb_sub(char* str[], int columns, int current) int read_mercenary_skilldb(void) { - sv_readdb(db_path, "mercenary_skill_db.txt", ',', 3, 3, -1, &read_mercenary_skilldb_sub); + sv->readdb(db_path, "mercenary_skill_db.txt", ',', 3, 3, -1, &read_mercenary_skilldb_sub); return 0; } diff --git a/src/map/mob.c b/src/map/mob.c index 86c0f8455..0f1ad0452 100644 --- a/src/map/mob.c +++ b/src/map/mob.c @@ -3907,7 +3907,7 @@ static void mob_readdb(void) } } - sv_readdb(db_path, filename[fi], ',', 31+2*MAX_MVP_DROP+2*MAX_MOB_DROP, 31+2*MAX_MVP_DROP+2*MAX_MOB_DROP, -1, &mob_readdb_sub); + sv->readdb(db_path, filename[fi], ',', 31+2*MAX_MVP_DROP+2*MAX_MOB_DROP, 31+2*MAX_MVP_DROP+2*MAX_MOB_DROP, -1, &mob_readdb_sub); } } @@ -3923,13 +3923,13 @@ static int mob_read_sqldb(void) uint32 lines = 0, count = 0; // retrieve all rows from the mob database - if( SQL_ERROR == Sql_Query(mmysql_handle, "SELECT * FROM `%s`", mob_db_name[fi]) ) { + if( SQL_ERROR == SQL->Query(mmysql_handle, "SELECT * FROM `%s`", mob_db_name[fi]) ) { Sql_ShowDebug(mmysql_handle); continue; } // process rows one by one - while( SQL_SUCCESS == Sql_NextRow(mmysql_handle) ) { + while( SQL_SUCCESS == SQL->NextRow(mmysql_handle) ) { // wrap the result into a TXT-compatible format char line[1024]; char* str[31+2*MAX_MVP_DROP+2*MAX_MOB_DROP]; @@ -3941,7 +3941,7 @@ static int mob_read_sqldb(void) { char* data; size_t len; - Sql_GetData(mmysql_handle, i, &data, &len); + SQL->GetData(mmysql_handle, i, &data, &len); strcpy(p, data); str[i] = p; @@ -3955,7 +3955,7 @@ static int mob_read_sqldb(void) } // free the query result - Sql_FreeResult(mmysql_handle); + SQL->FreeResult(mmysql_handle); ShowStatus("Done reading '"CL_WHITE"%lu"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", count, mob_db_name[fi]); } @@ -4471,7 +4471,7 @@ static void mob_readskilldb(void) { } } - sv_readdb(db_path, filename[fi], ',', 19, 19, -1, &mob_parse_row_mobskilldb); + sv->readdb(db_path, filename[fi], ',', 19, 19, -1, &mob_parse_row_mobskilldb); } } @@ -4495,13 +4495,13 @@ static int mob_read_sqlskilldb(void) uint32 lines = 0, count = 0; // retrieve all rows from the mob skill database - if( SQL_ERROR == Sql_Query(mmysql_handle, "SELECT * FROM `%s`", mob_skill_db_name[fi]) ) { + if( SQL_ERROR == SQL->Query(mmysql_handle, "SELECT * FROM `%s`", mob_skill_db_name[fi]) ) { Sql_ShowDebug(mmysql_handle); continue; } // process rows one by one - while( SQL_SUCCESS == Sql_NextRow(mmysql_handle) ) { + while( SQL_SUCCESS == SQL->NextRow(mmysql_handle) ) { // wrap the result into a TXT-compatible format char* str[19]; char* dummy = ""; @@ -4509,7 +4509,7 @@ static int mob_read_sqlskilldb(void) ++lines; for( i = 0; i < 19; ++i ) { - Sql_GetData(mmysql_handle, i, &str[i], NULL); + SQL->GetData(mmysql_handle, i, &str[i], NULL); if( str[i] == NULL ) str[i] = dummy; // get rid of NULL columns } @@ -4520,7 +4520,7 @@ static int mob_read_sqlskilldb(void) } // free the query result - Sql_FreeResult(mmysql_handle); + SQL->FreeResult(mmysql_handle); ShowStatus("Done reading '"CL_WHITE"%lu"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", count, mob_skill_db_name[fi]); } @@ -4586,7 +4586,7 @@ static bool mob_readdb_itemratio(char* str[], int columns, int current) */ static void mob_load(void) { - sv_readdb(db_path, "mob_item_ratio.txt", ',', 2, 2+MAX_ITEMRATIO_MOBS, -1, &mob_readdb_itemratio); // must be read before mobdb + sv->readdb(db_path, "mob_item_ratio.txt", ',', 2, 2+MAX_ITEMRATIO_MOBS, -1, &mob_readdb_itemratio); // must be read before mobdb mob_readchatdb(); if (db_use_sqldbs) { @@ -4598,9 +4598,9 @@ static void mob_load(void) mob_readdb(); mob_readskilldb(); } - sv_readdb(db_path, "mob_avail.txt", ',', 2, 12, -1, &mob_readdb_mobavail); + sv->readdb(db_path, "mob_avail.txt", ',', 2, 12, -1, &mob_readdb_mobavail); mob_read_randommonster(); - sv_readdb(db_path, DBPATH"mob_race2_db.txt", ',', 2, 20, -1, &mob_readdb_race2); + sv->readdb(db_path, DBPATH"mob_race2_db.txt", ',', 2, 20, -1, &mob_readdb_race2); } void mob_reload(void) { diff --git a/src/map/npc.c b/src/map/npc.c index a9fdb5ea6..3a3ae472d 100644 --- a/src/map/npc.c +++ b/src/map/npc.c @@ -1852,7 +1852,7 @@ int npc_unload(struct npc_data* nd, bool single) { ev_db->foreach(ev_db,npc_unload_ev,nd->exname); //Clean up all events related iter = mapit_geteachpc(); - for( bl = (struct block_list*)mapit_first(iter); mapit_exists(iter); bl = (struct block_list*)mapit_next(iter) ) { + for( bl = (struct block_list*)mapit->first(iter); mapit->exists(iter); bl = (struct block_list*)mapit->next(iter) ) { struct map_session_data *sd = ((TBL_PC*)bl); if( sd && sd->npc_timer_id != INVALID_TIMER ) { const struct TimerData *td = get_timer(sd->npc_timer_id); @@ -1866,7 +1866,7 @@ int npc_unload(struct npc_data* nd, bool single) { sd->npc_timer_id = INVALID_TIMER; } } - mapit_free(iter); + mapit->free(iter); if (nd->u.scr.timerid != INVALID_TIMER) { const struct TimerData *td; @@ -3606,7 +3606,7 @@ void npc_parsesrcfile(const char* filepath, bool runOnInit) lines++; // w1w2w3w4 - count = sv_parse(p, len+buffer-p, 0, '\t', pos, ARRAYLENGTH(pos), (e_svopt)(SV_TERMINATE_LF|SV_TERMINATE_CRLF)); + count = sv->parse(p, len+buffer-p, 0, '\t', pos, ARRAYLENGTH(pos), (e_svopt)(SV_TERMINATE_LF|SV_TERMINATE_CRLF)); if( count < 0 ) { ShowError("npc_parsesrcfile: Parse error in file '%s', line '%d'. Stopping...\n", filepath, strline(buffer,p-buffer)); @@ -3836,7 +3836,7 @@ int npc_reload(void) { //Remove all npcs/mobs. [Skotlex] iter = mapit_geteachiddb(); - for( bl = (struct block_list*)mapit_first(iter); mapit_exists(iter); bl = (struct block_list*)mapit_next(iter) ) { + for( bl = (struct block_list*)mapit->first(iter); mapit->exists(iter); bl = (struct block_list*)mapit->next(iter) ) { switch(bl->type) { case BL_NPC: if( bl->id != fake_nd->bl.id )// don't remove fake_nd @@ -3847,7 +3847,7 @@ int npc_reload(void) { break; } } - mapit_free(iter); + mapit->free(iter); if(battle_config.dynamic_mobs) {// dynamic check by [random] diff --git a/src/map/pc.c b/src/map/pc.c index 7d3b5c4a2..50188aeb3 100644 --- a/src/map/pc.c +++ b/src/map/pc.c @@ -9115,7 +9115,7 @@ int pc_autosave(int tid, unsigned int tick, int id, intptr_t data) save_flag = 1; //Noone was saved, so save first found char. iter = mapit_getallusers(); - for( sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); sd = (TBL_PC*)mapit_next(iter) ) + for( sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); sd = (TBL_PC*)mapit->next(iter) ) { if(sd->bl.id == last_save_id && save_flag != 1) { save_flag = 1; @@ -9132,7 +9132,7 @@ int pc_autosave(int tid, unsigned int tick, int id, intptr_t data) chrif_save(sd,0); break; } - mapit_free(iter); + mapit->free(iter); interval = autosave_interval/(map_usercount()+1); if(interval < minsave_interval) @@ -9620,10 +9620,10 @@ int pc_readdb(void) count = 0; // Reset and read skilltree memset(skill_tree,0,sizeof(skill_tree)); - sv_readdb(db_path, DBPATH"skill_tree.txt", ',', 3+MAX_PC_SKILL_REQUIRE*2, 4+MAX_PC_SKILL_REQUIRE*2, -1, &pc_readdb_skilltree); + sv->readdb(db_path, DBPATH"skill_tree.txt", ',', 3+MAX_PC_SKILL_REQUIRE*2, 4+MAX_PC_SKILL_REQUIRE*2, -1, &pc_readdb_skilltree); #if defined(RENEWAL_DROP) || defined(RENEWAL_EXP) - sv_readdb(db_path, "re/level_penalty.txt", ',', 4, 4, -1, &pc_readdb_levelpenalty); + sv->readdb(db_path, "re/level_penalty.txt", ',', 4, 4, -1, &pc_readdb_levelpenalty); for( k=1; k < 3; k++ ){ // fill in the blanks for( j = 0; j < RC_MAX; j++ ){ int tmp = 0; diff --git a/src/map/pc_groups.c b/src/map/pc_groups.c index 42a068693..1a83c8b63 100644 --- a/src/map/pc_groups.c +++ b/src/map/pc_groups.c @@ -452,10 +452,10 @@ void pc_groups_reload(void) { /* refresh online users permissions */ iter = mapit_getallusers(); - for (sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); sd = (TBL_PC*)mapit_next(iter)) { + for (sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); sd = (TBL_PC*)mapit->next(iter)) { pc_group_pc_load(sd); } - mapit_free(iter); + mapit->free(iter); } diff --git a/src/map/script.c b/src/map/script.c index fd2e2654f..3d5045f02 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -1095,18 +1095,16 @@ const char* parse_simpleexpr(const char *p) add_scriptc(C_STR); p++; while( *p && *p != '"' ){ - if( (unsigned char)p[-1] <= 0x7e && *p == '\\' ) - { + if( (unsigned char)p[-1] <= 0x7e && *p == '\\' ) { char buf[8]; - size_t len = skip_escaped_c(p) - p; - size_t n = sv_unescape_c(buf, p, len); + size_t len = sv->skip_escaped_c(p) - p; + size_t n = sv->unescape_c(buf, p, len); if( n != 1 ) ShowDebug("parse_simpleexpr: unexpected length %d after unescape (\"%.*s\" -> %.*s)\n", (int)n, (int)len, p, (int)n, buf); p += len; add_scriptb(*buf); continue; - } - else if( *p == '\n' ) + } else if( *p == '\n' ) disp_error_message("parse_simpleexpr: unexpected newline @ string",p); add_scriptb(*p++); } @@ -2040,16 +2038,16 @@ static const char* script_print_line(StringBuf* buf, const char* p, const char* int i; if( p == NULL || !p[0] ) return NULL; if( line < 0 ) - StringBuf_Printf(buf, "*% 5d : ", -line); + StrBuf->Printf(buf, "*% 5d : ", -line); else - StringBuf_Printf(buf, " % 5d : ", line); + StrBuf->Printf(buf, " % 5d : ", line); for(i=0;p[i] && p[i] != '\n';i++){ if(p + i != mark) - StringBuf_Printf(buf, "%c", p[i]); + StrBuf->Printf(buf, "%c", p[i]); else - StringBuf_Printf(buf, "\'%c\'", p[i]); + StrBuf->Printf(buf, "\'%c\'", p[i]); } - StringBuf_AppendStr(buf, "\n"); + StrBuf->AppendStr(buf, "\n"); return p+i+(p[i] == '\n' ? 1 : 0); } @@ -2074,10 +2072,10 @@ void script_error(const char* src, const char* file, int start_line, const char* p=lineend+1; } - StringBuf_Init(&buf); - StringBuf_AppendStr(&buf, "\a\n"); - StringBuf_Printf(&buf, "script error on %s line %d\n", file, line); - StringBuf_Printf(&buf, " %s\n", error_msg); + StrBuf->Init(&buf); + StrBuf->AppendStr(&buf, "\a\n"); + StrBuf->Printf(&buf, "script error on %s line %d\n", file, line); + StrBuf->Printf(&buf, " %s\n", error_msg); for(j = 0; j < 5; j++ ) { script_print_line(&buf, linestart[j], NULL, line + j - 5); } @@ -2085,8 +2083,8 @@ void script_error(const char* src, const char* file, int start_line, const char* for(j = 0; j < 5; j++) { p = script_print_line(&buf, p, NULL, line + j + 1 ); } - ShowError("%s", StringBuf_Value(&buf)); - StringBuf_Destroy(&buf); + ShowError("%s", StrBuf->Value(&buf)); + StrBuf->Destroy(&buf); } /*========================================== @@ -4062,7 +4060,7 @@ BUILDIN(menu) return false; } - StringBuf_Init(&buf); + StrBuf->Init(&buf); sd->npc_menu = 0; for( i = 2; i < script_lastdata(st); i += 2 ) { @@ -4073,7 +4071,7 @@ BUILDIN(menu) data = script_getdata(st, i+1); if( !data_islabel(data) ) {// not a label - StringBuf_Destroy(&buf); + StrBuf->Destroy(&buf); ShowError("script:menu: argument #%d (from 1) is not a label or label not found.\n", i); script_reportdata(data); st->state = END; @@ -4084,8 +4082,8 @@ BUILDIN(menu) if( text[0] == '\0' ) continue;// empty string, ignore if( sd->npc_menu > 0 ) - StringBuf_AppendStr(&buf, ":"); - StringBuf_AppendStr(&buf, text); + StrBuf->AppendStr(&buf, ":"); + StrBuf->AppendStr(&buf, text); sd->npc_menu += menu_countoptions(text, 0, NULL); } st->state = RERUNLINE; @@ -4094,18 +4092,18 @@ BUILDIN(menu) /** * menus beyond this length crash the client (see bugreport:6402) **/ - if( StringBuf_Length(&buf) >= 2047 ) { + if( StrBuf->Length(&buf) >= 2047 ) { struct npc_data * nd = map_id2nd(st->oid); char* menu; CREATE(menu, char, 2048); - safestrncpy(menu, StringBuf_Value(&buf), 2047); - ShowWarning("NPC Menu too long! (source:%s / length:%d)\n",nd?nd->name:"Unknown",StringBuf_Length(&buf)); + safestrncpy(menu, StrBuf->Value(&buf), 2047); + ShowWarning("NPC Menu too long! (source:%s / length:%d)\n",nd?nd->name:"Unknown",StrBuf->Length(&buf)); clif->scriptmenu(sd, st->oid, menu); aFree(menu); } else - clif->scriptmenu(sd, st->oid, StringBuf_Value(&buf)); + clif->scriptmenu(sd, st->oid, StrBuf->Value(&buf)); - StringBuf_Destroy(&buf); + StrBuf->Destroy(&buf); if( sd->npc_menu >= 0xff ) {// client supports only up to 254 entries; 0 is not used and 255 is reserved for cancel; excess entries are displayed but cause 'uint8' overflow @@ -4181,15 +4179,15 @@ BUILDIN(select) if( sd->state.menu_or_input == 0 ) { struct StringBuf buf; - StringBuf_Init(&buf); + StrBuf->Init(&buf); sd->npc_menu = 0; for( i = 2; i <= script_lastdata(st); ++i ) { text = script_getstr(st, i); if( sd->npc_menu > 0 ) - StringBuf_AppendStr(&buf, ":"); + StrBuf->AppendStr(&buf, ":"); - StringBuf_AppendStr(&buf, text); + StrBuf->AppendStr(&buf, text); sd->npc_menu += menu_countoptions(text, 0, NULL); } @@ -4199,17 +4197,17 @@ BUILDIN(select) /** * menus beyond this length crash the client (see bugreport:6402) **/ - if( StringBuf_Length(&buf) >= 2047 ) { + if( StrBuf->Length(&buf) >= 2047 ) { struct npc_data * nd = map_id2nd(st->oid); char* menu; CREATE(menu, char, 2048); - safestrncpy(menu, StringBuf_Value(&buf), 2047); - ShowWarning("NPC Menu too long! (source:%s / length:%d)\n",nd?nd->name:"Unknown",StringBuf_Length(&buf)); + safestrncpy(menu, StrBuf->Value(&buf), 2047); + ShowWarning("NPC Menu too long! (source:%s / length:%d)\n",nd?nd->name:"Unknown",StrBuf->Length(&buf)); clif->scriptmenu(sd, st->oid, menu); aFree(menu); } else - clif->scriptmenu(sd, st->oid, StringBuf_Value(&buf)); - StringBuf_Destroy(&buf); + clif->scriptmenu(sd, st->oid, StrBuf->Value(&buf)); + StrBuf->Destroy(&buf); if( sd->npc_menu >= 0xff ) { ShowWarning("buildin_select: Too many options specified (current=%d, max=254).\n", sd->npc_menu); @@ -4261,14 +4259,14 @@ BUILDIN(prompt) { struct StringBuf buf; - StringBuf_Init(&buf); + StrBuf->Init(&buf); sd->npc_menu = 0; for( i = 2; i <= script_lastdata(st); ++i ) { text = script_getstr(st, i); if( sd->npc_menu > 0 ) - StringBuf_AppendStr(&buf, ":"); - StringBuf_AppendStr(&buf, text); + StrBuf->AppendStr(&buf, ":"); + StrBuf->AppendStr(&buf, text); sd->npc_menu += menu_countoptions(text, 0, NULL); } @@ -4278,17 +4276,17 @@ BUILDIN(prompt) /** * menus beyond this length crash the client (see bugreport:6402) **/ - if( StringBuf_Length(&buf) >= 2047 ) { + if( StrBuf->Length(&buf) >= 2047 ) { struct npc_data * nd = map_id2nd(st->oid); char* menu; CREATE(menu, char, 2048); - safestrncpy(menu, StringBuf_Value(&buf), 2047); - ShowWarning("NPC Menu too long! (source:%s / length:%d)\n",nd?nd->name:"Unknown",StringBuf_Length(&buf)); + safestrncpy(menu, StrBuf->Value(&buf), 2047); + ShowWarning("NPC Menu too long! (source:%s / length:%d)\n",nd?nd->name:"Unknown",StrBuf->Length(&buf)); clif->scriptmenu(sd, st->oid, menu); aFree(menu); } else - clif->scriptmenu(sd, st->oid, StringBuf_Value(&buf)); - StringBuf_Destroy(&buf); + clif->scriptmenu(sd, st->oid, StrBuf->Value(&buf)); + StrBuf->Destroy(&buf); if( sd->npc_menu >= 0xff ) { @@ -4834,7 +4832,7 @@ BUILDIN(warpguild) } iter = mapit_getallusers(); - for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) ) + for( pl_sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); pl_sd = (TBL_PC*)mapit->next(iter) ) { if( pl_sd->status.guild_id != gid ) continue; @@ -4859,7 +4857,7 @@ BUILDIN(warpguild) break; } } - mapit_free(iter); + mapit->free(iter); return true; } @@ -9292,7 +9290,7 @@ BUILDIN(getusersname) group_level = pc_get_group_level(sd); iter = mapit_getallusers(); - for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) ) + for( pl_sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); pl_sd = (TBL_PC*)mapit->next(iter) ) { if (pc_has_permission(pl_sd, PC_PERM_HIDE_SESSION) && pc_get_group_level(pl_sd) > group_level) continue; // skip hidden sessions @@ -9303,7 +9301,7 @@ BUILDIN(getusersname) clif->scriptnext(sd,st->oid);*/ clif->scriptmes(sd,st->oid,pl_sd->status.name); } - mapit_free(iter); + mapit->free(iter); return true; } @@ -10567,7 +10565,7 @@ BUILDIN(pvpon) return true; iter = mapit_getallusers(); - for( sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); sd = (TBL_PC*)mapit_next(iter) ) + for( sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); sd = (TBL_PC*)mapit->next(iter) ) { if( sd->bl.m != m || sd->pvp_timer != INVALID_TIMER ) continue; // not applicable @@ -10579,7 +10577,7 @@ BUILDIN(pvpon) sd->pvp_won = 0; sd->pvp_lost = 0; } - mapit_free(iter); + mapit->free(iter); return true; } @@ -12303,7 +12301,7 @@ BUILDIN(recovery) struct s_mapiterator* iter; iter = mapit_getallusers(); - for( sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); sd = (TBL_PC*)mapit_next(iter) ) + for( sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); sd = (TBL_PC*)mapit->next(iter) ) { if(pc_isdead(sd)) status_revive(&sd->bl, 100, 100); @@ -12311,7 +12309,7 @@ BUILDIN(recovery) status_percent_heal(&sd->bl, 100, 100); clif->message(sd->fd,msg_txt(680)); } - mapit_free(iter); + mapit->free(iter); return true; } /*========================================== @@ -13596,7 +13594,7 @@ BUILDIN(sprintf) safestrncpy(buf, format, len+1); // Issue sprintf for each parameter - StringBuf_Init(&final_buf); + StrBuf->Init(&final_buf); q = buf; while((p = strchr(q, '%'))!=NULL){ if(p!=q){ @@ -13606,12 +13604,12 @@ BUILDIN(sprintf) buf2_len = len; } safestrncpy(buf2, q, len); - StringBuf_AppendStr(&final_buf, buf2); + StrBuf->AppendStr(&final_buf, buf2); q = p; } p = q+1; if(*p=='%'){ // %% - StringBuf_AppendStr(&final_buf, "%"); + StrBuf->AppendStr(&final_buf, "%"); q+=2; continue; } @@ -13625,7 +13623,7 @@ BUILDIN(sprintf) ShowError("buildin_sprintf: Not enough arguments passed!\n"); if(buf) aFree(buf); if(buf2) aFree(buf2); - StringBuf_Destroy(&final_buf); + StrBuf->Destroy(&final_buf); script_pushconststr(st,""); return false; } @@ -13647,21 +13645,21 @@ BUILDIN(sprintf) // the scripter's responsibility. data = script_getdata(st, arg+3); if(data_isstring(data)){ // String - StringBuf_Printf(&final_buf, buf2, script_getstr(st, arg+3)); + StrBuf->Printf(&final_buf, buf2, script_getstr(st, arg+3)); }else if(data_isint(data)){ // Number - StringBuf_Printf(&final_buf, buf2, script_getnum(st, arg+3)); + StrBuf->Printf(&final_buf, buf2, script_getnum(st, arg+3)); }else if(data_isreference(data)){ // Variable char* name = reference_getname(data); if(name[strlen(name)-1]=='$'){ // var Str - StringBuf_Printf(&final_buf, buf2, script_getstr(st, arg+3)); + StrBuf->Printf(&final_buf, buf2, script_getstr(st, arg+3)); }else{ // var Int - StringBuf_Printf(&final_buf, buf2, script_getnum(st, arg+3)); + StrBuf->Printf(&final_buf, buf2, script_getnum(st, arg+3)); } }else{ // Unsupported type ShowError("buildin_sprintf: Unknown argument type!\n"); if(buf) aFree(buf); if(buf2) aFree(buf2); - StringBuf_Destroy(&final_buf); + StrBuf->Destroy(&final_buf); script_pushconststr(st,""); return false; } @@ -13670,7 +13668,7 @@ BUILDIN(sprintf) // Append anything left if(*q){ - StringBuf_AppendStr(&final_buf, q); + StrBuf->AppendStr(&final_buf, q); } // Passed more, than needed @@ -13679,11 +13677,11 @@ BUILDIN(sprintf) script_reportsrc(st); } - script_pushstrcopy(st, StringBuf_Value(&final_buf)); + script_pushstrcopy(st, StrBuf->Value(&final_buf)); if(buf) aFree(buf); if(buf2) aFree(buf2); - StringBuf_Destroy(&final_buf); + StrBuf->Destroy(&final_buf); return true; } @@ -13878,7 +13876,7 @@ BUILDIN(replacestr) } } - StringBuf_Init(&output); + StrBuf->Init(&output); for(; i < inputlen; i++) { if(count && count == numFinds) { //found enough, stop looking @@ -13888,19 +13886,19 @@ BUILDIN(replacestr) for(f = 0; f <= findlen; f++) { if(f == findlen) { //complete match numFinds++; - StringBuf_AppendStr(&output, replace); + StrBuf->AppendStr(&output, replace); i += findlen - 1; break; } else { if(usecase) { if((i + f) > inputlen || input[i + f] != find[f]) { - StringBuf_Printf(&output, "%c", input[i]); + StrBuf->Printf(&output, "%c", input[i]); break; } } else { if(((i + f) > inputlen || input[i + f] != find[f]) && TOUPPER(input[i+f]) != TOUPPER(find[f])) { - StringBuf_Printf(&output, "%c", input[i]); + StrBuf->Printf(&output, "%c", input[i]); break; } } @@ -13910,10 +13908,10 @@ BUILDIN(replacestr) //append excess after enough found if(i < inputlen) - StringBuf_AppendStr(&output, &(input[i])); + StrBuf->AppendStr(&output, &(input[i])); - script_pushstrcopy(st, StringBuf_Value(&output)); - StringBuf_Destroy(&output); + script_pushstrcopy(st, StrBuf->Value(&output)); + StrBuf->Destroy(&output); return true; } @@ -14173,20 +14171,20 @@ int buildin_query_sql_sub(struct script_state* st, Sql* handle) // Execute the query query = script_getstr(st,2); - if( SQL_ERROR == Sql_QueryStr(handle, query) ) { + if( SQL_ERROR == SQL->QueryStr(handle, query) ) { Sql_ShowDebug(handle); script_pushint(st, 0); return false; } - if( Sql_NumRows(handle) == 0 ) { // No data received - Sql_FreeResult(handle); + if( SQL->NumRows(handle) == 0 ) { // No data received + SQL->FreeResult(handle); script_pushint(st, 0); return true; } // Count the number of columns to store - num_cols = Sql_NumColumns(handle); + num_cols = SQL->NumColumns(handle); if( num_vars < num_cols ) { ShowWarning("script:query_sql: Too many columns, discarding last %u columns.\n", (unsigned int)(num_cols-num_vars)); script_reportsrc(st); @@ -14196,12 +14194,12 @@ int buildin_query_sql_sub(struct script_state* st, Sql* handle) } // Store data - for( i = 0; i < max_rows && SQL_SUCCESS == Sql_NextRow(handle); ++i ) { + for( i = 0; i < max_rows && SQL_SUCCESS == SQL->NextRow(handle); ++i ) { for( j = 0; j < num_vars; ++j ) { char* str = NULL; if( j < num_cols ) - Sql_GetData(handle, j, &str, NULL); + SQL->GetData(handle, j, &str, NULL); data = script_getdata(st, j+3); name = reference_getname(data); @@ -14211,13 +14209,13 @@ int buildin_query_sql_sub(struct script_state* st, Sql* handle) setd_sub(st, sd, name, i, (void *)__64BPTRSIZE((str?atoi(str):0)), reference_getref(data)); } } - if( i == max_rows && max_rows < Sql_NumRows(handle) ) { - ShowWarning("script:query_sql: Only %d/%u rows have been stored.\n", max_rows, (unsigned int)Sql_NumRows(handle)); + if( i == max_rows && max_rows < SQL->NumRows(handle) ) { + ShowWarning("script:query_sql: Only %d/%u rows have been stored.\n", max_rows, (unsigned int)SQL->NumRows(handle)); script_reportsrc(st); } // Free data - Sql_FreeResult(handle); + SQL->FreeResult(handle); script_pushint(st, i); return true; @@ -14245,7 +14243,7 @@ BUILDIN(escape_sql) str = script_getstr(st,2); len = strlen(str); esc_str = (char*)aMalloc(len*2+1); - Sql_EscapeStringLen(mmysql_handle, esc_str, str, len); + SQL->EscapeStringLen(mmysql_handle, esc_str, str, len); script_pushstr(st, esc_str); return true; } @@ -15006,12 +15004,12 @@ BUILDIN(unittalk) if( bl != NULL ) { struct StringBuf sbuf; - StringBuf_Init(&sbuf); - StringBuf_Printf(&sbuf, "%s : %s", status_get_name(bl), message); - clif->disp_overhead(bl, StringBuf_Value(&sbuf)); + StrBuf->Init(&sbuf); + StrBuf->Printf(&sbuf, "%s : %s", status_get_name(bl), message); + clif->disp_overhead(bl, StrBuf->Value(&sbuf)); if( bl->type == BL_PC ) - clif->message(((TBL_PC*)bl)->fd, StringBuf_Value(&sbuf)); - StringBuf_Destroy(&sbuf); + clif->message(((TBL_PC*)bl)->fd, StrBuf->Value(&sbuf)); + StrBuf->Destroy(&sbuf); } return true; diff --git a/src/map/skill.c b/src/map/skill.c index 828d600c1..d10cdb1a9 100644 --- a/src/map/skill.c +++ b/src/map/skill.c @@ -17770,27 +17770,27 @@ void skill_readdb(void) { safestrncpy(skill_db[0].name, "UNKNOWN_SKILL", sizeof(skill_db[0].name)); safestrncpy(skill_db[0].desc, "Unknown Skill", sizeof(skill_db[0].desc)); - sv_readdb(db_path, DBPATH"skill_db.txt" , ',', 17, 17, MAX_SKILL_DB, skill->parse_row_skilldb); - sv_readdb(db_path, DBPATH"skill_require_db.txt" , ',', 32, 32, MAX_SKILL_DB, skill->parse_row_requiredb); + sv->readdb(db_path, DBPATH"skill_db.txt" , ',', 17, 17, MAX_SKILL_DB, skill->parse_row_skilldb); + sv->readdb(db_path, DBPATH"skill_require_db.txt" , ',', 32, 32, MAX_SKILL_DB, skill->parse_row_requiredb); #ifdef RENEWAL_CAST - sv_readdb(db_path, "re/skill_cast_db.txt" , ',', 8, 8, MAX_SKILL_DB, skill->parse_row_castdb); + sv->readdb(db_path, "re/skill_cast_db.txt" , ',', 8, 8, MAX_SKILL_DB, skill->parse_row_castdb); #else - sv_readdb(db_path, "pre-re/skill_cast_db.txt" , ',', 7, 7, MAX_SKILL_DB, skill->parse_row_castdb); + sv->readdb(db_path, "pre-re/skill_cast_db.txt" , ',', 7, 7, MAX_SKILL_DB, skill->parse_row_castdb); #endif - sv_readdb(db_path, DBPATH"skill_castnodex_db.txt", ',', 2, 3, MAX_SKILL_DB, skill->parse_row_castnodexdb); - sv_readdb(db_path, DBPATH"skill_unit_db.txt" , ',', 8, 8, MAX_SKILL_DB, skill->parse_row_unitdb); + sv->readdb(db_path, DBPATH"skill_castnodex_db.txt", ',', 2, 3, MAX_SKILL_DB, skill->parse_row_castnodexdb); + sv->readdb(db_path, DBPATH"skill_unit_db.txt" , ',', 8, 8, MAX_SKILL_DB, skill->parse_row_unitdb); skill->init_unit_layout(); - sv_readdb(db_path, "produce_db.txt" , ',', 4, 4+2*MAX_PRODUCE_RESOURCE, MAX_SKILL_PRODUCE_DB, skill->parse_row_producedb); - sv_readdb(db_path, "create_arrow_db.txt" , ',', 1+2, 1+2*MAX_ARROW_RESOURCE, MAX_SKILL_ARROW_DB, skill->parse_row_createarrowdb); - sv_readdb(db_path, "abra_db.txt" , ',', 4, 4, MAX_SKILL_ABRA_DB, skill->parse_row_abradb); + sv->readdb(db_path, "produce_db.txt" , ',', 4, 4+2*MAX_PRODUCE_RESOURCE, MAX_SKILL_PRODUCE_DB, skill->parse_row_producedb); + sv->readdb(db_path, "create_arrow_db.txt" , ',', 1+2, 1+2*MAX_ARROW_RESOURCE, MAX_SKILL_ARROW_DB, skill->parse_row_createarrowdb); + sv->readdb(db_path, "abra_db.txt" , ',', 4, 4, MAX_SKILL_ABRA_DB, skill->parse_row_abradb); //Warlock - sv_readdb(db_path, "spellbook_db.txt" , ',', 3, 3, MAX_SKILL_SPELLBOOK_DB, skill->parse_row_spellbookdb); + sv->readdb(db_path, "spellbook_db.txt" , ',', 3, 3, MAX_SKILL_SPELLBOOK_DB, skill->parse_row_spellbookdb); //Guillotine Cross - sv_readdb(db_path, "magicmushroom_db.txt" , ',', 1, 1, MAX_SKILL_MAGICMUSHROOM_DB, skill->parse_row_magicmushroomdb); - sv_readdb(db_path, "skill_reproduce_db.txt", ',', 1, 1, MAX_SKILL_DB, skill->parse_row_reproducedb); - sv_readdb(db_path, "skill_improvise_db.txt" , ',', 2, 2, MAX_SKILL_IMPROVISE_DB, skill->parse_row_improvisedb); - sv_readdb(db_path, "skill_changematerial_db.txt" , ',', 4, 4+2*5, MAX_SKILL_PRODUCE_DB, skill->parse_row_changematerialdb); + sv->readdb(db_path, "magicmushroom_db.txt" , ',', 1, 1, MAX_SKILL_MAGICMUSHROOM_DB, skill->parse_row_magicmushroomdb); + sv->readdb(db_path, "skill_reproduce_db.txt", ',', 1, 1, MAX_SKILL_DB, skill->parse_row_reproducedb); + sv->readdb(db_path, "skill_improvise_db.txt" , ',', 2, 2, MAX_SKILL_IMPROVISE_DB, skill->parse_row_improvisedb); + sv->readdb(db_path, "skill_changematerial_db.txt" , ',', 4, 4+2*5, MAX_SKILL_PRODUCE_DB, skill->parse_row_changematerialdb); } void skill_reload (void) { @@ -17815,9 +17815,9 @@ void skill_reload (void) { chrif_skillid2idx(0); /* lets update all players skill tree : so that if any skill modes were changed they're properly updated */ iter = mapit_getallusers(); - for( sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); sd = (TBL_PC*)mapit_next(iter) ) + for( sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); sd = (TBL_PC*)mapit->next(iter) ) clif->skillinfoblock(sd); - mapit_free(iter); + mapit->free(iter); } diff --git a/src/map/status.c b/src/map/status.c index f13c1ce3a..9fbfe26fe 100644 --- a/src/map/status.c +++ b/src/map/status.c @@ -11282,13 +11282,13 @@ int status_readdb(void) #ifdef RENEWAL_ASPD - sv_readdb(db_path, "re/job_db1.txt", ',', 6+MAX_WEAPON_TYPE, 6+MAX_WEAPON_TYPE, -1, &status_readdb_job1); + sv->readdb(db_path, "re/job_db1.txt", ',', 6+MAX_WEAPON_TYPE, 6+MAX_WEAPON_TYPE, -1, &status_readdb_job1); #else - sv_readdb(db_path, "pre-re/job_db1.txt", ',', 5+MAX_WEAPON_TYPE, 5+MAX_WEAPON_TYPE, -1, &status_readdb_job1); + sv->readdb(db_path, "pre-re/job_db1.txt", ',', 5+MAX_WEAPON_TYPE, 5+MAX_WEAPON_TYPE, -1, &status_readdb_job1); #endif - sv_readdb(db_path, "job_db2.txt", ',', 1, 1+MAX_LEVEL, -1, &status_readdb_job2); - sv_readdb(db_path, "size_fix.txt", ',', MAX_WEAPON_TYPE, MAX_WEAPON_TYPE, ARRAYLENGTH(atkmods), &status_readdb_sizefix); - sv_readdb(db_path, DBPATH"refine_db.txt", ',', 4+MAX_REFINE, 4+MAX_REFINE, ARRAYLENGTH(refine_info), &status_readdb_refine); + sv->readdb(db_path, "job_db2.txt", ',', 1, 1+MAX_LEVEL, -1, &status_readdb_job2); + sv->readdb(db_path, "size_fix.txt", ',', MAX_WEAPON_TYPE, MAX_WEAPON_TYPE, ARRAYLENGTH(atkmods), &status_readdb_sizefix); + sv->readdb(db_path, DBPATH"refine_db.txt", ',', 4+MAX_REFINE, 4+MAX_REFINE, ARRAYLENGTH(refine_info), &status_readdb_refine); return 0; } -- cgit v1.2.3-60-g2f50