From 02fcaed6bd32b0ffbc4f03b8f9de6f0720e6253f Mon Sep 17 00:00:00 2001 From: Haru Date: Sun, 16 Nov 2014 06:35:51 +0100 Subject: Whitespace cleanup (no code changes) This includes, and is not limited to: mixed or wrong indentation, excess whitespace (horizontal and vertical), misalignment, trailing spaces. Signed-off-by: Haru --- src/char/char.c | 1045 ++++++++++----------- src/char/geoip.c | 2 +- src/char/int_auction.c | 32 +- src/char/int_auction.h | 20 +- src/char/int_elemental.c | 26 +- src/char/int_elemental.h | 6 +- src/char/int_guild.c | 41 +- src/char/int_guild.h | 52 +- src/char/int_homun.c | 8 +- src/char/int_homun.h | 6 +- src/char/int_mail.c | 4 +- src/char/int_mail.h | 16 +- src/char/int_mercenary.c | 2 +- src/char/int_mercenary.h | 12 +- src/char/int_party.c | 23 +- src/char/int_party.h | 30 +- src/char/int_pet.c | 2 +- src/char/int_pet.h | 14 +- src/char/int_quest.c | 2 +- src/char/int_quest.h | 2 +- src/char/int_storage.c | 14 +- src/char/int_storage.h | 18 +- src/char/inter.c | 80 +- src/char/inter.h | 38 +- src/char/pincode.c | 25 +- src/common/HPM.c | 240 +++-- src/common/atomic.h | 14 +- src/common/cbasetypes.h | 113 ++- src/common/conf.c | 11 +- src/common/conf.h | 28 +- src/common/console.c | 90 +- src/common/core.c | 30 +- src/common/db.c | 21 +- src/common/db.h | 6 +- src/common/des.c | 16 +- src/common/ers.c | 40 +- src/common/ers.h | 2 +- src/common/grfio.c | 91 +- src/common/malloc.c | 74 +- src/common/malloc.h | 20 +- src/common/mapindex.c | 24 +- src/common/md5calc.c | 224 ++--- src/common/mmo.h | 22 +- src/common/mutex.c | 60 +- src/common/nullpo.c | 4 +- src/common/showmsg.c | 361 +++---- src/common/socket.c | 60 +- src/common/socket.h | 2 +- src/common/spinlock.h | 26 +- src/common/sql.c | 16 +- src/common/strlib.c | 16 +- src/common/strlib.h | 26 +- src/common/thread.c | 37 +- src/common/thread.h | 4 +- src/common/timer.c | 36 +- src/common/utils.c | 66 +- src/common/winapi.h | 6 +- src/login/account_sql.c | 79 +- src/login/ipban_sql.c | 2 +- src/login/login.c | 56 +- src/login/login.h | 58 +- src/map/atcommand.c | 2289 ++++++++++++++++++++++----------------------- src/map/battle.c | 347 +++---- src/map/battle.h | 161 ++-- src/map/battleground.c | 124 ++- src/map/buyingstore.c | 11 +- src/map/chat.c | 32 +- src/map/chat.h | 23 +- src/map/chrif.c | 293 +++--- src/map/chrif.h | 16 +- src/map/clif.c | 226 ++--- src/map/clif.h | 70 +- src/map/duel.h | 2 +- src/map/elemental.c | 41 +- src/map/elemental.h | 16 +- src/map/guild.c | 155 +-- src/map/guild.h | 4 +- src/map/homunculus.c | 64 +- src/map/homunculus.h | 2 +- src/map/instance.c | 12 +- src/map/instance.h | 8 +- src/map/intif.c | 147 +-- src/map/irc-bot.c | 2 +- src/map/itemdb.c | 53 +- src/map/itemdb.h | 24 +- src/map/log.c | 2 +- src/map/log.h | 6 +- src/map/map.c | 66 +- src/map/map.h | 115 ++- src/map/mercenary.h | 20 +- src/map/mob.c | 321 ++++--- src/map/mob.h | 12 +- src/map/npc.c | 49 +- src/map/npc.h | 2 +- src/map/packets.h | 208 ++-- src/map/packets_struct.h | 6 +- src/map/party.c | 36 +- src/map/party.h | 16 +- src/map/path.c | 4 +- src/map/pc.c | 280 +++--- src/map/pc.h | 166 ++-- src/map/pet.c | 23 +- src/map/pet.h | 12 +- src/map/script.h | 18 +- src/map/searchstore.c | 4 +- src/map/skill.c | 831 +++++++++------- src/map/skill.h | 164 ++-- src/map/status.c | 406 ++++---- src/map/status.h | 122 +-- src/map/storage.c | 144 +-- src/map/trade.c | 43 +- src/map/unit.c | 108 +-- src/map/vending.c | 30 +- src/plugins/HPMHooking.c | 43 +- src/plugins/db2sql.c | 46 +- src/plugins/dbghelpplug.c | 175 ++-- src/plugins/sample.c | 42 +- src/test/test_spinlock.c | 26 +- 118 files changed, 5599 insertions(+), 5570 deletions(-) (limited to 'src') diff --git a/src/char/char.c b/src/char/char.c index d5adaa251..72ca563c3 100644 --- a/src/char/char.c +++ b/src/char/char.c @@ -46,9 +46,9 @@ #include "../common/utils.h" // private declarations -#define CHAR_CONF_NAME "conf/char-server.conf" -#define LAN_CONF_NAME "conf/subnet.conf" -#define SQL_CONF_NAME "conf/inter-server.conf" +#define CHAR_CONF_NAME "conf/char-server.conf" +#define LAN_CONF_NAME "conf/subnet.conf" +#define SQL_CONF_NAME "conf/inter-server.conf" char char_db[256] = "char"; char scdata_db[256] = "sc_data"; @@ -117,8 +117,8 @@ char char_name_letters[1024] = ""; // list of letters/symbols allowed (or not) i int char_del_level = 0; //From which level u can delete character [Lupus] int char_del_delay = 86400; -int log_char = 1; // logging char or not [devil] -int log_inter = 1; // logging inter or not [devil] +int log_char = 1; // logging char or not [devil] +int log_inter = 1; // logging inter or not [devil] int char_aegis_delete = 0; // Verify if char is in guild/party or char and reacts as Aegis does (doesn't allow deletion), see chr->delete2_req for more information @@ -284,8 +284,8 @@ void char_set_char_offline(int char_id, int account_id) Sql_ShowDebug(inter->sql_handle); } - if ((character = (struct online_char_data*)idb_get(chr->online_char_db, account_id)) != NULL) - { //We don't free yet to avoid aCalloc/aFree spamming during char change. [Skotlex] + if ((character = (struct online_char_data*)idb_get(chr->online_char_db, account_id)) != NULL) { + //We don't free yet to avoid aCalloc/aFree spamming during char change. [Skotlex] if( character->server > -1 ) if( chr->server[character->server].users > 0 ) // Prevent this value from going negative. chr->server[character->server].users--; @@ -434,7 +434,7 @@ int char_mmo_char_tosql(int char_id, struct mmo_charstatus* p) else errors++; } - + if ( (p->base_exp != cp->base_exp) || (p->base_level != cp->base_level) || (p->job_level != cp->job_level) || (p->job_exp != cp->job_exp) || @@ -454,14 +454,15 @@ int char_mmo_char_tosql(int char_id, struct mmo_charstatus* p) (p->rename != cp->rename) || (p->slotchange != cp->slotchange) || (p->robe != cp->robe) || (p->show_equip != cp->show_equip) || (p->allow_party != cp->allow_party) || (p->font != cp->font) || (p->uniqueitem_counter != cp->uniqueitem_counter ) - ) { //Save status + ) { + //Save status unsigned int opt = 0; - + if( p->allow_party ) opt |= OPT_ALLOW_PARTY; if( p->show_equip ) opt |= OPT_SHOW_EQUIP; - + if( SQL_ERROR == SQL->Query(inter->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'," @@ -488,7 +489,7 @@ int char_mmo_char_tosql(int char_id, struct mmo_charstatus* p) } else strcat(save_status, " status"); } - + if( p->bank_vault != cp->bank_vault || p->mod_exp != cp->mod_exp || p->mod_drop != cp->mod_drop || p->mod_death != cp->mod_death ) { if( SQL_ERROR == SQL->Query(inter->sql_handle, "REPLACE INTO `%s` (`account_id`,`bank_vault`,`base_exp`,`base_drop`,`base_death`) VALUES ('%d','%d','%d','%d','%d')",account_data_db,p->account_id,p->bank_vault,p->mod_exp,p->mod_drop,p->mod_death) ) { Sql_ShowDebug(inter->sql_handle); @@ -503,7 +504,7 @@ int char_mmo_char_tosql(int char_id, struct mmo_charstatus* p) (p->class_ != cp->class_) || (p->partner_id != cp->partner_id) || (p->father != cp->father) || (p->mother != cp->mother) || (p->child != cp->child) || - (p->karma != cp->karma) || (p->manner != cp->manner) || + (p->karma != cp->karma) || (p->manner != cp->manner) || (p->fame != cp->fame) ) { @@ -586,7 +587,6 @@ int char_mmo_char_tosql(int char_id, struct mmo_charstatus* p) //insert here. for( i = 0, count = 0; i < MAX_SKILL; ++i ) { if( p->skill[i].id != 0 && p->skill[i].flag != SKILL_FLAG_TEMPORARY ) { - if( p->skill[i].lv == 0 && ( p->skill[i].flag == SKILL_FLAG_PERM_GRANTED || p->skill[i].flag == SKILL_FLAG_PERMANENT ) ) continue; 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 ) @@ -620,8 +620,8 @@ int char_mmo_char_tosql(int char_id, struct mmo_charstatus* p) } } - if(diff == 1) - { //Save friends + if(diff == 1) { + //Save friends if( SQL_ERROR == SQL->Query(inter->sql_handle, "DELETE FROM `%s` WHERE `char_id`='%d'", friend_db, char_id) ) { Sql_ShowDebug(inter->sql_handle); @@ -674,7 +674,7 @@ int char_mmo_char_tosql(int char_id, struct mmo_charstatus* p) strcat(save_status, " hotkeys"); } #endif - + StrBuf->Destroy(&buf); if (save_status[0]!='\0' && save_log) ShowInfo("Saved char %d - %s:%s.\n", char_id, p->name, save_status); @@ -715,7 +715,7 @@ int char_memitemdata_to_sql(const struct item items[], int max, int id, int tabl StrBuf->Init(&buf); StrBuf->AppendStr(&buf, "SELECT `id`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `expire_time`, `bound`"); - for( j = 0; j < MAX_SLOTS; ++j ) + for( j = 0; j < MAX_SLOTS; ++j ) StrBuf->Printf(&buf, ", `card%d`", j); StrBuf->Printf(&buf, " FROM `%s` WHERE `%s`='%d'", tablename, selectoption, id); @@ -739,7 +739,7 @@ int char_memitemdata_to_sql(const struct item items[], int max, int id, int tabl SQL->StmtBindColumn(stmt, 6, SQLDT_CHAR, &item.attribute, 0, NULL, NULL); SQL->StmtBindColumn(stmt, 7, SQLDT_UINT, &item.expire_time, 0, NULL, NULL); SQL->StmtBindColumn(stmt, 8, SQLDT_UCHAR, &item.bound, 0, NULL, NULL); - for( j = 0; j < MAX_SLOTS; ++j ) + for( j = 0; j < MAX_SLOTS; ++j ) SQL->StmtBindColumn(stmt, 9+j, SQLDT_SHORT, &item.card[j], 0, NULL, NULL); // bit array indicating which inventory items have already been matched @@ -756,29 +756,30 @@ int char_memitemdata_to_sql(const struct item items[], int max, int id, int tabl continue; if( items[i].nameid == item.nameid - && items[i].card[0] == item.card[0] - && items[i].card[2] == item.card[2] - && items[i].card[3] == item.card[3] - ) { //They are the same item. + && items[i].card[0] == item.card[0] + && items[i].card[2] == item.card[2] + && items[i].card[3] == item.card[3] + ) { + //They are the same item. ARR_FIND( 0, MAX_SLOTS, j, items[i].card[j] != item.card[j] ); - if( j == MAX_SLOTS && - items[i].amount == item.amount && - items[i].equip == item.equip && - items[i].identify == item.identify && - items[i].refine == item.refine && - items[i].attribute == item.attribute && - items[i].expire_time == item.expire_time && - items[i].bound == item.bound ) - ; //Do nothing. - else - { + if( j == MAX_SLOTS + && items[i].amount == item.amount + && items[i].equip == item.equip + && items[i].identify == item.identify + && items[i].refine == item.refine + && items[i].attribute == item.attribute + && items[i].expire_time == item.expire_time + && items[i].bound == item.bound + ) { + ; //Do nothing. + } else { // update all fields. StrBuf->Clear(&buf); StrBuf->Printf(&buf, "UPDATE `%s` SET `amount`='%d', `equip`='%d', `identify`='%d', `refine`='%d',`attribute`='%d', `expire_time`='%u', `bound`='%d'", tablename, items[i].amount, items[i].equip, items[i].identify, items[i].refine, items[i].attribute, items[i].expire_time, items[i].bound); - for( j = 0; j < MAX_SLOTS; ++j )for( j = 0; j < MAX_SLOTS; ++j ) + for( j = 0; j < MAX_SLOTS; ++j )for( j = 0; j < MAX_SLOTS; ++j ) StrBuf->Printf(&buf, ", `card%d`=%d", j, items[i].card[j]); - StrBuf->Printf(&buf, " WHERE `id`='%d' LIMIT 1", item.id); + StrBuf->Printf(&buf, " WHERE `id`='%d' LIMIT 1", item.id); if( SQL_ERROR == SQL->QueryStr(inter->sql_handle, StrBuf->Value(&buf)) ) { @@ -804,7 +805,7 @@ int char_memitemdata_to_sql(const struct item items[], int max, int id, int tabl StrBuf->Clear(&buf); StrBuf->Printf(&buf, "INSERT INTO `%s`(`%s`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `expire_time`, `bound`, `unique_id`", tablename, selectoption); - for( j = 0; j < MAX_SLOTS; ++j ) + for( j = 0; j < MAX_SLOTS; ++j ) StrBuf->Printf(&buf, ", `card%d`", j); StrBuf->AppendStr(&buf, ") VALUES "); @@ -823,7 +824,7 @@ int char_memitemdata_to_sql(const struct item items[], int max, int id, int tabl 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].bound, items[i].unique_id); - for( j = 0; j < MAX_SLOTS; ++j ) + for( j = 0; j < MAX_SLOTS; ++j ) StrBuf->Printf(&buf, ", '%d'", items[i].card[j]); StrBuf->AppendStr(&buf, ")"); } @@ -859,7 +860,7 @@ int char_inventory_to_sql(const struct item items[], int max, int id) { StrBuf->Init(&buf); StrBuf->AppendStr(&buf, "SELECT `id`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `expire_time`, `favorite`, `bound`"); - for( j = 0; j < MAX_SLOTS; ++j ) + for( j = 0; j < MAX_SLOTS; ++j ) StrBuf->Printf(&buf, ", `card%d`", j); StrBuf->Printf(&buf, " FROM `%s` WHERE `char_id`='%d'", inventory_db, id); @@ -884,7 +885,7 @@ int char_inventory_to_sql(const struct item items[], int max, int id) { SQL->StmtBindColumn(stmt, 7, SQLDT_UINT, &item.expire_time, 0, NULL, NULL); SQL->StmtBindColumn(stmt, 8, SQLDT_CHAR, &item.favorite, 0, NULL, NULL); SQL->StmtBindColumn(stmt, 9, SQLDT_UCHAR, &item.bound, 0, NULL, NULL); - for( j = 0; j < MAX_SLOTS; ++j ) + for( j = 0; j < MAX_SLOTS; ++j ) SQL->StmtBindColumn(stmt, 10+j, SQLDT_SHORT, &item.card[j], 0, NULL, NULL); // bit array indicating which inventory items have already been matched @@ -899,28 +900,30 @@ int char_inventory_to_sql(const struct item items[], int max, int id) { continue; if( items[i].nameid == item.nameid - && items[i].card[0] == item.card[0] - && items[i].card[2] == item.card[2] - && items[i].card[3] == item.card[3] - ) { //They are the same item. + && items[i].card[0] == item.card[0] + && items[i].card[2] == item.card[2] + && items[i].card[3] == item.card[3] + ) { + //They are the same item. ARR_FIND( 0, MAX_SLOTS, j, items[i].card[j] != item.card[j] ); - if( j == MAX_SLOTS && - items[i].amount == item.amount && - items[i].equip == item.equip && - items[i].identify == item.identify && - items[i].refine == item.refine && - items[i].attribute == item.attribute && - items[i].expire_time == item.expire_time && - items[i].favorite == item.favorite && - items[i].bound == item.bound ) - ; //Do nothing. - else { + if( j == MAX_SLOTS + && items[i].amount == item.amount + && items[i].equip == item.equip + && items[i].identify == item.identify + && items[i].refine == item.refine + && items[i].attribute == item.attribute + && items[i].expire_time == item.expire_time + && items[i].favorite == item.favorite + && items[i].bound == item.bound + ) { + ; //Do nothing. + } else { // update all fields. StrBuf->Clear(&buf); StrBuf->Printf(&buf, "UPDATE `%s` SET `amount`='%d', `equip`='%d', `identify`='%d', `refine`='%d',`attribute`='%d', `expire_time`='%u', `favorite`='%d', `bound`='%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, items[i].bound); - for( j = 0; j < MAX_SLOTS; ++j ) - StrBuf->Printf(&buf, ", `card%d`=%d", j, items[i].card[j]); + inventory_db, items[i].amount, items[i].equip, items[i].identify, items[i].refine, items[i].attribute, items[i].expire_time, items[i].favorite, items[i].bound); + for( j = 0; j < MAX_SLOTS; ++j ) + 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(inter->sql_handle, StrBuf->Value(&buf)) ) { @@ -944,7 +947,7 @@ int char_inventory_to_sql(const struct item items[], int max, int id) { StrBuf->Clear(&buf); StrBuf->Printf(&buf, "INSERT INTO `%s` (`char_id`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `expire_time`, `favorite`, `bound`, `unique_id`", inventory_db); - for( j = 0; j < MAX_SLOTS; ++j ) + for( j = 0; j < MAX_SLOTS; ++j ) StrBuf->Printf(&buf, ", `card%d`", j); StrBuf->AppendStr(&buf, ") VALUES "); @@ -962,7 +965,7 @@ int char_inventory_to_sql(const struct item items[], int max, int id) { StrBuf->Printf(&buf, "('%d', '%d', '%d', '%d', '%d', '%d', '%d', '%u', '%d', '%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].bound, items[i].unique_id); - for( j = 0; j < MAX_SLOTS; ++j ) + for( j = 0; j < MAX_SLOTS; ++j ) StrBuf->Printf(&buf, ", '%d'", items[i].card[j]); StrBuf->AppendStr(&buf, ")"); } @@ -1000,62 +1003,61 @@ int char_mmo_chars_fromsql(struct char_session_data* sd, uint8* buf) sd->found_char[i] = -1; sd->unban_time[i] = 0; } - + // read char data - if( SQL_ERROR == SQL->StmtPrepare(stmt, "SELECT " + if (SQL_ERROR == SQL->StmtPrepare(stmt, "SELECT " "`char_id`,`char_num`,`name`,`class`,`base_level`,`job_level`,`base_exp`,`job_exp`,`zeny`," "`str`,`agi`,`vit`,`int`,`dex`,`luk`,`max_hp`,`hp`,`max_sp`,`sp`," "`status_point`,`skill_point`,`option`,`karma`,`manner`,`hair`,`hair_color`," "`clothes_color`,`weapon`,`shield`,`head_top`,`head_mid`,`head_bottom`,`last_map`,`rename`,`delete_date`," "`robe`,`slotchange`,`unban_time`,`sex`" " FROM `%s` WHERE `account_id`='%d' AND `char_num` < '%d'", char_db, sd->account_id, MAX_CHARS) - || SQL_ERROR == SQL->StmtExecute(stmt) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 0, SQLDT_INT, &p.char_id, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 1, SQLDT_UCHAR, &p.slot, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 2, SQLDT_STRING, &p.name, sizeof(p.name), NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 3, SQLDT_SHORT, &p.class_, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 4, SQLDT_UINT, &p.base_level, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 5, SQLDT_UINT, &p.job_level, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 6, SQLDT_UINT, &p.base_exp, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 7, SQLDT_UINT, &p.job_exp, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 8, SQLDT_INT, &p.zeny, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 9, SQLDT_SHORT, &p.str, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 10, SQLDT_SHORT, &p.agi, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 11, SQLDT_SHORT, &p.vit, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 12, SQLDT_SHORT, &p.int_, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 13, SQLDT_SHORT, &p.dex, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 14, SQLDT_SHORT, &p.luk, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 15, SQLDT_INT, &p.max_hp, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 16, SQLDT_INT, &p.hp, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 17, SQLDT_INT, &p.max_sp, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 18, SQLDT_INT, &p.sp, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 19, SQLDT_UINT, &p.status_point, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 20, SQLDT_UINT, &p.skill_point, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 21, SQLDT_UINT, &p.option, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 22, SQLDT_UCHAR, &p.karma, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 23, SQLDT_SHORT, &p.manner, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 24, SQLDT_SHORT, &p.hair, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 25, SQLDT_SHORT, &p.hair_color, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 26, SQLDT_SHORT, &p.clothes_color, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 27, SQLDT_SHORT, &p.weapon, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 28, SQLDT_SHORT, &p.shield, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 29, SQLDT_SHORT, &p.head_top, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 30, SQLDT_SHORT, &p.head_mid, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 31, SQLDT_SHORT, &p.head_bottom, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 32, SQLDT_STRING, &last_map, sizeof(last_map), NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 33, SQLDT_USHORT, &p.rename, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 34, SQLDT_UINT32, &p.delete_date, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 35, SQLDT_SHORT, &p.robe, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 36, SQLDT_USHORT, &p.slotchange, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 37, SQLDT_LONG, &unban_time, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 38, SQLDT_ENUM, &sex, sizeof(sex), NULL, NULL) - ) - { + || SQL_ERROR == SQL->StmtExecute(stmt) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 0, SQLDT_INT, &p.char_id, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 1, SQLDT_UCHAR, &p.slot, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 2, SQLDT_STRING, &p.name, sizeof(p.name), NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 3, SQLDT_SHORT, &p.class_, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 4, SQLDT_UINT, &p.base_level, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 5, SQLDT_UINT, &p.job_level, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 6, SQLDT_UINT, &p.base_exp, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 7, SQLDT_UINT, &p.job_exp, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 8, SQLDT_INT, &p.zeny, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 9, SQLDT_SHORT, &p.str, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 10, SQLDT_SHORT, &p.agi, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 11, SQLDT_SHORT, &p.vit, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 12, SQLDT_SHORT, &p.int_, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 13, SQLDT_SHORT, &p.dex, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 14, SQLDT_SHORT, &p.luk, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 15, SQLDT_INT, &p.max_hp, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 16, SQLDT_INT, &p.hp, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 17, SQLDT_INT, &p.max_sp, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 18, SQLDT_INT, &p.sp, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 19, SQLDT_UINT, &p.status_point, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 20, SQLDT_UINT, &p.skill_point, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 21, SQLDT_UINT, &p.option, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 22, SQLDT_UCHAR, &p.karma, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 23, SQLDT_SHORT, &p.manner, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 24, SQLDT_SHORT, &p.hair, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 25, SQLDT_SHORT, &p.hair_color, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 26, SQLDT_SHORT, &p.clothes_color, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 27, SQLDT_SHORT, &p.weapon, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 28, SQLDT_SHORT, &p.shield, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 29, SQLDT_SHORT, &p.head_top, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 30, SQLDT_SHORT, &p.head_mid, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 31, SQLDT_SHORT, &p.head_bottom, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 32, SQLDT_STRING, &last_map, sizeof(last_map), NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 33, SQLDT_USHORT, &p.rename, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 34, SQLDT_UINT32, &p.delete_date, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 35, SQLDT_SHORT, &p.robe, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 36, SQLDT_USHORT, &p.slotchange, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 37, SQLDT_LONG, &unban_time, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 38, SQLDT_ENUM, &sex, sizeof(sex), NULL, NULL) + ) { SqlStmt_ShowDebug(stmt); SQL->StmtFree(stmt); return 0; } - + for( i = 0; i < MAX_CHARS && SQL_SUCCESS == SQL->StmtNextRow(stmt); i++ ) { p.last_point.map = mapindex->name2id(last_map); sd->found_char[p.slot] = p.char_id; @@ -1074,7 +1076,7 @@ int char_mmo_chars_fromsql(struct char_session_data* sd, uint8* buf) } j += chr->mmo_char_tobuf(WBUFP(buf, j), &p); } - + memset(sd->new_name,0,sizeof(sd->new_name)); SQL->StmtFree(stmt); @@ -1116,7 +1118,7 @@ int char_mmo_char_fromsql(int char_id, struct mmo_charstatus* p, bool load_every } // read char data - if( SQL_ERROR == SQL->StmtPrepare(stmt, "SELECT " + if (SQL_ERROR == SQL->StmtPrepare(stmt, "SELECT " "`char_id`,`account_id`,`char_num`,`name`,`class`,`base_level`,`job_level`,`base_exp`,`job_exp`,`zeny`," "`str`,`agi`,`vit`,`int`,`dex`,`luk`,`max_hp`,`hp`,`max_sp`,`sp`," "`status_point`,`skill_point`,`option`,`karma`,`manner`,`party_id`,`guild_id`,`pet_id`,`homun_id`,`elemental_id`,`hair`," @@ -1124,67 +1126,66 @@ int char_mmo_char_fromsql(int char_id, struct mmo_charstatus* p, bool load_every "`save_map`,`save_x`,`save_y`,`partner_id`,`father`,`mother`,`child`,`fame`,`rename`,`delete_date`,`robe`,`slotchange`," "`char_opt`,`font`,`uniqueitem_counter`,`sex`" " FROM `%s` WHERE `char_id`=? LIMIT 1", char_db) - || SQL_ERROR == SQL->StmtBindParam(stmt, 0, SQLDT_INT, &char_id, 0) - || SQL_ERROR == SQL->StmtExecute(stmt) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 0, SQLDT_INT, &p->char_id, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 1, SQLDT_INT, &p->account_id, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 2, SQLDT_UCHAR, &p->slot, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 3, SQLDT_STRING, &p->name, sizeof(p->name), NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 4, SQLDT_SHORT, &p->class_, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 5, SQLDT_UINT, &p->base_level, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 6, SQLDT_UINT, &p->job_level, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 7, SQLDT_UINT, &p->base_exp, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 8, SQLDT_UINT, &p->job_exp, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 9, SQLDT_INT, &p->zeny, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 10, SQLDT_SHORT, &p->str, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 11, SQLDT_SHORT, &p->agi, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 12, SQLDT_SHORT, &p->vit, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 13, SQLDT_SHORT, &p->int_, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 14, SQLDT_SHORT, &p->dex, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 15, SQLDT_SHORT, &p->luk, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 16, SQLDT_INT, &p->max_hp, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 17, SQLDT_INT, &p->hp, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 18, SQLDT_INT, &p->max_sp, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 19, SQLDT_INT, &p->sp, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 20, SQLDT_UINT, &p->status_point, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 21, SQLDT_UINT, &p->skill_point, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 22, SQLDT_UINT, &p->option, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 23, SQLDT_UCHAR, &p->karma, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 24, SQLDT_SHORT, &p->manner, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 25, SQLDT_INT, &p->party_id, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 26, SQLDT_INT, &p->guild_id, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 27, SQLDT_INT, &p->pet_id, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 28, SQLDT_INT, &p->hom_id, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 29, SQLDT_INT, &p->ele_id, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 30, SQLDT_SHORT, &p->hair, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 31, SQLDT_SHORT, &p->hair_color, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 32, SQLDT_SHORT, &p->clothes_color, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 33, SQLDT_SHORT, &p->weapon, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 34, SQLDT_SHORT, &p->shield, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 35, SQLDT_SHORT, &p->head_top, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 36, SQLDT_SHORT, &p->head_mid, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 37, SQLDT_SHORT, &p->head_bottom, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 38, SQLDT_STRING, &last_map, sizeof(last_map), NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 39, SQLDT_SHORT, &p->last_point.x, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 40, SQLDT_SHORT, &p->last_point.y, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 41, SQLDT_STRING, &save_map, sizeof(save_map), NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 42, SQLDT_SHORT, &p->save_point.x, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 43, SQLDT_SHORT, &p->save_point.y, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 44, SQLDT_INT, &p->partner_id, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 45, SQLDT_INT, &p->father, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 46, SQLDT_INT, &p->mother, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 47, SQLDT_INT, &p->child, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 48, SQLDT_INT, &p->fame, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 49, SQLDT_USHORT, &p->rename, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 50, SQLDT_UINT32, &p->delete_date, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 51, SQLDT_SHORT, &p->robe, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 52, SQLDT_USHORT, &p->slotchange, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 53, SQLDT_UINT, &opt, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 54, SQLDT_UCHAR, &p->font, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 55, SQLDT_UINT, &p->uniqueitem_counter, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 56, SQLDT_ENUM, &sex, sizeof(sex), NULL, NULL) - ) - { + || SQL_ERROR == SQL->StmtBindParam(stmt, 0, SQLDT_INT, &char_id, 0) + || SQL_ERROR == SQL->StmtExecute(stmt) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 0, SQLDT_INT, &p->char_id, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 1, SQLDT_INT, &p->account_id, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 2, SQLDT_UCHAR, &p->slot, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 3, SQLDT_STRING, &p->name, sizeof(p->name), NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 4, SQLDT_SHORT, &p->class_, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 5, SQLDT_UINT, &p->base_level, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 6, SQLDT_UINT, &p->job_level, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 7, SQLDT_UINT, &p->base_exp, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 8, SQLDT_UINT, &p->job_exp, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 9, SQLDT_INT, &p->zeny, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 10, SQLDT_SHORT, &p->str, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 11, SQLDT_SHORT, &p->agi, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 12, SQLDT_SHORT, &p->vit, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 13, SQLDT_SHORT, &p->int_, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 14, SQLDT_SHORT, &p->dex, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 15, SQLDT_SHORT, &p->luk, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 16, SQLDT_INT, &p->max_hp, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 17, SQLDT_INT, &p->hp, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 18, SQLDT_INT, &p->max_sp, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 19, SQLDT_INT, &p->sp, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 20, SQLDT_UINT, &p->status_point, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 21, SQLDT_UINT, &p->skill_point, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 22, SQLDT_UINT, &p->option, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 23, SQLDT_UCHAR, &p->karma, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 24, SQLDT_SHORT, &p->manner, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 25, SQLDT_INT, &p->party_id, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 26, SQLDT_INT, &p->guild_id, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 27, SQLDT_INT, &p->pet_id, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 28, SQLDT_INT, &p->hom_id, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 29, SQLDT_INT, &p->ele_id, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 30, SQLDT_SHORT, &p->hair, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 31, SQLDT_SHORT, &p->hair_color, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 32, SQLDT_SHORT, &p->clothes_color, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 33, SQLDT_SHORT, &p->weapon, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 34, SQLDT_SHORT, &p->shield, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 35, SQLDT_SHORT, &p->head_top, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 36, SQLDT_SHORT, &p->head_mid, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 37, SQLDT_SHORT, &p->head_bottom, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 38, SQLDT_STRING, &last_map, sizeof(last_map), NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 39, SQLDT_SHORT, &p->last_point.x, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 40, SQLDT_SHORT, &p->last_point.y, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 41, SQLDT_STRING, &save_map, sizeof(save_map), NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 42, SQLDT_SHORT, &p->save_point.x, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 43, SQLDT_SHORT, &p->save_point.y, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 44, SQLDT_INT, &p->partner_id, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 45, SQLDT_INT, &p->father, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 46, SQLDT_INT, &p->mother, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 47, SQLDT_INT, &p->child, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 48, SQLDT_INT, &p->fame, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 49, SQLDT_USHORT, &p->rename, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 50, SQLDT_UINT32, &p->delete_date, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 51, SQLDT_SHORT, &p->robe, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 52, SQLDT_USHORT, &p->slotchange, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 53, SQLDT_UINT, &opt, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 54, SQLDT_UCHAR, &p->font, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 55, SQLDT_UINT, &p->uniqueitem_counter, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 56, SQLDT_ENUM, &sex, sizeof(sex), NULL, NULL) + ) { SqlStmt_ShowDebug(stmt); SQL->StmtFree(stmt); return 0; @@ -1195,7 +1196,7 @@ int char_mmo_char_fromsql(int char_id, struct mmo_charstatus* p, bool load_every SQL->StmtFree(stmt); return 0; } - + switch( sex[0] ) { case 'M': p->sex = 1; @@ -1208,9 +1209,9 @@ int char_mmo_char_fromsql(int char_id, struct mmo_charstatus* p, bool load_every p->sex = 99; break; } - + account_id = p->account_id; - + p->last_point.map = mapindex->name2id(last_map); p->save_point.map = mapindex->name2id(save_map); @@ -1219,13 +1220,13 @@ int char_mmo_char_fromsql(int char_id, struct mmo_charstatus* p, bool load_every p->last_point.x = MAP_DEFAULT_X; p->last_point.y = MAP_DEFAULT_Y; } - + if( p->save_point.map == 0 ) { p->save_point.map = (unsigned short)strdb_iget(mapindex->db, MAP_DEFAULT); p->save_point.x = MAP_DEFAULT_X; p->save_point.y = MAP_DEFAULT_Y; } - + strcat(t_msg, " status"); if (!load_everything) // For quick selection of data when displaying the char menu @@ -1237,12 +1238,13 @@ int char_mmo_char_fromsql(int char_id, struct mmo_charstatus* p, bool load_every //read memo data //`memo` (`memo_id`,`char_id`,`map`,`x`,`y`) memset(&tmp_point, 0, sizeof(tmp_point)); - if( SQL_ERROR == SQL->StmtPrepare(stmt, "SELECT `map`,`x`,`y` FROM `%s` WHERE `char_id`=? ORDER by `memo_id` LIMIT %d", memo_db, MAX_MEMOPOINTS) - || SQL_ERROR == SQL->StmtBindParam(stmt, 0, SQLDT_INT, &char_id, 0) - || SQL_ERROR == SQL->StmtExecute(stmt) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 0, SQLDT_STRING, &point_map, sizeof(point_map), NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 1, SQLDT_SHORT, &tmp_point.x, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 2, SQLDT_SHORT, &tmp_point.y, 0, NULL, NULL) ) + if (SQL_ERROR == SQL->StmtPrepare(stmt, "SELECT `map`,`x`,`y` FROM `%s` WHERE `char_id`=? ORDER by `memo_id` LIMIT %d", memo_db, MAX_MEMOPOINTS) + || SQL_ERROR == SQL->StmtBindParam(stmt, 0, SQLDT_INT, &char_id, 0) + || SQL_ERROR == SQL->StmtExecute(stmt) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 0, SQLDT_STRING, &point_map, sizeof(point_map), NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 1, SQLDT_SHORT, &tmp_point.x, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 2, SQLDT_SHORT, &tmp_point.y, 0, NULL, NULL) + ) SqlStmt_ShowDebug(stmt); for( i = 0; i < MAX_MEMOPOINTS && SQL_SUCCESS == SQL->StmtNextRow(stmt); ++i ) { @@ -1253,28 +1255,29 @@ int char_mmo_char_fromsql(int char_id, struct mmo_charstatus* p, bool load_every //read inventory //`inventory` (`id`,`char_id`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `card0`, `card1`, `card2`, `card3`, `expire_time`, `favorite`, `bound`, `unique_id`) - StrBuf->Init(&buf); + StrBuf->Init(&buf); StrBuf->AppendStr(&buf, "SELECT `id`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `expire_time`, `favorite`, `bound`, `unique_id`"); - for( i = 0; i < MAX_SLOTS; ++i ) + for( i = 0; i < MAX_SLOTS; ++i ) StrBuf->Printf(&buf, ", `card%d`", i); StrBuf->Printf(&buf, " FROM `%s` WHERE `char_id`=? LIMIT %d", inventory_db, MAX_INVENTORY); memset(&tmp_item, 0, sizeof(tmp_item)); - if( SQL_ERROR == SQL->StmtPrepareStr(stmt, StrBuf->Value(&buf)) - || SQL_ERROR == SQL->StmtBindParam(stmt, 0, SQLDT_INT, &char_id, 0) - || SQL_ERROR == SQL->StmtExecute(stmt) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 0, SQLDT_INT, &tmp_item.id, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 1, SQLDT_SHORT, &tmp_item.nameid, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 2, SQLDT_SHORT, &tmp_item.amount, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 3, SQLDT_UINT, &tmp_item.equip, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 4, SQLDT_CHAR, &tmp_item.identify, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 5, SQLDT_CHAR, &tmp_item.refine, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 6, SQLDT_CHAR, &tmp_item.attribute, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 7, SQLDT_UINT, &tmp_item.expire_time, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 8, SQLDT_CHAR, &tmp_item.favorite, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 9, SQLDT_UCHAR, &tmp_item.bound, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 10, SQLDT_UINT64, &tmp_item.unique_id, 0, NULL, NULL) ) - SqlStmt_ShowDebug(stmt); + if (SQL_ERROR == SQL->StmtPrepareStr(stmt, StrBuf->Value(&buf)) + || SQL_ERROR == SQL->StmtBindParam(stmt, 0, SQLDT_INT, &char_id, 0) + || SQL_ERROR == SQL->StmtExecute(stmt) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 0, SQLDT_INT, &tmp_item.id, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 1, SQLDT_SHORT, &tmp_item.nameid, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 2, SQLDT_SHORT, &tmp_item.amount, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 3, SQLDT_UINT, &tmp_item.equip, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 4, SQLDT_CHAR, &tmp_item.identify, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 5, SQLDT_CHAR, &tmp_item.refine, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 6, SQLDT_CHAR, &tmp_item.attribute, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 7, SQLDT_UINT, &tmp_item.expire_time, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 8, SQLDT_CHAR, &tmp_item.favorite, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 9, SQLDT_UCHAR, &tmp_item.bound, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 10, SQLDT_UINT64, &tmp_item.unique_id, 0, NULL, NULL) + ) + SqlStmt_ShowDebug(stmt); for( i = 0; i < MAX_SLOTS; ++i ) if( SQL_ERROR == SQL->StmtBindColumn(stmt, 11+i, SQLDT_SHORT, &tmp_item.card[i], 0, NULL, NULL) ) SqlStmt_ShowDebug(stmt); @@ -1286,27 +1289,28 @@ int char_mmo_char_fromsql(int char_id, struct mmo_charstatus* p, bool load_every //read cart //`cart_inventory` (`id`,`char_id`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `card0`, `card1`, `card2`, `card3`, expire_time`, `bound`, `unique_id`) - StrBuf->Clear(&buf); + StrBuf->Clear(&buf); StrBuf->AppendStr(&buf, "SELECT `id`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `expire_time`, `bound`, `unique_id`"); - for( j = 0; j < MAX_SLOTS; ++j ) + for( j = 0; j < MAX_SLOTS; ++j ) StrBuf->Printf(&buf, ", `card%d`", j); StrBuf->Printf(&buf, " FROM `%s` WHERE `char_id`=? LIMIT %d", cart_db, MAX_CART); memset(&tmp_item, 0, sizeof(tmp_item)); - if( SQL_ERROR == SQL->StmtPrepareStr(stmt, StrBuf->Value(&buf)) - || SQL_ERROR == SQL->StmtBindParam(stmt, 0, SQLDT_INT, &char_id, 0) - || SQL_ERROR == SQL->StmtExecute(stmt) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 0, SQLDT_INT, &tmp_item.id, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 1, SQLDT_SHORT, &tmp_item.nameid, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 2, SQLDT_SHORT, &tmp_item.amount, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 3, SQLDT_UINT, &tmp_item.equip, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 4, SQLDT_CHAR, &tmp_item.identify, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 5, SQLDT_CHAR, &tmp_item.refine, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 6, SQLDT_CHAR, &tmp_item.attribute, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 7, SQLDT_UINT, &tmp_item.expire_time, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 8, SQLDT_UCHAR, &tmp_item.bound, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 9, SQLDT_UINT64, &tmp_item.unique_id, 0, NULL, NULL) ) - SqlStmt_ShowDebug(stmt); + if (SQL_ERROR == SQL->StmtPrepareStr(stmt, StrBuf->Value(&buf)) + || SQL_ERROR == SQL->StmtBindParam(stmt, 0, SQLDT_INT, &char_id, 0) + || SQL_ERROR == SQL->StmtExecute(stmt) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 0, SQLDT_INT, &tmp_item.id, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 1, SQLDT_SHORT, &tmp_item.nameid, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 2, SQLDT_SHORT, &tmp_item.amount, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 3, SQLDT_UINT, &tmp_item.equip, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 4, SQLDT_CHAR, &tmp_item.identify, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 5, SQLDT_CHAR, &tmp_item.refine, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 6, SQLDT_CHAR, &tmp_item.attribute, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 7, SQLDT_UINT, &tmp_item.expire_time, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 8, SQLDT_UCHAR, &tmp_item.bound, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 9, SQLDT_UINT64, &tmp_item.unique_id, 0, NULL, NULL) + ) + SqlStmt_ShowDebug(stmt); for( i = 0; i < MAX_SLOTS; ++i ) if( SQL_ERROR == SQL->StmtBindColumn(stmt, 10+i, SQLDT_SHORT, &tmp_item.card[i], 0, NULL, NULL) ) SqlStmt_ShowDebug(stmt); @@ -1322,14 +1326,15 @@ int char_mmo_char_fromsql(int char_id, struct mmo_charstatus* p, bool load_every //read skill //`skill` (`char_id`, `id`, `lv`) memset(&tmp_skill, 0, sizeof(tmp_skill)); - if( SQL_ERROR == SQL->StmtPrepare(stmt, "SELECT `id`, `lv`,`flag` FROM `%s` WHERE `char_id`=? LIMIT %d", skill_db, MAX_SKILL) - || SQL_ERROR == SQL->StmtBindParam(stmt, 0, SQLDT_INT, &char_id, 0) - || SQL_ERROR == SQL->StmtExecute(stmt) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 0, SQLDT_USHORT, &tmp_skill.id , 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 1, SQLDT_UCHAR , &tmp_skill.lv , 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 2, SQLDT_UCHAR , &tmp_skill.flag, 0, NULL, NULL) ) + if (SQL_ERROR == SQL->StmtPrepare(stmt, "SELECT `id`, `lv`,`flag` FROM `%s` WHERE `char_id`=? LIMIT %d", skill_db, MAX_SKILL) + || SQL_ERROR == SQL->StmtBindParam(stmt, 0, SQLDT_INT, &char_id, 0) + || SQL_ERROR == SQL->StmtExecute(stmt) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 0, SQLDT_USHORT, &tmp_skill.id , 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 1, SQLDT_UCHAR , &tmp_skill.lv , 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 2, SQLDT_UCHAR , &tmp_skill.flag, 0, NULL, NULL) + ) SqlStmt_ShowDebug(stmt); - + if( tmp_skill.flag != SKILL_FLAG_PERM_GRANTED ) tmp_skill.flag = SKILL_FLAG_PERMANENT; @@ -1344,12 +1349,12 @@ int char_mmo_char_fromsql(int char_id, struct mmo_charstatus* p, bool load_every //read friends //`friends` (`char_id`, `friend_account`, `friend_id`) memset(&tmp_friend, 0, sizeof(tmp_friend)); - if( SQL_ERROR == SQL->StmtPrepare(stmt, "SELECT c.`account_id`, c.`char_id`, c.`name` FROM `%s` c LEFT JOIN `%s` f ON f.`friend_account` = c.`account_id` AND f.`friend_id` = c.`char_id` WHERE f.`char_id`=? LIMIT %d", char_db, friend_db, MAX_FRIENDS) - || SQL_ERROR == SQL->StmtBindParam(stmt, 0, SQLDT_INT, &char_id, 0) - || SQL_ERROR == SQL->StmtExecute(stmt) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 0, SQLDT_INT, &tmp_friend.account_id, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 1, SQLDT_INT, &tmp_friend.char_id, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 2, SQLDT_STRING, &tmp_friend.name, sizeof(tmp_friend.name), NULL, NULL) ) + if (SQL_ERROR == SQL->StmtPrepare(stmt, "SELECT c.`account_id`, c.`char_id`, c.`name` FROM `%s` c LEFT JOIN `%s` f ON f.`friend_account` = c.`account_id` AND f.`friend_id` = c.`char_id` WHERE f.`char_id`=? LIMIT %d", char_db, friend_db, MAX_FRIENDS) + || SQL_ERROR == SQL->StmtBindParam(stmt, 0, SQLDT_INT, &char_id, 0) + || SQL_ERROR == SQL->StmtExecute(stmt) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 0, SQLDT_INT, &tmp_friend.account_id, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 1, SQLDT_INT, &tmp_friend.char_id, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 2, SQLDT_STRING, &tmp_friend.name, sizeof(tmp_friend.name), NULL, NULL) ) SqlStmt_ShowDebug(stmt); for( i = 0; i < MAX_FRIENDS && SQL_SUCCESS == SQL->StmtNextRow(stmt); ++i ) @@ -1360,13 +1365,13 @@ int char_mmo_char_fromsql(int char_id, struct mmo_charstatus* p, bool load_every //read hotkeys //`hotkey` (`char_id`, `hotkey`, `type`, `itemskill_id`, `skill_lvl` memset(&tmp_hotkey, 0, sizeof(tmp_hotkey)); - if( SQL_ERROR == SQL->StmtPrepare(stmt, "SELECT `hotkey`, `type`, `itemskill_id`, `skill_lvl` FROM `%s` WHERE `char_id`=?", hotkey_db) - || SQL_ERROR == SQL->StmtBindParam(stmt, 0, SQLDT_INT, &char_id, 0) - || SQL_ERROR == SQL->StmtExecute(stmt) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 0, SQLDT_INT, &hotkey_num, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 1, SQLDT_UCHAR, &tmp_hotkey.type, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 2, SQLDT_UINT, &tmp_hotkey.id, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 3, SQLDT_USHORT, &tmp_hotkey.lv, 0, NULL, NULL) ) + if (SQL_ERROR == SQL->StmtPrepare(stmt, "SELECT `hotkey`, `type`, `itemskill_id`, `skill_lvl` FROM `%s` WHERE `char_id`=?", hotkey_db) + || SQL_ERROR == SQL->StmtBindParam(stmt, 0, SQLDT_INT, &char_id, 0) + || SQL_ERROR == SQL->StmtExecute(stmt) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 0, SQLDT_INT, &hotkey_num, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 1, SQLDT_UCHAR, &tmp_hotkey.type, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 2, SQLDT_UINT, &tmp_hotkey.id, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 3, SQLDT_USHORT, &tmp_hotkey.lv, 0, NULL, NULL) ) SqlStmt_ShowDebug(stmt); while( SQL_SUCCESS == SQL->StmtNextRow(stmt) ) @@ -1385,21 +1390,21 @@ int char_mmo_char_fromsql(int char_id, struct mmo_charstatus* p, bool load_every /* default */ p->mod_exp = p->mod_drop = p->mod_death = 100; - + //`account_data` (`account_id`,`bank_vault`,`base_exp`,`base_drop`,`base_death`) - if( SQL_ERROR == SQL->StmtPrepare(stmt, "SELECT `bank_vault`,`base_exp`,`base_drop`,`base_death` FROM `%s` WHERE `account_id`=? LIMIT 1", account_data_db) - || SQL_ERROR == SQL->StmtBindParam(stmt, 0, SQLDT_INT, &account_id, 0) - || SQL_ERROR == SQL->StmtExecute(stmt) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 0, SQLDT_INT, &p->bank_vault, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 1, SQLDT_USHORT, &p->mod_exp, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 2, SQLDT_USHORT, &p->mod_drop, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 3, SQLDT_USHORT, &p->mod_death, 0, NULL, NULL) ) + if (SQL_ERROR == SQL->StmtPrepare(stmt, "SELECT `bank_vault`,`base_exp`,`base_drop`,`base_death` FROM `%s` WHERE `account_id`=? LIMIT 1", account_data_db) + || SQL_ERROR == SQL->StmtBindParam(stmt, 0, SQLDT_INT, &account_id, 0) + || SQL_ERROR == SQL->StmtExecute(stmt) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 0, SQLDT_INT, &p->bank_vault, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 1, SQLDT_USHORT, &p->mod_exp, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 2, SQLDT_USHORT, &p->mod_drop, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 3, SQLDT_USHORT, &p->mod_death, 0, NULL, NULL) ) SqlStmt_ShowDebug(stmt); - + if( SQL_SUCCESS == SQL->StmtNextRow(stmt) ) strcat(t_msg, " accdata"); - if (save_log) ShowInfo("Loaded char (%d - %s): %s\n", char_id, p->name, t_msg); //ok. all data load successfully! + if (save_log) ShowInfo("Loaded char (%d - %s): %s\n", char_id, p->name, t_msg); //ok. all data load successfully! SQL->StmtFree(stmt); StrBuf->Destroy(&buf); @@ -1408,7 +1413,7 @@ int char_mmo_char_fromsql(int char_id, struct mmo_charstatus* p, bool load_every p->allow_party = true; if( opt & OPT_SHOW_EQUIP ) p->show_equip = true; - + cp = idb_ensure(chr->char_db_, char_id, chr->create_charstatus); memcpy(cp, p, sizeof(struct mmo_charstatus)); return 1; @@ -1446,7 +1451,7 @@ bool char_char_slotchange(struct char_session_data *sd, int fd, unsigned short f return false; from_id = sd->found_char[from]; - + if( sd->found_char[to] > 0 ) {/* moving char to occupied slot */ bool result = false; /* update both at once */ @@ -1456,27 +1461,26 @@ bool char_char_slotchange(struct char_session_data *sd, int fd, unsigned short f Sql_ShowDebug(inter->sql_handle); else result = true; - + if( SQL_ERROR == SQL->QueryStr(inter->sql_handle, (result == true) ? "COMMIT" : "ROLLBACK") ) { Sql_ShowDebug(inter->sql_handle); result = false; } if( !result ) return false; - } else {/* slot is free. */ if( SQL_ERROR == SQL->Query(inter->sql_handle, "UPDATE `%s` SET `char_num`='%d' WHERE `char_id`='%d' LIMIT 1", char_db, to, sd->found_char[from] ) ) { Sql_ShowDebug(inter->sql_handle); return false; } } - + /* update count */ if( SQL_ERROR == SQL->Query(inter->sql_handle, "UPDATE `%s` SET `slotchange`=`slotchange`-1 WHERE `char_id`='%d' LIMIT 1", char_db, from_id ) ) { Sql_ShowDebug(inter->sql_handle); return false; } - + return true; } @@ -1605,7 +1609,7 @@ int char_make_new_char_sql(struct char_session_data* sd, char* name_, int str, i flag = chr->check_char_name(name,esc_name); if( flag < 0 ) return flag; - + //check other inputs #if PACKETVER >= 20120307 if(slot < 0 || slot >= sd->char_slots) @@ -1943,7 +1947,7 @@ int char_mmo_char_tobuf(uint8* buffer, struct mmo_charstatus* p) { //When the weapon is sent and your option is riding, the client crashes on login!? WBUFW(buf,56) = p->option&(0x20|0x80000|0x100000|0x200000|0x400000|0x800000|0x1000000|0x2000000|0x4000000|0x8000000) ? 0 : p->weapon; #endif - + WBUFW(buf,58) = p->base_level; WBUFW(buf,60) = min(p->skill_point, INT16_MAX); WBUFW(buf,62) = p->head_bottom; @@ -1993,7 +1997,7 @@ int char_mmo_char_tobuf(uint8* buffer, struct mmo_charstatus* p) { return 106+offset; } - + /* Made Possible by Yommy~! <3 */ void char_mmo_char_send099d(int fd, struct char_session_data *sd) { WFIFOHEAD(fd,4 + (MAX_CHARS*MAX_CHAR_BUF)); @@ -2007,16 +2011,15 @@ void char_mmo_char_send099d(int fd, struct char_session_data *sd) { void char_mmo_char_send_ban_list(int fd, struct char_session_data *sd) { int i; time_t now = time(NULL); - + ARR_FIND(0, MAX_CHARS, i, sd->unban_time[i]); - if( i != MAX_CHARS ) { int c; - + WFIFOHEAD(fd, 4 + (MAX_CHARS*24)); WFIFOW(fd, 0) = 0x20d; - + for(i = 0, c = 0; i < MAX_CHARS; i++) { if( sd->unban_time[i] ) { timestamp2string((char*)WFIFOP(fd,8 + (28*c)), 20, sd->unban_time[i], "%Y-%m-%d %H:%M:%S"); @@ -2034,9 +2037,9 @@ void char_mmo_char_send_ban_list(int fd, struct char_session_data *sd) { c++; } } - + WFIFOW(fd, 2) = 4 + (24*c); - + WFIFOSET(fd, WFIFOW(fd, 2)); } } @@ -2045,7 +2048,6 @@ void char_mmo_char_send_ban_list(int fd, struct char_session_data *sd) { // [Ind/Hercules] notify client about charselect window data //---------------------------------------- void char_mmo_char_send_slots_info(int fd, struct char_session_data* sd) { - WFIFOHEAD(fd,29); WFIFOW(fd,0) = 0x82d; WFIFOW(fd,2) = 29; @@ -2068,7 +2070,7 @@ int char_mmo_char_send_characters(int fd, struct char_session_data* sd) #endif if (save_log) ShowInfo("Loading Char Data ("CL_BOLD"%d"CL_RESET")\n",sd->account_id); - + j = 24 + offset; // offset WFIFOHEAD(fd,j + MAX_CHARS*MAX_CHAR_BUF); WFIFOW(fd,0) = 0x6b; @@ -2184,10 +2186,10 @@ static void char_auth_ok(int fd, struct char_session_data *sd) { struct online_char_data* character; - if( (character = (struct online_char_data*)idb_get(chr->online_char_db, sd->account_id)) != NULL ) - { // check if character is not online already. [Skotlex] - if (character->server > -1) - { //Character already online. KICK KICK KICK + if( (character = (struct online_char_data*)idb_get(chr->online_char_db, sd->account_id)) != NULL ) { + // check if character is not online already. [Skotlex] + if (character->server > -1) { + //Character already online. KICK KICK KICK mapif->disconnectplayer(chr->server[character->server].fd, character->account_id, character->char_id, 2); if (character->waiting_disconnect == INVALID_TIMER) character->waiting_disconnect = timer->add(timer->gettick()+20000, chr->waiting_disconnect, character->account_id, 0); @@ -2196,8 +2198,8 @@ static void char_auth_ok(int fd, struct char_session_data *sd) chr->authfail_fd(fd, 8); return; } - if (character->fd >= 0 && character->fd != fd) - { //There's already a connection from this account that hasn't picked a char yet. + if (character->fd >= 0 && character->fd != fd) { + //There's already a connection from this account that hasn't picked a char yet. chr->authfail_fd(fd, 8); return; } @@ -2457,7 +2459,7 @@ void mapif_ban(int id, unsigned int flag, int status) void char_parse_fromlogin_ban(int fd) { - mapif->ban(RFIFOL(fd,2), RFIFOB(fd,6), RFIFOL(fd,7)); + mapif->ban(RFIFOL(fd,2), RFIFOB(fd,6), RFIFOL(fd,7)); // disconnect player if online on char-server chr->disconnect_player(RFIFOL(fd,2)); RFIFOSKIP(fd,11); @@ -2470,8 +2472,8 @@ void char_parse_fromlogin_kick(int fd) RFIFOSKIP(fd,6); if( character != NULL ) {// account is already marked as online! - if( character->server > -1 ) - { //Kick it from the map server it is on. + if( character->server > -1 ) { + //Kick it from the map server it is on. mapif->disconnectplayer(chr->server[character->server].fd, character->account_id, character->char_id, 2); if (character->waiting_disconnect == INVALID_TIMER) character->waiting_disconnect = timer->add(timer->gettick()+AUTH_TIMEOUT, chr->waiting_disconnect, character->account_id, 0); @@ -2514,8 +2516,8 @@ void char_parse_fromlogin_update_ip(int fd) login_ip = new_ip; //Update login ip, too. new_ip = host2ip(char_ip_str); - if (new_ip && new_ip != chr->ip) - { //Update ip. + if (new_ip && new_ip != chr->ip) { + //Update ip. chr->ip = new_ip; ShowInfo("Updating IP for [%s].\n", char_ip_str); // notify login server about the change @@ -2565,15 +2567,14 @@ int char_parse_fromlogin(int fd) { while(RFIFOREST(fd) >= 2) { uint16 command = RFIFOW(fd,0); - + if( HPM->packetsc[hpParse_FromLogin] ) { int success = HPM->parse_packets(fd,hpParse_FromLogin); if( success == 1 ) continue; else if( success == 2 ) return 0; } - - switch( command ) { + switch (command) { // acknowledgment of connect-to-loginserver request case 0x2711: if (RFIFOREST(fd) < 3) @@ -2708,47 +2709,43 @@ void char_global_accreg_to_login_send (void) { **/ void char_global_accreg_to_login_add (const char *key, unsigned int index, intptr_t val, bool is_string) { int nlen = WFIFOW(chr->login_fd, 2); - size_t len; - - len = strlen(key)+1; - + size_t len = strlen(key)+1; + WFIFOB(chr->login_fd, nlen) = (unsigned char)len;/* won't be higher; the column size is 32 */ nlen += 1; - + safestrncpy((char*)WFIFOP(chr->login_fd,nlen), key, len); nlen += len; - + WFIFOL(chr->login_fd, nlen) = index; nlen += 4; - + if( is_string ) { WFIFOB(chr->login_fd, nlen) = val ? 2 : 3; nlen += 1; - + if( val ) { char *sval = (char*)val; len = strlen(sval)+1; - + WFIFOB(chr->login_fd, nlen) = (unsigned char)len;/* won't be higher; the column size is 254 */ nlen += 1; - + safestrncpy((char*)WFIFOP(chr->login_fd,nlen), sval, len); nlen += len; } - } else { WFIFOB(chr->login_fd, nlen) = val ? 0 : 1; nlen += 1; - + if( val ) { WFIFOL(chr->login_fd, nlen) = (int)val; nlen += 4; } - } - + WFIFOW(chr->login_fd,12) += 1; - + WFIFOW(chr->login_fd, 2) = nlen; if( WFIFOW(chr->login_fd, 2) > 60000 ) { int account_id = WFIFOL(chr->login_fd,4), char_id = WFIFOL(chr->login_fd,8); @@ -3153,20 +3150,21 @@ void char_parse_frommap_save_character(int fd, int id) return; } //Check account only if this ain't final save. Final-save goes through because of the char-map reconnect - if (RFIFOB(fd,12) || ( - (character = (struct online_char_data*)idb_get(chr->online_char_db, aid)) != NULL && - character->char_id == cid)) - { + if (RFIFOB(fd,12) + || ( (character = (struct online_char_data*)idb_get(chr->online_char_db, aid)) != NULL + && character->char_id == cid) + ) { struct mmo_charstatus char_dat; memcpy(&char_dat, RFIFOP(fd,13), sizeof(struct mmo_charstatus)); chr->mmo_char_tosql(cid, &char_dat); - } else { //This may be valid on char-server reconnection, when re-sending characters that already logged off. + } else { + //This may be valid on char-server reconnection, when re-sending characters that already logged off. ShowError("parse_from_map (save-char): Received data for non-existing/offline character (%d:%d).\n", aid, cid); chr->set_char_online(id, cid, aid); } - if (RFIFOB(fd,12)) - { //Flag, set character offline after saving. [Skotlex] + if (RFIFOB(fd,12)) { + //Flag, set character offline after saving. [Skotlex] chr->set_char_offline(cid, aid); chr->save_character_ack(fd, aid, cid); } @@ -3241,16 +3239,15 @@ void char_parse_frommap_change_map_server(int fd) map_fd = chr->server[map_id].fd; //Char should just had been saved before this packet, so this should be safe. [Skotlex] char_data = (struct mmo_charstatus*)uidb_get(chr->char_db_,RFIFOL(fd,14)); - if (char_data == NULL) { //Really shouldn't happen. + if (char_data == NULL) { + //Really shouldn't happen. struct mmo_charstatus char_dat; chr->mmo_char_fromsql(RFIFOL(fd,14), &char_dat, true); char_data = (struct mmo_charstatus*)uidb_get(chr->char_db_,RFIFOL(fd,14)); } - if( runflag == CHARSERVER_ST_RUNNING && - session_isActive(map_fd) && - char_data ) - { //Send the map server the auth of this player. + if (runflag == CHARSERVER_ST_RUNNING && session_isActive(map_fd) && char_data) { + //Send the map server the auth of this player. struct online_char_data* data; struct char_auth_node* node; @@ -3427,13 +3424,13 @@ void char_parse_frommap_change_account(int fd) SQL->GetData(inter->sql_handle, 1, &data, NULL); char_id = atoi(data); SQL->GetData(inter->sql_handle, 2, &data, NULL); unban_time = atol(data); - if( chr->login_fd <= 0 ) + if( chr->login_fd <= 0 ) { result = 3; // 3-login-server offline - //FIXME: need to move this check to login server [ultramage] - // else - // if( acc != -1 && isGM(acc) < isGM(account_id) ) - // result = 2; // 2-gm level too low - else { +#if 0 //FIXME: need to move this check to login server [ultramage] + } else if( acc != -1 && isGM(acc) < isGM(account_id) ) { + result = 2; // 2-gm level too low +#endif // 0 + } else { switch( type ) { case 1: // block loginif->block_account(account_id, 5); @@ -3791,16 +3788,14 @@ int char_parse_frommap(int fd) } while(RFIFOREST(fd) >= 2) { - if( HPM->packetsc[hpParse_FromMap] ) { if( (i = HPM->parse_packets(fd,hpParse_FromMap)) ) { if( i == 1 ) continue; if( i == 2 ) return 0; } } - - switch(RFIFOW(fd,0)) { + switch(RFIFOW(fd,0)) { case 0x2b0a: if( RFIFOREST(fd) < RFIFOW(fd, 2) ) return 0; @@ -3973,7 +3968,7 @@ int char_parse_frommap(int fd) chr->parse_frommap_request_stats_report(fd); } break; - + /* individual sc data insertion/update */ case 0x2740: if( RFIFOREST(fd) < 28 ) @@ -3992,13 +3987,12 @@ int char_parse_frommap(int fd) } break; - default: { // inter server - packet int r = inter->parse_frommap(fd); - if (r == 1) break; // processed - if (r == 2) return 0; // need more packet + if (r == 1) break; // processed + if (r == 2) return 0; // need more packet // no inter server packet. no char server packet -> disconnect ShowError("Unknown packet 0x%04x from map server, disconnecting.\n", RFIFOW(fd,0)); @@ -4111,7 +4105,6 @@ void char_delete2_accept_actual_ack(int fd, int char_id, uint32 result) /// Any (0x718): An unknown error has occurred. void char_delete2_accept_ack(int fd, int char_id, uint32 result) {// HC: <082a>.W .L .L - #if PACKETVER >= 20130000 /* not sure the exact date -- must refresh or client gets stuck */ if( result == 1 ) { struct char_session_data* sd = (struct char_session_data*)session[fd]->session_data; @@ -4272,7 +4265,7 @@ static void char_delete2_accept(int fd, struct char_session_data* sd) // refresh character list cache sd->found_char[i] = -1; - + chr->delete2_accept_ack(fd, char_id, 1); } @@ -4455,10 +4448,11 @@ void char_parse_char_select(int fd, struct char_session_data* sd, uint32 ipl) return; } - if ( SQL_SUCCESS != SQL->Query(inter->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(inter->sql_handle) - || SQL_SUCCESS != SQL->GetData(inter->sql_handle, 0, &data, NULL) ) - { //Not found?? May be forged packet. + if (SQL_SUCCESS != SQL->Query(inter->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(inter->sql_handle) + || SQL_SUCCESS != SQL->GetData(inter->sql_handle, 0, &data, NULL) + ) { + //Not found?? May be forged packet. Sql_ShowDebug(inter->sql_handle); SQL->FreeResult(inter->sql_handle); chr->auth_error(fd, 0); @@ -4652,11 +4646,11 @@ void char_parse_char_delete_char(int fd, struct char_session_data* sd, unsigned RFIFOSKIP(fd,( cmd == 0x68) ? 46 : 56); // Check if e-mail is correct - if(strcmpi(email, sd->email) && //email does not matches and - ( - strcmp("a@a.com", sd->email) || //it is not default email, or - (strcmp("a@a.com", email) && strcmp("", email)) //email sent does not matches default - )) { //Fail + if (strcmpi(email, sd->email) != 0 /* emails don't match */ + && ( strcmp("a@a.com", sd->email) != 0 /* it's not the default email */ + || (strcmp("a@a.com", email) != 0 && strcmp("", email) != 0) /* sent email isn't the default */ + )) { + //Fail chr->delete_char_failed(fd, 0); return; } @@ -4933,8 +4927,8 @@ int char_parse_char(int fd) if(session[fd]->flag.eof) { - if( sd != NULL && sd->auth ) - { // already authed client + if( sd != NULL && sd->auth ) { + // already authed client struct online_char_data* data = (struct online_char_data*)idb_get(chr->online_char_db, sd->account_id); if( data != NULL && data->fd == fd) data->fd = -1; @@ -4954,11 +4948,10 @@ int char_parse_char(int fd) if( success == 1 ) continue; else if( success == 2 ) return 0; } - + cmd = RFIFOW(fd,0); switch( cmd ) { - // request to connect // 0065 .L .L .L .W .B case 0x65: @@ -5082,36 +5075,36 @@ int char_parse_char(int fd) chr->parse_char_login_map_server(fd); } return 0; // avoid processing of follow-up packets here - + // checks the entered pin case 0x8b8: FIFOSD_CHECK(10); chr->parse_char_pincode_check(fd, sd); break; - + // request for PIN window case 0x8c5: FIFOSD_CHECK(6); chr->parse_char_pincode_window(fd, sd); break; - + // pincode change request case 0x8be: FIFOSD_CHECK(14); chr->parse_char_pincode_change(fd, sd); break; - + // activate PIN system and set first PIN case 0x8ba: FIFOSD_CHECK(10); chr->parse_char_pincode_first_pin(fd, sd); break; - + case 0x9a1: FIFOSD_CHECK(2); chr->parse_char_request_chars(fd, sd); break; - + /* 0x8d4 .W .W .W (2+2+2+2) */ case 0x8d4: FIFOSD_CHECK(8); @@ -5119,7 +5112,7 @@ int char_parse_char(int fd) chr->parse_char_move_character(fd, sd); } break; - + // unknown packet received default: if (chr->parse_char_unknown_packet(fd, ipl)) @@ -5257,7 +5250,7 @@ int char_check_connect_login_server(int tid, int64 tick, int id, intptr_t data) chr->login_fd = 0; return 0; } - + session[chr->login_fd]->func_parse = chr->parse_fromlogin; session[chr->login_fd]->flag.server = 1; realloc_fifo(chr->login_fd, FIFOSIZE_SERVERLINK, FIFOSIZE_SERVERLINK); @@ -5273,8 +5266,8 @@ int char_check_connect_login_server(int tid, int64 tick, int id, intptr_t data) //------------------------------------------------ static int char_waiting_disconnect(int tid, int64 tick, int id, intptr_t data) { struct online_char_data* character; - if ((character = (struct online_char_data*)idb_get(chr->online_char_db, id)) != NULL && character->waiting_disconnect == tid) - { //Mark it offline due to timeout. + if ((character = (struct online_char_data*)idb_get(chr->online_char_db, id)) != NULL && character->waiting_disconnect == tid) { + //Mark it offline due to timeout. character->waiting_disconnect = INVALID_TIMER; chr->set_char_offline(character->char_id, character->account_id); } @@ -5590,8 +5583,8 @@ int char_config_read(const char* cfgName) start_zeny = atoi(w2); if (start_zeny < 0) start_zeny = 0; - } else if(strcmpi(w1,"log_char")==0) { //log char or not [devil] - log_char = atoi(w2); + } else if(strcmpi(w1,"log_char")==0) { + log_char = atoi(w2); //log char or not [devil] } else if (strcmpi(w1, "unknown_char_name") == 0) { safestrncpy(unknown_char_name, w2, sizeof(unknown_char_name)); unknown_char_name[NAME_LENGTH-1] = '\0'; @@ -5644,11 +5637,11 @@ int char_config_read(const char* cfgName) int do_final(void) { int i; - + ShowStatus("Terminating...\n"); HPM->event(HPET_FINAL); - + chr->set_all_offline(-1); chr->set_all_offline_sql(); @@ -5679,7 +5672,7 @@ int do_final(void) { for(i = 0; i < MAX_MAP_SERVERS; i++ ) if( chr->server[i].map ) aFree(chr->server[i].map); - + HPM->event(HPET_POST_FINAL); ShowStatus("Finished.\n"); @@ -5766,11 +5759,11 @@ int do_init(int argc, char **argv) { #endif HPM->config_read(NULL, 0); HPM->event(HPET_PRE_INIT); - + //Read map indexes mapindex->init(); start_point.map = mapindex->name2id("new_zone01"); - + chr->config_read((argc < 2) ? CHAR_CONF_NAME : argv[1]); chr->lan_config_read((argc > 3) ? argv[3] : LAN_CONF_NAME); chr->sql_config_read(SQL_CONF_NAME); @@ -5780,14 +5773,14 @@ int do_init(int argc, char **argv) { ShowNotice("Please edit your 'login' table to create a proper inter-server user/password (gender 'S')\n"); ShowNotice("And then change the user/password to use in conf/char-server.conf (or conf/import/char_conf.txt)\n"); } - + inter->init_sql((argc > 2) ? argv[2] : inter_cfgName); // inter server configuration auth_db = idb_alloc(DB_OPT_RELEASE_DATA); chr->online_char_db = idb_alloc(DB_OPT_RELEASE_DATA); HPM->event(HPET_INIT); - + chr->mmo_char_sql_init(); chr->read_fame_list(); //Read fame lists. @@ -5837,18 +5830,18 @@ int do_init(int argc, char **argv) { Sql_ShowDebug(inter->sql_handle); set_defaultparse(chr->parse_char); - + if( (chr->char_fd = make_listen_bind(bind_ip,chr->port)) == -1 ) { ShowFatalError("Failed to bind to port '"CL_WHITE"%d"CL_RESET"'\n",chr->port); exit(EXIT_FAILURE); } - + Sql_HerculesUpdateCheck(inter->sql_handle); #ifdef CONSOLE_INPUT console->input->setSQL(inter->sql_handle); #endif ShowStatus("The char-server is "CL_GREEN"ready"CL_RESET" (Server is listening on the port %d).\n\n", chr->port); - + if( runflag != CORE_ST_STOP ) { shutdown_callback = do_shutdown; @@ -5856,7 +5849,7 @@ int do_init(int argc, char **argv) { } HPM->event(HPET_READY); - + return 0; } @@ -5883,179 +5876,179 @@ void char_load_defaults(void) void char_defaults(void) { - chr = &char_s; - - memset(chr->server, 0, sizeof(chr->server)); - - chr->login_fd = 0; - chr->char_fd = -1; - chr->online_char_db = NULL; - chr->char_db_ = NULL; - - memset(chr->userid, 0, sizeof(chr->userid)); - memset(chr->passwd, 0, sizeof(chr->passwd)); - - chr->ip = 0; - chr->port = 6121; - chr->server_type = 0; - chr->new_display = 0; - - chr->waiting_disconnect = char_waiting_disconnect; - chr->delete_char_sql = char_delete_char_sql; - chr->create_online_char_data = char_create_online_char_data; - chr->set_account_online = char_set_account_online; - chr->set_account_offline = char_set_account_offline; - chr->set_char_charselect = char_set_char_charselect; - chr->set_char_online = char_set_char_online; - chr->set_char_offline = char_set_char_offline; - chr->db_setoffline = char_db_setoffline; - chr->db_kickoffline = char_db_kickoffline; - chr->set_login_all_offline = char_set_login_all_offline; - chr->set_all_offline = char_set_all_offline; - chr->set_all_offline_sql = char_set_all_offline_sql; - chr->create_charstatus = char_create_charstatus; - chr->mmo_char_tosql = char_mmo_char_tosql; - chr->memitemdata_to_sql = char_memitemdata_to_sql; - chr->inventory_to_sql = char_inventory_to_sql; - chr->mmo_chars_fromsql = char_mmo_chars_fromsql; - chr->mmo_char_fromsql = char_mmo_char_fromsql; - chr->mmo_char_sql_init = char_mmo_char_sql_init; - chr->char_slotchange = char_char_slotchange; - chr->rename_char_sql = char_rename_char_sql; - chr->check_char_name = char_check_char_name; - chr->make_new_char_sql = char_make_new_char_sql; - chr->divorce_char_sql = char_divorce_char_sql; - chr->count_users = char_count_users; - chr->mmo_char_tobuf = char_mmo_char_tobuf; - chr->mmo_char_send099d = char_mmo_char_send099d; - chr->mmo_char_send_ban_list = char_mmo_char_send_ban_list; - chr->mmo_char_send_slots_info = char_mmo_char_send_slots_info; - chr->mmo_char_send_characters = char_mmo_char_send_characters; - chr->char_married = char_char_married; - chr->char_child = char_char_child; - chr->char_family = char_char_family; - chr->disconnect_player = char_disconnect_player; - chr->authfail_fd = char_authfail_fd; - chr->request_account_data = char_request_account_data; - chr->auth_ok = char_auth_ok; - chr->ping_login_server = char_ping_login_server; - chr->parse_fromlogin_connection_state = char_parse_fromlogin_connection_state; - chr->auth_error = char_auth_error; - chr->parse_fromlogin_auth_state = char_parse_fromlogin_auth_state; - chr->parse_fromlogin_account_data = char_parse_fromlogin_account_data; - chr->parse_fromlogin_login_pong = char_parse_fromlogin_login_pong; - chr->changesex = char_changesex; - chr->parse_fromlogin_changesex_reply = char_parse_fromlogin_changesex_reply; - chr->parse_fromlogin_account_reg2 = char_parse_fromlogin_account_reg2; - chr->parse_fromlogin_ban = char_parse_fromlogin_ban; - chr->parse_fromlogin_kick = char_parse_fromlogin_kick; - chr->update_ip = char_update_ip; - chr->parse_fromlogin_update_ip = char_parse_fromlogin_update_ip; - chr->parse_fromlogin_accinfo2_failed = char_parse_fromlogin_accinfo2_failed; - chr->parse_fromlogin_accinfo2_ok = char_parse_fromlogin_accinfo2_ok; - chr->parse_fromlogin = char_parse_fromlogin; - chr->request_accreg2 = char_request_accreg2; - chr->global_accreg_to_login_start = char_global_accreg_to_login_start; - chr->global_accreg_to_login_send = char_global_accreg_to_login_send; - chr->global_accreg_to_login_add = char_global_accreg_to_login_add; - chr->read_fame_list = char_read_fame_list; - chr->send_fame_list = char_send_fame_list; - chr->update_fame_list = char_update_fame_list; - chr->loadName = char_loadName; - chr->parse_frommap_datasync = char_parse_frommap_datasync; - chr->parse_frommap_skillid2idx = char_parse_frommap_skillid2idx; - chr->map_received_ok = char_map_received_ok; - chr->send_maps = char_send_maps; - chr->parse_frommap_map_names = char_parse_frommap_map_names; - chr->send_scdata = char_send_scdata; - chr->parse_frommap_request_scdata = char_parse_frommap_request_scdata; - chr->parse_frommap_set_users_count = char_parse_frommap_set_users_count; - chr->parse_frommap_set_users = char_parse_frommap_set_users; - chr->save_character_ack = char_save_character_ack; - chr->parse_frommap_save_character = char_parse_frommap_save_character; - chr->select_ack = char_select_ack; - chr->parse_frommap_char_select_req = char_parse_frommap_char_select_req; - chr->change_map_server_ack = char_change_map_server_ack; - chr->parse_frommap_change_map_server = char_parse_frommap_change_map_server; - chr->parse_frommap_remove_friend = char_parse_frommap_remove_friend; - chr->char_name_ack = char_char_name_ack; - chr->parse_frommap_char_name_request = char_parse_frommap_char_name_request; - chr->parse_frommap_change_email = char_parse_frommap_change_email; - chr->ban = char_ban; - chr->unban = char_unban; - chr->ask_name_ack = char_ask_name_ack; - chr->parse_frommap_change_account = char_parse_frommap_change_account; - chr->parse_frommap_fame_list = char_parse_frommap_fame_list; - chr->parse_frommap_divorce_char = char_parse_frommap_divorce_char; - chr->parse_frommap_ragsrvinfo = char_parse_frommap_ragsrvinfo; - chr->parse_frommap_set_char_offline = char_parse_frommap_set_char_offline; - chr->parse_frommap_set_all_offline = char_parse_frommap_set_all_offline; - chr->parse_frommap_set_char_online = char_parse_frommap_set_char_online; - chr->parse_frommap_build_fame_list = char_parse_frommap_build_fame_list; - chr->parse_frommap_save_status_change_data = char_parse_frommap_save_status_change_data; - chr->send_pong = char_send_pong; - chr->parse_frommap_ping = char_parse_frommap_ping; - chr->map_auth_ok = char_map_auth_ok; - chr->map_auth_failed = char_map_auth_failed; - chr->parse_frommap_auth_request = char_parse_frommap_auth_request; - chr->parse_frommap_update_ip = char_parse_frommap_update_ip; - chr->parse_frommap_request_stats_report = char_parse_frommap_request_stats_report; - chr->parse_frommap_scdata_update = char_parse_frommap_scdata_update; - chr->parse_frommap_scdata_delete = char_parse_frommap_scdata_delete; - chr->parse_frommap = char_parse_frommap; - chr->search_mapserver = char_search_mapserver; - chr->mapif_init = char_mapif_init; - chr->lan_subnetcheck = char_lan_subnetcheck; - chr->delete2_ack = char_delete2_ack; - chr->delete2_accept_actual_ack = char_delete2_accept_actual_ack; - chr->delete2_accept_ack = char_delete2_accept_ack; - chr->delete2_cancel_ack = char_delete2_cancel_ack; - chr->delete2_req = char_delete2_req; - chr->delete2_accept = char_delete2_accept; - chr->delete2_cancel = char_delete2_cancel; - chr->send_account_id = char_send_account_id; - chr->parse_char_connect = char_parse_char_connect; - chr->send_map_info = char_send_map_info; - chr->send_wait_char_server = char_send_wait_char_server; - chr->search_default_maps_mapserver = char_search_default_maps_mapserver; - chr->parse_char_select = char_parse_char_select; - chr->creation_failed = char_creation_failed; - chr->creation_ok = char_creation_ok; - chr->parse_char_create_new_char = char_parse_char_create_new_char; - chr->delete_char_failed = char_delete_char_failed; - chr->delete_char_ok = char_delete_char_ok; - chr->parse_char_delete_char = char_parse_char_delete_char; - chr->parse_char_ping = char_parse_char_ping; - chr->allow_rename = char_allow_rename; - chr->parse_char_rename_char = char_parse_char_rename_char; - chr->parse_char_rename_char2 = char_parse_char_rename_char2; - chr->rename_char_ack = char_rename_char_ack; - chr->parse_char_rename_char_confirm = char_parse_char_rename_char_confirm; - chr->captcha_notsupported = char_captcha_notsupported; - chr->parse_char_request_captcha = char_parse_char_request_captcha; - chr->parse_char_check_captcha = char_parse_char_check_captcha; - chr->parse_char_delete2_req = char_parse_char_delete2_req; - chr->parse_char_delete2_accept = char_parse_char_delete2_accept; - chr->parse_char_delete2_cancel = char_parse_char_delete2_cancel; - chr->login_map_server_ack = char_login_map_server_ack; - chr->parse_char_login_map_server = char_parse_char_login_map_server; - chr->parse_char_pincode_check = char_parse_char_pincode_check; - chr->parse_char_pincode_window = char_parse_char_pincode_window; - chr->parse_char_pincode_change = char_parse_char_pincode_change; - chr->parse_char_pincode_first_pin = char_parse_char_pincode_first_pin; - chr->parse_char_request_chars = char_parse_char_request_chars; - chr->change_character_slot_ack = char_change_character_slot_ack; - chr->parse_char_move_character = char_parse_char_move_character; - chr->parse_char_unknown_packet = char_parse_char_unknown_packet; - chr->parse_char = char_parse_char; - chr->broadcast_user_count = char_broadcast_user_count; - chr->send_accounts_tologin_sub = char_send_accounts_tologin_sub; - chr->send_accounts_tologin = char_send_accounts_tologin; - chr->check_connect_login_server = char_check_connect_login_server; - chr->online_data_cleanup_sub = char_online_data_cleanup_sub; - chr->online_data_cleanup = char_online_data_cleanup; - chr->lan_config_read = char_lan_config_read; - chr->sql_config_read = char_sql_config_read; - chr->config_dispatch = char_config_dispatch; - chr->config_read = char_config_read; + chr = &char_s; + + memset(chr->server, 0, sizeof(chr->server)); + + chr->login_fd = 0; + chr->char_fd = -1; + chr->online_char_db = NULL; + chr->char_db_ = NULL; + + memset(chr->userid, 0, sizeof(chr->userid)); + memset(chr->passwd, 0, sizeof(chr->passwd)); + + chr->ip = 0; + chr->port = 6121; + chr->server_type = 0; + chr->new_display = 0; + + chr->waiting_disconnect = char_waiting_disconnect; + chr->delete_char_sql = char_delete_char_sql; + chr->create_online_char_data = char_create_online_char_data; + chr->set_account_online = char_set_account_online; + chr->set_account_offline = char_set_account_offline; + chr->set_char_charselect = char_set_char_charselect; + chr->set_char_online = char_set_char_online; + chr->set_char_offline = char_set_char_offline; + chr->db_setoffline = char_db_setoffline; + chr->db_kickoffline = char_db_kickoffline; + chr->set_login_all_offline = char_set_login_all_offline; + chr->set_all_offline = char_set_all_offline; + chr->set_all_offline_sql = char_set_all_offline_sql; + chr->create_charstatus = char_create_charstatus; + chr->mmo_char_tosql = char_mmo_char_tosql; + chr->memitemdata_to_sql = char_memitemdata_to_sql; + chr->inventory_to_sql = char_inventory_to_sql; + chr->mmo_chars_fromsql = char_mmo_chars_fromsql; + chr->mmo_char_fromsql = char_mmo_char_fromsql; + chr->mmo_char_sql_init = char_mmo_char_sql_init; + chr->char_slotchange = char_char_slotchange; + chr->rename_char_sql = char_rename_char_sql; + chr->check_char_name = char_check_char_name; + chr->make_new_char_sql = char_make_new_char_sql; + chr->divorce_char_sql = char_divorce_char_sql; + chr->count_users = char_count_users; + chr->mmo_char_tobuf = char_mmo_char_tobuf; + chr->mmo_char_send099d = char_mmo_char_send099d; + chr->mmo_char_send_ban_list = char_mmo_char_send_ban_list; + chr->mmo_char_send_slots_info = char_mmo_char_send_slots_info; + chr->mmo_char_send_characters = char_mmo_char_send_characters; + chr->char_married = char_char_married; + chr->char_child = char_char_child; + chr->char_family = char_char_family; + chr->disconnect_player = char_disconnect_player; + chr->authfail_fd = char_authfail_fd; + chr->request_account_data = char_request_account_data; + chr->auth_ok = char_auth_ok; + chr->ping_login_server = char_ping_login_server; + chr->parse_fromlogin_connection_state = char_parse_fromlogin_connection_state; + chr->auth_error = char_auth_error; + chr->parse_fromlogin_auth_state = char_parse_fromlogin_auth_state; + chr->parse_fromlogin_account_data = char_parse_fromlogin_account_data; + chr->parse_fromlogin_login_pong = char_parse_fromlogin_login_pong; + chr->changesex = char_changesex; + chr->parse_fromlogin_changesex_reply = char_parse_fromlogin_changesex_reply; + chr->parse_fromlogin_account_reg2 = char_parse_fromlogin_account_reg2; + chr->parse_fromlogin_ban = char_parse_fromlogin_ban; + chr->parse_fromlogin_kick = char_parse_fromlogin_kick; + chr->update_ip = char_update_ip; + chr->parse_fromlogin_update_ip = char_parse_fromlogin_update_ip; + chr->parse_fromlogin_accinfo2_failed = char_parse_fromlogin_accinfo2_failed; + chr->parse_fromlogin_accinfo2_ok = char_parse_fromlogin_accinfo2_ok; + chr->parse_fromlogin = char_parse_fromlogin; + chr->request_accreg2 = char_request_accreg2; + chr->global_accreg_to_login_start = char_global_accreg_to_login_start; + chr->global_accreg_to_login_send = char_global_accreg_to_login_send; + chr->global_accreg_to_login_add = char_global_accreg_to_login_add; + chr->read_fame_list = char_read_fame_list; + chr->send_fame_list = char_send_fame_list; + chr->update_fame_list = char_update_fame_list; + chr->loadName = char_loadName; + chr->parse_frommap_datasync = char_parse_frommap_datasync; + chr->parse_frommap_skillid2idx = char_parse_frommap_skillid2idx; + chr->map_received_ok = char_map_received_ok; + chr->send_maps = char_send_maps; + chr->parse_frommap_map_names = char_parse_frommap_map_names; + chr->send_scdata = char_send_scdata; + chr->parse_frommap_request_scdata = char_parse_frommap_request_scdata; + chr->parse_frommap_set_users_count = char_parse_frommap_set_users_count; + chr->parse_frommap_set_users = char_parse_frommap_set_users; + chr->save_character_ack = char_save_character_ack; + chr->parse_frommap_save_character = char_parse_frommap_save_character; + chr->select_ack = char_select_ack; + chr->parse_frommap_char_select_req = char_parse_frommap_char_select_req; + chr->change_map_server_ack = char_change_map_server_ack; + chr->parse_frommap_change_map_server = char_parse_frommap_change_map_server; + chr->parse_frommap_remove_friend = char_parse_frommap_remove_friend; + chr->char_name_ack = char_char_name_ack; + chr->parse_frommap_char_name_request = char_parse_frommap_char_name_request; + chr->parse_frommap_change_email = char_parse_frommap_change_email; + chr->ban = char_ban; + chr->unban = char_unban; + chr->ask_name_ack = char_ask_name_ack; + chr->parse_frommap_change_account = char_parse_frommap_change_account; + chr->parse_frommap_fame_list = char_parse_frommap_fame_list; + chr->parse_frommap_divorce_char = char_parse_frommap_divorce_char; + chr->parse_frommap_ragsrvinfo = char_parse_frommap_ragsrvinfo; + chr->parse_frommap_set_char_offline = char_parse_frommap_set_char_offline; + chr->parse_frommap_set_all_offline = char_parse_frommap_set_all_offline; + chr->parse_frommap_set_char_online = char_parse_frommap_set_char_online; + chr->parse_frommap_build_fame_list = char_parse_frommap_build_fame_list; + chr->parse_frommap_save_status_change_data = char_parse_frommap_save_status_change_data; + chr->send_pong = char_send_pong; + chr->parse_frommap_ping = char_parse_frommap_ping; + chr->map_auth_ok = char_map_auth_ok; + chr->map_auth_failed = char_map_auth_failed; + chr->parse_frommap_auth_request = char_parse_frommap_auth_request; + chr->parse_frommap_update_ip = char_parse_frommap_update_ip; + chr->parse_frommap_request_stats_report = char_parse_frommap_request_stats_report; + chr->parse_frommap_scdata_update = char_parse_frommap_scdata_update; + chr->parse_frommap_scdata_delete = char_parse_frommap_scdata_delete; + chr->parse_frommap = char_parse_frommap; + chr->search_mapserver = char_search_mapserver; + chr->mapif_init = char_mapif_init; + chr->lan_subnetcheck = char_lan_subnetcheck; + chr->delete2_ack = char_delete2_ack; + chr->delete2_accept_actual_ack = char_delete2_accept_actual_ack; + chr->delete2_accept_ack = char_delete2_accept_ack; + chr->delete2_cancel_ack = char_delete2_cancel_ack; + chr->delete2_req = char_delete2_req; + chr->delete2_accept = char_delete2_accept; + chr->delete2_cancel = char_delete2_cancel; + chr->send_account_id = char_send_account_id; + chr->parse_char_connect = char_parse_char_connect; + chr->send_map_info = char_send_map_info; + chr->send_wait_char_server = char_send_wait_char_server; + chr->search_default_maps_mapserver = char_search_default_maps_mapserver; + chr->parse_char_select = char_parse_char_select; + chr->creation_failed = char_creation_failed; + chr->creation_ok = char_creation_ok; + chr->parse_char_create_new_char = char_parse_char_create_new_char; + chr->delete_char_failed = char_delete_char_failed; + chr->delete_char_ok = char_delete_char_ok; + chr->parse_char_delete_char = char_parse_char_delete_char; + chr->parse_char_ping = char_parse_char_ping; + chr->allow_rename = char_allow_rename; + chr->parse_char_rename_char = char_parse_char_rename_char; + chr->parse_char_rename_char2 = char_parse_char_rename_char2; + chr->rename_char_ack = char_rename_char_ack; + chr->parse_char_rename_char_confirm = char_parse_char_rename_char_confirm; + chr->captcha_notsupported = char_captcha_notsupported; + chr->parse_char_request_captcha = char_parse_char_request_captcha; + chr->parse_char_check_captcha = char_parse_char_check_captcha; + chr->parse_char_delete2_req = char_parse_char_delete2_req; + chr->parse_char_delete2_accept = char_parse_char_delete2_accept; + chr->parse_char_delete2_cancel = char_parse_char_delete2_cancel; + chr->login_map_server_ack = char_login_map_server_ack; + chr->parse_char_login_map_server = char_parse_char_login_map_server; + chr->parse_char_pincode_check = char_parse_char_pincode_check; + chr->parse_char_pincode_window = char_parse_char_pincode_window; + chr->parse_char_pincode_change = char_parse_char_pincode_change; + chr->parse_char_pincode_first_pin = char_parse_char_pincode_first_pin; + chr->parse_char_request_chars = char_parse_char_request_chars; + chr->change_character_slot_ack = char_change_character_slot_ack; + chr->parse_char_move_character = char_parse_char_move_character; + chr->parse_char_unknown_packet = char_parse_char_unknown_packet; + chr->parse_char = char_parse_char; + chr->broadcast_user_count = char_broadcast_user_count; + chr->send_accounts_tologin_sub = char_send_accounts_tologin_sub; + chr->send_accounts_tologin = char_send_accounts_tologin; + chr->check_connect_login_server = char_check_connect_login_server; + chr->online_data_cleanup_sub = char_online_data_cleanup_sub; + chr->online_data_cleanup = char_online_data_cleanup; + chr->lan_config_read = char_lan_config_read; + chr->sql_config_read = char_sql_config_read; + chr->config_dispatch = char_config_dispatch; + chr->config_read = char_config_read; } diff --git a/src/char/geoip.c b/src/char/geoip.c index 34b731af8..4fe03ab07 100644 --- a/src/char/geoip.c +++ b/src/char/geoip.c @@ -160,7 +160,7 @@ void geoip_init(void) fseek(db, -4l, SEEK_CUR); } } - + fclose(db); if (db_type != 1) { diff --git a/src/char/int_auction.c b/src/char/int_auction.c index 684faa46b..e28240ca6 100644 --- a/src/char/int_auction.c +++ b/src/char/int_auction.c @@ -129,7 +129,7 @@ unsigned int inter_auction_create(struct auction_data *auction) void mapif_auction_message(int char_id, unsigned char result) { unsigned char buf[74]; - + WBUFW(buf,0) = 0x3854; WBUFL(buf,2) = char_id; WBUFL(buf,6) = result; @@ -148,7 +148,7 @@ static int inter_auction_end_timer(int tid, int64 tick, int id, intptr_t data) { } else inter_mail->sendmail(0, "Auction Manager", auction->seller_id, auction->seller_name, "Auction", "No buyers have been found for your auction.", 0, &auction->item); - + ShowInfo("Auction End: id %u.\n", auction->auction_id); auction->auction_end_timer = INVALID_TIMER; @@ -201,7 +201,7 @@ void inter_auctions_fromsql(void) SQL->GetData(inter->sql_handle, 2, &data, NULL); safestrncpy(auction->seller_name, data, NAME_LENGTH); SQL->GetData(inter->sql_handle, 3, &data, NULL); auction->buyer_id = atoi(data); SQL->GetData(inter->sql_handle, 4, &data, NULL); safestrncpy(auction->buyer_name, data, NAME_LENGTH); - SQL->GetData(inter->sql_handle, 5, &data, NULL); auction->price = atoi(data); + SQL->GetData(inter->sql_handle, 5, &data, NULL); auction->price = atoi(data); SQL->GetData(inter->sql_handle, 6, &data, NULL); auction->buynow = atoi(data); SQL->GetData(inter->sql_handle, 7, &data, NULL); auction->hours = atoi(data); SQL->GetData(inter->sql_handle, 8, &data, NULL); auction->timestamp = atoi(data); @@ -493,17 +493,17 @@ void inter_auction_sql_final(void) void inter_auction_defaults(void) { - inter_auction = &inter_auction_s; - - inter_auction->db = NULL; // int auction_id -> struct auction_data* - - inter_auction->count = inter_auction_count; - inter_auction->save = inter_auction_save; - inter_auction->create = inter_auction_create; - inter_auction->end_timer = inter_auction_end_timer; - inter_auction->delete_ = inter_auction_delete; - inter_auction->fromsql = inter_auctions_fromsql; - inter_auction->parse_frommap = inter_auction_parse_frommap; - inter_auction->sql_init = inter_auction_sql_init; - inter_auction->sql_final = inter_auction_sql_final; + inter_auction = &inter_auction_s; + + inter_auction->db = NULL; // int auction_id -> struct auction_data* + + inter_auction->count = inter_auction_count; + inter_auction->save = inter_auction_save; + inter_auction->create = inter_auction_create; + inter_auction->end_timer = inter_auction_end_timer; + inter_auction->delete_ = inter_auction_delete; + inter_auction->fromsql = inter_auctions_fromsql; + inter_auction->parse_frommap = inter_auction_parse_frommap; + inter_auction->sql_init = inter_auction_sql_init; + inter_auction->sql_final = inter_auction_sql_final; } diff --git a/src/char/int_auction.h b/src/char/int_auction.h index 03efcdc51..ad8ac7b67 100644 --- a/src/char/int_auction.h +++ b/src/char/int_auction.h @@ -12,16 +12,16 @@ void inter_auction_defaults(void); * inter_auction_interface interface **/ struct inter_auction_interface { - DBMap* db; // int auction_id -> struct auction_data* - int (*count) (int char_id, bool buy); - void (*save) (struct auction_data *auction); - unsigned int (*create) (struct auction_data *auction); - int (*end_timer) (int tid, int64 tick, int id, intptr_t data); - void (*delete_) (struct auction_data *auction); - void (*fromsql) (void); - int (*parse_frommap) (int fd); - int (*sql_init) (void); - void (*sql_final) (void); + DBMap* db; // int auction_id -> struct auction_data* + int (*count) (int char_id, bool buy); + void (*save) (struct auction_data *auction); + unsigned int (*create) (struct auction_data *auction); + int (*end_timer) (int tid, int64 tick, int id, intptr_t data); + void (*delete_) (struct auction_data *auction); + void (*fromsql) (void); + int (*parse_frommap) (int fd); + int (*sql_init) (void); + void (*sql_final) (void); }; struct inter_auction_interface *inter_auction; diff --git a/src/char/int_elemental.c b/src/char/int_elemental.c index 3f8e7b190..d14d1e1e0 100644 --- a/src/char/int_elemental.c +++ b/src/char/int_elemental.c @@ -25,7 +25,7 @@ struct inter_elemental_interface inter_elemental_s; 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(inter->sql_handle, "INSERT INTO `%s` (`char_id`,`class`,`mode`,`hp`,`sp`,`max_hp`,`max_sp`,`atk1`,`atk2`,`matk`,`aspd`,`def`,`mdef`,`flee`,`hit`,`life_time`)" @@ -52,11 +52,11 @@ bool mapif_elemental_save(struct s_elemental* ele) { bool mapif_elemental_load(int ele_id, int char_id, struct s_elemental *ele) { char* data; - + memset(ele, 0, sizeof(struct s_elemental)); ele->elemental_id = ele_id; ele->char_id = char_id; - + if( SQL_ERROR == SQL->Query(inter->sql_handle, "SELECT `class`, `mode`, `hp`, `sp`, `max_hp`, `max_sp`, `atk1`, `atk2`, `matk`, `aspd`," "`def`, `mdef`, `flee`, `hit`, `life_time` FROM `%s` WHERE `ele_id` = '%d' AND `char_id` = '%d'", @@ -65,12 +65,12 @@ bool mapif_elemental_load(int ele_id, int char_id, struct s_elemental *ele) { Sql_ShowDebug(inter->sql_handle); return false; } - + if( SQL_SUCCESS != SQL->NextRow(inter->sql_handle) ) { SQL->FreeResult(inter->sql_handle); return false; } - + SQL->GetData(inter->sql_handle, 0, &data, NULL); ele->class_ = atoi(data); SQL->GetData(inter->sql_handle, 1, &data, NULL); ele->mode = atoi(data); SQL->GetData(inter->sql_handle, 2, &data, NULL); ele->hp = atoi(data); @@ -89,7 +89,7 @@ bool mapif_elemental_load(int ele_id, int char_id, struct s_elemental *ele) { SQL->FreeResult(inter->sql_handle); if( save_log ) ShowInfo("Elemental loaded (%d - %d).\n", ele->elemental_id, ele->char_id); - + return true; } @@ -98,13 +98,13 @@ bool mapif_elemental_delete(int ele_id) { Sql_ShowDebug(inter->sql_handle); return false; } - + return true; } void mapif_elemental_send(int fd, struct s_elemental *ele, unsigned char flag) { int size = sizeof(struct s_elemental) + 5; - + WFIFOHEAD(fd,size); WFIFOW(fd,0) = 0x387c; WFIFOW(fd,2) = size; @@ -161,7 +161,7 @@ void inter_elemental_sql_final(void) { *------------------------------------------*/ int inter_elemental_parse_frommap(int fd) { unsigned short cmd = RFIFOW(fd,0); - + switch( cmd ) { case 0x307c: mapif->parse_elemental_create(fd, (struct s_elemental*)RFIFOP(fd,4)); break; case 0x307d: mapif->parse_elemental_load(fd, (int)RFIFOL(fd,2), (int)RFIFOL(fd,6)); break; @@ -175,9 +175,9 @@ int inter_elemental_parse_frommap(int fd) { void inter_elemental_defaults(void) { - inter_elemental = &inter_elemental_s; + inter_elemental = &inter_elemental_s; - inter_elemental->sql_init = inter_elemental_sql_init; - inter_elemental->sql_final = inter_elemental_sql_final; - inter_elemental->parse_frommap = inter_elemental_parse_frommap; + inter_elemental->sql_init = inter_elemental_sql_init; + inter_elemental->sql_final = inter_elemental_sql_final; + inter_elemental->parse_frommap = inter_elemental_parse_frommap; } diff --git a/src/char/int_elemental.h b/src/char/int_elemental.h index 995dfbfab..611d97550 100644 --- a/src/char/int_elemental.h +++ b/src/char/int_elemental.h @@ -12,9 +12,9 @@ void inter_elemental_defaults(void); * inter_elemental_interface interface **/ struct inter_elemental_interface { - void (*sql_init) (void); - void (*sql_final) (void); - int (*parse_frommap) (int fd); + void (*sql_init) (void); + void (*sql_final) (void); + int (*parse_frommap) (int fd); }; struct inter_elemental_interface *inter_elemental; diff --git a/src/char/int_guild.c b/src/char/int_guild.c index 9817f912d..a5623f83d 100644 --- a/src/char/int_guild.c +++ b/src/char/int_guild.c @@ -208,8 +208,10 @@ int inter_guild_tosql(struct guild *g,int flag) strcat(t_info, " level"); if( add_comma ) StrBuf->AppendStr(&buf, ", "); - //else //last condition using add_coma setting - // add_comma = true; +#if 0 + else //last condition using add_coma setting + add_comma = true; +#endif // 0 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); } StrBuf->Printf(&buf, " WHERE `guild_id`=%d", g->guild_id); @@ -364,8 +366,8 @@ struct guild * inter_guild_fromsql(int guild_id) SQL->GetData(inter->sql_handle, 2, &data, NULL); g->guild_lv = atoi(data); SQL->GetData(inter->sql_handle, 3, &data, NULL); g->connect_member = atoi(data); SQL->GetData(inter->sql_handle, 4, &data, NULL); g->max_member = atoi(data); - if( g->max_member > MAX_GUILD ) - { // Fix reduction of MAX_GUILD [PoW] + 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; } @@ -491,8 +493,8 @@ struct guild * inter_guild_fromsql(int guild_id) return NULL; } - for(i = 0; i < MAX_GUILDSKILL; i++) - { //Skill IDs must always be initialized. [Skotlex] + for (i = 0; i < MAX_GUILDSKILL; i++) { + //Skill IDs must always be initialized. [Skotlex] g->skill[i].id = i + GD_SKILLBASE; } @@ -858,8 +860,7 @@ int inter_guild_calcinfo(struct guild *g) g->average_lv /= c; // Check if guild stats has change - if(g->max_member != before.max_member || g->guild_lv != before.guild_lv || g->skill_point != before.skill_point ) - { + if (g->max_member != before.max_member || g->guild_lv != before.guild_lv || g->skill_point != before.skill_point) { g->save_flag |= GS_LEVEL; mapif->guild_info(-1,g); return 1; @@ -1271,8 +1272,8 @@ int mapif_parse_GuildLeave(int fd, int guild_id, int account_id, int char_id, in return 0; } - if( flag ) - { // Write expulsion reason + if (flag) { + // Write expulsion reason // Find an empty slot int j; ARR_FIND( 0, MAX_GUILDEXPULSION, j, g->expulsion[j].account_id == 0 ); @@ -1484,10 +1485,10 @@ int mapif_parse_GuildMemberInfoChange(int fd, int guild_id, int account_id, int return 0; // Search the member - for(i=0;imax_member;i++) - if( g->member[i].account_id==account_id && - g->member[i].char_id==char_id ) - break; + for (i = 0; i < g->max_member; i++) { + if (g->member[i].account_id == account_id && g->member[i].char_id==char_id) + break; + } // Not Found if(i==g->max_member){ @@ -1507,7 +1508,7 @@ int mapif_parse_GuildMemberInfoChange(int fd, int guild_id, int account_id, int break; } case GMI_EXP: - { // EXP + { uint64 exp, old_exp=g->member[i].exp; g->member[i].exp=*((uint64 *)data); g->member[i].modified = GS_MEMBER_MODIFIED; @@ -1688,7 +1689,7 @@ int mapif_parse_GuildAlliance(int fd, int guild_id1, int guild_id2, int account_ g[1] = inter_guild->fromsql(guild_id2); if(g[0] && g[1]==NULL && (flag & GUILD_ALLIANCE_REMOVE)) //Requested to remove an alliance with a not found guild. - return mapif->parse_GuildDeleteAlliance(g[0], guild_id2, account_id1, account_id2, flag); //Try to do a manual removal of said guild. + return mapif->parse_GuildDeleteAlliance(g[0], guild_id2, account_id1, account_id2, flag); //Try to do a manual removal of said guild. if(g[0]==NULL || g[1]==NULL) return 0; @@ -1734,7 +1735,7 @@ int mapif_parse_GuildNotice(int fd, int guild_id, const char *mes1, const char * memcpy(g->mes1,mes1,MAX_GUILDMES1); memcpy(g->mes2,mes2,MAX_GUILDMES2); - g->save_flag |= GS_MES; //Change mes of guild + g->save_flag |= GS_MES; //Change mes of guild return mapif->guild_notice(g); } @@ -1752,7 +1753,7 @@ int mapif_parse_GuildEmblem(int fd, int len, int guild_id, int dummy, const char memcpy(g->emblem_data,data,len); g->emblem_len=len; g->emblem_id++; - g->save_flag |= GS_EMBLEM; //Change guild + g->save_flag |= GS_EMBLEM; //Change guild return mapif->guild_emblem(g); } @@ -1842,8 +1843,8 @@ int mapif_parse_GuildMasterChange(int fd, int guild_id, const char* name, int le // Data packet length that you set to inter.c //- Shouldn't do checking and packet length, RFIFOSKIP is done by the caller // Must Return -// 1 : ok -// 0 : error +// 1 : ok +// 0 : error int inter_guild_parse_frommap(int fd) { RFIFOHEAD(fd); diff --git a/src/char/int_guild.h b/src/char/int_guild.h index c72856709..960150f4f 100644 --- a/src/char/int_guild.h +++ b/src/char/int_guild.h @@ -28,32 +28,32 @@ void inter_guild_defaults(void); * inter_guild interface **/ struct inter_guild_interface { - DBMap* guild_db; // int guild_id -> struct guild* - DBMap* castle_db; - unsigned int exp[MAX_GUILDLEVEL]; - - int (*save_timer) (int tid, int64 tick, int id, intptr_t data); - int (*removemember_tosql) (int account_id, int char_id); - int (*tosql) (struct guild *g, int flag); - struct guild* (*fromsql) (int guild_id); - int (*castle_tosql) (struct guild_castle *gc); - struct guild_castle* (*castle_fromsql) (int castle_id); - bool (*exp_parse_row) (char* split[], int column, int current); - int (*CharOnline) (int char_id, int guild_id); - int (*CharOffline) (int char_id, int guild_id); - int (*sql_init) (void); - int (*db_final) (DBKey key, DBData *data, va_list ap); - void (*sql_final) (void); - int (*search_guildname) (char *str); - bool (*check_empty) (struct guild *g); - unsigned int (*nextexp) (int level); - int (*checkskill) (struct guild *g, int id); - int (*calcinfo) (struct guild *g); - int (*sex_changed) (int guild_id, int account_id, int char_id, short gender); - int (*charname_changed) (int guild_id, int account_id, int char_id, char *name); - int (*parse_frommap) (int fd); - int (*leave) (int guild_id, int account_id, int char_id); - int (*broken) (int guild_id); + DBMap* guild_db; // int guild_id -> struct guild* + DBMap* castle_db; + unsigned int exp[MAX_GUILDLEVEL]; + + int (*save_timer) (int tid, int64 tick, int id, intptr_t data); + int (*removemember_tosql) (int account_id, int char_id); + int (*tosql) (struct guild *g, int flag); + struct guild* (*fromsql) (int guild_id); + int (*castle_tosql) (struct guild_castle *gc); + struct guild_castle* (*castle_fromsql) (int castle_id); + bool (*exp_parse_row) (char* split[], int column, int current); + int (*CharOnline) (int char_id, int guild_id); + int (*CharOffline) (int char_id, int guild_id); + int (*sql_init) (void); + int (*db_final) (DBKey key, DBData *data, va_list ap); + void (*sql_final) (void); + int (*search_guildname) (char *str); + bool (*check_empty) (struct guild *g); + unsigned int (*nextexp) (int level); + int (*checkskill) (struct guild *g, int id); + int (*calcinfo) (struct guild *g); + int (*sex_changed) (int guild_id, int account_id, int char_id, short gender); + int (*charname_changed) (int guild_id, int account_id, int char_id, char *name); + int (*parse_frommap) (int fd); + int (*leave) (int guild_id, int account_id, int char_id); + int (*broken) (int guild_id); }; struct inter_guild_interface *inter_guild; diff --git a/src/char/int_homun.c b/src/char/int_homun.c index d3cc1c46c..7f9323bdd 100644 --- a/src/char/int_homun.c +++ b/src/char/int_homun.c @@ -167,8 +167,8 @@ bool mapif_homunculus_load(int homun_id, struct s_homunculus* hd) return false; } - if( !SQL->NumRows(inter->sql_handle) ) - { //No homunculus found. + if (!SQL->NumRows(inter->sql_handle)) { + //No homunculus found. SQL->FreeResult(inter->sql_handle); return false; } @@ -236,8 +236,8 @@ bool mapif_homunculus_load(int homun_id, struct s_homunculus* hd) bool mapif_homunculus_delete(int homun_id) { - if( SQL_ERROR == SQL->Query(inter->sql_handle, "DELETE FROM `%s` WHERE `homun_id` = '%u'", homunculus_db, homun_id) - || SQL_ERROR == SQL->Query(inter->sql_handle, "DELETE FROM `%s` WHERE `homun_id` = '%u'", skill_homunculus_db, homun_id) + if (SQL_ERROR == SQL->Query(inter->sql_handle, "DELETE FROM `%s` WHERE `homun_id` = '%u'", homunculus_db, homun_id) + || SQL_ERROR == SQL->Query(inter->sql_handle, "DELETE FROM `%s` WHERE `homun_id` = '%u'", skill_homunculus_db, homun_id) ) { Sql_ShowDebug(inter->sql_handle); return false; diff --git a/src/char/int_homun.h b/src/char/int_homun.h index 69b30b781..5bfa355d4 100644 --- a/src/char/int_homun.h +++ b/src/char/int_homun.h @@ -14,9 +14,9 @@ void inter_homunculus_defaults(void); * inter_homunculus interface **/ struct inter_homunculus_interface { - int (*sql_init) (void); - void (*sql_final) (void); - int (*parse_frommap) (int fd); + int (*sql_init) (void); + void (*sql_final) (void); + int (*parse_frommap) (int fd); }; struct inter_homunculus_interface *inter_homunculus; diff --git a/src/char/int_mail.c b/src/char/int_mail.c index c400ea01f..2c0a85f33 100644 --- a/src/char/int_mail.c +++ b/src/char/int_mail.c @@ -336,7 +336,7 @@ void mapif_parse_mail_delete(int fd) void mapif_mail_new(struct mail_message *msg) { unsigned char buf[74]; - + if( !msg || !msg->id ) return; @@ -405,7 +405,7 @@ void mapif_parse_mail_return(int fd) void mapif_mail_send(int fd, struct mail_message* msg) { int len = sizeof(struct mail_message) + 4; - + WFIFOHEAD(fd,len); WFIFOW(fd,0) = 0x384d; WFIFOW(fd,2) = len; diff --git a/src/char/int_mail.h b/src/char/int_mail.h index b69b27079..5ce7bafa2 100644 --- a/src/char/int_mail.h +++ b/src/char/int_mail.h @@ -16,14 +16,14 @@ void inter_mail_defaults(void); * inter_mail interface **/ struct inter_mail_interface { - int (*sql_init) (void); - void (*sql_final) (void); - int (*parse_frommap) (int fd); - int (*fromsql) (int char_id, struct mail_data* md); - int (*savemessage) (struct mail_message* msg); - bool (*loadmessage) (int mail_id, struct mail_message* msg); - bool (*DeleteAttach) (int mail_id); - void (*sendmail) (int send_id, const char* send_name, int dest_id, const char* dest_name, const char* title, const char* body, int zeny, struct item *item); + int (*sql_init) (void); + void (*sql_final) (void); + int (*parse_frommap) (int fd); + int (*fromsql) (int char_id, struct mail_data* md); + int (*savemessage) (struct mail_message* msg); + bool (*loadmessage) (int mail_id, struct mail_message* msg); + bool (*DeleteAttach) (int mail_id); + void (*sendmail) (int send_id, const char* send_name, int dest_id, const char* dest_name, const char* title, const char* body, int zeny, struct item *item); }; struct inter_mail_interface *inter_mail; diff --git a/src/char/int_mercenary.c b/src/char/int_mercenary.c index 0e91b6785..2bd94b97e 100644 --- a/src/char/int_mercenary.c +++ b/src/char/int_mercenary.c @@ -129,7 +129,7 @@ bool mapif_mercenary_load(int merc_id, int char_id, struct s_mercenary *merc) SQL->FreeResult(inter->sql_handle); if( save_log ) ShowInfo("Mercenary loaded (%d - %d).\n", merc->mercenary_id, merc->char_id); - + return true; } diff --git a/src/char/int_mercenary.h b/src/char/int_mercenary.h index 900065cb7..b22ea61b2 100644 --- a/src/char/int_mercenary.h +++ b/src/char/int_mercenary.h @@ -14,12 +14,12 @@ void inter_mercenary_defaults(void); * inter_mercenary interface **/ struct inter_mercenary_interface { - bool (*owner_fromsql) (int char_id, struct mmo_charstatus *status); - bool (*owner_tosql) (int char_id, struct mmo_charstatus *status); - bool (*owner_delete) (int char_id); - int (*sql_init) (void); - void (*sql_final) (void); - int (*parse_frommap) (int fd); + bool (*owner_fromsql) (int char_id, struct mmo_charstatus *status); + bool (*owner_tosql) (int char_id, struct mmo_charstatus *status); + bool (*owner_delete) (int char_id); + int (*sql_init) (void); + void (*sql_final) (void); + int (*parse_frommap) (int fd); }; struct inter_mercenary_interface *inter_mercenary; diff --git a/src/char/int_party.c b/src/char/int_party.c index 49873feff..b16f106be 100644 --- a/src/char/int_party.c +++ b/src/char/int_party.c @@ -156,7 +156,7 @@ int inter_party_tosql(struct party *p, int flag, int index) party_db, p->member[index].account_id, p->member[index].char_id, party_id) ) Sql_ShowDebug(inter->sql_handle); } - + if( flag & PS_ADDMEMBER ) {// Add one party member. if( SQL_ERROR == SQL->Query(inter->sql_handle, "UPDATE `%s` SET `party_id`='%d' WHERE `account_id`='%d' AND `char_id`='%d'", @@ -192,7 +192,7 @@ struct party_data *inter_party_fromsql(int party_id) #endif if( party_id <= 0 ) return NULL; - + //Load from memory p = (struct party_data*)idb_get(inter_party->db, party_id); if( p != NULL ) @@ -483,7 +483,7 @@ int mapif_parse_CreateParty(int fd, char *name, int item, int item2, struct part } p = (struct party_data*)aCalloc(1, sizeof(struct party_data)); - + memcpy(p->party.name,name,NAME_LENGTH); p->party.exp=0; p->party.item=(item?1:0)|(item2?2:0); @@ -624,7 +624,7 @@ int mapif_parse_PartyLeave(int fd, int party_id, int account_id, int char_id) inter_party->check_lv(p); } } - + if (inter_party->check_empty(p) == 0) mapif->party_info(-1, &p->party, 0); return 0; @@ -716,13 +716,10 @@ int mapif_parse_PartyLeaderChange(int fd, int party_id, int account_id, int char if(!p) return 0; - for (i = 0; i < MAX_PARTY; i++) - { + for (i = 0; i < MAX_PARTY; i++) { if(p->party.member[i].leader) p->party.member[i].leader = 0; - if(p->party.member[i].account_id == account_id && - p->party.member[i].char_id == char_id) - { + if(p->party.member[i].account_id == account_id && p->party.member[i].char_id == char_id) { p->party.member[i].leader = 1; inter_party->tosql(&p->party,PS_LEADER, i); } @@ -736,8 +733,8 @@ int mapif_parse_PartyLeaderChange(int fd, int party_id, int account_id, int char // Data packet length is set to inter.c that you // Do NOT go and check the packet length, RFIFOSKIP is done by the caller // Return : -// 0 : error -// 1 : ok +// 0 : error +// 1 : ok int inter_party_parse_frommap(int fd) { RFIFOHEAD(fd); @@ -787,7 +784,7 @@ int inter_party_CharOnline(int char_id, int party_id) } if (party_id == 0) return 0; //No party... - + p = inter_party->fromsql(party_id); if(!p) { ShowError("Character %d's party %d not found!\n", char_id, party_id); @@ -833,7 +830,7 @@ int inter_party_CharOffline(int char_id, int party_id) { } if (party_id == 0) return 0; //No party... - + //Character has a party, set character offline and check if they were the only member online if ((p = inter_party->fromsql(party_id)) == NULL) return 0; diff --git a/src/char/int_party.h b/src/char/int_party.h index 68fae32a8..0c70a5300 100644 --- a/src/char/int_party.h +++ b/src/char/int_party.h @@ -29,21 +29,21 @@ void inter_party_defaults(void); * inter_party interface **/ struct inter_party_interface { - struct party_data *pt; - DBMap* db; // int party_id -> struct party_data* - int (*check_lv) (struct party_data *p); - void (*calc_state) (struct party_data *p); - int (*tosql) (struct party *p, int flag, int index); - struct party_data* (*fromsql) (int party_id); - int (*sql_init) (void); - void (*sql_final) (void); - struct party_data* (*search_partyname) (const char *str); - int (*check_exp_share) (struct party_data *p); - int (*check_empty) (struct party_data *p); - int (*parse_frommap) (int fd); - int (*leave) (int party_id,int account_id, int char_id); - int (*CharOnline) (int char_id, int party_id); - int (*CharOffline) (int char_id, int party_id); + struct party_data *pt; + DBMap* db; // int party_id -> struct party_data* + int (*check_lv) (struct party_data *p); + void (*calc_state) (struct party_data *p); + int (*tosql) (struct party *p, int flag, int index); + struct party_data* (*fromsql) (int party_id); + int (*sql_init) (void); + void (*sql_final) (void); + struct party_data* (*search_partyname) (const char *str); + int (*check_exp_share) (struct party_data *p); + int (*check_empty) (struct party_data *p); + int (*parse_frommap) (int fd); + int (*leave) (int party_id,int account_id, int char_id); + int (*CharOnline) (int char_id, int party_id); + int (*CharOffline) (int char_id, int party_id); }; struct inter_party_interface *inter_party; diff --git a/src/char/int_pet.c b/src/char/int_pet.c index c68fe6476..b37037844 100644 --- a/src/char/int_pet.c +++ b/src/char/int_pet.c @@ -222,7 +222,7 @@ int mapif_create_pet(int fd, int account_id, int char_id, short pet_class, short inter_pet->pt->pet_id = -1; //Signal NEW pet. if (inter_pet->tosql(inter_pet->pt->pet_id,inter_pet->pt)) mapif->pet_created(fd, account_id, inter_pet->pt); - else //Failed... + else //Failed... mapif->pet_created(fd, account_id, NULL); return 0; diff --git a/src/char/int_pet.h b/src/char/int_pet.h index fcb052f34..873613307 100644 --- a/src/char/int_pet.h +++ b/src/char/int_pet.h @@ -12,13 +12,13 @@ void inter_pet_defaults(void); * inter_pet interface **/ struct inter_pet_interface { - struct s_pet *pt; - int (*tosql) (int pet_id, struct s_pet* p); - int (*fromsql) (int pet_id, struct s_pet* p); - int (*sql_init) (void); - void (*sql_final) (void); - int (*delete_) (int pet_id); - int (*parse_frommap) (int fd); + struct s_pet *pt; + int (*tosql) (int pet_id, struct s_pet* p); + int (*fromsql) (int pet_id, struct s_pet* p); + int (*sql_init) (void); + void (*sql_final) (void); + int (*delete_) (int pet_id); + int (*parse_frommap) (int fd); }; struct inter_pet_interface *inter_pet; diff --git a/src/char/int_quest.c b/src/char/int_quest.c index a5721c430..b993cbc14 100644 --- a/src/char/int_quest.c +++ b/src/char/int_quest.c @@ -299,5 +299,5 @@ void inter_quest_defaults(void) { inter_quest = &inter_quest_s; - inter_quest->parse_frommap = inter_quest_parse_frommap; + inter_quest->parse_frommap = inter_quest_parse_frommap; } diff --git a/src/char/int_quest.h b/src/char/int_quest.h index 17740341b..265a3f97a 100644 --- a/src/char/int_quest.h +++ b/src/char/int_quest.h @@ -10,7 +10,7 @@ void inter_quest_defaults(void); * inter_quest interface **/ struct inter_quest_interface { - int (*parse_frommap) (int fd); + int (*parse_frommap) (int fd); }; struct inter_quest_interface *inter_quest; diff --git a/src/char/int_storage.c b/src/char/int_storage.c index 7cef7e6f0..d64e11b89 100644 --- a/src/char/int_storage.c +++ b/src/char/int_storage.c @@ -21,7 +21,7 @@ #include "../common/sql.h" #include "../common/strlib.h" // StringBuf -#define STORAGE_MEMINC 16 +#define STORAGE_MEMINC 16 struct inter_storage_interface inter_storage_s; @@ -47,7 +47,7 @@ int inter_storage_fromsql(int account_id, struct storage_data* p) // storage {`account_id`/`id`/`nameid`/`amount`/`equip`/`identify`/`refine`/`attribute`/`card0`/`card1`/`card2`/`card3`} StrBuf->Init(&buf); StrBuf->AppendStr(&buf, "SELECT `id`,`nameid`,`amount`,`equip`,`identify`,`refine`,`attribute`,`expire_time`,`bound`,`unique_id`"); - for( j = 0; j < MAX_SLOTS; ++j ) + for( j = 0; j < MAX_SLOTS; ++j ) StrBuf->Printf(&buf, ",`card%d`", j); StrBuf->Printf(&buf, " FROM `%s` WHERE `account_id`='%d' ORDER BY `nameid`", storage_db, account_id); @@ -69,7 +69,7 @@ int inter_storage_fromsql(int account_id, struct storage_data* p) SQL->GetData(inter->sql_handle, 7, &data, NULL); item->expire_time = (unsigned int)atoi(data); SQL->GetData(inter->sql_handle, 8, &data, NULL); item->bound = atoi(data); SQL->GetData(inter->sql_handle, 9, &data, NULL); item->unique_id = strtoull(data, NULL, 10); - for( j = 0; j < MAX_SLOTS; ++j ) + for( j = 0; j < MAX_SLOTS; ++j ) { SQL->GetData(inter->sql_handle, 10+j, &data, NULL); item->card[j] = atoi(data); } @@ -105,7 +105,7 @@ int inter_storage_guild_storage_fromsql(int guild_id, struct guild_storage* p) // storage {`guild_id`/`id`/`nameid`/`amount`/`equip`/`identify`/`refine`/`attribute`/`card0`/`card1`/`card2`/`card3`} StrBuf->Init(&buf); StrBuf->AppendStr(&buf, "SELECT `id`,`nameid`,`amount`,`equip`,`identify`,`refine`,`attribute`,`bound`,`unique_id`"); - for( j = 0; j < MAX_SLOTS; ++j ) + for( j = 0; j < MAX_SLOTS; ++j ) StrBuf->Printf(&buf, ",`card%d`", j); StrBuf->Printf(&buf, " FROM `%s` WHERE `guild_id`='%d' ORDER BY `nameid`", guild_storage_db, guild_id); @@ -125,7 +125,7 @@ int inter_storage_guild_storage_fromsql(int guild_id, struct guild_storage* p) SQL->GetData(inter->sql_handle, 6, &data, NULL); item->attribute = atoi(data); SQL->GetData(inter->sql_handle, 7, &data, NULL); item->bound = atoi(data); SQL->GetData(inter->sql_handle, 8, &data, NULL); item->unique_id = strtoull(data, NULL, 10); - item->expire_time = 0; + item->expire_time = 0; for( j = 0; j < MAX_SLOTS; ++j ) { SQL->GetData(inter->sql_handle, 9+j, &data, NULL); item->card[j] = atoi(data); @@ -180,7 +180,7 @@ int mapif_load_guild_storage(int fd, int account_id, int guild_id, char flag) WFIFOL(fd,8) = guild_id; WFIFOB(fd,12) = flag; //1 open storage, 0 don't open inter_storage->guild_storage_fromsql(guild_id, (struct guild_storage*)WFIFOP(fd,13)); - WFIFOSET(fd, WFIFOW(fd,2)); + WFIFOSET(fd, WFIFOW(fd,2)); return 0; } // guild does not exist @@ -305,7 +305,7 @@ int mapif_parse_ItemBoundRetrieve_sub(int fd) i++; } SQL->FreeResult(inter->sql_handle); - + if(!i) { //No items found - No need to continue StrBuf->Destroy(&buf); SQL->StmtFree(stmt); diff --git a/src/char/int_storage.h b/src/char/int_storage.h index dcf8f07c1..6c380f29b 100644 --- a/src/char/int_storage.h +++ b/src/char/int_storage.h @@ -13,15 +13,15 @@ void inter_storage_defaults(void); * inter_storage interface **/ struct inter_storage_interface { - int (*tosql) (int account_id, struct storage_data* p); - int (*fromsql) (int account_id, struct storage_data* p); - int (*guild_storage_tosql) (int guild_id, struct guild_storage* p); - int (*guild_storage_fromsql) (int guild_id, struct guild_storage* p); - int (*sql_init) (void); - void (*sql_final) (void); - int (*delete_) (int account_id); - int (*guild_storage_delete) (int guild_id); - int (*parse_frommap) (int fd); + int (*tosql) (int account_id, struct storage_data* p); + int (*fromsql) (int account_id, struct storage_data* p); + int (*guild_storage_tosql) (int guild_id, struct guild_storage* p); + int (*guild_storage_fromsql) (int guild_id, struct guild_storage* p); + int (*sql_init) (void); + void (*sql_final) (void); + int (*delete_) (int account_id); + int (*guild_storage_delete) (int guild_id); + int (*parse_frommap) (int fd); }; struct inter_storage_interface *inter_storage; diff --git a/src/char/inter.c b/src/char/inter.c index 1efe103c0..ab91e25b9 100644 --- a/src/char/inter.c +++ b/src/char/inter.c @@ -32,8 +32,8 @@ #include "../common/strlib.h" #include "../common/timer.h" -#define WISDATA_TTL (60*1000) //Wis data Time To Live (60 seconds) -#define WISDELLIST_MAX 256 // Number of elements in the list Delete data Wis +#define WISDATA_TTL (60*1000) // Wis data Time To Live (60 seconds) +#define WISDELLIST_MAX 256 // Number of elements in the list Delete data Wis struct inter_interface inter_s; @@ -48,7 +48,7 @@ unsigned int party_share_level = 10; // recv. packet list int inter_recv_packet_length[] = { - -1,-1, 7,-1, -1,13,36, (2 + 4 + 4 + 4 + NAME_LENGTH), 0, 0, 0, 0, 0, 0, 0, 0, // 3000- + -1,-1, 7,-1, -1,13,36, (2 + 4 + 4 + 4 + NAME_LENGTH), 0, 0, 0, 0, 0, 0, 0, 0, // 3000- 6,-1, 0, 0, 0, 0, 0, 0, 10,-1, 0, 0, 0, 0, 0, 0, // 3010- -1,10,-1,14, 14,19, 6,-1, 14,14, 0, 0, 0, 0, 0, 0, // 3020- Party -1, 6,-1,-1, 55,19, 6,-1, 14,-1,-1,-1, 18,19,186,-1, // 3030- @@ -433,7 +433,8 @@ void mapif_parse_accinfo(int fd) account_id = atoi(query); - if (account_id < START_ACCOUNT_NUM) { // is string + if (account_id < START_ACCOUNT_NUM) { + // is string if ( SQL_ERROR == SQL->Query(inter->sql_handle, "SELECT `account_id`,`name`,`class`,`base_level`,`job_level`,`online` FROM `%s` WHERE `name` LIKE '%s' LIMIT 10", char_db, query_esq) || SQL->NumRows(inter->sql_handle) == 0 ) { if( SQL->NumRows(inter->sql_handle) == 0 ) { @@ -480,7 +481,8 @@ void mapif_parse_accinfo(int fd) return; } void mapif_parse_accinfo2(bool success, int map_fd, int u_fd, int u_aid, int account_id, const char *userid, const char *user_pass, - const char *email, const char *last_ip, const char *lastlogin, const char *pin_code, const char *birthdate, int group_id, int logincount, int state) + const char *email, const char *last_ip, const char *lastlogin, const char *pin_code, const char *birthdate, + int group_id, int logincount, int state) { if (map_fd <= 0 || !session_isActive(map_fd)) return; // check if we have a valid fd @@ -588,7 +590,6 @@ void inter_savereg(int account_id, int char_id, const char *key, unsigned int in } } } - } // Load account_reg from sql (type=2) @@ -614,7 +615,7 @@ int inter_accreg_fromsql(int account_id,int char_id, int fd, int type) ShowError("inter->accreg_fromsql: Invalid type %d\n", type); return 0; } - + WFIFOHEAD(fd, 60000 + 300); WFIFOW(fd, 0) = 0x3804; /* 0x2 = length, set prior to being sent */ @@ -624,7 +625,7 @@ int inter_accreg_fromsql(int account_id,int char_id, int fd, int type) WFIFOB(fd, 13) = 1;/* is string type */ WFIFOW(fd, 14) = 0;/* count */ plen = 16; - + /** * Vessel! * @@ -632,16 +633,15 @@ int inter_accreg_fromsql(int account_id,int char_id, int fd, int type) * { keyLength(B), key(), index(L), valLength(B), val() } **/ while ( SQL_SUCCESS == SQL->NextRow(inter->sql_handle) ) { - SQL->GetData(inter->sql_handle, 0, &data, NULL); len = strlen(data)+1; - + WFIFOB(fd, plen) = (unsigned char)len;/* won't be higher; the column size is 32 */ plen += 1; - + safestrncpy((char*)WFIFOP(fd,plen), data, len); plen += len; - + SQL->GetData(inter->sql_handle, 1, &data, NULL); WFIFOL(fd, plen) = (unsigned int)atol(data); @@ -652,16 +652,16 @@ int inter_accreg_fromsql(int account_id,int char_id, int fd, int type) WFIFOB(fd, plen) = (unsigned char)len;/* won't be higher; the column size is 254 */ plen += 1; - + safestrncpy((char*)WFIFOP(fd,plen), data, len); plen += len; WFIFOW(fd, 14) += 1; - + if( plen > 60000 ) { WFIFOW(fd, 2) = plen; WFIFOSET(fd, plen); - + /* prepare follow up */ WFIFOHEAD(fd, 60000 + 300); WFIFOW(fd, 0) = 0x3804; @@ -674,13 +674,13 @@ int inter_accreg_fromsql(int account_id,int char_id, int fd, int type) plen = 16; } } - + /* mark & go. */ WFIFOW(fd, 2) = plen; WFIFOSET(fd, plen); SQL->FreeResult(inter->sql_handle); - + switch( type ) { case 3: //char reg if( SQL_ERROR == SQL->Query(inter->sql_handle, "SELECT `key`, `index`, `value` FROM `%s` WHERE `char_id`='%d'", char_reg_num_db, char_id) ) @@ -704,7 +704,7 @@ int inter_accreg_fromsql(int account_id,int char_id, int fd, int type) WFIFOB(fd, 13) = 0;/* is int type */ WFIFOW(fd, 14) = 0;/* count */ plen = 16; - + /** * Vessel! * @@ -712,32 +712,31 @@ int inter_accreg_fromsql(int account_id,int char_id, int fd, int type) * { keyLength(B), key(), index(L), value(L) } **/ while ( SQL_SUCCESS == SQL->NextRow(inter->sql_handle) ) { - SQL->GetData(inter->sql_handle, 0, &data, NULL); len = strlen(data)+1; - + WFIFOB(fd, plen) = (unsigned char)len;/* won't be higher; the column size is 32 */ plen += 1; - + safestrncpy((char*)WFIFOP(fd,plen), data, len); plen += len; - + SQL->GetData(inter->sql_handle, 1, &data, NULL); - + WFIFOL(fd, plen) = (unsigned int)atol(data); plen += 4; - + SQL->GetData(inter->sql_handle, 2, &data, NULL); - + WFIFOL(fd, plen) = atoi(data); plen += 4; - + WFIFOW(fd, 14) += 1; - + if( plen > 60000 ) { WFIFOW(fd, 2) = plen; WFIFOSET(fd, plen); - + /* prepare follow up */ WFIFOHEAD(fd, 60000 + 300); WFIFOW(fd, 0) = 0x3804; @@ -750,12 +749,12 @@ int inter_accreg_fromsql(int account_id,int char_id, int fd, int type) plen = 16; } } - + /* mark as complete & go. */ WFIFOB(fd, 12) = type; WFIFOW(fd, 2) = plen; WFIFOSET(fd, plen); - + SQL->FreeResult(inter->sql_handle); return 1; } @@ -970,12 +969,14 @@ int mapif_wis_end(struct WisData *wd, int flag) return 0; } +#if 0 // Account registry transfer to map-server -//static void mapif_account_reg(int fd, unsigned char *src) -//{ -// WBUFW(src,0)=0x3804; //NOTE: writing to RFIFO -// mapif->sendallwos(fd, src, WBUFW(src,2)); -//} +static void mapif_account_reg(int fd, unsigned char *src) +{ + WBUFW(src,0)=0x3804; //NOTE: writing to RFIFO + mapif->sendallwos(fd, src, WBUFW(src,2)); +} +#endif // 0 // Send the requested account_reg int mapif_account_reg_reply(int fd,int account_id,int char_id, int type) @@ -1124,7 +1125,7 @@ int mapif_parse_WisReply(int fd) flag = RFIFOB(fd,6); wd = (struct WisData*)idb_get(wis_db, id); if (wd == NULL) - return 0; // This wisp was probably suppress before, because it was timeout of because of target was found on another map-server + return 0; // This wisp was probably suppress before, because it was timeout of because of target was found on another map-server if ((--wd->count) <= 0 || flag != 1) { mapif->wis_end(wd, flag); // flag: 0: success to send whisper, 1: target character is not logged in?, 2: ignored by target @@ -1150,7 +1151,7 @@ int mapif_parse_WisToGM(int fd) int mapif_parse_Registry(int fd) { int account_id = RFIFOL(fd, 4), char_id = RFIFOL(fd, 8), count = RFIFOW(fd, 12); - + if( count ) { int cursor = 14, i; char key[32], sval[254]; @@ -1159,7 +1160,7 @@ int mapif_parse_Registry(int fd) if( isLoginActive ) chr->global_accreg_to_login_start(account_id,char_id); - + for(i = 0; i < count; i++) { safestrncpy(key, (char*)RFIFOP(fd, cursor + 1), RFIFOB(fd, cursor)); cursor += RFIFOB(fd, cursor) + 1; @@ -1185,7 +1186,6 @@ int mapif_parse_Registry(int fd) case 3: inter->savereg(account_id,char_id,key,index,0,true); break; - default: ShowError("mapif->parse_Registry: unknown type %d\n",RFIFOB(fd, cursor - 1)); return 1; @@ -1193,7 +1193,7 @@ int mapif_parse_Registry(int fd) } - if( isLoginActive ) + if (isLoginActive) chr->global_accreg_to_login_send(); } return 0; diff --git a/src/char/inter.h b/src/char/inter.h index f15c8b0f7..c4bb43c1d 100644 --- a/src/char/inter.h +++ b/src/char/inter.h @@ -21,25 +21,25 @@ void inter_defaults(void); * inter interface **/ struct inter_interface { - Sql* sql_handle; - const char* (*msg_txt) (int msg_number); - bool (*msg_config_read) (const char *cfg_name, bool allow_override); - void (*do_final_msg) (void); - const char* (*job_name) (int class_); - void (*vmsg_to_fd) (int fd, int u_fd, int aid, char* msg, va_list ap); - void (*msg_to_fd) (int fd, int u_fd, int aid, char *msg, ...); - void (*savereg) (int account_id, int char_id, const char *key, unsigned int index, intptr_t val, bool is_string); - int (*accreg_fromsql) (int account_id,int char_id, int fd, int type); - int (*config_read) (const char* cfgName); - int (*vlog) (char* fmt, va_list ap); - int (*log) (char* fmt, ...); - int (*init_sql) (const char *file); - int (*mapif_init) (int fd); - int (*check_ttl_wisdata_sub) (DBKey key, DBData *data, va_list ap); - int (*check_ttl_wisdata) (void); - int (*check_length) (int fd, int length); - int (*parse_frommap) (int fd); - void (*final) (void); + Sql* sql_handle; + const char* (*msg_txt) (int msg_number); + bool (*msg_config_read) (const char *cfg_name, bool allow_override); + void (*do_final_msg) (void); + const char* (*job_name) (int class_); + void (*vmsg_to_fd) (int fd, int u_fd, int aid, char* msg, va_list ap); + void (*msg_to_fd) (int fd, int u_fd, int aid, char *msg, ...); + void (*savereg) (int account_id, int char_id, const char *key, unsigned int index, intptr_t val, bool is_string); + int (*accreg_fromsql) (int account_id,int char_id, int fd, int type); + int (*config_read) (const char* cfgName); + int (*vlog) (char* fmt, va_list ap); + int (*log) (char* fmt, ...); + int (*init_sql) (const char *file); + int (*mapif_init) (int fd); + int (*check_ttl_wisdata_sub) (DBKey key, DBData *data, va_list ap); + int (*check_ttl_wisdata) (void); + int (*check_length) (int fd, int length); + int (*parse_frommap) (int fd); + void (*final) (void); }; struct inter_interface *inter; diff --git a/src/char/pincode.c b/src/char/pincode.c index a4ec89484..299079358 100644 --- a/src/char/pincode.c +++ b/src/char/pincode.c @@ -20,14 +20,14 @@ struct pincode_interface pincode_s; void pincode_handle ( int fd, struct char_session_data* sd ) { struct online_char_data* character = (struct online_char_data*)idb_get(chr->online_char_db, sd->account_id); - + if( character && character->pincode_enable > pincode->charselect ){ character->pincode_enable = pincode->charselect * 2; }else{ pincode->sendstate( fd, sd, PINCODE_OK ); return; } - + if( strlen(sd->pincode) == 4 ){ if( pincode->changetime && time(NULL) > (sd->pincode_change+pincode->changetime) ){ // User hasn't changed his PIN code for a long time pincode->sendstate( fd, sd, PINCODE_EXPIRED ); @@ -43,7 +43,7 @@ void pincode_handle ( int fd, struct char_session_data* sd ) { void pincode_check(int fd, struct char_session_data* sd) { char pin[5] = "\0\0\0\0"; - + strncpy(pin, (char*)RFIFOP(fd, 6), 4+1); pincode->decrypt(sd->pincode_seed, pin); if( pincode->compare( fd, sd, pin ) ){ @@ -74,7 +74,7 @@ void pincode_change(int fd, struct char_session_data* sd) { pincode->decrypt(sd->pincode_seed,oldpin); if( !pincode->compare( fd, sd, oldpin ) ) return; - + strncpy(newpin, (char*)RFIFOP(fd,10), sizeof(newpin)); pincode->decrypt(sd->pincode_seed,newpin); pincode->update( sd->account_id, newpin ); @@ -128,7 +128,7 @@ void pincode_notifyLoginPinError(int account_id) { void pincode_decrypt(unsigned int userSeed, char* pin) { int i, pos; char tab[10] = {0,1,2,3,4,5,6,7,8,9}; - + for( i = 1; i < 10; i++ ){ userSeed = pincode->baseSeed + userSeed * pincode->multiplier; pos = userSeed % (i + 1); @@ -138,18 +138,17 @@ void pincode_decrypt(unsigned int userSeed, char* pin) { tab[i] ^= tab[pos]; } } - + for( i = 0; i < 4; i++ ){ pin[i] = tab[pin[i] - '0']; } - + sprintf(pin, "%d%d%d%d", pin[0], pin[1], pin[2], pin[3]); } bool pincode_config_read(char *w1, char *w2) { - + while ( true ) { - if ( strcmpi(w1, "pincode_enabled") == 0 ) { pincode->enabled = atoi(w2); #if PACKETVER < 20110309 @@ -168,18 +167,18 @@ bool pincode_config_read(char *w1, char *w2) { } } else if ( strcmpi(w1, "pincode_charselect") == 0 ) { pincode->charselect = atoi(w2); - } else + } else { return false; - + } break; } - + return true; } void pincode_defaults(void) { pincode = &pincode_s; - + pincode->enabled = PINCODE_OK; pincode->changetime = 0; pincode->maxtry = 3; diff --git a/src/common/HPM.c b/src/common/HPM.c index 003f2d935..e38451161 100644 --- a/src/common/HPM.c +++ b/src/common/HPM.c @@ -56,22 +56,22 @@ void hplugin_export_symbol(void *var, char *name) { void *hplugin_import_symbol(char *name, unsigned int pID) { unsigned int i; - + for( i = 0; i < HPM->symbol_count; i++ ) { if( strcmp(HPM->symbols[i]->name,name) == 0 ) return HPM->symbols[i]->ptr; } - + ShowError("HPM:get_symbol:%s: '"CL_WHITE"%s"CL_RESET"' not found!\n",HPM->pid2name(pID),name); return NULL; } bool hplugin_iscompatible(char* version) { unsigned int req_major = 0, req_minor = 0; - + if( version == NULL ) return false; - + sscanf(version, "%u.%u", &req_major, &req_minor); return ( req_major == HPM->version[0] && req_minor <= HPM->version[1] ) ? true : false; @@ -110,7 +110,7 @@ bool hplugin_populate(struct hplugin *plugin, const char *filename) { HPM_POP(ShowFatalError), }; 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); @@ -119,7 +119,7 @@ bool hplugin_populate(struct hplugin *plugin, const char *filename) { } *Link = ToLink[i].Ref; } - + return true; } #undef HPM_POP @@ -133,54 +133,54 @@ struct hplugin *hplugin_load(const char* filename) { int *HPMDataCheckVer; unsigned int *HPMDataCheckLen; struct s_HPMDataCheck *HPMDataCheck; - + if( HPM->exists(filename) ) { ShowWarning("HPM:plugin_load: attempting to load duplicate '"CL_WHITE"%s"CL_RESET"', skipping...\n", filename); return NULL; } - + plugin = HPM->create(); - + if( !( plugin->dll = plugin_open(filename) ) ){ ShowWarning("HPM:plugin_load: failed to load '"CL_WHITE"%s"CL_RESET"', skipping...\n", filename); HPM->unload(plugin); return NULL; } - + if( !( info = plugin_import(plugin->dll, "pinfo",struct hplugin_info*) ) ) { ShowDebug("HPM:plugin_load: failed to retrieve 'plugin_info' for '"CL_WHITE"%s"CL_RESET"', skipping...\n", filename); HPM->unload(plugin); return NULL; } - + if( !(info->type & SERVER_TYPE) ) { HPM->unload(plugin); return NULL; } - + if( !HPM->iscompatible(info->req_version) ) { ShowWarning("HPM:plugin_load: '"CL_WHITE"%s"CL_RESET"' incompatible version '%s' -> '%s', skipping...\n", filename, info->req_version, HPM_VERSION); HPM->unload(plugin); return NULL; } - + plugin->info = info; plugin->filename = aStrdup(filename); - + if( !( import_symbol_ref = plugin_import(plugin->dll, "import_symbol",void **) ) ) { ShowWarning("HPM:plugin_load: failed to retrieve 'import_symbol' for '"CL_WHITE"%s"CL_RESET"', skipping...\n", filename); HPM->unload(plugin); return NULL; } - + *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 NULL; } - + *sql_handle = HPM->import_symbol("sql_handle",plugin->idx); if( !( HPMi = plugin_import(plugin->dll, "HPMi",struct HPMi_interface **) ) ) { @@ -188,44 +188,44 @@ struct hplugin *hplugin_load(const char* filename) { HPM->unload(plugin); return NULL; } - + if( !( *HPMi = plugin_import(plugin->dll, "HPMi_s",struct HPMi_interface *) ) ) { ShowWarning("HPM:plugin_load: failed to retrieve 'HPMi_s' for '"CL_WHITE"%s"CL_RESET"', skipping...\n", filename); HPM->unload(plugin); return NULL; } plugin->hpi = *HPMi; - + if( ( plugin->hpi->event[HPET_INIT] = plugin_import(plugin->dll, "plugin_init",void (*)(void)) ) ) anyEvent = true; - + if( ( plugin->hpi->event[HPET_FINAL] = plugin_import(plugin->dll, "plugin_final",void (*)(void)) ) ) anyEvent = true; - + if( ( plugin->hpi->event[HPET_READY] = plugin_import(plugin->dll, "server_online",void (*)(void)) ) ) anyEvent = true; - + if( ( plugin->hpi->event[HPET_POST_FINAL] = plugin_import(plugin->dll, "server_post_final",void (*)(void)) ) ) anyEvent = true; - + if( ( plugin->hpi->event[HPET_PRE_INIT] = plugin_import(plugin->dll, "server_preinit",void (*)(void)) ) ) anyEvent = true; - + if( !anyEvent ) { ShowWarning("HPM:plugin_load: no events found for '"CL_WHITE"%s"CL_RESET"', skipping...\n", filename); HPM->unload(plugin); return NULL; } - + if( !HPM->populate(plugin,filename) ) return NULL; - + if( !( HPMDataCheckLen = plugin_import(plugin->dll, "HPMDataCheckLen", unsigned int *) ) ) { ShowWarning("HPM:plugin_load: failed to retrieve 'HPMDataCheckLen' for '"CL_WHITE"%s"CL_RESET"', most likely not including HPMDataCheck.h, skipping...\n", filename); HPM->unload(plugin); return NULL; } - + if( !( HPMDataCheckVer = plugin_import(plugin->dll, "HPMDataCheckVer", int *) ) ) { ShowWarning("HPM:plugin_load: failed to retrieve 'HPMDataCheckVer' for '"CL_WHITE"%s"CL_RESET"', most likely an outdated plugin, skipping...\n", filename); HPM->unload(plugin); @@ -237,14 +237,14 @@ struct hplugin *hplugin_load(const char* filename) { HPM->unload(plugin); return NULL; } - + // TODO: Remove the HPM->DataCheck != NULL check once login and char support is complete if (HPM->DataCheck != NULL && !HPM->DataCheck(HPMDataCheck,*HPMDataCheckLen,*HPMDataCheckVer,plugin->info->name)) { ShowWarning("HPM:plugin_load: '"CL_WHITE"%s"CL_RESET"' failed DataCheck, out of sync from the core (recompile plugin), skipping...\n", filename); HPM->unload(plugin); return NULL; } - + /* id */ plugin->hpi->pid = plugin->idx; /* core */ @@ -261,13 +261,13 @@ struct hplugin *hplugin_load(const char* filename) { /* server specific */ if( HPM->load_sub ) HPM->load_sub(plugin); - + return plugin; } void hplugin_unload(struct hplugin* plugin) { unsigned int i = plugin->idx, cursor = 0; - + if( plugin->filename ) aFree(plugin->filename); if( plugin->dll ) @@ -297,25 +297,25 @@ void hplugins_config_read(const char * const *extra_plugins, int extra_plugins_c const char *config_filename = "conf/plugins.conf"; // FIXME hardcoded name FILE *fp; int i; - + /* yes its ugly, its temporary and will be gone as soon as the new inter-server.conf is set */ if( (fp = fopen("conf/import/plugins.conf","r")) ) { config_filename = "conf/import/plugins.conf"; fclose(fp); } - + if (libconfig->read_file(&plugins_conf, config_filename)) return; if( HPM->symbol_defaults_sub ) HPM->symbol_defaults_sub(); - + plist = libconfig->lookup(&plugins_conf, "plugins_list"); for (i = 0; i < extra_plugins_count; i++) { config_setting_t *entry = libconfig->setting_add(plist, NULL, CONFIG_TYPE_STRING); config_setting_set_string(entry, extra_plugins[i]); } - + if (plist != NULL) { int length = libconfig->setting_length(plist); char filename[60]; @@ -356,7 +356,7 @@ void hplugins_config_read(const char * const *extra_plugins, int extra_plugins_c } libconfig->destroy(&plugins_conf); } - + if( HPM->plugin_count ) ShowStatus("HPM: There are '"CL_WHITE"%d"CL_RESET"' plugins loaded, type '"CL_WHITE"plugins"CL_RESET"' to list them\n", HPM->plugin_count); } @@ -365,9 +365,9 @@ CPCMD(plugins) { ShowInfo("HPC: there are no plugins loaded\n"); } else { unsigned int i; - + ShowInfo("HPC: There are '"CL_WHITE"%d"CL_RESET"' plugins loaded\n",HPM->plugin_count); - + for(i = 0; i < HPM->plugin_count; i++) { ShowInfo("HPC: - '"CL_WHITE"%s"CL_RESET"' (%s)\n",HPM->plugins[i]->info->name,HPM->plugins[i]->filename); } @@ -400,18 +400,18 @@ void hplugins_addToHPData(enum HPluginDataTypes type, unsigned int pluginID, voi struct HPluginData *HPData, **HPDataSRC; struct HPDataOperationStorage action; unsigned int i, max; - + HPM->grabHPData(&action,type,ptr); if( action.hdatac == NULL ) { /* woo it failed! */ ShowError("HPM:addToHPData:%s: failed, type %d (%u|%u)\n",HPM->pid2name(pluginID),type,pluginID,index); return; } - + /* flag */ HPDataSRC = *(action.HPDataSRCPtr); max = *(action.hdatac); - + /* duplicate check */ for(i = 0; i < max; i++) { if( HPDataSRC[i]->pluginID == pluginID && HPDataSRC[i]->type == index ) { @@ -419,20 +419,20 @@ void hplugins_addToHPData(enum HPluginDataTypes type, unsigned int pluginID, voi return; } } - + /* HPluginData is always same size, probably better to use the ERS (with reasonable chunk size e.g. 10/25/50) */ CREATE(HPData, struct HPluginData, 1); - + /* input */ HPData->pluginID = pluginID; HPData->type = index; HPData->flag.free = autofree ? 1 : 0; HPData->data = data; - + /* resize */ *(action.hdatac) += 1; RECREATE(*(action.HPDataSRCPtr),struct HPluginData *,*(action.hdatac)); - + /* RECREATE modified the address */ HPDataSRC = *(action.HPDataSRCPtr); HPDataSRC[*(action.hdatac) - 1] = HPData; @@ -442,23 +442,23 @@ void *hplugins_getFromHPData(enum HPluginDataTypes type, unsigned int pluginID, struct HPDataOperationStorage action; struct HPluginData **HPDataSRC; unsigned int i, max; - + HPM->grabHPData(&action,type,ptr); - + if( action.hdatac == NULL ) { /* woo it failed! */ ShowError("HPM:getFromHPData:%s: failed, type %d (%u|%u)\n",HPM->pid2name(pluginID),type,pluginID,index); return NULL; } - + /* flag */ HPDataSRC = *(action.HPDataSRCPtr); max = *(action.hdatac); - + for(i = 0; i < max; i++) { if( HPDataSRC[i]->pluginID == pluginID && HPDataSRC[i]->type == index ) return HPDataSRC[i]->data; } - + return NULL; } @@ -466,30 +466,30 @@ void hplugins_removeFromHPData(enum HPluginDataTypes type, unsigned int pluginID struct HPDataOperationStorage action; struct HPluginData **HPDataSRC; unsigned int i, max; - + HPM->grabHPData(&action,type,ptr); - + if( action.hdatac == NULL ) { /* woo it failed! */ ShowError("HPM:removeFromHPData:%s: failed, type %d (%u|%u)\n",HPM->pid2name(pluginID),type,pluginID,index); return; } - + /* flag */ HPDataSRC = *(action.HPDataSRCPtr); max = *(action.hdatac); - + for(i = 0; i < max; i++) { if( HPDataSRC[i]->pluginID == pluginID && HPDataSRC[i]->type == index ) break; } - + if( i != max ) { unsigned int cursor; - + aFree(HPDataSRC[i]->data);/* when its removed we delete it regardless of autofree */ aFree(HPDataSRC[i]); HPDataSRC[i] = NULL; - + for(i = 0, cursor = 0; i < max; i++) { if( HPDataSRC[i] == NULL ) continue; @@ -499,13 +499,12 @@ void hplugins_removeFromHPData(enum HPluginDataTypes type, unsigned int pluginID } *(action.hdatac) = cursor; } - } bool hplugins_addpacket(unsigned short cmd, short length,void (*receive) (int fd),unsigned int point,unsigned int pluginID) { struct HPluginPacket *packet; unsigned int i; - + if( point >= hpPHP_MAX ) { ShowError("HPM->addPacket:%s: unknown point '%u' specified for packet 0x%04x (len %d)\n",HPM->pid2name(pluginID),point,cmd,length); return false; @@ -517,15 +516,15 @@ bool hplugins_addpacket(unsigned short cmd, short length,void (*receive) (int fd return false; } } - + RECREATE(HPM->packets[point], struct HPluginPacket, ++HPM->packetsc[point]); packet = &HPM->packets[point][HPM->packetsc[point] - 1]; - + packet->pluginID = pluginID; packet->cmd = cmd; packet->len = length; packet->receive = receive; - + return true; } /* @@ -535,52 +534,52 @@ bool hplugins_addpacket(unsigned short cmd, short length,void (*receive) (int fd */ unsigned char hplugins_parse_packets(int fd, enum HPluginPacketHookingPoints point) { unsigned int i; - + for(i = 0; i < HPM->packetsc[point]; i++) { if( HPM->packets[point][i].cmd == RFIFOW(fd,0) ) break; } - + if( i != HPM->packetsc[point] ) { struct HPluginPacket *packet = &HPM->packets[point][i]; short length; - + if( (length = packet->len) == -1 ) { if( (length = RFIFOW(fd, 2)) > (int)RFIFOREST(fd) ) - return 2; + return 2; } - + packet->receive(fd); RFIFOSKIP(fd, length); return 1; } - + return 0; } char *hplugins_id2name (unsigned int pid) { unsigned int i; - + for( i = 0; i < HPM->plugin_count; i++ ) { if( HPM->plugins[i]->idx == pid ) return HPM->plugins[i]->info->name; } - + return "UnknownPlugin"; } char* HPM_file2ptr(const char *file) { unsigned int i; - + for(i = 0; i < HPM->fnamec; i++) { if( HPM->fnames[i].addr == file ) return HPM->fnames[i].name; } - + i = HPM->fnamec; - + /* we handle this memory outside of the server's memory manager because we need it to exist after the memory manager goes down */ HPM->fnames = realloc(HPM->fnames,(++HPM->fnamec)*sizeof(struct HPMFileNameCache)); - + HPM->fnames[i].addr = file; HPM->fnames[i].name = strdup(file); @@ -611,9 +610,9 @@ bool HPM_AddHook(enum HPluginHookType type, const char *target, void *hook, unsi /* if not check if a sub-hooking list is available (from the server) and run it by */ if( HPM->addhook_sub && HPM->addhook_sub(type,target,hook,pID) ) return true; - + ShowError("HPM:AddHook: unknown Hooking Point '%s'!\n",target); - + return false; } void HPM_HookStop (const char *func, unsigned int pID) { @@ -632,82 +631,82 @@ bool hpm_parse_arg(const char *arg, int *index, char *argv[], bool param) { if( data->has_param && param ) *index += 1; return true; } - + return false; } void hpm_arg_help(void) { DBIterator *iter = db_iterator(HPM->arg_db); struct HPMArgData *data = NULL; - + for( data = dbi_first(iter); dbi_exists(iter); data = dbi_next(iter) ) { if( data->help != NULL ) data->help(); else ShowInfo(" %s (%s)\t\t\n",data->name,HPM->pid2name(data->pluginID)); } - + dbi_destroy(iter); } bool hpm_add_arg(unsigned int pluginID, char *name, bool has_param, void (*func) (char *param),void (*help) (void)) { struct HPMArgData *data = NULL; - + if( strdb_exists(HPM->arg_db, name) ) { ShowError("HPM:add_arg:%s duplicate! (from %s)\n",name,HPM->pid2name(pluginID)); return false; } - + CREATE(data, struct HPMArgData, 1); - + data->pluginID = pluginID; data->name = aStrdup(name); data->func = func; data->help = help; data->has_param = has_param; - + strdb_put(HPM->arg_db, data->name, data); - + return true; } bool hplugins_addconf(unsigned int pluginID, enum HPluginConfType type, char *name, void (*func) (const char *val)) { struct HPConfListenStorage *conf; unsigned int i; - + if( type >= HPCT_MAX ) { ShowError("HPM->addConf:%s: unknown point '%u' specified for config '%s'\n",HPM->pid2name(pluginID),type,name); return false; } - + for(i = 0; i < HPM->confsc[type]; i++) { if( !strcmpi(name,HPM->confs[type][i].key) ) { ShowError("HPM->addConf:%s: duplicate '%s', already in use by '%s'!",HPM->pid2name(pluginID),name,HPM->pid2name(HPM->confs[type][i].pluginID)); return false; } } - + RECREATE(HPM->confs[type], struct HPConfListenStorage, ++HPM->confsc[type]); conf = &HPM->confs[type][HPM->confsc[type] - 1]; - + conf->pluginID = pluginID; safestrncpy(conf->key, name, HPM_ADDCONF_LENGTH); conf->func = func; - + return true; } bool hplugins_parse_conf(const char *w1, const char *w2, enum HPluginConfType point) { unsigned int i; - + /* exists? */ for(i = 0; i < HPM->confsc[point]; i++) { if( !strcmpi(w1,HPM->confs[point][i].key) ) break; } - + /* trigger and we're set! */ if( i != HPM->confsc[point] ) { HPM->confs[point][i].func(w2); return true; } - + return false; } @@ -721,7 +720,7 @@ bool HPM_DataCheck(struct s_HPMDataCheck *src, unsigned int size, int version, c ShowError("HPMDataCheck:%s: DataCheck API version mismatch %d != %d\n", name, datacheck_version, version); return false; } - + for (i = 0; i < size; i++) { if (!(src[i].type|SERVER_TYPE)) continue; @@ -737,7 +736,7 @@ bool HPM_DataCheck(struct s_HPMDataCheck *src, unsigned int size, int version, c } } } - + return true; } @@ -746,12 +745,12 @@ void HPM_datacheck_init(const struct s_HPMDataCheck *src, unsigned int length, i datacheck_version = version; datacheck_data = src; - + /** * Populates datacheck_db for easy lookup later on **/ datacheck_db = strdb_alloc(DB_OPT_BASE,0); - + for(i = 0; i < length; i++) { strdb_uiput(datacheck_db, src[i].name, i); } @@ -805,12 +804,12 @@ void hpm_init(void) { datacheck_db = NULL; datacheck_data = NULL; datacheck_version = 0; - + HPM->symbols = NULL; HPM->plugins = NULL; HPM->plugin_count = HPM->symbol_count = 0; HPM->off = false; - + memcpy(&iMalloc_HPM, iMalloc, sizeof(struct malloc_interface)); HPMiMalloc = &iMalloc_HPM; HPMiMalloc->malloc = HPM_mmalloc; @@ -820,21 +819,21 @@ void hpm_init(void) { HPMiMalloc->astrdup = HPM_astrdup; sscanf(HPM_VERSION, "%u.%u", &HPM->version[0], &HPM->version[1]); - + if( HPM->version[0] == 0 && HPM->version[1] == 0 ) { ShowError("HPM:init:failed to retrieve HPM version!!\n"); return; } - + for(i = 0; i < hpPHP_MAX; i++) { HPM->packets[i] = NULL; HPM->packetsc[i] = 0; } - + HPM->arg_db = strdb_alloc(DB_OPT_RELEASE_DATA, 0); - + HPM->symbol_defaults(); - + #ifdef CONSOLE_INPUT console->input->addCommand("plugins",CPCMD_A(plugins)); #endif @@ -842,64 +841,63 @@ void hpm_init(void) { } void hpm_memdown(void) { unsigned int i; - + /* this memory is handled outside of the server's memory manager and thus cleared after memory manager goes down */ - + for( i = 0; i < HPM->fnamec; i++ ) { free(HPM->fnames[i].name); } - + if( HPM->fnames ) free(HPM->fnames); - } int hpm_arg_db_clear_sub(DBKey key, DBData *data, va_list args) { struct HPMArgData *a = DB->data2ptr(data); - + aFree(a->name); - + return 0; } void hpm_final(void) { unsigned int i; - + HPM->off = true; - + for( i = 0; i < HPM->plugin_count; i++ ) { HPM->unload(HPM->plugins[i]); } - + if( HPM->plugins ) aFree(HPM->plugins); - + for( i = 0; i < HPM->symbol_count; i++ ) { aFree(HPM->symbols[i]); } - + if( HPM->symbols ) aFree(HPM->symbols); - + for( i = 0; i < hpPHP_MAX; i++ ) { if( HPM->packets[i] ) aFree(HPM->packets[i]); } - + for( i = 0; i < HPCT_MAX; i++ ) { if( HPM->confsc[i] ) aFree(HPM->confs[i]); } - + HPM->arg_db->destroy(HPM->arg_db,HPM->arg_db_clear_sub); - + /* HPM->fnames is cleared after the memory manager goes down */ iMalloc->post_shutdown = hpm_memdown; - + return; } void hpm_defaults(void) { unsigned int i; HPM = &HPM_s; - + HPM->fnames = NULL; HPM->fnamec = 0; HPM->force_return = false; @@ -919,7 +917,7 @@ void hpm_defaults(void) { /* */ HPM->init = hpm_init; HPM->final = hpm_final; - + HPM->create = hplugin_create; HPM->load = hplugin_load; HPM->unload = hplugin_unload; diff --git a/src/common/atomic.h b/src/common/atomic.h index e73b1c464..a42dfad1c 100644 --- a/src/common/atomic.h +++ b/src/common/atomic.h @@ -8,9 +8,9 @@ // (Interlocked CompareExchange, Add .. and so on ..) // // Implementation varies / depends on: -// - Architecture -// - Compiler -// - Operating System +// - Architecture +// - Compiler +// - Operating System // // our Abstraction is fully API-Compatible to Microsoft's implementation @ NT5.0+ // @@ -29,13 +29,13 @@ forceinline int64 InterlockedCompareExchange64(volatile int64 *dest, int64 exch, _asm{ lea esi,_cmp; lea edi,exch; - + mov eax,[esi]; mov edx,4[esi]; mov ebx,[edi]; mov ecx,4[edi]; mov esi,dest; - + lock CMPXCHG8B [esi]; } } @@ -109,7 +109,7 @@ static forceinline int64 InterlockedIncrement64(volatile int64 *addend){ static forceinline int32 InterlockedIncrement(volatile int32 *addend){ - return __sync_add_and_fetch(addend, 1); + return __sync_add_and_fetch(addend, 1); }//end: InterlockedIncrement() @@ -139,7 +139,7 @@ static forceinline int64 InterlockedExchange64(volatile int64 *target, int64 val static forceinline int32 InterlockedExchange(volatile int32 *target, int32 val){ - return __sync_lock_test_and_set(target, val); + return __sync_lock_test_and_set(target, val); }//end: InterlockedExchange() diff --git a/src/common/cbasetypes.h b/src/common/cbasetypes.h index 18bc0b8cb..df1d364d4 100644 --- a/src/common/cbasetypes.h +++ b/src/common/cbasetypes.h @@ -117,56 +117,56 @@ // Integers with guaranteed _exact_ size. ////////////////////////////////////////////////////////////////////////// -typedef int8_t int8; -typedef int16_t int16; -typedef int32_t int32; -typedef int64_t int64; +typedef int8_t int8; +typedef int16_t int16; +typedef int32_t int32; +typedef int64_t int64; -typedef int8_t sint8; -typedef int16_t sint16; -typedef int32_t sint32; -typedef int64_t sint64; +typedef int8_t sint8; +typedef int16_t sint16; +typedef int32_t sint32; +typedef int64_t sint64; -typedef uint8_t uint8; -typedef uint16_t uint16; -typedef uint32_t uint32; -typedef uint64_t uint64; +typedef uint8_t uint8; +typedef uint16_t uint16; +typedef uint32_t uint32; +typedef uint64_t uint64; #undef UINT8_MIN #undef UINT16_MIN #undef UINT32_MIN #undef UINT64_MIN -#define UINT8_MIN ((uint8) UINT8_C(0x00)) -#define UINT16_MIN ((uint16)UINT16_C(0x0000)) -#define UINT32_MIN ((uint32)UINT32_C(0x00000000)) -#define UINT64_MIN ((uint64)UINT64_C(0x0000000000000000)) +#define UINT8_MIN ((uint8) UINT8_C(0x00)) +#define UINT16_MIN ((uint16)UINT16_C(0x0000)) +#define UINT32_MIN ((uint32)UINT32_C(0x00000000)) +#define UINT64_MIN ((uint64)UINT64_C(0x0000000000000000)) #undef UINT8_MAX #undef UINT16_MAX #undef UINT32_MAX #undef UINT64_MAX -#define UINT8_MAX ((uint8) UINT8_C(0xFF)) -#define UINT16_MAX ((uint16)UINT16_C(0xFFFF)) -#define UINT32_MAX ((uint32)UINT32_C(0xFFFFFFFF)) -#define UINT64_MAX ((uint64)UINT64_C(0xFFFFFFFFFFFFFFFF)) +#define UINT8_MAX ((uint8) UINT8_C(0xFF)) +#define UINT16_MAX ((uint16)UINT16_C(0xFFFF)) +#define UINT32_MAX ((uint32)UINT32_C(0xFFFFFFFF)) +#define UINT64_MAX ((uint64)UINT64_C(0xFFFFFFFFFFFFFFFF)) #undef SINT8_MIN #undef SINT16_MIN #undef SINT32_MIN #undef SINT64_MIN -#define SINT8_MIN ((sint8) INT8_C(0x80)) -#define SINT16_MIN ((sint16)INT16_C(0x8000)) -#define SINT32_MIN ((sint32)INT32_C(0x80000000)) -#define SINT64_MIN ((sint32)INT64_C(0x8000000000000000)) +#define SINT8_MIN ((sint8) INT8_C(0x80)) +#define SINT16_MIN ((sint16)INT16_C(0x8000)) +#define SINT32_MIN ((sint32)INT32_C(0x80000000)) +#define SINT64_MIN ((sint32)INT64_C(0x8000000000000000)) #undef SINT8_MAX #undef SINT16_MAX #undef SINT32_MAX #undef SINT64_MAX -#define SINT8_MAX ((sint8) INT8_C(0x7F)) -#define SINT16_MAX ((sint16)INT16_C(0x7FFF)) -#define SINT32_MAX ((sint32)INT32_C(0x7FFFFFFF)) -#define SINT64_MAX ((sint64)INT64_C(0x7FFFFFFFFFFFFFFF)) +#define SINT8_MAX ((sint8) INT8_C(0x7F)) +#define SINT16_MAX ((sint16)INT16_C(0x7FFF)) +#define SINT32_MAX ((sint32)INT32_C(0x7FFFFFFF)) +#define SINT64_MAX ((sint64)INT64_C(0x7FFFFFFFFFFFFFFF)) ////////////////////////////////////////////////////////////////////////// // Integers with guaranteed _minimum_ size. @@ -191,10 +191,10 @@ typedef unsigned long int ppuint32; #if defined(WIN32) && !defined(MINGW) // does not have a signed size_t ////////////////////////////// -#if defined(_WIN64) // native 64bit windows platform -typedef __int64 ssize_t; +#if defined(_WIN64) // native 64bit windows platform +typedef __int64 ssize_t; #else -typedef int ssize_t; +typedef int ssize_t; #endif ////////////////////////////// #endif @@ -236,22 +236,22 @@ typedef uintptr_t uintptr; // some redefine of function redefines for some Compilers ////////////////////////////////////////////////////////////////////////// #if defined(_MSC_VER) || defined(__BORLANDC__) -#define strcasecmp stricmp -#define strncasecmp strnicmp -#define strncmpi strnicmp -#define snprintf _snprintf +#define strcasecmp stricmp +#define strncasecmp strnicmp +#define strncmpi strnicmp +#define snprintf _snprintf #if defined(_MSC_VER) && _MSC_VER < 1400 -#define vsnprintf _vsnprintf +#define vsnprintf _vsnprintf #endif #else -#define strcmpi strcasecmp -#define stricmp strcasecmp -#define strncmpi strncasecmp -#define strnicmp strncasecmp +#define strcmpi strcasecmp +#define stricmp strcasecmp +#define strncmpi strncasecmp +#define strnicmp strncasecmp #endif #if defined(_MSC_VER) && _MSC_VER > 1200 -#define strtoull _strtoui64 -#define strtoll _strtoi64 +#define strtoull _strtoui64 +#define strtoll _strtoi64 #endif // keyword replacement @@ -286,8 +286,8 @@ typedef uintptr_t uintptr; #ifndef __bool_true_false_are_defined // If stdbool.h is not available or does not define this typedef char bool; -#define false (1==0) -#define true (1==1) +#define false (1==0) +#define true (1==1) #define __bool_true_false_are_defined #endif // __bool_true_false_are_defined @@ -308,18 +308,17 @@ typedef char bool; #if 0 //to be activated soon, more tests needed on how VS works with the macro above #ifdef WIN32 #undef swap -#define swap(a,b)__asm \ -{ \ - __asm mov eax, dword ptr [a] \ - __asm cmp eax, dword ptr [b] \ - __asm je _ret \ - __asm xor eax, dword ptr [b] \ - __asm mov dword ptr [a], eax \ - __asm xor eax, dword ptr [b] \ - __asm mov dword ptr [b], eax \ - __asm xor eax, dword ptr [a] \ - __asm mov dword ptr [a], eax \ - __asm _ret: \ +#define swap(a,b)__asm { \ + __asm mov eax, dword ptr [a] \ + __asm cmp eax, dword ptr [b] \ + __asm je _ret \ + __asm xor eax, dword ptr [b] \ + __asm mov dword ptr [a], eax \ + __asm xor eax, dword ptr [b] \ + __asm mov dword ptr [b], eax \ + __asm xor eax, dword ptr [a] \ + __asm mov dword ptr [a], eax \ + __asm _ret: \ } #endif #endif @@ -343,7 +342,7 @@ typedef char bool; ////////////////////////////////////////////////////////////////////////// // number of bits in a byte #ifndef NBBY -#define NBBY 8 +#define NBBY 8 #endif ////////////////////////////////////////////////////////////////////////// diff --git a/src/common/conf.c b/src/common/conf.c index 34d1cacbf..c974decf9 100644 --- a/src/common/conf.c +++ b/src/common/conf.c @@ -34,10 +34,10 @@ void config_setting_copy_simple(config_setting_t *parent, const config_setting_t } else { config_setting_t *set; - + if( libconfig->setting_get_member(parent, config_setting_name(src)) != NULL ) return; - + if ((set = libconfig->setting_add(parent, config_setting_name(src), config_setting_type(src))) == NULL) return; @@ -83,14 +83,14 @@ void config_setting_copy_aggregate(config_setting_t *parent, const config_settin if( libconfig->setting_get_member(parent, config_setting_name(src)) != NULL ) return; - + newAgg = libconfig->setting_add(parent, config_setting_name(src), config_setting_type(src)); if (newAgg == NULL) return; n = config_setting_length(src); - + for (i = 0; i < n; i++) { if (config_setting_is_group(src)) { libconfig->setting_copy_simple(newAgg, libconfig->setting_get_elem(src, i)); @@ -101,7 +101,6 @@ void config_setting_copy_aggregate(config_setting_t *parent, const config_settin } int config_setting_copy(config_setting_t *parent, const config_setting_t *src) { - if (!config_setting_is_group(parent) && !config_setting_is_list(parent)) return CONFIG_FALSE; @@ -115,7 +114,7 @@ int config_setting_copy(config_setting_t *parent, const config_setting_t *src) { void libconfig_defaults(void) { libconfig = &libconfig_s; - + libconfig->read = config_read; libconfig->write = config_write; /* */ diff --git a/src/common/conf.h b/src/common/conf.h index c232a035c..9ea5f5b72 100644 --- a/src/common/conf.h +++ b/src/common/conf.h @@ -22,21 +22,21 @@ struct libconfig_interface { int (*read_string) (config_t *config, const char *str); int (*read_file_src) (config_t *config, const char *filename); int (*write_file) (config_t *config, const char *filename); - + void (*set_destructor) (config_t *config, void (*destructor)(void *)); void (*set_include_dir) (config_t *config, const char *include_dir); - + void (*init) (config_t *config); void (*destroy) (config_t *config); - + int (*setting_get_int) (const config_setting_t *setting); long long (*setting_get_int64) (const config_setting_t *setting); double (*setting_get_float) (const config_setting_t *setting); - + int (*setting_get_bool) (const config_setting_t *setting); - + const char * (*setting_get_string) (const config_setting_t *setting); - + int (*setting_lookup_int) (const config_setting_t *setting, const char *name, int *value); int (*setting_lookup_int64) (const config_setting_t *setting, const char *name, long long *value); int (*setting_lookup_float) (const config_setting_t *setting, const char *name, double *value); @@ -47,10 +47,10 @@ struct libconfig_interface { int (*setting_set_float) (config_setting_t *setting, double value); int (*setting_set_bool) (config_setting_t *setting, int value); int (*setting_set_string) (config_setting_t *setting, const char *value); - + int (*setting_set_format) (config_setting_t *setting, short format); short (*setting_get_format) (const config_setting_t *setting); - + int (*setting_get_int_elem) (const config_setting_t *setting, int idx); long long (*setting_get_int64_elem) (const config_setting_t *setting, int idx); double (*setting_get_float_elem) (const config_setting_t *setting, int idx); @@ -61,19 +61,19 @@ struct libconfig_interface { config_setting_t * (*setting_set_float_elem) (config_setting_t *setting, int idx, double value); config_setting_t * (*setting_set_bool_elem) (config_setting_t *setting, int idx, int value); config_setting_t * (*setting_set_string_elem) (config_setting_t *setting, int idx, const char *value); - + int (*setting_index) (const config_setting_t *setting); int (*setting_length) (const config_setting_t *setting); - + config_setting_t * (*setting_get_elem) (const config_setting_t *setting, unsigned int idx); config_setting_t * (*setting_get_member) (const config_setting_t *setting, const char *name); - + config_setting_t * (*setting_add) (config_setting_t *parent, const char *name, int type); int (*setting_remove) (config_setting_t *parent, const char *name); - + int (*setting_remove_elem) (config_setting_t *parent, unsigned int idx); void (*setting_set_hook) (config_setting_t *setting, void *hook); - + config_setting_t * (*lookup) (const config_t *config, const char *path); config_setting_t * (*lookup_from) (config_setting_t *setting, const char *path); int (*lookup_int) (const config_t *config, const char *path, int *value); @@ -81,7 +81,7 @@ struct libconfig_interface { int (*lookup_float) (const config_t *config, const char *path, double *value); int (*lookup_bool) (const config_t *config, const char *path, int *value); int (*lookup_string) (const config_t *config, const char *path, const char **value); - + /* those are custom and are from src/common/conf.c */ /* Functions to copy settings from libconfig/contrib */ int (*read_file) (config_t *config, const char *config_filename); diff --git a/src/common/console.c b/src/common/console.c index 6a82db555..577d1a3f0 100644 --- a/src/common/console.c +++ b/src/common/console.c @@ -43,7 +43,7 @@ struct console_input_interface console_input_s; #endif /*====================================== - * CORE : Display title + * CORE : Display title *--------------------------------------*/ void display_title(void) { const char *vcstype = sysinfo->vcstype(); @@ -80,18 +80,18 @@ int console_parse_key_pressed(void) { fd_set fds; tv.tv_sec = 0; tv.tv_usec = 0; - + FD_ZERO(&fds); FD_SET(STDIN_FILENO, &fds); - + select(STDIN_FILENO+1, &fds, NULL, NULL, &tv); - + return FD_ISSET(STDIN_FILENO, &fds); } #endif /* _WIN32 */ /*====================================== - * CORE: Console commands + * CORE: Console commands *--------------------------------------*/ /** @@ -152,20 +152,22 @@ CPCMD_C(skip,update) { } /** - * Defines a main category - * Categories can't be used as commands! + * Defines a main category. + * + * Categories can't be used as commands! * E.G. - * sql update skip - * 'sql' is the main category + * - sql update skip + * 'sql' is the main category * CP_DEF_C(category) **/ #define CP_DEF_C(x) { #x , NULL , NULL, NULL } /** - * Defines a sub-category - * Sub-categories can't be used as commands! + * Defines a sub-category. + * + * Sub-categories can't be used as commands! * E.G. - * sql update skip - * 'update' is a sub-category + * - sql update skip + * 'update' is a sub-category * CP_DEF_C2(command, category) **/ #define CP_DEF_C2(x,y) { #x , NULL , #y, NULL } @@ -209,21 +211,21 @@ void console_load_defaults(void) { }; unsigned int i, len = ARRAYLENGTH(default_list); struct CParseEntry *cmd; - + RECREATE(console->input->cmds,struct CParseEntry *, len); - + for(i = 0; i < len; i++) { CREATE(cmd, struct CParseEntry, 1); - + safestrncpy(cmd->cmd, default_list[i].name, CP_CMD_LENGTH); - + if( default_list[i].func ) cmd->u.func = default_list[i].func; else cmd->u.next = NULL; - + cmd->next_count = 0; - + console->input->cmd_count++; console->input->cmds[i] = cmd; default_list[i].self = cmd; @@ -232,7 +234,7 @@ void console_load_defaults(void) { console->input->cmd_list[console->input->cmd_list_count - 1] = cmd; } } - + for(i = 0; i < len; i++) { unsigned int k; if( !default_list[i].connect ) @@ -256,10 +258,10 @@ void console_parse_create(char *name, CParseFunc func) { char *tok; char sublist[CP_CMD_LENGTH * 5]; struct CParseEntry *cmd; - + safestrncpy(sublist, name, CP_CMD_LENGTH * 5); tok = strtok(sublist,":"); - + for ( i = 0; i < console->input->cmd_list_count; i++ ) { if( strcmpi(tok,console->input->cmd_list[i]->cmd) == 0 ) break; @@ -278,12 +280,11 @@ void console_parse_create(char *name, CParseFunc func) { cmd = console->input->cmd_list[i]; while( ( tok = strtok(NULL, ":") ) != NULL ) { - for(i = 0; i < cmd->next_count; i++) { if( strcmpi(cmd->u.next[i]->cmd,tok) == 0 ) break; } - + if ( i == cmd->next_count ) { RECREATE(console->input->cmds,struct CParseEntry *, ++console->input->cmd_count); CREATE(console->input->cmds[console->input->cmd_count-1], struct CParseEntry, 1); @@ -294,7 +295,6 @@ void console_parse_create(char *name, CParseFunc func) { cmd = console->input->cmds[console->input->cmd_count-1]; continue; } - } cmd->u.func = func; } @@ -320,24 +320,24 @@ void console_parse_sub(char *line) { char *tok; char sublist[CP_CMD_LENGTH * 5]; unsigned int i, len = 0; - + memcpy(bline, line, 200); tok = strtok(line, " "); - + for ( i = 0; i < console->input->cmd_list_count; i++ ) { if( strcmpi(tok,console->input->cmd_list[i]->cmd) == 0 ) break; } - + if( i == console->input->cmd_list_count ) { ShowError("'"CL_WHITE"%s"CL_RESET"' is not a known command, type '"CL_WHITE"help"CL_RESET"' to list all commands\n",line); return; } - + cmd = console->input->cmd_list[i]; - + len += snprintf(sublist,CP_CMD_LENGTH * 5,"%s", cmd->cmd) + 1; - + if( cmd->next_count == 0 && console->input->cmd_list[i]->u.func ) { char *r = NULL; if( (tok = strtok(NULL, " ")) ) { @@ -381,8 +381,8 @@ void console_parse_sub(char *line) { } } void console_parse(char* line) { - int c, i = 0, len = MAX_CONSOLE_INPUT - 1;/* we leave room for the \0 :P */ - + int c, i = 0, len = MAX_CONSOLE_INPUT - 1;/* we leave room for the \0 :P */ + while( (c = fgetc(stdin)) != EOF ) { if( --len == 0 ) break; @@ -391,33 +391,32 @@ void console_parse(char* line) { break;/* new line~! we leave it for the next cycle */ } } - + line[i++] = '\0'; } void *cThread_main(void *x) { - while( console->input->ptstate ) {/* loopx */ if( console->input->key_pressed() ) { char input[MAX_CONSOLE_INPUT]; - + console->input->parse(input); if( input[0] != '\0' ) {/* did we get something? */ EnterSpinLock(&console->input->ptlock); - + if( cinput.count == CONSOLE_PARSE_SIZE ) { LeaveSpinLock(&console->input->ptlock); continue;/* drop */ } - + safestrncpy(cinput.queue[cinput.count++],input,MAX_CONSOLE_INPUT); LeaveSpinLock(&console->input->ptlock); } } ramutex_lock( console->input->ptmutex ); - racond_wait( console->input->ptcond, console->input->ptmutex, -1 ); + racond_wait( console->input->ptcond, console->input->ptmutex, -1 ); ramutex_unlock( console->input->ptmutex ); } - + return NULL; } int console_parse_timer(int tid, int64 tick, int id, intptr_t data) { @@ -435,7 +434,7 @@ void console_parse_final(void) { if( console->input->ptstate ) { InterlockedDecrement(&console->input->ptstate); racond_signal(console->input->ptcond); - + /* wait for thread to close */ rathread_wait(console->input->pthread, NULL); @@ -445,22 +444,21 @@ void console_parse_final(void) { } void console_parse_init(void) { cinput.count = 0; - + console->input->ptstate = 1; InitializeSpinLock(&console->input->ptlock); - + console->input->ptmutex = ramutex_create(); console->input->ptcond = racond_create(); - + if( (console->input->pthread = rathread_create(console->input->pthread_main, NULL)) == NULL ){ ShowFatalError("console_parse_init: failed to spawn console_parse thread.\n"); exit(EXIT_FAILURE); } - + timer->add_func_list(console->input->parse_timer, "console_parse_timer"); timer->add_interval(timer->gettick() + 1000, console->input->parse_timer, 0, 0, 500);/* start listening in 1s; re-try every 0.5s */ - } void console_setSQL(Sql *SQL_handle) { console->input->SQL = SQL_handle; diff --git a/src/common/core.c b/src/common/core.c index 99dbc36ec..04434a5dd 100644 --- a/src/common/core.c +++ b/src/common/core.c @@ -48,14 +48,14 @@ char **arg_v = NULL; char *SERVER_NAME = NULL; -#ifndef MINICORE // minimalist Core +#ifndef MINICORE // minimalist Core // Added by Gabuzomeu // // This is an implementation of signal() using sigaction() for portability. // (sigaction() is POSIX; signal() is not.) Taken from Stevens' _Advanced // Programming in the UNIX Environment_. // -#ifdef WIN32 // windows don't have SIGPIPE +#ifdef WIN32 // windows don't have SIGPIPE #define SIGPIPE SIGINT #endif @@ -69,7 +69,7 @@ sigfunc *compat_signal(int signo, sigfunc *func) { sigemptyset(&sact.sa_mask); sact.sa_flags = 0; #ifdef SA_INTERRUPT - sact.sa_flags |= SA_INTERRUPT; /* SunOS */ + sact.sa_flags |= SA_INTERRUPT; /* SunOS */ #endif if (sigaction(signo, &sact, &oact) < 0) @@ -80,7 +80,7 @@ sigfunc *compat_signal(int signo, sigfunc *func) { #endif /*====================================== - * CORE : Console events for Windows + * CORE : Console events for Windows *--------------------------------------*/ #ifdef _WIN32 static BOOL WINAPI console_handler(DWORD c_event) { @@ -106,7 +106,7 @@ static void cevents_init(void) { #endif /*====================================== - * CORE : Signal Sub Function + * CORE : Signal Sub Function *--------------------------------------*/ static void sig_proc(int sn) { static int is_called = 0; @@ -132,11 +132,11 @@ static void sig_proc(int sn) { case SIGXFSZ: // ignore and allow it to set errno to EFBIG ShowWarning ("Max file size reached!\n"); - //run_flag = 0; // should we quit? + //run_flag = 0; // should we quit? break; case SIGPIPE: - //ShowInfo ("Broken pipe found... closing socket\n"); // set to eof in socket.c - break; // does nothing here + //ShowInfo ("Broken pipe found... closing socket\n"); // set to eof in socket.c + break; // does nothing here #endif } } @@ -185,7 +185,7 @@ void core_defaults(void) { #endif } /*====================================== - * CORE : MAINROUTINE + * CORE : MAINROUTINE *--------------------------------------*/ int main (int argc, char **argv) { int retval = EXIT_SUCCESS; @@ -209,7 +209,7 @@ int main (int argc, char **argv) { } } } - + iMalloc->init();// needed for Show* in display_title() [FlavioJS] sysinfo->init(); @@ -229,7 +229,7 @@ int main (int argc, char **argv) { rathread_init(); DB->init(); signals_init(); - + #ifdef _WIN32 cevents_init(); #endif @@ -239,11 +239,11 @@ int main (int argc, char **argv) { /* timer first */ rnd_init(); srand((unsigned int)timer->gettick()); - + console->init(); - + HCache->init(); - + HPM->init(); sockt->init(); @@ -258,7 +258,7 @@ int main (int argc, char **argv) { } console->final(); - + retval = do_final(); HPM->final(); timer->final(); diff --git a/src/common/db.c b/src/common/db.c index b227d66bc..044df19aa 100644 --- a/src/common/db.c +++ b/src/common/db.c @@ -579,7 +579,7 @@ static void db_rebalance_erase(DBNode *node, DBNode **root) x = x_parent; x_parent = x_parent->parent; } else { - if (w->right == NULL || w->right->color == BLACK) { + if (w->right == NULL || w->right->color == BLACK) { if (w->left) w->left->color = BLACK; w->color = RED; db_rotate_right(w, root); @@ -1231,7 +1231,7 @@ static void db_release_both(DBKey key, DBData data, DBRelease which) DBData* dbit_obj_first(DBIterator* self, DBKey* out_key) { DBIterator_impl* it = (DBIterator_impl*)self; - + DB_COUNTSTAT(dbit_first); // position before the first entry it->ht_index = -1; @@ -1253,7 +1253,7 @@ DBData* dbit_obj_first(DBIterator* self, DBKey* out_key) DBData* dbit_obj_last(DBIterator* self, DBKey* out_key) { DBIterator_impl* it = (DBIterator_impl*)self; - + DB_COUNTSTAT(dbit_last); // position after the last entry it->ht_index = HASH_SIZE; @@ -1375,7 +1375,6 @@ DBData* dbit_obj_prev(DBIterator* self, DBKey* out_key) node = &fake; } - while( node ) {// next node if( node->left ) @@ -1662,17 +1661,17 @@ static unsigned int db_obj_vgetall(DBMap* self, DBData **buf, unsigned int max, } va_end(argscopy); } - + if (node->left) { node = node->left; continue; } - + if (node->right) { node = node->right; continue; } - + while (node) { parent = node->parent; if (parent && parent->right && parent->left == node) { @@ -1859,7 +1858,7 @@ static DBData* db_obj_ensure(DBMap* self, DBKey key, DBCreateData create, ...) * @see #db_malloc_dbn(void) * @see DBMap#put * FIXME: If this method fails shouldn't it return another value? - * Other functions rely on this to know if they were able to put something [Panikon] + * Other functions rely on this to know if they were able to put something [Panikon] */ static int db_obj_put(DBMap* self, DBKey key, DBData data, DBData *out_data) { @@ -1981,7 +1980,7 @@ static int db_obj_remove(DBMap* self, DBKey key, DBData *out_data) db->alloc_file, db->alloc_line); return 0; // nullpo candidate } - if (!(db->options&DB_OPT_ALLOW_NULL_KEY) && db_is_key_null(db->type, key)) { + if (!(db->options&DB_OPT_ALLOW_NULL_KEY) && db_is_key_null(db->type, key)) { ShowError("db_remove: Attempted to use non-allowed NULL key for db allocated at %s:%d\n",db->alloc_file, db->alloc_line); return 0; // nullpo candidate } @@ -2645,7 +2644,7 @@ DBKey db_str2key(const char *key) DBKey db_i642key(int64 key) { DBKey ret; - + DB_COUNTSTAT(db_i642key); ret.i64 = key; return ret; @@ -2660,7 +2659,7 @@ DBKey db_i642key(int64 key) DBKey db_ui642key(uint64 key) { DBKey ret; - + DB_COUNTSTAT(db_ui642key); ret.ui64 = key; return ret; diff --git a/src/common/db.h b/src/common/db.h index f500520a9..88265c3e8 100644 --- a/src/common/db.h +++ b/src/common/db.h @@ -848,7 +848,7 @@ DBKey (*i642key) (int64 key); * @public */ DBKey (*ui642key) (uint64 key); - + /** * Manual cast from 'int' to the struct DBData. * @param data Data to be casted @@ -1500,7 +1500,7 @@ void linkdb_foreach (struct linkdb_node** head, LinkDBFunc func, ...); VECTOR_INDEX(__heap,0) = VECTOR_POP(__heap); /* put last at index */ \ if( !VECTOR_LENGTH(__heap) ) /* removed last, nothing to do */ \ break; \ - BHEAP_SIFTUP(__heap,0,__topcmp,__swp); \ + BHEAP_SIFTUP(__heap,0,__topcmp,__swp); \ }while(0) @@ -1562,7 +1562,7 @@ void linkdb_foreach (struct linkdb_node** head, LinkDBFunc func, ...); /// @param __idx Index of an inserted element /// @param __topcmp Comparator /// @param __swp Swapper -#define BHEAP_SIFTDOWN(__heap,__startidx,__idx,__topcmp,__swp) \ +#define BHEAP_SIFTDOWN(__heap,__startidx,__idx,__topcmp,__swp) \ do{ \ size_t _i2_ = __idx; \ while( _i2_ > __startidx ) \ diff --git a/src/common/des.c b/src/common/des.c index 7f952be76..89a920bc9 100644 --- a/src/common/des.c +++ b/src/common/des.c @@ -103,14 +103,14 @@ static void E(BIT64* src) } #endif // optimized - tmp.b[0] = ((src->b[7]<<5) | (src->b[4]>>3)) & 0x3f; // ..0 vutsr - tmp.b[1] = ((src->b[4]<<1) | (src->b[5]>>7)) & 0x3f; // ..srqpo n - tmp.b[2] = ((src->b[4]<<5) | (src->b[5]>>3)) & 0x3f; // ..o nmlkj - tmp.b[3] = ((src->b[5]<<1) | (src->b[6]>>7)) & 0x3f; // ..kjihg f - tmp.b[4] = ((src->b[5]<<5) | (src->b[6]>>3)) & 0x3f; // ..g fedcb - tmp.b[5] = ((src->b[6]<<1) | (src->b[7]>>7)) & 0x3f; // ..cba98 7 - tmp.b[6] = ((src->b[6]<<5) | (src->b[7]>>3)) & 0x3f; // ..8 76543 - tmp.b[7] = ((src->b[7]<<1) | (src->b[4]>>7)) & 0x3f; // ..43210 v + tmp.b[0] = ((src->b[7]<<5) | (src->b[4]>>3)) & 0x3f; // ..0 vutsr + tmp.b[1] = ((src->b[4]<<1) | (src->b[5]>>7)) & 0x3f; // ..srqpo n + tmp.b[2] = ((src->b[4]<<5) | (src->b[5]>>3)) & 0x3f; // ..o nmlkj + tmp.b[3] = ((src->b[5]<<1) | (src->b[6]>>7)) & 0x3f; // ..kjihg f + tmp.b[4] = ((src->b[5]<<5) | (src->b[6]>>3)) & 0x3f; // ..g fedcb + tmp.b[5] = ((src->b[6]<<1) | (src->b[7]>>7)) & 0x3f; // ..cba98 7 + tmp.b[6] = ((src->b[6]<<5) | (src->b[7]>>3)) & 0x3f; // ..8 76543 + tmp.b[7] = ((src->b[7]<<1) | (src->b[4]>>7)) & 0x3f; // ..43210 v *src = tmp; } diff --git a/src/common/ers.c b/src/common/ers.c index c8a11d2a9..489d8f7ae 100644 --- a/src/common/ers.c +++ b/src/common/ers.c @@ -83,19 +83,19 @@ typedef struct ers_cache // Free objects count unsigned int Free; - + // Used blocks count unsigned int Used; - + // Objects in-use count unsigned int UsedObjs; - + // Default = ERS_BLOCK_ENTRIES, can be adjusted for performance for individual cache sizes. unsigned int ChunkSize; - + // Misc options, some options are shared from the instance enum ERSOptions Options; - + // Linked list struct ers_cache *Next, *Prev; } ers_cache_t; @@ -103,10 +103,10 @@ typedef struct ers_cache struct ers_instance_t { // Interface to ERS struct eri VTable; - + // Name, used for debugging purposes char *Name; - + // Misc options enum ERSOptions Options; @@ -115,7 +115,7 @@ struct ers_instance_t { // Count of objects in use, used for detecting memory leaks unsigned int Count; - + #ifdef DEBUG /* for data analysis [Ind/Hercules] */ unsigned int Peak; @@ -149,7 +149,7 @@ static ers_cache_t *ers_find_cache(unsigned int size, enum ERSOptions Options) { cache->Max = 0; cache->ChunkSize = ERS_BLOCK_ENTRIES; cache->Options = (Options & ERS_CACHE_OPTIONS); - + if (CacheList == NULL) { CacheList = cache; @@ -181,7 +181,7 @@ static void ers_free_cache(ers_cache_t *cache, bool remove) CacheList = cache->Next; aFree(cache->Blocks); - + aFree(cache); } @@ -216,7 +216,7 @@ static void *ers_obj_alloc_entry(ERS *self) instance->Count++; instance->Cache->UsedObjs++; - + #ifdef DEBUG if( instance->Count > instance->Peak ) instance->Peak = instance->Count; @@ -240,7 +240,7 @@ static void ers_obj_free_entry(ERS *self, void *entry) if( instance->Cache->Options & ERS_OPT_CLEAN ) memset((unsigned char*)reuse + sizeof(struct ers_list), 0, instance->Cache->ObjectSize - sizeof(struct ers_list)); - + reuse->Next = instance->Cache->ReuseList; instance->Cache->ReuseList = reuse; instance->Count--; @@ -277,27 +277,27 @@ static void ers_obj_destroy(ERS *self) if (instance->Next) instance->Next->Prev = instance->Prev; - + if (instance->Prev) instance->Prev->Next = instance->Next; else InstanceList = instance->Next; - + if( instance->Options & ERS_OPT_FREE_NAME ) aFree(instance->Name); - + aFree(instance); } void ers_cache_size(ERS *self, unsigned int new_size) { struct ers_instance_t *instance = (struct ers_instance_t *)self; - + nullpo_retv(instance); - + if( !(instance->Cache->Options&ERS_OPT_FLEX_CHUNK) ) { ShowWarning("ers_cache_size: '%s' has adjusted its chunk size to '%d', however ERS_OPT_FLEX_CHUNK is missing!\n",instance->Name,new_size); } - + instance->Cache->ChunkSize = new_size; } @@ -321,7 +321,7 @@ ERS *ers_new(uint32 size, char *name, enum ERSOptions options) instance->Options = options; instance->Cache = ers_find_cache(size,instance->Options); - + instance->Cache->ReferenceCount++; if (InstanceList == NULL) { @@ -384,7 +384,7 @@ void ers_report(void) { **/ void ers_final(void) { struct ers_instance_t *instance = InstanceList, *next; - + while( instance ) { next = instance->Next; ers_obj_destroy((ERS*)instance); diff --git a/src/common/ers.h b/src/common/ers.h index 904f7fb81..8c56118ae 100644 --- a/src/common/ers.h +++ b/src/common/ers.h @@ -77,7 +77,7 @@ enum ERSOptions { ERS_OPT_FREE_NAME = 0x4,/* name is dynamic memory, and should be freed */ ERS_OPT_CLEAN = 0x8,/* clears used memory upon ers_free so that its all new to be reused on the next alloc */ ERS_OPT_FLEX_CHUNK = 0x10,/* signs that it should look for its own cache given it'll have a dynamic chunk size, so that it doesn't affect the other ERS it'd otherwise be sharing */ - + /* Compound, is used to determine whether it should be looking for a cache of matching options */ ERS_CACHE_OPTIONS = ERS_OPT_CLEAN|ERS_OPT_FLEX_CHUNK, }; diff --git a/src/common/grfio.c b/src/common/grfio.c index 5be0c8237..eeda7e4b5 100644 --- a/src/common/grfio.c +++ b/src/common/grfio.c @@ -21,7 +21,7 @@ #include "../common/utils.h" //---------------------------- -// file entry table struct +// file entry table struct //---------------------------- typedef struct FILELIST { int srclen; ///< compressed size @@ -50,14 +50,14 @@ typedef struct FILELIST { // stores info about every loaded file -FILELIST* filelist = NULL; -int filelist_entrys = 0; -int filelist_maxentry = 0; +FILELIST* filelist = NULL; +int filelist_entrys = 0; +int filelist_maxentry = 0; // stores grf file names -char** gentry_table = NULL; -int gentry_entrys = 0; -int gentry_maxentry = 0; +char** gentry_table = NULL; +int gentry_entrys = 0; +int gentry_maxentry = 0; // the path to the data directory char data_dir[1024] = ""; @@ -109,22 +109,23 @@ static uint8_t grf_substitution(uint8_t in) return out; } -/* this is not used anywhere, is it ok to delete? */ -//static void grf_shuffle_enc(BIT64* src) { -// BIT64 out; -// -// out.b[0] = src->b[3]; -// out.b[1] = src->b[4]; -// out.b[2] = src->b[5]; -// out.b[3] = src->b[0]; -// out.b[4] = src->b[1]; -// out.b[5] = src->b[6]; -// out.b[6] = src->b[2]; -// out.b[7] = grf_substitution(src->b[7]); -// -// *src = out; -//} +#if 0 /* this is not used anywhere, is it ok to delete? */ +static void grf_shuffle_enc(BIT64* src) +{ + BIT64 out; + out.b[0] = src->b[3]; + out.b[1] = src->b[4]; + out.b[2] = src->b[5]; + out.b[3] = src->b[0]; + out.b[4] = src->b[1]; + out.b[5] = src->b[6]; + out.b[6] = src->b[2]; + out.b[7] = grf_substitution(src->b[7]); + + *src = out; +} +#endif // 0 static void grf_shuffle_dec(BIT64* src) { @@ -425,7 +426,7 @@ void* grfio_reads(const char* fname, int* size) *size = declen; } else { if (entry != NULL && entry->gentry < 0) { - entry->gentry = -entry->gentry; // local file checked + entry->gentry = -entry->gentry; // local file checked } else { ShowError("grfio_reads: %s not found (local file: %s)\n", fname, lfname); return NULL; @@ -515,7 +516,7 @@ static int grfio_entryread(const char* grfname, int gentry) FILE* fp = fopen(grfname, "rb"); if( fp == NULL ) { ShowWarning("GRF data file not found: '%s'\n",grfname); - return 1; // 1:not found error + return 1; // 1:not found error } else ShowInfo("GRF data file found: '%s'\n",grfname); @@ -527,7 +528,7 @@ static int grfio_entryread(const char* grfname, int gentry) if( strcmp((const char*)grf_header,"Master of Magic") != 0 || fseek(fp,getlong(grf_header+0x1e),SEEK_CUR) != 0 ) { fclose(fp); ShowError("GRF %s read error\n", grfname); - return 2; // 2:file format error + return 2; // 2:file format error } grf_version = getlong(grf_header+0x2a) >> 8; @@ -565,11 +566,11 @@ static int grfio_entryread(const char* grfname, int gentry) aentry.srcpos = getlong(grf_filelist+ofs2+13)+0x2e; aentry.type = type; safestrncpy(aentry.fn, fname, sizeof(aentry.fn)); - aentry.fnd = NULL; -#ifdef GRFIO_LOCAL - aentry.gentry = -(gentry+1); // As Flag for making it a negative number carrying out the first time LocalFileCheck + aentry.fnd = NULL; +#ifdef GRFIO_LOCAL + aentry.gentry = -(gentry+1); // As Flag for making it a negative number carrying out the first time LocalFileCheck #else - aentry.gentry = (char)(gentry+1); // With no first time LocalFileCheck + aentry.gentry = (char)(gentry+1); // With no first time LocalFileCheck #endif filelist_modify(&aentry); } @@ -584,8 +585,8 @@ static int grfio_entryread(const char* grfname, int gentry) uLongf rSize, eSize; if(fread(eheader,1,8,fp) != 8) ShowError("An error occurred in fread while reading header buffer\n"); - rSize = getlong(eheader); // Read Size - eSize = getlong(eheader+4); // Extend Size + rSize = getlong(eheader); // Read Size + eSize = getlong(eheader+4); // Extend Size if( (long)rSize > grf_size-ftell(fp) ) { fclose(fp); @@ -593,11 +594,11 @@ static int grfio_entryread(const char* grfname, int gentry) return 4; } - rBuf = (unsigned char *)aMalloc(rSize); // Get a Read Size - grf_filelist = (unsigned char *)aMalloc(eSize); // Get a Extend Size + rBuf = (unsigned char *)aMalloc(rSize); // Get a Read Size + grf_filelist = (unsigned char *)aMalloc(eSize); // Get a Extend Size if(fread(rBuf,1,rSize,fp) != rSize) ShowError("An error occurred in fread \n"); fclose(fp); - decode_zip(grf_filelist, &eSize, rBuf, rSize); // Decode function + decode_zip(grf_filelist, &eSize, rBuf, rSize); // Decode function aFree(rBuf); entrys = getlong(grf_header+0x26) - 7; @@ -623,11 +624,11 @@ static int grfio_entryread(const char* grfname, int gentry) aentry.srcpos = getlong(grf_filelist+ofs2+13)+0x2e; aentry.type = (char)type; safestrncpy(aentry.fn, fname, sizeof(aentry.fn)); - aentry.fnd = NULL; -#ifdef GRFIO_LOCAL - aentry.gentry = -(gentry+1); // As Flag for making it a negative number carrying out the first time LocalFileCheck + aentry.fnd = NULL; +#ifdef GRFIO_LOCAL + aentry.gentry = -(gentry+1); // As Flag for making it a negative number carrying out the first time LocalFileCheck #else - aentry.gentry = (char)(gentry+1); // With no first time LocalFileCheck + aentry.gentry = (char)(gentry+1); // With no first time LocalFileCheck #endif filelist_modify(&aentry); } @@ -642,9 +643,9 @@ static int grfio_entryread(const char* grfname, int gentry) return 4; } - filelist_compact(); // Unnecessary area release of filelist + filelist_compact(); // Unnecessary area release of filelist - return 0; // 0:no error + return 0; // 0:no error } @@ -714,7 +715,7 @@ static void grfio_resourcecheck(void) fclose(fp); ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", i, "resnametable.txt"); - return; // we're done here! + return; // we're done here! } // read resnametable from loaded GRF's, only if it cannot be loaded from the data directory @@ -745,12 +746,12 @@ static void grfio_resourcecheck(void) /// Reads a grf file and adds it to the list. static int grfio_add(const char* fname) { - if( gentry_entrys >= gentry_maxentry ) - { - #define GENTRY_ADDS 4 // The number increment of gentry_table entries + if (gentry_entrys >= gentry_maxentry) { +#define GENTRY_ADDS 4 // The number increment of gentry_table entries gentry_maxentry += GENTRY_ADDS; gentry_table = (char**)aRealloc(gentry_table, gentry_maxentry * sizeof(char*)); memset(gentry_table + (gentry_maxentry - GENTRY_ADDS), 0, sizeof(char*) * GENTRY_ADDS); +#undef GENTRY_ADDS } gentry_table[gentry_entrys++] = aStrdup(fname); @@ -792,7 +793,7 @@ void grfio_init(const char* fname) FILE* data_conf; int grf_num = 0; - hashinit(); // hash table initialization + hashinit(); // hash table initialization data_conf = fopen(fname, "r"); if( data_conf != NULL ) diff --git a/src/common/malloc.c b/src/common/malloc.c index eae9ad423..625875b76 100644 --- a/src/common/malloc.c +++ b/src/common/malloc.c @@ -143,7 +143,7 @@ void aFree_(void *p, const char *file, int line, const char *func) * Since the complex processing, I might be slightly heavier. * * (I'm sorry for the poor description ^ ^;) such as data structures -* Divided into "blocks" of a plurality of memory, "unit" of a plurality of blocks further +* Divided into "blocks" of a plurality of memory, "unit" of a plurality of blocks further * I have to divide. Size of the unit, a plurality of distribution equal to the capacity of one block * That's what you have. For example, if one unit of 32KB, one block 1 Yu 32Byte * Knit, or are able to gather 1024, gathered 512 units 64Byte @@ -155,33 +155,33 @@ void aFree_(void *p, const char *file, int line, const char *func) */ /* Alignment of the block */ -#define BLOCK_ALIGNMENT1 16 -#define BLOCK_ALIGNMENT2 64 +#define BLOCK_ALIGNMENT1 16 +#define BLOCK_ALIGNMENT2 64 /* Amount of data entering a block */ -#define BLOCK_DATA_COUNT1 128 -#define BLOCK_DATA_COUNT2 608 +#define BLOCK_DATA_COUNT1 128 +#define BLOCK_DATA_COUNT2 608 /* The size of the block: 16*128 + 64*576 = 40KB */ -#define BLOCK_DATA_SIZE1 ( BLOCK_ALIGNMENT1 * BLOCK_DATA_COUNT1 ) -#define BLOCK_DATA_SIZE2 ( BLOCK_ALIGNMENT2 * BLOCK_DATA_COUNT2 ) -#define BLOCK_DATA_SIZE ( BLOCK_DATA_SIZE1 + BLOCK_DATA_SIZE2 ) +#define BLOCK_DATA_SIZE1 ( BLOCK_ALIGNMENT1 * BLOCK_DATA_COUNT1 ) +#define BLOCK_DATA_SIZE2 ( BLOCK_ALIGNMENT2 * BLOCK_DATA_COUNT2 ) +#define BLOCK_DATA_SIZE ( BLOCK_DATA_SIZE1 + BLOCK_DATA_SIZE2 ) /* The number of blocks to be allocated at a time. */ -#define BLOCK_ALLOC 104 +#define BLOCK_ALLOC 104 /* block */ struct block { - struct block* block_next; /* Then the allocated area */ - struct block* unfill_prev; /* The previous area not filled */ - struct block* unfill_next; /* The next area not filled */ - unsigned short unit_size; /* The size of the unit */ - unsigned short unit_hash; /* The hash of the unit */ - unsigned short unit_count; /* The number of units */ - unsigned short unit_used; /* The number of used units */ - unsigned short unit_unfill; /* The number of unused units */ - unsigned short unit_maxused; /* The maximum value of units used */ - char data[ BLOCK_DATA_SIZE ]; + struct block *block_next; ///< Then the allocated area + struct block *unfill_prev; ///< The previous area not filled + struct block *unfill_next; ///< The next area not filled + unsigned short unit_size; ///< The size of the unit + unsigned short unit_hash; ///< The hash of the unit + unsigned short unit_count; ///< The number of units + unsigned short unit_used; ///< The number of used units + unsigned short unit_unfill; ///< The number of unused units + unsigned short unit_maxused; ///< The maximum value of units used + char data[BLOCK_DATA_SIZE]; }; struct unit_head { @@ -222,7 +222,7 @@ static unsigned short size2hash( size_t size ) return (unsigned short)(size - BLOCK_DATA_SIZE1 + BLOCK_ALIGNMENT2 - 1) / BLOCK_ALIGNMENT2 + BLOCK_DATA_COUNT1; } else { - return 0xffff; // If it exceeds the block length hash I do not + return 0xffff; // If it exceeds the block length hash I do not } } @@ -375,13 +375,13 @@ void *mrealloc_(void *memblock, size_t size, const char *file, int line, const c void *mreallocz_(void *memblock, size_t size, const char *file, int line, const char *func) { size_t old_size; void *p = NULL; - + if(memblock == NULL) { p = iMalloc->malloc(size,file,line,func); memset(p,0,size); return p; } - + old_size = ((struct unit_head *)((char *)memblock - sizeof(struct unit_head) + sizeof(long)))->size; if( old_size == 0 ) { old_size = ((struct unit_head_large *)((char *)memblock - sizeof(struct unit_head_large) + sizeof(long)))->size; @@ -702,7 +702,7 @@ void memmgr_report (int extra) { unsigned int count; } data[100]; memset(&data, 0, sizeof(data)); - + if( extra != 0 ) msize = extra; @@ -732,7 +732,7 @@ void memmgr_report (int extra) { } block = block->block_next; } - + while(large) { if( large->size > msize ) { for( j = 0; j < 100; j++ ) { @@ -760,7 +760,7 @@ void memmgr_report (int extra) { } ShowMessage("[malloc] : reporting %u instances | %.2f MB\n",count,(double)((size)/1024)/1024); ShowMessage("[malloc] : internal usage %.2f MB | %.2f MB\n",(double)((memmgr_usage_bytes_t-memmgr_usage_bytes)/1024)/1024,(double)((memmgr_usage_bytes_t)/1024)/1024); - + if (extra) { ShowMessage("[malloc] : unit_head_large: %"PRIuS" bytes\n", sizeof(struct unit_head_large)); ShowMessage("[malloc] : unit_head: %"PRIuS" bytes\n", sizeof(struct unit_head)); @@ -848,19 +848,19 @@ void malloc_defaults(void) { // Athena's built-in Memory Manager #ifdef USE_MEMMGR - iMalloc->malloc = mmalloc_; - iMalloc->calloc = mcalloc_; - iMalloc->realloc = mrealloc_; - iMalloc->reallocz= mreallocz_; - iMalloc->astrdup = mstrdup_; - iMalloc->free = mfree_; + iMalloc->malloc = mmalloc_; + iMalloc->calloc = mcalloc_; + iMalloc->realloc = mrealloc_; + iMalloc->reallocz = mreallocz_; + iMalloc->astrdup = mstrdup_; + iMalloc->free = mfree_; #else - iMalloc->malloc = aMalloc_; - iMalloc->calloc = aCalloc_; - iMalloc->realloc = aRealloc_; - iMalloc->reallocz= aRealloc_;/* not using memory manager huhum o.o perhaps we could still do something about */ - iMalloc->astrdup = aStrdup_; - iMalloc->free = aFree_; + iMalloc->malloc = aMalloc_; + iMalloc->calloc = aCalloc_; + iMalloc->realloc = aRealloc_; + iMalloc->reallocz = aRealloc_;/* not using memory manager huhum o.o perhaps we could still do something about */ + iMalloc->astrdup = aStrdup_; + iMalloc->free = aFree_; #endif iMalloc->post_shutdown = NULL; } diff --git a/src/common/malloc.h b/src/common/malloc.h index 8dace2d68..53d2ebdd2 100644 --- a/src/common/malloc.h +++ b/src/common/malloc.h @@ -68,19 +68,19 @@ void malloc_defaults(void); struct malloc_interface { - void (*init) (void); - void (*final) (void); + void (*init) (void); + void (*final) (void); /* */ - void* (*malloc )(size_t size, const char *file, int line, const char *func); - void* (*calloc )(size_t num, size_t size, const char *file, int line, const char *func); - void* (*realloc )(void *p, size_t size, const char *file, int line, const char *func); + void* (*malloc)(size_t size, const char *file, int line, const char *func); + void* (*calloc)(size_t num, size_t size, const char *file, int line, const char *func); + void* (*realloc)(void *p, size_t size, const char *file, int line, const char *func); void* (*reallocz)(void *p, size_t size, const char *file, int line, const char *func); - char* (*astrdup )(const char *p, const char *file, int line, const char *func); - void (*free )(void *p, const char *file, int line, const char *func); + char* (*astrdup)(const char *p, const char *file, int line, const char *func); + void (*free)(void *p, const char *file, int line, const char *func); /* */ - void (*memory_check)(void); - bool (*verify_ptr)(void* ptr); - size_t (*usage) (void); + void (*memory_check)(void); + bool (*verify_ptr)(void* ptr); + size_t (*usage) (void); /* */ void (*post_shutdown) (void); }; diff --git a/src/common/mapindex.c b/src/common/mapindex.c index 0873b3e59..ec829ee56 100644 --- a/src/common/mapindex.c +++ b/src/common/mapindex.c @@ -24,7 +24,7 @@ struct mapindex_interface mapindex_s; const char* mapindex_getmapname(const char* string, char* output) { static char buf[MAP_NAME_LENGTH]; char* dest = (output != NULL) ? output : buf; - + size_t len = strnlen(string, MAP_NAME_LENGTH_EXT); if (len == MAP_NAME_LENGTH_EXT) { ShowWarning("(mapindex_normalize_name) Map name '%*s' is too long!\n", 2*MAP_NAME_LENGTH_EXT, string); @@ -32,11 +32,11 @@ const char* mapindex_getmapname(const char* string, char* output) { } if (len >= 4 && stricmp(&string[len-4], ".gat") == 0) len -= 4; // strip .gat extension - + len = min(len, MAP_NAME_LENGTH-1); safestrncpy(dest, string, len+1); memset(&dest[len], '\0', MAP_NAME_LENGTH-len); - + return dest; } @@ -65,7 +65,7 @@ const char* mapindex_getmapname_ext(const char* string, char* output) { } memset(&dest[len], '\0', MAP_NAME_LENGTH_EXT-len); - + return dest; } @@ -105,7 +105,7 @@ int mapindex_addmap(int index, const char* name) { safestrncpy(mapindex->list[index].name, map_name, MAP_NAME_LENGTH); strdb_iput(mapindex->db, map_name, index); - + if (mapindex->num <= index) mapindex->num = index+1; @@ -115,12 +115,12 @@ int mapindex_addmap(int index, const char* name) { unsigned short mapindex_name2id(const char* name) { int i; char map_name[MAP_NAME_LENGTH]; - + mapindex->getmapname(name, map_name); if( (i = strdb_iget(mapindex->db, map_name)) ) return i; - + ShowDebug("mapindex_name2id: Map \"%s\" not found in index list!\n", map_name); return 0; } @@ -139,14 +139,14 @@ int mapindex_init(void) { int last_index = -1; int index, total = 0; char map_name[13]; - + if( ( fp = fopen(mapindex->config_file,"r") ) == NULL ){ ShowFatalError("Unable to read mapindex config file %s!\n", mapindex->config_file); exit(EXIT_FAILURE); //Server can't really run without this file. } mapindex->db = strdb_alloc(DB_OPT_DUP_KEY, MAP_NAME_LENGTH); - + while(fgets(line, sizeof(line), fp)) { if(line[0] == '/' && line[1] == '/') continue; @@ -168,7 +168,7 @@ int mapindex_init(void) { if( !strdb_iget(mapindex->db, MAP_DEFAULT) ) { ShowError("mapindex_init: MAP_DEFAULT '%s' not found in cache! update mapindex.h MAP_DEFAULT var!!!\n",MAP_DEFAULT); } - + return total; } @@ -183,14 +183,14 @@ void mapindex_final(void) { void mapindex_defaults(void) { mapindex = &mapindex_s; - + /* TODO: place it in inter-server.conf? */ snprintf(mapindex->config_file, 80, "%s","db/map_index.txt"); /* */ mapindex->db = NULL; mapindex->num = 0; memset (&mapindex->list, 0, sizeof (mapindex->list)); - + /* */ mapindex->init = mapindex_init; mapindex->final = mapindex_final; diff --git a/src/common/md5calc.c b/src/common/md5calc.c index e7b506e27..18e502da2 100644 --- a/src/common/md5calc.c +++ b/src/common/md5calc.c @@ -25,22 +25,22 @@ static unsigned int *pX; // String Table static const unsigned int T[] = { - 0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee, //0 - 0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501, //4 - 0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be, //8 - 0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821, //12 - 0xf61e2562, 0xc040b340, 0x265e5a51, 0xe9b6c7aa, //16 - 0xd62f105d, 0x2441453, 0xd8a1e681, 0xe7d3fbc8, //20 - 0x21e1cde6, 0xc33707d6, 0xf4d50d87, 0x455a14ed, //24 - 0xa9e3e905, 0xfcefa3f8, 0x676f02d9, 0x8d2a4c8a, //28 - 0xfffa3942, 0x8771f681, 0x6d9d6122, 0xfde5380c, //32 - 0xa4beea44, 0x4bdecfa9, 0xf6bb4b60, 0xbebfbc70, //36 - 0x289b7ec6, 0xeaa127fa, 0xd4ef3085, 0x4881d05, //40 - 0xd9d4d039, 0xe6db99e5, 0x1fa27cf8, 0xc4ac5665, //44 - 0xf4292244, 0x432aff97, 0xab9423a7, 0xfc93a039, //48 - 0x655b59c3, 0x8f0ccc92, 0xffeff47d, 0x85845dd1, //52 - 0x6fa87e4f, 0xfe2ce6e0, 0xa3014314, 0x4e0811a1, //56 - 0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391 //60 + 0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee, //0 + 0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501, //4 + 0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be, //8 + 0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821, //12 + 0xf61e2562, 0xc040b340, 0x265e5a51, 0xe9b6c7aa, //16 + 0xd62f105d, 0x2441453, 0xd8a1e681, 0xe7d3fbc8, //20 + 0x21e1cde6, 0xc33707d6, 0xf4d50d87, 0x455a14ed, //24 + 0xa9e3e905, 0xfcefa3f8, 0x676f02d9, 0x8d2a4c8a, //28 + 0xfffa3942, 0x8771f681, 0x6d9d6122, 0xfde5380c, //32 + 0xa4beea44, 0x4bdecfa9, 0xf6bb4b60, 0xbebfbc70, //36 + 0x289b7ec6, 0xeaa127fa, 0xd4ef3085, 0x4881d05, //40 + 0xd9d4d039, 0xe6db99e5, 0x1fa27cf8, 0xc4ac5665, //44 + 0xf4292244, 0x432aff97, 0xab9423a7, 0xfc93a039, //48 + 0x655b59c3, 0x8f0ccc92, 0xffeff47d, 0x85845dd1, //52 + 0x6fa87e4f, 0xfe2ce6e0, 0xa3014314, 0x4e0811a1, //56 + 0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391 //60 }; // ROTATE_LEFT The left is made to rotate x [ n-bit ]. This is diverted as it is from RFC. @@ -49,25 +49,25 @@ static const unsigned int T[] = { // The function used for other calculation static unsigned int F(unsigned int X, unsigned int Y, unsigned int Z) { - return (X & Y) | (~X & Z); + return (X & Y) | (~X & Z); } static unsigned int G(unsigned int X, unsigned int Y, unsigned int Z) { - return (X & Z) | (Y & ~Z); + return (X & Z) | (Y & ~Z); } static unsigned int H(unsigned int X, unsigned int Y, unsigned int Z) { - return X ^ Y ^ Z; + return X ^ Y ^ Z; } static unsigned int I(unsigned int X, unsigned int Y, unsigned int Z) { - return Y ^ (X | ~Z); + return Y ^ (X | ~Z); } static unsigned int Round(unsigned int a, unsigned int b, unsigned int FGHI, - unsigned int k, unsigned int s, unsigned int i) + unsigned int k, unsigned int s, unsigned int i) { - return b + ROTATE_LEFT(a + FGHI + pX[k] + T[i], s); + return b + ROTATE_LEFT(a + FGHI + pX[k] + T[i], s); } static void Round1(unsigned int *a, unsigned int b, unsigned int c, @@ -113,103 +113,103 @@ static void MD5_Round_Calculate(const unsigned char *block, | ( ((unsigned int )block[j+3]) << 24 ); - //Round 1 - Round1(&A,B,C,D, 0, 7, 0); Round1(&D,A,B,C, 1, 12, 1); Round1(&C,D,A,B, 2, 17, 2); Round1(&B,C,D,A, 3, 22, 3); - Round1(&A,B,C,D, 4, 7, 4); Round1(&D,A,B,C, 5, 12, 5); Round1(&C,D,A,B, 6, 17, 6); Round1(&B,C,D,A, 7, 22, 7); - Round1(&A,B,C,D, 8, 7, 8); Round1(&D,A,B,C, 9, 12, 9); Round1(&C,D,A,B, 10, 17, 10); Round1(&B,C,D,A, 11, 22, 11); - Round1(&A,B,C,D, 12, 7, 12); Round1(&D,A,B,C, 13, 12, 13); Round1(&C,D,A,B, 14, 17, 14); Round1(&B,C,D,A, 15, 22, 15); - - //Round 2 - Round2(&A,B,C,D, 1, 5, 16); Round2(&D,A,B,C, 6, 9, 17); Round2(&C,D,A,B, 11, 14, 18); Round2(&B,C,D,A, 0, 20, 19); - Round2(&A,B,C,D, 5, 5, 20); Round2(&D,A,B,C, 10, 9, 21); Round2(&C,D,A,B, 15, 14, 22); Round2(&B,C,D,A, 4, 20, 23); - Round2(&A,B,C,D, 9, 5, 24); Round2(&D,A,B,C, 14, 9, 25); Round2(&C,D,A,B, 3, 14, 26); Round2(&B,C,D,A, 8, 20, 27); - Round2(&A,B,C,D, 13, 5, 28); Round2(&D,A,B,C, 2, 9, 29); Round2(&C,D,A,B, 7, 14, 30); Round2(&B,C,D,A, 12, 20, 31); - - //Round 3 - Round3(&A,B,C,D, 5, 4, 32); Round3(&D,A,B,C, 8, 11, 33); Round3(&C,D,A,B, 11, 16, 34); Round3(&B,C,D,A, 14, 23, 35); - Round3(&A,B,C,D, 1, 4, 36); Round3(&D,A,B,C, 4, 11, 37); Round3(&C,D,A,B, 7, 16, 38); Round3(&B,C,D,A, 10, 23, 39); - Round3(&A,B,C,D, 13, 4, 40); Round3(&D,A,B,C, 0, 11, 41); Round3(&C,D,A,B, 3, 16, 42); Round3(&B,C,D,A, 6, 23, 43); - Round3(&A,B,C,D, 9, 4, 44); Round3(&D,A,B,C, 12, 11, 45); Round3(&C,D,A,B, 15, 16, 46); Round3(&B,C,D,A, 2, 23, 47); - - //Round 4 - Round4(&A,B,C,D, 0, 6, 48); Round4(&D,A,B,C, 7, 10, 49); Round4(&C,D,A,B, 14, 15, 50); Round4(&B,C,D,A, 5, 21, 51); - Round4(&A,B,C,D, 12, 6, 52); Round4(&D,A,B,C, 3, 10, 53); Round4(&C,D,A,B, 10, 15, 54); Round4(&B,C,D,A, 1, 21, 55); - Round4(&A,B,C,D, 8, 6, 56); Round4(&D,A,B,C, 15, 10, 57); Round4(&C,D,A,B, 6, 15, 58); Round4(&B,C,D,A, 13, 21, 59); - Round4(&A,B,C,D, 4, 6, 60); Round4(&D,A,B,C, 11, 10, 61); Round4(&C,D,A,B, 2, 15, 62); Round4(&B,C,D,A, 9, 21, 63); - - // Then perform the following additions. (let's add) - *A2 = A + AA; - *B2 = B + BB; - *C2 = C + CC; - *D2 = D + DD; - - //The clearance of confidential information - memset(pX, 0, sizeof(X)); + //Round 1 + Round1(&A,B,C,D, 0, 7, 0); Round1(&D,A,B,C, 1, 12, 1); Round1(&C,D,A,B, 2, 17, 2); Round1(&B,C,D,A, 3, 22, 3); + Round1(&A,B,C,D, 4, 7, 4); Round1(&D,A,B,C, 5, 12, 5); Round1(&C,D,A,B, 6, 17, 6); Round1(&B,C,D,A, 7, 22, 7); + Round1(&A,B,C,D, 8, 7, 8); Round1(&D,A,B,C, 9, 12, 9); Round1(&C,D,A,B, 10, 17, 10); Round1(&B,C,D,A, 11, 22, 11); + Round1(&A,B,C,D, 12, 7, 12); Round1(&D,A,B,C, 13, 12, 13); Round1(&C,D,A,B, 14, 17, 14); Round1(&B,C,D,A, 15, 22, 15); + + //Round 2 + Round2(&A,B,C,D, 1, 5, 16); Round2(&D,A,B,C, 6, 9, 17); Round2(&C,D,A,B, 11, 14, 18); Round2(&B,C,D,A, 0, 20, 19); + Round2(&A,B,C,D, 5, 5, 20); Round2(&D,A,B,C, 10, 9, 21); Round2(&C,D,A,B, 15, 14, 22); Round2(&B,C,D,A, 4, 20, 23); + Round2(&A,B,C,D, 9, 5, 24); Round2(&D,A,B,C, 14, 9, 25); Round2(&C,D,A,B, 3, 14, 26); Round2(&B,C,D,A, 8, 20, 27); + Round2(&A,B,C,D, 13, 5, 28); Round2(&D,A,B,C, 2, 9, 29); Round2(&C,D,A,B, 7, 14, 30); Round2(&B,C,D,A, 12, 20, 31); + + //Round 3 + Round3(&A,B,C,D, 5, 4, 32); Round3(&D,A,B,C, 8, 11, 33); Round3(&C,D,A,B, 11, 16, 34); Round3(&B,C,D,A, 14, 23, 35); + Round3(&A,B,C,D, 1, 4, 36); Round3(&D,A,B,C, 4, 11, 37); Round3(&C,D,A,B, 7, 16, 38); Round3(&B,C,D,A, 10, 23, 39); + Round3(&A,B,C,D, 13, 4, 40); Round3(&D,A,B,C, 0, 11, 41); Round3(&C,D,A,B, 3, 16, 42); Round3(&B,C,D,A, 6, 23, 43); + Round3(&A,B,C,D, 9, 4, 44); Round3(&D,A,B,C, 12, 11, 45); Round3(&C,D,A,B, 15, 16, 46); Round3(&B,C,D,A, 2, 23, 47); + + //Round 4 + Round4(&A,B,C,D, 0, 6, 48); Round4(&D,A,B,C, 7, 10, 49); Round4(&C,D,A,B, 14, 15, 50); Round4(&B,C,D,A, 5, 21, 51); + Round4(&A,B,C,D, 12, 6, 52); Round4(&D,A,B,C, 3, 10, 53); Round4(&C,D,A,B, 10, 15, 54); Round4(&B,C,D,A, 1, 21, 55); + Round4(&A,B,C,D, 8, 6, 56); Round4(&D,A,B,C, 15, 10, 57); Round4(&C,D,A,B, 6, 15, 58); Round4(&B,C,D,A, 13, 21, 59); + Round4(&A,B,C,D, 4, 6, 60); Round4(&D,A,B,C, 11, 10, 61); Round4(&C,D,A,B, 2, 15, 62); Round4(&B,C,D,A, 9, 21, 63); + + // Then perform the following additions. (let's add) + *A2 = A + AA; + *B2 = B + BB; + *C2 = C + CC; + *D2 = D + DD; + + //The clearance of confidential information + memset(pX, 0, sizeof(X)); } static void MD5_String2binary(const char * string, unsigned char * output) { //var - /*8bit*/ - unsigned char padding_message[64]; //Extended message 512bit 64byte - unsigned char *pstring; //The position of string in the present scanning notes is held. - - /*32bit*/ - unsigned int string_byte_len, //The byte chief of string is held. - string_bit_len, //The bit length of string is held. - copy_len, //The number of bytes which is used by 1-3 and which remained - msg_digest[4]; //Message digest 128bit 4byte - unsigned int *A = &msg_digest[0], //The message digest in accordance with RFC (reference) - *B = &msg_digest[1], - *C = &msg_digest[2], - *D = &msg_digest[3]; + /*8bit*/ + unsigned char padding_message[64]; //Extended message 512bit 64byte + unsigned char *pstring; //The position of string in the present scanning notes is held. + + /*32bit*/ + unsigned int string_byte_len, //The byte chief of string is held. + string_bit_len, //The bit length of string is held. + copy_len, //The number of bytes which is used by 1-3 and which remained + msg_digest[4]; //Message digest 128bit 4byte + unsigned int *A = &msg_digest[0], //The message digest in accordance with RFC (reference) + *B = &msg_digest[1], + *C = &msg_digest[2], + *D = &msg_digest[3]; int i; //prog - //Step 3.Initialize MD Buffer (although it is the initialization; step 3 of A, B, C, and D -- unavoidable -- a head) - *A = 0x67452301; - *B = 0xefcdab89; - *C = 0x98badcfe; - *D = 0x10325476; - - //Step 1.Append Padding Bits (extension of a mark bit) - //1-1 - string_byte_len = (unsigned int)strlen(string); //The byte chief of a character sequence is acquired. - pstring = (unsigned char *)string; //The position of the present character sequence is set. - - //1-2 Repeat calculation until length becomes less than 64 bytes. - for (i=string_byte_len; 64<=i; i-=64,pstring+=64) - MD5_Round_Calculate(pstring, A,B,C,D); - - //1-3 - copy_len = string_byte_len % 64; //The number of bytes which remained is computed. - strncpy((char *)padding_message, (char *)pstring, copy_len); //A message is copied to an extended bit sequence. - memset(padding_message+copy_len, 0, 64 - copy_len); //It buries by 0 until it becomes extended bit length. - padding_message[copy_len] |= 0x80; //The next of a message is 1. - - //1-4 - //If 56 bytes or more (less than 64 bytes) of remainder becomes, it will calculate by extending to 64 bytes. - if (56 <= copy_len) { - MD5_Round_Calculate(padding_message, A,B,C,D); - memset(padding_message, 0, 56); //56 bytes is newly fill uped with 0. - } - - //Step 2.Append Length (the information on length is added) - string_bit_len = string_byte_len * 8; //From the byte chief to bit length (32 bytes of low rank) - memcpy(&padding_message[56], &string_bit_len, 4); //32 bytes of low rank is set. - - //When bit length cannot be expressed in 32 bytes of low rank, it is a beam raising to a higher rank. - if (UINT_MAX / 8 < string_byte_len) { - unsigned int high = (string_byte_len - UINT_MAX / 8) * 8; - memcpy(&padding_message[60], &high, 4); - } else - memset(&padding_message[60], 0, 4); //In this case, it is good for a higher rank at 0. - - //Step 4.Process Message in 16-Word Blocks (calculation of MD5) - MD5_Round_Calculate(padding_message, A,B,C,D); - - //Step 5.Output (output) - memcpy(output,msg_digest,16); + //Step 3.Initialize MD Buffer (although it is the initialization; step 3 of A, B, C, and D -- unavoidable -- a head) + *A = 0x67452301; + *B = 0xefcdab89; + *C = 0x98badcfe; + *D = 0x10325476; + + //Step 1.Append Padding Bits (extension of a mark bit) + //1-1 + string_byte_len = (unsigned int)strlen(string); //The byte chief of a character sequence is acquired. + pstring = (unsigned char *)string; //The position of the present character sequence is set. + + //1-2 Repeat calculation until length becomes less than 64 bytes. + for (i=string_byte_len; 64<=i; i-=64,pstring+=64) + MD5_Round_Calculate(pstring, A,B,C,D); + + //1-3 + copy_len = string_byte_len % 64; //The number of bytes which remained is computed. + strncpy((char *)padding_message, (char *)pstring, copy_len); //A message is copied to an extended bit sequence. + memset(padding_message+copy_len, 0, 64 - copy_len); //It buries by 0 until it becomes extended bit length. + padding_message[copy_len] |= 0x80; //The next of a message is 1. + + //1-4 + //If 56 bytes or more (less than 64 bytes) of remainder becomes, it will calculate by extending to 64 bytes. + if (56 <= copy_len) { + MD5_Round_Calculate(padding_message, A,B,C,D); + memset(padding_message, 0, 56); //56 bytes is newly fill uped with 0. + } + + //Step 2.Append Length (the information on length is added) + string_bit_len = string_byte_len * 8; //From the byte chief to bit length (32 bytes of low rank) + memcpy(&padding_message[56], &string_bit_len, 4); //32 bytes of low rank is set. + + //When bit length cannot be expressed in 32 bytes of low rank, it is a beam raising to a higher rank. + if (UINT_MAX / 8 < string_byte_len) { + unsigned int high = (string_byte_len - UINT_MAX / 8) * 8; + memcpy(&padding_message[60], &high, 4); + } else + memset(&padding_message[60], 0, 4); //In this case, it is good for a higher rank at 0. + + //Step 4.Process Message in 16-Word Blocks (calculation of MD5) + MD5_Round_Calculate(padding_message, A,B,C,D); + + //Step 5.Output (output) + memcpy(output,msg_digest,16); } //------------------------------------------------------------------- @@ -227,7 +227,7 @@ void MD5_String(const char * string, char * output) unsigned char digest[16]; MD5_String2binary(string,digest); - sprintf(output, "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", + sprintf(output, "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", digest[ 0], digest[ 1], digest[ 2], digest[ 3], digest[ 4], digest[ 5], digest[ 6], digest[ 7], digest[ 8], digest[ 9], digest[10], digest[11], diff --git a/src/common/mmo.h b/src/common/mmo.h index 597b25126..fd054ba91 100644 --- a/src/common/mmo.h +++ b/src/common/mmo.h @@ -73,14 +73,14 @@ #define HOTKEY_SAVING #if PACKETVER < 20090603 - // (27 = 9 skills x 3 bars) (0x02b9,191) - #define MAX_HOTKEYS 27 + // (27 = 9 skills x 3 bars) (0x02b9,191) + #define MAX_HOTKEYS 27 #elif PACKETVER < 20090617 - // (36 = 9 skills x 4 bars) (0x07d9,254) - #define MAX_HOTKEYS 36 + // (36 = 9 skills x 4 bars) (0x07d9,254) + #define MAX_HOTKEYS 36 #else // >= 20090617 - // (38 = 9 skills x 4 bars & 2 Quickslots)(0x07d9,268) - #define MAX_HOTKEYS 38 + // (38 = 9 skills x 4 bars & 2 Quickslots)(0x07d9,268) + #define MAX_HOTKEYS 38 #endif // 20090603 #endif // 20070227 @@ -469,7 +469,7 @@ struct mmo_charstatus { /* `account_data` modifiers */ unsigned short mod_exp,mod_drop,mod_death; - + unsigned char font; uint32 uniqueitem_counter; @@ -593,15 +593,15 @@ struct guild { struct guild_alliance alliance[MAX_GUILDALLIANCE]; struct guild_expulsion expulsion[MAX_GUILDEXPULSION]; struct guild_skill skill[MAX_GUILDSKILL]; - + /* used on char.c to state what kind of data is being saved/processed */ unsigned short save_flag; - + short *instance; unsigned short instances; - + struct hChSysCh *channel; - + /* HPM Custom Struct */ struct HPluginData **hdata; unsigned int hdatac; diff --git a/src/common/mutex.c b/src/common/mutex.c index f046febf6..31202d440 100644 --- a/src/common/mutex.c +++ b/src/common/mutex.c @@ -52,19 +52,19 @@ struct racond{ ramutex *ramutex_create(void) { struct ramutex *m; - + m = (struct ramutex*)aMalloc( sizeof(struct ramutex) ); if (m == NULL) { ShowFatalError("ramutex_create: OOM while allocating %"PRIuS" bytes.\n", sizeof(struct ramutex)); return NULL; } - + #ifdef WIN32 InitializeCriticalSection(&m->hMutex); #else pthread_mutex_init(&m->hMutex, NULL); #endif - + return m; }//end: ramutex_create() @@ -101,7 +101,7 @@ bool ramutex_trylock(ramutex *m) { #else if(pthread_mutex_trylock(&m->hMutex) == 0) return true; - + return false; #endif }//end: ramutex_trylock() @@ -126,7 +126,7 @@ void ramutex_unlock(ramutex *m) { racond *racond_create(void) { struct racond *c; - + c = (struct racond*)aMalloc( sizeof(struct racond) ); if (c == NULL) { ShowFatalError("racond_create: OOM while allocating %"PRIuS" bytes\n", sizeof(struct racond)); @@ -135,13 +135,13 @@ racond *racond_create(void) { #ifdef WIN32 c->nWaiters = 0; - c->events[ EVENT_COND_SIGNAL ] = CreateEvent( NULL, FALSE, FALSE, NULL ); - c->events[ EVENT_COND_BROADCAST ] = CreateEvent( NULL, TRUE, FALSE, NULL ); + c->events[EVENT_COND_SIGNAL] = CreateEvent(NULL, FALSE, FALSE, NULL); + c->events[EVENT_COND_BROADCAST] = CreateEvent(NULL, TRUE, FALSE, NULL); InitializeCriticalSection( &c->waiters_lock ); #else pthread_cond_init(&c->hCond, NULL); #endif - + return c; }//end: racond_create() @@ -174,24 +174,20 @@ void racond_wait(racond *c, ramutex *m, sysint timeout_ticks) { ms = INFINITE; else ms = (timeout_ticks > MAXDWORD) ? (MAXDWORD - 1) : (DWORD)timeout_ticks; - - + // we can release the mutex (m) here, cause win's // manual reset events maintain state when used with // SetEvent() ramutex_unlock(m); result = WaitForMultipleObjects(2, c->events, FALSE, ms); - - + EnterCriticalSection(&c->waiters_lock); c->nWaiters--; if( (result == WAIT_OBJECT_0 + EVENT_COND_BROADCAST) && (c->nWaiters == 0) ) is_last = true; // Broadcast called! LeaveCriticalSection(&c->waiters_lock); - - // we are the last waiter that has to be notified, or to stop waiting // so we have to do a manual reset if(is_last == true) @@ -206,10 +202,10 @@ void racond_wait(racond *c, ramutex *m, sysint timeout_ticks) { }else{ struct timespec wtime; int64 exact_timeout = timer->gettick() + timeout_ticks; - + wtime.tv_sec = exact_timeout/1000; wtime.tv_nsec = (exact_timeout%1000)*1000000; - + pthread_cond_timedwait( &c->hCond, &m->hMutex, &wtime); } @@ -219,13 +215,15 @@ void racond_wait(racond *c, ramutex *m, sysint timeout_ticks) { void racond_signal(racond *c) { #ifdef WIN32 -// bool has_waiters = false; -// EnterCriticalSection(&c->waiters_lock); -// if(c->nWaiters > 0) -// has_waiters = true; -// LeaveCriticalSection(&c->waiters_lock); - -// if(has_waiters == true) +# if 0 + bool has_waiters = false; + EnterCriticalSection(&c->waiters_lock); + if(c->nWaiters > 0) + has_waiters = true; + LeaveCriticalSection(&c->waiters_lock); + + if(has_waiters == true) +# endif // 0 SetEvent( c->events[ EVENT_COND_SIGNAL ] ); #else pthread_cond_signal(&c->hCond); @@ -235,13 +233,15 @@ void racond_signal(racond *c) { void racond_broadcast(racond *c) { #ifdef WIN32 -// bool has_waiters = false; -// EnterCriticalSection(&c->waiters_lock); -// if(c->nWaiters > 0) -// has_waiters = true; -// LeaveCriticalSection(&c->waiters_lock); - -// if(has_waiters == true) +# if 0 + bool has_waiters = false; + EnterCriticalSection(&c->waiters_lock); + if(c->nWaiters > 0) + has_waiters = true; + LeaveCriticalSection(&c->waiters_lock); + + if(has_waiters == true) +# endif // 0 SetEvent( c->events[ EVENT_COND_BROADCAST ] ); #else pthread_cond_broadcast(&c->hCond); diff --git a/src/common/nullpo.c b/src/common/nullpo.c index a3471b00d..0333c02ef 100644 --- a/src/common/nullpo.c +++ b/src/common/nullpo.c @@ -24,10 +24,10 @@ void assert_report(const char *file, int line, const char *func, const char *targetname, const char *title) { if (file == NULL) file = "??"; - + if (func == NULL || *func == '\0') func = "unknown"; - + ShowError("--- %s --------------------------------------------\n", title); ShowError("%s:%d: '%s' in function `%s'\n", file, line, targetname, func); ShowError("--- end %s ----------------------------------------\n", title); diff --git a/src/common/showmsg.c b/src/common/showmsg.c index f3982d364..0dd645eeb 100644 --- a/src/common/showmsg.c +++ b/src/common/showmsg.c @@ -93,20 +93,20 @@ int console_msg_log = 0;//[Ind] msg error logging // // \033[#;...;#m - Set Graphics Rendition (SGR) // -// printf("\x1b[1;31;40m"); // Bright red on black -// printf("\x1b[3;33;45m"); // Blinking yellow on magenta (blink not implemented) -// printf("\x1b[1;30;47m"); // Bright black (grey) on dim white +// printf("\x1b[1;31;40m"); // Bright red on black +// printf("\x1b[3;33;45m"); // Blinking yellow on magenta (blink not implemented) +// printf("\x1b[1;30;47m"); // Bright black (grey) on dim white // // Style Foreground Background -// 1st Digit 2nd Digit 3rd Digit RGB -// 0 - Reset 30 - Black 40 - Black 000 -// 1 - FG Bright 31 - Red 41 - Red 100 -// 2 - Unknown 32 - Green 42 - Green 010 -// 3 - Blink 33 - Yellow 43 - Yellow 110 -// 4 - Underline 34 - Blue 44 - Blue 001 -// 5 - BG Bright 35 - Magenta 45 - Magenta 101 -// 6 - Unknown 36 - Cyan 46 - Cyan 011 -// 7 - Reverse 37 - White 47 - White 111 +// 1st Digit 2nd Digit 3rd Digit RGB +// 0 - Reset 30 - Black 40 - Black 000 +// 1 - FG Bright 31 - Red 41 - Red 100 +// 2 - Unknown 32 - Green 42 - Green 010 +// 3 - Blink 33 - Yellow 43 - Yellow 110 +// 4 - Underline 34 - Blue 44 - Blue 001 +// 5 - BG Bright 35 - Magenta 45 - Magenta 101 +// 6 - Unknown 36 - Cyan 46 - Cyan 011 +// 7 - Reverse 37 - White 47 - White 111 // 8 - Concealed (invisible) // // \033[#A - Cursor Up (CUU) @@ -181,7 +181,7 @@ Escape sequences for Select Character Set #define is_console(handle) (FILE_TYPE_CHAR==GetFileType(handle)) /////////////////////////////////////////////////////////////////////////////// -int VFPRINTF(HANDLE handle, const char *fmt, va_list argptr) +int VFPRINTF(HANDLE handle, const char *fmt, va_list argptr) { ///////////////////////////////////////////////////////////////// /* XXX Two streams are being used. Disabled to avoid inconsistency [flaviojs] @@ -207,19 +207,18 @@ int VFPRINTF(HANDLE handle, const char *fmt, va_list argptr) // start with processing p = BUFVAL(tempbuf); - while ((q = strchr(p, 0x1b)) != NULL) - { // find the escape character + while ((q = strchr(p, 0x1b)) != NULL) { + // find the escape character if( 0==WriteConsole(handle, p, (DWORD)(q-p), &written, 0) ) // write up to the escape WriteFile(handle, p, (DWORD)(q-p), &written, 0); - if( q[1]!='[' ) - { // write the escape char (whatever purpose it has) + if (q[1]!='[') { + // write the escape char (whatever purpose it has) if(0==WriteConsole(handle, q, 1, &written, 0) ) WriteFile(handle,q, 1, &written, 0); - p=q+1; //and start searching again - } - else - { // from here, we will skip the '\033[' + p=q+1; //and start searching again + } else { + // from here, we will skip the '\033[' // we break at the first unprocessible position // assuming regular text is starting there uint8 numbers[16], numpoint=0; @@ -231,84 +230,72 @@ int VFPRINTF(HANDLE handle, const char *fmt, va_list argptr) // skip escape and bracket q=q+2; - for(;;) - { - if( ISDIGIT(*q) ) - { // add number to number array, only accept 2digits, shift out the rest + for (;;) { + if (ISDIGIT(*q)) { + // add number to number array, only accept 2digits, shift out the rest // so // \033[123456789m will become \033[89m numbers[numpoint] = (numbers[numpoint]<<4) | (*q-'0'); ++q; // and next character continue; - } - else if( *q == ';' ) - { // delimiter - if(numpoint7) num=7; // set white for 37, 38 and 39 + if(num>7) num=7; // set white for 37, 38 and 39 info.wAttributes &= ~(FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE); if( (num & 0x01)>0 ) // lowest bit set = red info.wAttributes |= FOREGROUND_RED; @@ -316,12 +303,11 @@ int VFPRINTF(HANDLE handle, const char *fmt, va_list argptr) info.wAttributes |= FOREGROUND_GREEN; if( (num & 0x04)>0 ) // third bit set = blue info.wAttributes |= FOREGROUND_BLUE; - } - else if( 0x40 == (0xF0 & numbers[i]) ) - { // background + } else if (0x40 == (0xF0 & numbers[i])) { + // background uint8 num = numbers[i]&0x0F; if(num==9) info.wAttributes |= BACKGROUND_INTENSITY; - if(num>7) num=7; // set white for 47, 48 and 49 + if(num>7) num=7; // set white for 47, 48 and 49 info.wAttributes &= ~(BACKGROUND_RED|BACKGROUND_GREEN|BACKGROUND_BLUE); if( (num & 0x01)>0 ) // lowest bit set = red info.wAttributes |= BACKGROUND_RED; @@ -333,61 +319,51 @@ int VFPRINTF(HANDLE handle, const char *fmt, va_list argptr) } // set the attributes SetConsoleTextAttribute(handle, info.wAttributes); - } - else if( *q=='J' ) - { // \033[#J - Erase Display (ED) - // \033[0J - Clears the screen from cursor to end of display. The cursor position is unchanged. - // \033[1J - Clears the screen from start to cursor. The cursor position is unchanged. - // \033[2J - Clears the screen and moves the cursor to the home position (line 1, column 1). + } else if (*q=='J') { + // \033[#J - Erase Display (ED) + // \033[0J - Clears the screen from cursor to end of display. The cursor position is unchanged. + // \033[1J - Clears the screen from start to cursor. The cursor position is unchanged. + // \033[2J - Clears the screen and moves the cursor to the home position (line 1, column 1). uint8 num = (numbers[numpoint]>>4)*10+(numbers[numpoint]&0x0F); int cnt; DWORD tmp; COORD origin = {0,0}; - if(num==1) - { // chars from start up to and including cursor + if (num == 1) { + // chars from start up to and including cursor cnt = info.dwSize.X * info.dwCursorPosition.Y + info.dwCursorPosition.X + 1; - } - else if(num==2) - { // Number of chars on screen. + } else if (num == 2) { + // Number of chars on screen. cnt = info.dwSize.X * info.dwSize.Y; SetConsoleCursorPosition(handle, origin); - } - else// 0 and default - { // number of chars from cursor to end + } else { /* 0 and default */ + // number of chars from cursor to end origin = info.dwCursorPosition; cnt = info.dwSize.X * (info.dwSize.Y - info.dwCursorPosition.Y) - info.dwCursorPosition.X; } FillConsoleOutputAttribute(handle, info.wAttributes, cnt, origin, &tmp); FillConsoleOutputCharacter(handle, ' ', cnt, origin, &tmp); - } - else if( *q=='K' ) - { // \033[K : clear line from actual position to end of the line - // \033[0K - Clears all characters from the cursor position to the end of the line. - // \033[1K - Clears all characters from start of line to the cursor position. - // \033[2K - Clears all characters of the whole line. + } else if (*q=='K') { + // \033[K : clear line from actual position to end of the line + // \033[0K - Clears all characters from the cursor position to the end of the line. + // \033[1K - Clears all characters from start of line to the cursor position. + // \033[2K - Clears all characters of the whole line. uint8 num = (numbers[numpoint]>>4)*10+(numbers[numpoint]&0x0F); COORD origin = {0,info.dwCursorPosition.Y}; //warning C4204 SHORT cnt; DWORD tmp; - if(num==1) - { + if (num == 1) { cnt = info.dwCursorPosition.X + 1; - } - else if(num==2) - { + } else if (num == 2) { cnt = info.dwSize.X; - } - else// 0 and default - { + } else { /* 0 and default */ origin = info.dwCursorPosition; cnt = info.dwSize.X - info.dwCursorPosition.X; // how many spaces until line is full } FillConsoleOutputAttribute(handle, info.wAttributes, cnt, origin, &tmp); FillConsoleOutputCharacter(handle, ' ', cnt, origin, &tmp); - } - else if( *q == 'H' || *q == 'f' ) - { // \033[#;#H - Cursor Position (CUP) + } else if (*q == 'H' || *q == 'f') { + // \033[#;#H - Cursor Position (CUP) // \033[#;#f - Horizontal & Vertical Position // The first # specifies the line number, the second # specifies the column. // The default for both is 1 @@ -397,59 +373,52 @@ int VFPRINTF(HANDLE handle, const char *fmt, va_list argptr) if( info.dwCursorPosition.X >= info.dwSize.X ) info.dwCursorPosition.Y = info.dwSize.X-1; if( info.dwCursorPosition.Y >= info.dwSize.Y ) info.dwCursorPosition.Y = info.dwSize.Y-1; SetConsoleCursorPosition(handle, info.dwCursorPosition); - } - else if( *q=='s' ) - { // \033[s - Save Cursor Position (SCP) + } else if (*q=='s') { + // \033[s - Save Cursor Position (SCP) /* XXX Two streams are being used. Disabled to avoid inconsistency [flaviojs] CONSOLE_SCREEN_BUFFER_INFO info; GetConsoleScreenBufferInfo(handle, &info); saveposition = info.dwCursorPosition; */ - } - else if( *q=='u' ) - { // \033[u - Restore cursor position (RCP) + } else if (*q=='u') { + // \033[u - Restore cursor position (RCP) /* XXX Two streams are being used. Disabled to avoid inconsistency [flaviojs] SetConsoleCursorPosition(handle, saveposition); */ - } - else if( *q == 'A' ) - { // \033[#A - Cursor Up (CUU) + } else if (*q == 'A') { + // \033[#A - Cursor Up (CUU) // Moves the cursor UP # number of lines info.dwCursorPosition.Y -= (numbers[numpoint])?(numbers[numpoint]>>4)*10+(numbers[numpoint]&0x0F):1; if( info.dwCursorPosition.Y < 0 ) info.dwCursorPosition.Y = 0; SetConsoleCursorPosition(handle, info.dwCursorPosition); - } - else if( *q == 'B' ) - { // \033[#B - Cursor Down (CUD) + } else if (*q == 'B') { + // \033[#B - Cursor Down (CUD) // Moves the cursor DOWN # number of lines info.dwCursorPosition.Y += (numbers[numpoint])?(numbers[numpoint]>>4)*10+(numbers[numpoint]&0x0F):1; if( info.dwCursorPosition.Y >= info.dwSize.Y ) info.dwCursorPosition.Y = info.dwSize.Y-1; SetConsoleCursorPosition(handle, info.dwCursorPosition); - } - else if( *q == 'C' ) - { // \033[#C - Cursor Forward (CUF) + } else if (*q == 'C') { + // \033[#C - Cursor Forward (CUF) // Moves the cursor RIGHT # number of columns info.dwCursorPosition.X += (numbers[numpoint])?(numbers[numpoint]>>4)*10+(numbers[numpoint]&0x0F):1; if( info.dwCursorPosition.X >= info.dwSize.X ) info.dwCursorPosition.X = info.dwSize.X-1; SetConsoleCursorPosition(handle, info.dwCursorPosition); - } - else if( *q == 'D' ) - { // \033[#D - Cursor Backward (CUB) + } else if (*q == 'D') { + // \033[#D - Cursor Backward (CUB) // Moves the cursor LEFT # number of columns info.dwCursorPosition.X -= (numbers[numpoint])?(numbers[numpoint]>>4)*10+(numbers[numpoint]&0x0F):1; if( info.dwCursorPosition.X < 0 ) info.dwCursorPosition.X = 0; SetConsoleCursorPosition(handle, info.dwCursorPosition); - } - else if( *q == 'E' ) - { // \033[#E - Cursor Next Line (CNL) + } else if (*q == 'E') { + // \033[#E - Cursor Next Line (CNL) // Moves the cursor down the indicated # of rows, to column 1 info.dwCursorPosition.Y += (numbers[numpoint])?(numbers[numpoint]>>4)*10+(numbers[numpoint]&0x0F):1; info.dwCursorPosition.X = 0; @@ -457,9 +426,8 @@ int VFPRINTF(HANDLE handle, const char *fmt, va_list argptr) if( info.dwCursorPosition.Y >= info.dwSize.Y ) info.dwCursorPosition.Y = info.dwSize.Y-1; SetConsoleCursorPosition(handle, info.dwCursorPosition); - } - else if( *q == 'F' ) - { // \033[#F - Cursor Preceding Line (CPL) + } else if (*q == 'F') { + // \033[#F - Cursor Preceding Line (CPL) // Moves the cursor up the indicated # of rows, to column 1. info.dwCursorPosition.Y -= (numbers[numpoint])?(numbers[numpoint]>>4)*10+(numbers[numpoint]&0x0F):1; info.dwCursorPosition.X = 0; @@ -467,21 +435,18 @@ int VFPRINTF(HANDLE handle, const char *fmt, va_list argptr) if( info.dwCursorPosition.Y < 0 ) info.dwCursorPosition.Y = 0; SetConsoleCursorPosition(handle, info.dwCursorPosition); - } - else if( *q == 'G' ) - { // \033[#G - Cursor Horizontal Absolute (CHA) + } else if (*q == 'G') { + // \033[#G - Cursor Horizontal Absolute (CHA) // Moves the cursor to indicated column in current row. info.dwCursorPosition.X = (numbers[numpoint])?(numbers[numpoint]>>4)*10+((numbers[numpoint]&0x0F)-1):0; if( info.dwCursorPosition.X >= info.dwSize.X ) info.dwCursorPosition.X = info.dwSize.X-1; SetConsoleCursorPosition(handle, info.dwCursorPosition); - } - else if( *q == 'L' || *q == 'M' || *q == '@' || *q == 'P') - { // not implemented, just skip - } - else - { // no number nor valid sequencer + } else if (*q == 'L' || *q == 'M' || *q == '@' || *q == 'P') { + // not implemented, just skip + } else { + // no number nor valid sequencer // something is fishy, we break and give the current char free --q; } @@ -491,7 +456,7 @@ int VFPRINTF(HANDLE handle, const char *fmt, va_list argptr) }// end while } } - if (*p) // write the rest of the buffer + if (*p) // write the rest of the buffer if( 0==WriteConsole(handle, p, (DWORD)strlen(p), &written, 0) ) WriteFile(handle, p, (DWORD)strlen(p), &written, 0); FREEBUF(tempbuf); @@ -519,7 +484,7 @@ int FPRINTF(HANDLE handle, const char *fmt, ...) { #define is_console(file) (0!=isatty(fileno(file))) //vprintf_without_ansiformats -int VFPRINTF(FILE *file, const char *fmt, va_list argptr) +int VFPRINTF(FILE *file, const char *fmt, va_list argptr) { char *p, *q; NEWBUF(tempbuf); // temporary buffer @@ -538,88 +503,70 @@ int VFPRINTF(FILE *file, const char *fmt, va_list argptr) // start with processing p = BUFVAL(tempbuf); - while ((q = strchr(p, 0x1b)) != NULL) - { // find the escape character + while ((q = strchr(p, 0x1b)) != NULL) { + // find the escape character fprintf(file, "%.*s", (int)(q-p), p); // write up to the escape - if( q[1]!='[' ) - { // write the escape char (whatever purpose it has) + if (q[1]!='[') { + // write the escape char (whatever purpose it has) fprintf(file, "%.*s", 1, q); - p=q+1; //and start searching again - } - else - { // from here, we will skip the '\033[' + p=q+1; //and start searching again + } else { + // from here, we will skip the '\033[' // we break at the first unprocessible position // assuming regular text is starting there // skip escape and bracket q=q+2; - while(1) - { - if( ISDIGIT(*q) ) - { + while(1) { + if (ISDIGIT(*q)) { ++q; // and next character continue; - } - else if( *q == ';' ) - { // delimiter + } else if (*q == ';') { + // delimiter ++q; // and next number continue; - } - else if( *q == 'm' ) - { // \033[#;...;#m - Set Graphics Rendition (SGR) + } else if (*q == 'm') { + // \033[#;...;#m - Set Graphics Rendition (SGR) // set the attributes + } else if (*q=='J') { + // \033[#J - Erase Display (ED) } - else if( *q=='J' ) - { // \033[#J - Erase Display (ED) - } - else if( *q=='K' ) - { // \033[K : clear line from actual position to end of the line - } - else if( *q == 'H' || *q == 'f' ) - { // \033[#;#H - Cursor Position (CUP) + else if (*q=='K') { + // \033[K : clear line from actual position to end of the line + } else if (*q == 'H' || *q == 'f') { + // \033[#;#H - Cursor Position (CUP) // \033[#;#f - Horizontal & Vertical Position - } - else if( *q=='s' ) - { // \033[s - Save Cursor Position (SCP) - } - else if( *q=='u' ) - { // \033[u - Restore cursor position (RCP) - } - else if( *q == 'A' ) - { // \033[#A - Cursor Up (CUU) + } else if (*q=='s') { + // \033[s - Save Cursor Position (SCP) + } else if (*q=='u') { + // \033[u - Restore cursor position (RCP) + } else if (*q == 'A') { + // \033[#A - Cursor Up (CUU) // Moves the cursor UP # number of lines - } - else if( *q == 'B' ) - { // \033[#B - Cursor Down (CUD) + } else if (*q == 'B') { + // \033[#B - Cursor Down (CUD) // Moves the cursor DOWN # number of lines - } - else if( *q == 'C' ) - { // \033[#C - Cursor Forward (CUF) + } else if (*q == 'C') { + // \033[#C - Cursor Forward (CUF) // Moves the cursor RIGHT # number of columns - } - else if( *q == 'D' ) - { // \033[#D - Cursor Backward (CUB) + } else if (*q == 'D') { + // \033[#D - Cursor Backward (CUB) // Moves the cursor LEFT # number of columns - } - else if( *q == 'E' ) - { // \033[#E - Cursor Next Line (CNL) + } else if (*q == 'E') { + // \033[#E - Cursor Next Line (CNL) // Moves the cursor down the indicated # of rows, to column 1 - } - else if( *q == 'F' ) - { // \033[#F - Cursor Preceding Line (CPL) + } else if (*q == 'F') { + // \033[#F - Cursor Preceding Line (CPL) // Moves the cursor up the indicated # of rows, to column 1. - } - else if( *q == 'G' ) - { // \033[#G - Cursor Horizontal Absolute (CHA) + } else if (*q == 'G') { + // \033[#G - Cursor Horizontal Absolute (CHA) // Moves the cursor to indicated column in current row. - } - else if( *q == 'L' || *q == 'M' || *q == '@' || *q == 'P') - { // not implemented, just skip - } - else - { // no number nor valid sequencer + } else if (*q == 'L' || *q == 'M' || *q == '@' || *q == 'P') { + // not implemented, just skip + } else { + // no number nor valid sequencer // something is fishy, we break and give the current char free --q; } @@ -629,7 +576,7 @@ int VFPRINTF(FILE *file, const char *fmt, va_list argptr) }// end while } } - if (*p) // write the rest of the buffer + if (*p) // write the rest of the buffer fprintf(file, "%s", p); FREEBUF(tempbuf); return 0; @@ -661,7 +608,7 @@ int vShowMessage_(enum msg_type flag, const char *string, va_list ap) #if defined(DEBUGLOGMAP) || defined(DEBUGLOGCHAR) || defined(DEBUGLOGLOGIN) FILE *fp; #endif - + if (!string || *string == '\0') { ShowError("Empty string passed to vShowMessage_().\n"); return 1; @@ -700,8 +647,8 @@ int vShowMessage_(enum msg_type flag, const char *string, va_list ap) ) return 0; //Do not print it. - if (timestamp_format[0] && flag != MSG_NONE) - { //Display time format. [Skotlex] + if (timestamp_format[0] && flag != MSG_NONE) { + //Display time format. [Skotlex] time_t t = time(NULL); strftime(prefix, 80, timestamp_format, localtime(&t)); } else prefix[0]='\0'; @@ -738,8 +685,8 @@ int vShowMessage_(enum msg_type flag, const char *string, va_list ap) return 1; } - if (flag == MSG_ERROR || flag == MSG_FATALERROR || flag == MSG_SQL) - { //Send Errors to StdErr [Skotlex] + if (flag == MSG_ERROR || flag == MSG_FATALERROR || flag == MSG_SQL) { + //Send Errors to StdErr [Skotlex] FPRINTF(STDERR, "%s ", prefix); va_copy(apcopy, ap); VFPRINTF(STDERR, string, apcopy); @@ -757,7 +704,7 @@ int vShowMessage_(enum msg_type flag, const char *string, va_list ap) #if defined(DEBUGLOGMAP) || defined(DEBUGLOGCHAR) || defined(DEBUGLOGLOGIN) if(strlen(DEBUGLOGPATH) > 0) { fp=fopen(DEBUGLOGPATH,"a"); - if (fp == NULL) { + if (fp == NULL) { FPRINTF(STDERR, CL_RED"[ERROR]"CL_RESET": Could not open '"CL_WHITE"%s"CL_RESET"', access denied.\n", DEBUGLOGPATH); FFLUSH(STDERR); } else { @@ -779,7 +726,7 @@ int vShowMessage_(enum msg_type flag, const char *string, va_list ap) void ClearScreen(void) { #ifndef _WIN32 - ShowMessage(CL_CLS); // to prevent empty string passed messages + ShowMessage(CL_CLS); // to prevent empty string passed messages #endif } int ShowMessage_(enum msg_type flag, const char *string, ...) __attribute__((format(printf, 2, 3))); diff --git a/src/common/socket.c b/src/common/socket.c index c57cba32d..f307dc4a9 100644 --- a/src/common/socket.c +++ b/src/common/socket.c @@ -274,7 +274,7 @@ const char* error_msg(void) } /*====================================== - * CORE : Default processing functions + * CORE : Default processing functions *--------------------------------------*/ int null_recv(int fd) { return 0; } int null_send(int fd) { return 0; } @@ -289,7 +289,7 @@ void set_defaultparse(ParseFunc defaultparse) /*====================================== - * CORE : Socket options + * CORE : Socket options *--------------------------------------*/ void set_nonblocking(int fd, unsigned long yes) { @@ -302,7 +302,7 @@ void set_nonblocking(int fd, unsigned long yes) void setsocketopts(int fd, struct hSockOpt *opt) { int yes = 1; // reuse fix struct linger lopt; - + #if !defined(WIN32) // set SO_REAUSEADDR to true, unix only. on windows this option causes // the previous owner of the socket to give up, which is not desirable @@ -319,14 +319,14 @@ void setsocketopts(int fd, struct hSockOpt *opt) { if( opt && opt->setTimeo ) { struct timeval timeout; - + timeout.tv_sec = 5; timeout.tv_usec = 0; - + sSetsockopt(fd,SOL_SOCKET,SO_RCVTIMEO,(char *)&timeout,sizeof(timeout)); sSetsockopt(fd,SOL_SOCKET,SO_SNDTIMEO,(char *)&timeout,sizeof(timeout)); } - + // force the socket into no-wait, graceful-close mode (should be the default, but better make sure) //(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winsock/winsock/closesocket_2.asp) lopt.l_onoff = 0; // SO_DONTLINGER @@ -336,7 +336,7 @@ void setsocketopts(int fd, struct hSockOpt *opt) { } /*====================================== - * CORE : Socket Sub Function + * CORE : Socket Sub Function *--------------------------------------*/ void set_eof(int fd) { @@ -448,7 +448,7 @@ void flush_fifos(void) } /*====================================== - * CORE : Connection functions + * CORE : Connection functions *--------------------------------------*/ int connect_client(int listen_fd) { int fd; @@ -659,19 +659,19 @@ int realloc_writefifo(int fd, size_t addition) if( !sockt->session_isValid(fd) ) // might not happen return 0; - if( session[fd]->wdata_size + addition > session[fd]->max_wdata ) - { // grow rule; grow in multiples of WFIFO_SIZE + if (session[fd]->wdata_size + addition > session[fd]->max_wdata) { + // grow rule; grow in multiples of WFIFO_SIZE newsize = WFIFO_SIZE; while( session[fd]->wdata_size + addition > newsize ) newsize += WFIFO_SIZE; - } - else - if( session[fd]->max_wdata >= (size_t)2*(session[fd]->flag.server?FIFOSIZE_SERVERLINK:WFIFO_SIZE) - && (session[fd]->wdata_size+addition)*4 < session[fd]->max_wdata ) - { // shrink rule, shrink by 2 when only a quarter of the fifo is used, don't shrink below nominal size. + } else if (session[fd]->max_wdata >= (size_t)2*(session[fd]->flag.server?FIFOSIZE_SERVERLINK:WFIFO_SIZE) + && (session[fd]->wdata_size+addition)*4 < session[fd]->max_wdata + ) { + // shrink rule, shrink by 2 when only a quarter of the fifo is used, don't shrink below nominal size. newsize = session[fd]->max_wdata / 2; - } - else // no change + } else { + // no change return 0; + } RECREATE(session[fd]->wdata, unsigned char, newsize); session[fd]->max_wdata = newsize; @@ -682,7 +682,7 @@ int realloc_writefifo(int fd, size_t addition) /// advance the RFIFO cursor (marking 'len' bytes as processed) int RFIFOSKIP(int fd, size_t len) { - struct socket_data *s; + struct socket_data *s; if ( !sockt->session_isActive(fd) ) return 0; @@ -711,8 +711,8 @@ int WFIFOSET(int fd, size_t len) return 0; // we have written len bytes to the buffer already before calling WFIFOSET - if(s->wdata_size+len > s->max_wdata) - { // actually there was a buffer overflow already + if (s->wdata_size+len > s->max_wdata) { + // actually there was a buffer overflow already uint32 ip = s->client_addr; ShowFatalError("WFIFOSET: Write Buffer Overflow. Connection %d (%d.%d.%d.%d) has written %u bytes on a %u/%u bytes buffer.\n", fd, CONVIP(ip), (unsigned int)len, (unsigned int)s->wdata_size, (unsigned int)s->max_wdata); ShowDebug("Likely command that caused it: 0x%x\n", (*(uint16*)(s->wdata + s->wdata_size))); @@ -839,8 +839,8 @@ int do_sockets(int next) if(session[i]->wdata_size) session[i]->func_send(i); - if(session[i]->flag.eof) //func_send can't free a session, this is safe. - { //Finally, even if there is no data to parse, connections signaled eof should be closed, so we call parse_func [Skotlex] + if (session[i]->flag.eof) { //func_send can't free a session, this is safe. + //Finally, even if there is no data to parse, connections signaled eof should be closed, so we call parse_func [Skotlex] session[i]->func_parse(i); //This should close the session immediately. } } @@ -870,7 +870,7 @@ int do_sockets(int next) if(!session[i]) continue; - + RFIFOFLUSH(i); // after parse, check client's RFIFO size to know if there is an invalid packet (too big and not parsed) if (session[i]->rdata_size == session[i]->max_rdata) { @@ -883,7 +883,7 @@ int do_sockets(int next) if (sockt->last_tick != socket_data_last_tick) { char buf[1024]; - + sprintf(buf, "In: %.03f kB/s (%.03f kB/s, Q: %.03f kB) | Out: %.03f kB/s (%.03f kB/s, Q: %.03f kB) | RAM: %.03f MB", socket_data_i/1024., socket_data_ci/1024., socket_data_qi/1024., socket_data_o/1024., socket_data_co/1024., socket_data_qo/1024., iMalloc->usage()/1024.); #ifdef _WIN32 SetConsoleTitle(buf); @@ -1232,7 +1232,7 @@ void socket_final(void) aFree(session[0]->rdata); aFree(session[0]->wdata); aFree(session[0]); - + aFree(session); } @@ -1396,7 +1396,7 @@ void socket_init(void) #endif CREATE(session, struct socket_data *, FD_SETSIZE); - + socket_config_read(SOCKET_CONF_FILENAME); // initialize last send-receive tick @@ -1414,7 +1414,7 @@ void socket_init(void) #endif ShowInfo("Server supports up to '"CL_WHITE"%"PRId64""CL_RESET"' concurrent connections.\n", rlim_cur); - + /* Hercules Plugin Manager */ HPM->share(session,"session"); } @@ -1498,11 +1498,11 @@ void socket_datasync(int fd, bool send) { WFIFOW(fd, 0) = 0x2b0a; WFIFOW(fd, 2) = p_len; - + for( i = 0; i < alen; i++ ) { WFIFOL(fd, 4 + ( i * 4 ) ) = data_list[i].length; } - + WFIFOSET(fd, p_len); } else { for( i = 0; i < alen; i++ ) { @@ -1602,7 +1602,7 @@ void send_shortlist_do_sends() void socket_defaults(void) { sockt = &sockt_s; - + sockt->fd_max = 0; /* */ sockt->stall_time = 60; diff --git a/src/common/socket.h b/src/common/socket.h index 42b0efe3b..b9c562a29 100644 --- a/src/common/socket.h +++ b/src/common/socket.h @@ -97,7 +97,7 @@ struct socket_data { ParseFunc func_parse; void* session_data; // stores application-specific data related to the session - + struct HPluginData **hdata; unsigned int hdatac; }; diff --git a/src/common/spinlock.h b/src/common/spinlock.h index bde36b8e5..85a78ed33 100644 --- a/src/common/spinlock.h +++ b/src/common/spinlock.h @@ -13,7 +13,7 @@ // For more information, see LICENCE in the main folder // // - + #include "../common/atomic.h" #include "../common/cbasetypes.h" #include "../common/thread.h" @@ -33,7 +33,7 @@ typedef struct __declspec( align(64) ) SPIN_LOCK{ typedef struct SPIN_LOCK{ volatile int32 lock; volatile int32 nest; // nesting level. - + volatile int32 sync_lock; } __attribute__((aligned(64))) SPIN_LOCK; #endif @@ -56,7 +56,7 @@ static forceinline void FinalizeSpinLock(SPIN_LOCK *lck){ static forceinline void EnterSpinLock(SPIN_LOCK *lck){ int tid = rathread_get_tid(); - + // Get Sync Lock && Check if the requester thread already owns the lock. // if it owns, increase nesting level getsynclock(&lck->sync_lock); @@ -67,18 +67,14 @@ static forceinline void EnterSpinLock(SPIN_LOCK *lck){ } // drop sync lock dropsynclock(&lck->sync_lock); - - + // Spin until we've got it ! while(1){ - - if(InterlockedCompareExchange(&lck->lock, tid, 0) == 0){ - - InterlockedIncrement(&lck->nest); - return; // Got Lock - } - - rathread_yield(); // Force ctxswitch to another thread. + if(InterlockedCompareExchange(&lck->lock, tid, 0) == 0){ + InterlockedIncrement(&lck->nest); + return; // Got Lock + } + rathread_yield(); // Force ctxswitch to another thread. } } @@ -88,12 +84,12 @@ static forceinline void LeaveSpinLock(SPIN_LOCK *lck){ int tid = rathread_get_tid(); getsynclock(&lck->sync_lock); - + if(InterlockedCompareExchange(&lck->lock, tid, tid) == tid){ // this thread owns the lock. if(InterlockedDecrement(&lck->nest) == 0) InterlockedExchange(&lck->lock, 0); // Unlock! } - + dropsynclock(&lck->sync_lock); } diff --git a/src/common/sql.c b/src/common/sql.c index c75b90cec..7f89e9828 100644 --- a/src/common/sql.c +++ b/src/common/sql.c @@ -1004,10 +1004,10 @@ void Sql_HerculesUpdateCheck(Sql* self) { FILE* ifp;/* index fp */ unsigned int performed = 0; StringBuf buf; - + if( self == NULL ) return;/* return silently, build has no mysql connection */ - + if( !( ifp = fopen("sql-files/upgrades/index.txt", "r") ) ) { ShowError("SQL upgrade index was not found!\n"); return; @@ -1055,7 +1055,7 @@ void Sql_HerculesUpdateCheck(Sql* self) { ShowMessage("%s",StrBuf->Value(&buf)); ShowSQL("To manually skip, type: 'sql update skip '\n"); } - + StrBuf->Destroy(&buf); } @@ -1063,21 +1063,21 @@ void Sql_HerculesUpdateSkip(Sql* self,const char *filename) { char path[41];// "sql-files/upgrades/" (19) + "yyyy-mm-dd--hh-mm" (17) + ".sql" (4) + 1 char timestamp[11];// "1360186680" (10) + 1 FILE* ifp;/* index fp */ - + if( !self ) { ShowError("SQL not hooked!\n"); return; } - + snprintf(path,41,"sql-files/upgrades/%s",filename); - + if( !( ifp = fopen(path, "r") ) ) { ShowError("Upgrade file '%s' was not found!\n",filename); return; } - + fseek (ifp,1,SEEK_SET);/* woo. skip the # */ - + if( fgets(timestamp,sizeof(timestamp),ifp) ) { unsigned int timestampui = (unsigned int)atol(timestamp); if( SQL_ERROR == SQL->Query(self, "SELECT 1 FROM `sql_updates` WHERE `timestamp` = '%u' LIMIT 1", timestampui) ) diff --git a/src/common/strlib.c b/src/common/strlib.c index 35e0c63b0..8b63b4161 100644 --- a/src/common/strlib.c +++ b/src/common/strlib.c @@ -62,11 +62,12 @@ char* jstrescapecpy (char* pt, const char* spt) //a escape character is found, the target's final length increases! [Skotlex] int i =0, j=0; - if (!spt) { //Return an empty string [Skotlex] + if (!spt) { + //Return an empty string [Skotlex] pt[0] = '\0'; return &pt[0]; } - + while (spt[i] != '\0') { switch (spt[i]) { case '\'': @@ -252,7 +253,8 @@ char* strtok_r_(char *s1, const char *s2, char **lasts) { // for NetBSD 5.x and possibly some Solaris versions. #if !(defined(WIN32) && defined(_MSC_VER) && _MSC_VER >= 1400) && !defined(HAVE_STRNLEN) /* Find the length of STRING, but scan at most MAXLEN characters. - If no '\0' terminator is found in that many characters, return MAXLEN. */ + * If no '\0' terminator is found in that many characters, return MAXLEN. + */ size_t strnlen(const char* string, size_t maxlen) { const char* end = (const char*)memchr(string, '\0', maxlen); return end ? (size_t) (end - string) : maxlen; @@ -1136,13 +1138,13 @@ void strlib_defaults(void) { 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; #else strlib->strnlen = NULL; #endif - + #if defined(WIN32) && defined(_MSC_VER) && _MSC_VER <= 1200 strlib->strtoull = strtoull; #else @@ -1155,7 +1157,7 @@ void strlib_defaults(void) { strlib->safesnprintf = safesnprintf; strlib->strline = strline; strlib->bin2hex = bin2hex; - + StrBuf->Malloc = StringBuf_Malloc; StrBuf->Init = StringBuf_Init; StrBuf->Printf = StringBuf_Printf; @@ -1167,7 +1169,7 @@ void strlib_defaults(void) { 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; diff --git a/src/common/strlib.h b/src/common/strlib.h index 8f61470cf..0c596cb8f 100644 --- a/src/common/strlib.h +++ b/src/common/strlib.h @@ -63,31 +63,31 @@ struct strlib_interface { char *(*trim) (char* str); char *(*normalize_name) (char* str,const char* delims); const char *(*stristr) (const char *haystack, const char *needle); - + /* only used when '!(defined(WIN32) && defined(_MSC_VER) && _MSC_VER >= 1400) && !defined(HAVE_STRNLEN)', needs to be defined at all times however */ size_t (*strnlen) (const char* string, size_t maxlen); /* only used when 'defined(WIN32) && defined(_MSC_VER) && _MSC_VER <= 1200', needs to be defined at all times however */ uint64 (*strtoull) (const char* str, char** endptr, int base); - + int (*e_mail_check) (char* email); int (*config_switch) (const char* str); - + /// strncpy that always null-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 null-terminates the buffer. /// Returns the size of the string (without null-terminator) /// or -1 if the buffer is too small. int (*safesnprintf) (char *buf, size_t sz, const char *fmt, ...) __attribute__((format(printf, 3, 4))); - + /// 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. @@ -119,14 +119,14 @@ struct sv_interface { /// @param svstate Parse state /// @return 1 if a field was parsed, 0 if done, -1 on error. int (*parse_next) (struct s_svstate* svstate); - + /// 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. @@ -134,20 +134,20 @@ struct sv_interface { /// Other entries are the start of fields (null-terminated). /// 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. diff --git a/src/common/thread.c b/src/common/thread.c index 1d0285302..a00bd6333 100644 --- a/src/common/thread.c +++ b/src/common/thread.c @@ -36,7 +36,7 @@ struct rAthread { unsigned int myID; - + RATHREAD_PRIO prio; rAthreadProc proc; void *param; @@ -62,7 +62,7 @@ static struct rAthread l_threads[RA_THREADS_MAX]; void rathread_init(void) { register unsigned int i; memset(&l_threads, 0x00, RA_THREADS_MAX * sizeof(struct rAthread) ); - + for(i = 0; i < RA_THREADS_MAX; i++){ l_threads[i].myID = i; } @@ -80,7 +80,7 @@ void rathread_init(void) { void rathread_final(void) { register unsigned int i; - + // Unterminated Threads Left? // Shouldn't happen .. // Kill 'em all! @@ -91,8 +91,7 @@ void rathread_final(void) { rathread_destroy(&l_threads[i]); } } - - + }//end: rathread_final() @@ -112,7 +111,7 @@ static void *raThreadMainRedirector( void *p ){ sigset_t set; // on Posix Thread platforms #endif void *ret; - + // Update myID @ TLS to right id. #ifdef HAS_TLS g_rathread_ID = ((rAthread*)p)->myID; @@ -129,7 +128,7 @@ static void *raThreadMainRedirector( void *p ){ sigaddset(&set, SIGPIPE); pthread_sigmask(SIG_BLOCK, &set, NULL); - + #endif @@ -181,14 +180,12 @@ rAthread *rathread_createEx(rAthreadProc entryPoint, void *param, size_t szStack break; } } - + if(handle == NULL){ ShowError("rAthread: cannot create new thread (entryPoint: %p) - no free thread slot found!", entryPoint); return NULL; } - - - + handle->proc = entryPoint; handle->param = param; @@ -197,7 +194,7 @@ rAthread *rathread_createEx(rAthreadProc entryPoint, void *param, size_t szStack #else pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, szStack); - + if(pthread_create(&handle->hThread, &attr, raThreadMainRedirector, (void*)handle) != 0){ handle->proc = NULL; handle->param = NULL; @@ -207,7 +204,7 @@ rAthread *rathread_createEx(rAthreadProc entryPoint, void *param, size_t szStack #endif rathread_prio_set( handle, prio ); - + return handle; }//end: rathread_createEx @@ -220,10 +217,9 @@ void rathread_destroy(rAthread *handle) { } #else if( pthread_cancel( handle->hThread ) == 0){ - // We have to join it, otherwise pthread wont re-cycle its internal resources assoc. with this thread. pthread_join( handle->hThread, NULL ); - + // Tell our manager to release resources ;) rat_thread_terminated(handle); } @@ -233,7 +229,7 @@ void rathread_destroy(rAthread *handle) { rAthread *rathread_self(void) { #ifdef HAS_TLS rAthread *handle = &l_threads[g_rathread_ID]; - + if(handle->proc != NULL) // entry point set, so its used! return handle; #else @@ -247,14 +243,13 @@ rAthread *rathread_self(void) { pthread_t hSelf; hSelf = pthread_self(); #endif - + for(i = 0; i < RA_THREADS_MAX; i++){ if(l_threads[i].hThread == hSelf && l_threads[i].proc != NULL) return &l_threads[i]; } - #endif - + return NULL; }//end: rathread_self() @@ -270,14 +265,12 @@ int rathread_get_tid(void) { #else return (intptr_t)pthread_self(); #endif - #endif - + }//end: rathread_get_tid() bool rathread_wait(rAthread *handle, void **out_exitCode) { - // Hint: // no thread data cleanup routine call here! // its managed by the callProxy itself.. diff --git a/src/common/thread.h b/src/common/thread.h index c7582366d..f00e7290d 100644 --- a/src/common/thread.h +++ b/src/common/thread.h @@ -104,8 +104,8 @@ RATHREAD_PRIO rathread_prio_get(rAthread *handle); * Tells the OS scheduler to yield the execution of the calling thread * * @note: this will not "pause" the thread, - * it just allows the OS to spent the remaining time - * of the slice to another thread. + * it just allows the OS to spend the remaining time + * of the slice to another thread. */ void rathread_yield(void); diff --git a/src/common/timer.c b/src/common/timer.c index 5d0a45b99..f2bfa98b3 100644 --- a/src/common/timer.c +++ b/src/common/timer.c @@ -59,7 +59,7 @@ time_t start_time; /*---------------------------- - * Timer debugging + * Timer debugging *----------------------------*/ struct timer_func_list { struct timer_func_list* next; @@ -101,31 +101,31 @@ char* search_timer_func_list(TimerFunc func) } /*---------------------------- - * Get tick time + * Get tick time *----------------------------*/ #if defined(ENABLE_RDTSC) static uint64 RDTSC_BEGINTICK = 0, RDTSC_CLOCK = 0; static __inline uint64 rdtsc_(void) { - register union{ - uint64 qw; - uint32 dw[2]; + register union { + uint64 qw; + uint32 dw[2]; } t; asm volatile("rdtsc":"=a"(t.dw[0]), "=d"(t.dw[1]) ); - + return t.qw; } static void rdtsc_calibrate(void){ uint64 t1, t2; int32 i; - + ShowStatus("Calibrating Timer Source, please wait... "); - + RDTSC_CLOCK = 0; - + for(i = 0; i < 5; i++){ t1 = rdtsc_(); usleep(1000000); //1000 MS @@ -133,9 +133,9 @@ static void rdtsc_calibrate(void){ RDTSC_CLOCK += (t2 - t1) / 1000; } RDTSC_CLOCK /= 5; - + RDTSC_BEGINTICK = rdtsc_(); - + ShowMessage(" done. (Frequency: %u Mhz)\n", (uint32)(RDTSC_CLOCK/1000) ); } @@ -233,7 +233,7 @@ int64 timer_gettick(void) { ////////////////////////////////////////////////////////////////////////// /*====================================== - * CORE : Timer Heap + * CORE : Timer Heap *--------------------------------------*/ /// Adds a timer to the timer_heap @@ -243,7 +243,7 @@ static void push_timer_heap(int tid) { } /*========================== - * Timer Management + * Timer Management *--------------------------*/ /// Returns a free timer id. @@ -281,7 +281,7 @@ static int acquire_timer(void) { /// Returns the timer's id. int timer_add(int64 tick, TimerFunc func, int id, intptr_t data) { int tid; - + tid = acquire_timer(); timer_data[tid].tick = tick; timer_data[tid].func = func; @@ -304,7 +304,7 @@ int timer_add_interval(int64 tick, TimerFunc func, int id, intptr_t data, int in tick, func, search_timer_func_list(func), id, data, DIFF_TICK(tick, timer->gettick())); return INVALID_TIMER; } - + tid = acquire_timer(); timer_data[tid].tick = tick; timer_data[tid].func = func; @@ -351,7 +351,7 @@ int64 timer_addtick(int tid, int64 tick) { /// Returns the new tick value, or -1 if it fails. int64 timer_settick(int tid, int64 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) ) { @@ -444,8 +444,8 @@ void timer_final(void) { struct timer_func_list *next; for( tfl=tfl_root; tfl != NULL; tfl = next ) { - next = tfl->next; // copy next pointer - aFree(tfl->name); // free structures + next = tfl->next; // copy next pointer + aFree(tfl->name); // free structures aFree(tfl); } diff --git a/src/common/utils.c b/src/common/utils.c index 79232b25c..d73aab066 100644 --- a/src/common/utils.c +++ b/src/common/utils.c @@ -92,7 +92,8 @@ void ShowDump(const void *buffer, size_t length) { #ifdef WIN32 static char* checkpath(char *path, const char *srcpath) -{ // just make sure the char*path is not const +{ + // just make sure the char*path is not const char *p=path; if(NULL!=path && NULL!=srcpath) while(*srcpath) { @@ -112,16 +113,15 @@ void findfile(const char *p, const char *pat, void (func)(const char*)) WIN32_FIND_DATAA FindFileData; HANDLE hFind; char tmppath[MAX_PATH+1]; - const char *path = (p ==NULL)? "." : p; const char *pattern = (pat==NULL)? "" : pat; - + checkpath(tmppath,path); if( PATHSEP != tmppath[strlen(tmppath)-1]) strcat(tmppath, "\\*"); else strcat(tmppath, "*"); - + hFind = FindFirstFileA(tmppath, &FindFileData); if (hFind != INVALID_HANDLE_VALUE) { @@ -153,7 +153,8 @@ void findfile(const char *p, const char *pat, void (func)(const char*)) #define MAX_DIR_PATH 2048 static char* checkpath(char *path, const char*srcpath) -{ // just make sure the char*path is not const +{ + // just make sure the char*path is not const char *p=path; if(NULL!=path && NULL!=srcpath) while(*srcpath) { @@ -170,9 +171,9 @@ static char* checkpath(char *path, const char*srcpath) void findfile(const char *p, const char *pat, void (func)(const char*)) { - DIR* dir; // pointer to the scanned directory. - struct dirent* entry; // pointer to one directory entry. - struct stat dir_stat; // used by stat(). + DIR* dir; ///< pointer to the scanned directory. + struct dirent* entry; ///< pointer to one directory entry. + struct stat dir_stat; ///< used by stat(). char tmppath[MAX_DIR_PATH+1]; char path[MAX_DIR_PATH+1]= "."; const char *pattern = (pat==NULL)? "" : pat; @@ -289,17 +290,17 @@ int32 MakeLongLE(int32 val) // Reads an uint16 in little-endian from the buffer uint16 GetUShort(const unsigned char* buf) { - return ( ((uint16)(buf[0])) ) - |( ((uint16)(buf[1])) << 0x08 ); + return ( ((uint16)(buf[0])) ) + | ( ((uint16)(buf[1])) << 0x08 ); } // Reads an uint32 in little-endian from the buffer uint32 GetULong(const unsigned char* buf) { - return ( ((uint32)(buf[0])) ) - |( ((uint32)(buf[1])) << 0x08 ) - |( ((uint32)(buf[2])) << 0x10 ) - |( ((uint32)(buf[3])) << 0x18 ); + return ( ((uint32)(buf[0])) ) + | ( ((uint32)(buf[1])) << 0x08 ) + | ( ((uint32)(buf[2])) << 0x10 ) + | ( ((uint32)(buf[3])) << 0x18 ); } // Reads an int32 in little-endian from the buffer @@ -356,15 +357,15 @@ bool HCache_check(const char *file) { time_t rtime; if( !(first = fopen(file,"rb")) ) - return false; + return false; if( file[0] == '.' && file[1] == '/' ) - file += 2; + file += 2; else if( file[0] == '.' ) - file++; - + file++; + snprintf(s_path, 255, "./cache/%s", file); - + if( !(second = fopen(s_path,"rb")) ) { fclose(first); return false; @@ -375,34 +376,34 @@ bool HCache_check(const char *file) { fclose(second); return false; } - + fstat(fileno(first), &bufa); fstat(fileno(second), &bufb); - + fclose(first); fclose(second); - + if( bufa.st_mtime > bufb.st_mtime ) return false; - + return true; } FILE *HCache_open(const char *file, const char *opt) { FILE *first; char s_path[255]; - + if( file[0] == '.' && file[1] == '/' ) file += 2; else if( file[0] == '.' ) file++; - + snprintf(s_path, 255, "./cache/%s", file); - + if( !(first = fopen(s_path,opt)) ) { return NULL; } - + if( opt[0] != 'r' ) { char dT[1];/* 1-byte key to ensure our method is the latest, we can modify to ensure the method matches */ dT[0] = HCACHE_KEY; @@ -410,19 +411,19 @@ FILE *HCache_open(const char *file, const char *opt) { hwrite(&HCache->recompile_time,sizeof(HCache->recompile_time),1,first); } fseek(first, 20, SEEK_SET);/* skip first 20, might wanna store something else later */ - + return first; } void HCache_init(void) { FILE *server; - + if( (server = fopen(SERVER_NAME,"rb")) ) { struct stat buf; - + fstat(fileno(server), &buf); HCache->recompile_time = buf.st_mtime; fclose(server); - + HCache->enabled = true; } else ShowWarning("Unable to open '%s', caching capabilities have been disabled!\n",SERVER_NAME); @@ -437,11 +438,10 @@ size_t hwrite(const void * ptr, size_t size, size_t count, FILE * stream) { } void HCache_defaults(void) { - HCache = &HCache_s; HCache->init = HCache_init; - + HCache->check = HCache_check; HCache->open = HCache_open; HCache->recompile_time = 0; diff --git a/src/common/winapi.h b/src/common/winapi.h index a8a38f30e..f53d9cbbd 100644 --- a/src/common/winapi.h +++ b/src/common/winapi.h @@ -2,10 +2,10 @@ #define STRICT -#define NTDDI_VERSION NTDDI_WIN2K +#define NTDDI_VERSION NTDDI_WIN2K #define _WIN32_WINNT 0x0500 -#define WINVER 0x0500 -#define _WIN32_IE 0x0600 +#define WINVER 0x0500 +#define _WIN32_IE 0x0600 #define WIN32_LEAN_AND_MEAN #define NOCOMM #define NOKANJI diff --git a/src/login/account_sql.c b/src/login/account_sql.c index 5f9357c81..adbb7914d 100644 --- a/src/login/account_sql.c +++ b/src/login/account_sql.c @@ -222,7 +222,7 @@ static bool account_db_sql_get_property(AccountDB* self, const char* key, char* if( strcmpi(key, "db_username") == 0 ) safesnprintf(buf, buflen, "%s", db->global_db_username); else - if( strcmpi(key, "db_password") == 0 ) + if( strcmpi(key, "db_password") == 0 ) safesnprintf(buf, buflen, "%s", db->global_db_password); else if( strcmpi(key, "db_database") == 0 ) @@ -248,7 +248,7 @@ static bool account_db_sql_get_property(AccountDB* self, const char* key, char* if( strcmpi(key, "db_username") == 0 ) safesnprintf(buf, buflen, "%s", db->db_username); else - if( strcmpi(key, "db_password") == 0 ) + if( strcmpi(key, "db_password") == 0 ) safesnprintf(buf, buflen, "%s", db->db_password); else if( strcmpi(key, "db_database") == 0 ) @@ -573,7 +573,7 @@ static bool mmo_auth_fromsql(AccountDB_SQL* db, struct mmo_account* acc, int acc SQL->GetData(sql_handle, 13, &data, NULL); acc->char_slots = (uint8)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 = (unsigned int)atol(data); - + SQL->FreeResult(sql_handle); return true; @@ -665,19 +665,19 @@ void mmo_save_accreg2(AccountDB* self, int fd, int account_id, int char_id) { Sql* sql_handle = ((AccountDB_SQL*)self)->accounts; AccountDB_SQL* db = (AccountDB_SQL*)self; int count = RFIFOW(fd, 12); - + if( count ) { int cursor = 14, i; char key[32], sval[254]; unsigned int index; - + for(i = 0; i < count; i++) { safestrncpy(key, (char*)RFIFOP(fd, cursor + 1), RFIFOB(fd, cursor)); cursor += RFIFOB(fd, cursor) + 1; - + index = RFIFOL(fd, cursor); cursor += 4; - + switch (RFIFOB(fd, cursor++)) { /* int */ case 0: @@ -700,24 +700,21 @@ void mmo_save_accreg2(AccountDB* self, int fd, int account_id, int char_id) { if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `account_id` = '%d' AND `key` = '%s' AND `index` = '%u' LIMIT 1", db->global_acc_reg_str_db, account_id, key, index) ) Sql_ShowDebug(sql_handle); break; - default: ShowError("mmo_save_accreg2: DA HOO UNKNOWN TYPE %d\n",RFIFOB(fd, cursor - 1)); return; } - } - } - } + void mmo_send_accreg2(AccountDB* self, int fd, int account_id, int char_id) { Sql* sql_handle = ((AccountDB_SQL*)self)->accounts; AccountDB_SQL* db = (AccountDB_SQL*)self; char* data; int plen = 0; size_t len; - + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `key`, `index`, `value` FROM `%s` WHERE `account_id`='%d'", db->global_acc_reg_str_db, account_id) ) Sql_ShowDebug(sql_handle); @@ -730,7 +727,7 @@ void mmo_send_accreg2(AccountDB* self, int fd, int account_id, int char_id) { WFIFOB(fd, 13) = 1;/* is string type */ WFIFOW(fd, 14) = 0;/* count */ plen = 16; - + /** * Vessel! * @@ -738,36 +735,35 @@ void mmo_send_accreg2(AccountDB* self, int fd, int account_id, int char_id) { * { keyLength(B), key(), index(L), valLength(B), val() } **/ while ( SQL_SUCCESS == SQL->NextRow(sql_handle) ) { - SQL->GetData(sql_handle, 0, &data, NULL); len = strlen(data)+1; - + WFIFOB(fd, plen) = (unsigned char)len;/* won't be higher; the column size is 32 */ plen += 1; - + safestrncpy((char*)WFIFOP(fd,plen), data, len); plen += len; - + SQL->GetData(sql_handle, 1, &data, NULL); - + WFIFOL(fd, plen) = (unsigned int)atol(data); plen += 4; - + SQL->GetData(sql_handle, 2, &data, NULL); len = strlen(data)+1; - + WFIFOB(fd, plen) = (unsigned char)len;/* won't be higher; the column size is 254 */ plen += 1; - + safestrncpy((char*)WFIFOP(fd,plen), data, len); plen += len; - + WFIFOW(fd, 14) += 1; - + if( plen > 60000 ) { WFIFOW(fd, 2) = plen; WFIFOSET(fd, plen); - + /* prepare follow up */ WFIFOHEAD(fd, 60000 + 300); WFIFOW(fd, 0) = 0x3804; @@ -780,16 +776,16 @@ void mmo_send_accreg2(AccountDB* self, int fd, int account_id, int char_id) { plen = 16; } } - + /* mark & go. */ WFIFOW(fd, 2) = plen; WFIFOSET(fd, plen); - + SQL->FreeResult(sql_handle); - + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `key`, `index`, `value` FROM `%s` WHERE `account_id`='%d'", db->global_acc_reg_num_db, account_id) ) Sql_ShowDebug(sql_handle); - + WFIFOHEAD(fd, 60000 + 300); WFIFOW(fd, 0) = 0x3804; /* 0x2 = length, set prior to being sent */ @@ -799,7 +795,7 @@ void mmo_send_accreg2(AccountDB* self, int fd, int account_id, int char_id) { WFIFOB(fd, 13) = 0;/* is int type */ WFIFOW(fd, 14) = 0;/* count */ plen = 16; - + /** * Vessel! * @@ -807,32 +803,31 @@ void mmo_send_accreg2(AccountDB* self, int fd, int account_id, int char_id) { * { keyLength(B), key(), index(L), value(L) } **/ while ( SQL_SUCCESS == SQL->NextRow(sql_handle) ) { - SQL->GetData(sql_handle, 0, &data, NULL); len = strlen(data)+1; - + WFIFOB(fd, plen) = (unsigned char)len;/* won't be higher; the column size is 32 */ plen += 1; - + safestrncpy((char*)WFIFOP(fd,plen), data, len); plen += len; - + SQL->GetData(sql_handle, 1, &data, NULL); - + WFIFOL(fd, plen) = (unsigned int)atol(data); plen += 4; - + SQL->GetData(sql_handle, 2, &data, NULL); - + WFIFOL(fd, plen) = atoi(data); plen += 4; - + WFIFOW(fd, 14) += 1; - + if( plen > 60000 ) { WFIFOW(fd, 2) = plen; WFIFOSET(fd, plen); - + /* prepare follow up */ WFIFOHEAD(fd, 60000 + 300); WFIFOW(fd, 0) = 0x3804; @@ -842,15 +837,15 @@ void mmo_send_accreg2(AccountDB* self, int fd, int account_id, int char_id) { WFIFOB(fd, 12) = 0;/* var type (only set when all vars have been sent, regardless of type) */ WFIFOB(fd, 13) = 0;/* is int type */ WFIFOW(fd, 14) = 0;/* count */ - + plen = 16; } } - + /* mark as complete & go. */ WFIFOB(fd, 12) = 1; WFIFOW(fd, 2) = plen; WFIFOSET(fd, plen); - + SQL->FreeResult(sql_handle); } diff --git a/src/login/ipban_sql.c b/src/login/ipban_sql.c index 82512b0f0..bfc90ad11 100644 --- a/src/login/ipban_sql.c +++ b/src/login/ipban_sql.c @@ -105,7 +105,7 @@ void ipban_final(void) if( login_config.ipban_cleanup_interval > 0 ) // release data timer->delete(cleanup_timer_id, ipban_cleanup); - + ipban_cleanup(0,0,0,0); // always clean up on login-server stop // close connections diff --git a/src/login/login.c b/src/login/login.c index 2a322ba40..c006d9c45 100644 --- a/src/login/login.c +++ b/src/login/login.c @@ -223,7 +223,7 @@ bool login_check_password(const char* md5key, int passwdenc, const char* passwd, { // password mode set to 1 -> md5(md5key, refpass) enable with // password mode set to 2 -> md5(refpass, md5key) enable with - + return ((passwdenc&0x01) && login->check_encrypted(md5key, refpass, passwd)) || ((passwdenc&0x02) && login->check_encrypted(refpass, md5key, passwd)); } @@ -767,7 +767,7 @@ void login_fromchar_accinfo(int fd, int account_id, int u_fd, int u_aid, int u_g safestrncpy((char*)WFIFOP(fd,119), acc->lastlogin, 24); WFIFOL(fd,143) = acc->logincount; WFIFOL(fd,147) = acc->state; - if (u_group >= acc->group_id) + if (u_group >= acc->group_id) safestrncpy((char*)WFIFOP(fd,151), acc->pincode, 5); else memset(WFIFOP(fd,151), '\0', 5); @@ -840,7 +840,7 @@ int login_parse_fromchar(int fd) if( j == 2 ) return 0; } } - + switch( command ) { case 0x2712: // request from char-server to authenticate an account @@ -880,7 +880,7 @@ int login_parse_fromchar(int fd) break; // Map server send information to change an email of an account via char-server - case 0x2722: // 0x2722 .L .40B .40B + case 0x2722: // 0x2722 .L .40B .40B if (RFIFOREST(fd) < 86) return 0; { @@ -912,7 +912,7 @@ int login_parse_fromchar(int fd) } break; - case 0x2728: // We receive account_reg2 from a char-server, and we send them to other map-servers. + case 0x2728: // We receive account_reg2 from a char-server, and we send them to other map-servers. if( RFIFOREST(fd) < 4 || RFIFOREST(fd) < RFIFOW(fd,2) ) return 0; { @@ -920,7 +920,7 @@ int login_parse_fromchar(int fd) } break; - case 0x272a: // Receiving of map-server via char-server an unban request + case 0x272a: // Receiving of map-server via char-server an unban request if( RFIFOREST(fd) < 6 ) return 0; { @@ -940,7 +940,7 @@ int login_parse_fromchar(int fd) login->fromchar_parse_account_offline(fd); break; - case 0x272d: // Receive list of all online accounts. [Skotlex] + case 0x272d: // Receive list of all online accounts. [Skotlex] if (RFIFOREST(fd) < 4 || RFIFOREST(fd) < RFIFOW(fd,2)) return 0; { @@ -974,7 +974,7 @@ int login_parse_fromchar(int fd) login->fromchar_parse_change_pincode(fd); } break; - + case 0x2739: // PIN Code was entered wrong too often if( RFIFOREST(fd) < 6 ) return 0; @@ -983,7 +983,7 @@ int login_parse_fromchar(int fd) return 0; } break; - + case 0x2740: // Accinfo request forwarded by charserver on mapserver's account if( RFIFOREST(fd) < 22 ) return 0; @@ -1045,7 +1045,7 @@ int login_mmo_auth_new(const char* userid, const char* pass, const char sex, con safestrncpy(acc.pincode, "\0", sizeof(acc.pincode)); acc.pincode_change = 0; acc.char_slots = 0; - + if( !accounts->create(accounts, &acc) ) return 0; @@ -1117,7 +1117,7 @@ int login_mmo_auth(struct login_session_data* sd, bool isServer) { ShowNotice("Empty userid (received pass: '%s', ip: %s)\n", sd->passwd, ip); return 0; // 0 = Unregistered ID } - + if( !accounts->load_str(accounts, &acc, sd->userid) ) { ShowNotice("Unknown account (account: %s, received pass: %s, ip: %s)\n", sd->userid, sd->passwd, ip); return 0; // 0 = Unregistered ID @@ -1139,7 +1139,7 @@ int login_mmo_auth(struct login_session_data* sd, bool isServer) { ShowNotice("Connection refused (account: %s, pass: %s, state: %d, ip: %s)\n", sd->userid, sd->passwd, acc.state, ip); return acc.state - 1; } - + if( login_config.client_hash_check && !isServer ) { struct client_hash_node *node = NULL; bool match = false; @@ -1302,12 +1302,12 @@ void login_auth_ok(struct login_session_data* sd) WFIFOW(fd,47+n*32+4) = ntows(htons(server[i].port)); // [!] LE byte order here [!] memcpy(WFIFOP(fd,47+n*32+6), server[i].name, 20); WFIFOW(fd,47+n*32+26) = server[i].users; - + if( server[i].type == CST_PAYING && sd->expiration_time > time(NULL) ) WFIFOW(fd,47+n*32+28) = CST_NORMAL; else WFIFOW(fd,47+n*32+28) = server[i].type; - + WFIFOW(fd,47+n*32+30) = server[i].new_; n++; } @@ -1634,10 +1634,10 @@ int login_parse_login(int fd) if( result == 2 ) return 0; } } - + switch( command ) { - case 0x0200: // New alive packet: structure: 0x200 .24B. used to verify if client is always alive. + case 0x0200: // New alive packet: structure: 0x200 .24B. used to verify if client is always alive. if (RFIFOREST(fd) < 26) return 0; login->parse_ping(fd, sd); @@ -1678,14 +1678,14 @@ int login_parse_login(int fd) } break; - case 0x01db: // Sending request of the coding key + case 0x01db: // Sending request of the coding key RFIFOSKIP(fd,2); { login->parse_request_coding_key(fd, sd); } break; - case 0x2710: // Connection request of a char-server + case 0x2710: // Connection request of a char-server if (RFIFOREST(fd) < 86) return 0; { @@ -1863,9 +1863,9 @@ int do_final(void) { struct client_hash_node *hn = login_config.client_hash_nodes; ShowStatus("Terminating...\n"); - + HPM->event(HPET_FINAL); - + while (hn) { struct client_hash_node *tmp = hn; hn = hn->next; @@ -1887,7 +1887,7 @@ int do_final(void) { accounts = NULL; // destroyed in account_engine login->online_db->destroy(login->online_db, NULL); login->auth_db->destroy(login->auth_db, NULL); - + for( i = 0; i < ARRAYLENGTH(server); ++i ) chrif_server_destroy(i); @@ -1984,7 +1984,7 @@ int do_init(int argc, char** argv) login_config_read((argc > 1) ? argv[1] : LOGIN_CONF_NAME); login->lan_config_read((argc > 2) ? argv[2] : LAN_CONF_NAME); - + for( i = 0; i < ARRAYLENGTH(server); ++i ) chrif_server_init(i); @@ -1994,7 +1994,7 @@ int do_init(int argc, char** argv) // initialize static and dynamic ipban system ipban_init(); - + // Online user database init login->online_db = idb_alloc(DB_OPT_RELEASE_DATA); timer->add_func_list(login->waiting_disconnect_timer, "login->waiting_disconnect_timer"); @@ -2022,23 +2022,23 @@ int do_init(int argc, char** argv) } HPM->event(HPET_INIT); - + // server port open & binding if( (login->fd = make_listen_bind(login_config.login_ip,login_config.login_port)) == -1 ) { ShowFatalError("Failed to bind to port '"CL_WHITE"%d"CL_RESET"'\n",login_config.login_port); exit(EXIT_FAILURE); } - + if( runflag != CORE_ST_STOP ) { shutdown_callback = do_shutdown_login; runflag = LOGINSERVER_ST_RUNNING; } - + ShowStatus("The login-server is "CL_GREEN"ready"CL_RESET" (Server is listening on the port %u).\n\n", login_config.login_port); login_log(0, "login server", 100, "login server started"); - + HPM->event(HPET_READY); - + return 0; } diff --git a/src/login/login.h b/src/login/login.h index f86abaf4b..4c9bbd8b7 100644 --- a/src/login/login.h +++ b/src/login/login.h @@ -46,7 +46,7 @@ struct login_session_data { int has_client_hash; int fd; - + time_t expiration_time; }; @@ -69,34 +69,34 @@ struct client_hash_node { struct Login_Config { - uint32 login_ip; // the address to bind to - uint16 login_port; // the port to bind to - unsigned int ipban_cleanup_interval; // interval (in seconds) to clean up expired IP bans - unsigned int ip_sync_interval; // interval (in minutes) to execute a DNS/IP update (for dynamic IPs) - bool log_login; // whether to log login server actions or not - char date_format[32]; // date format used in messages - bool new_account_flag,new_acc_length_limit; // auto-registration via _M/_F ? / if yes minimum length is 4? - int start_limited_time; // new account expiration time (-1: unlimited) - bool use_md5_passwds; // work with password hashes instead of plaintext passwords? - int group_id_to_connect; // required group id to connect - int min_group_id_to_connect; // minimum group id to connect - bool check_client_version; // check the clientversion set in the clientinfo ? - uint32 client_version_to_connect; // the client version needed to connect (if checking is enabled) - int allowed_regs; // account registration flood protection [Kevin] - int time_allowed; // time in seconds - - bool ipban; // perform IP blocking (via contents of `ipbanlist`) ? - bool dynamic_pass_failure_ban; // automatic IP blocking due to failed login attemps ? - unsigned int dynamic_pass_failure_ban_interval; // how far to scan the loginlog for password failures - unsigned int dynamic_pass_failure_ban_limit; // number of failures needed to trigger the ipban - unsigned int dynamic_pass_failure_ban_duration; // duration of the ipban - bool use_dnsbl; // dns blacklist blocking ? - char dnsbl_servs[1024]; // comma-separated list of dnsbl servers - - int client_hash_check; // flags for checking client md5 - struct client_hash_node *client_hash_nodes; // linked list containg md5 hash for each gm group - - // Advanced subnet check [LuzZza] + uint32 login_ip; ///< the address to bind to + uint16 login_port; ///< the port to bind to + unsigned int ipban_cleanup_interval; ///< interval (in seconds) to clean up expired IP bans + unsigned int ip_sync_interval; ///< interval (in minutes) to execute a DNS/IP update (for dynamic IPs) + bool log_login; ///< whether to log login server actions or not + char date_format[32]; ///< date format used in messages + bool new_account_flag,new_acc_length_limit; ///< auto-registration via _M/_F ? / if yes minimum length is 4? + int start_limited_time; ///< new account expiration time (-1: unlimited) + bool use_md5_passwds; ///< work with password hashes instead of plaintext passwords? + int group_id_to_connect; ///< required group id to connect + int min_group_id_to_connect; ///< minimum group id to connect + bool check_client_version; ///< check the clientversion set in the clientinfo ? + uint32 client_version_to_connect; ///< the client version needed to connect (if checking is enabled) + int allowed_regs; ///< account registration flood protection [Kevin] + int time_allowed; ///< time in seconds + + bool ipban; ///< perform IP blocking (via contents of `ipbanlist`) ? + bool dynamic_pass_failure_ban; ///< automatic IP blocking due to failed login attemps ? + unsigned int dynamic_pass_failure_ban_interval; ///< how far to scan the loginlog for password failures + unsigned int dynamic_pass_failure_ban_limit; ///< number of failures needed to trigger the ipban + unsigned int dynamic_pass_failure_ban_duration; ///< duration of the ipban + bool use_dnsbl; ///< dns blacklist blocking ? + char dnsbl_servs[1024]; ///< comma-separated list of dnsbl servers + + int client_hash_check; ///< flags for checking client md5 + struct client_hash_node *client_hash_nodes; ///< linked list containg md5 hash for each gm group + + /// Advanced subnet check [LuzZza] struct s_subnet { uint32 mask; uint32 char_ip; diff --git a/src/map/atcommand.c b/src/map/atcommand.c index dac51d153..254da5c5b 100644 --- a/src/map/atcommand.c +++ b/src/map/atcommand.c @@ -162,15 +162,15 @@ ACMD(send) { int len=0,off,end,type; long num; - + // read message type as hex number (without the 0x) if(!message || !*message || !((sscanf(message, "len %x", &type)==1 && (len=1)) || sscanf(message, "%x", &type)==1) ) { clif->message(fd, msg_txt(900)); // Usage: - clif->message(fd, msg_txt(901)); // @send len - clif->message(fd, msg_txt(902)); // @send {}* - clif->message(fd, msg_txt(903)); // Value: or S"" + clif->message(fd, msg_txt(901)); // @send len + clif->message(fd, msg_txt(902)); // @send {}* + clif->message(fd, msg_txt(903)); // Value: or S"" return false; } @@ -200,14 +200,13 @@ ACMD(send) } while(0) //define GET_VALUE if (type > 0 && type < MAX_PACKET_DB) { - if(len) {// show packet length sprintf(atcmd_output, msg_txt(904), type, packet_db[type].len); // Packet 0x%x length: %d clif->message(fd, atcmd_output); return true; } - + len=packet_db[type].len; off=2; if(len == 0) @@ -222,7 +221,7 @@ ACMD(send) } WFIFOHEAD(sd->fd, len); WFIFOW(sd->fd,0)=TOW(type); - + // parse packet contents SKIP_VALUE(message); while(*message != 0 && off < len){ @@ -266,7 +265,7 @@ ACMD(send) ++message; } } - + // parse string ++message; CHECK_EOS(message); @@ -344,7 +343,7 @@ ACMD(send) ++message; CHECK_EOS(message); } - + // terminate the string if(off < end) {// fill the rest with 0's @@ -358,7 +357,7 @@ ACMD(send) } SKIP_VALUE(message); } - + if(packet_db[type].len == -1) {// send dynamic packet WFIFOW(sd->fd,2)=TOW(off); WFIFOSET(sd->fd,off); @@ -388,21 +387,20 @@ ACMD(mapmove) { unsigned short map_index; short x = 0, y = 0; int16 m = -1; - + memset(map_name, '\0', sizeof(map_name)); - + if (!message || !*message || (sscanf(message, "%15s %hd %hd", map_name, &x, &y) < 3 && sscanf(message, "%15[^,],%hd,%hd", map_name, &x, &y) < 1)) { - clif->message(fd, msg_txt(909)); // Please enter a map (usage: @warp/@rura/@mapmove ). return false; } - + map_index = mapindex->name2id(map_name); if (map_index) m = map->mapindex2mapid(map_index); - + if (!map_index || m < 0) { // m < 0 means on different server or that map is disabled! [Kevin] clif->message(fd, msg_txt(1)); // Map not found. return false; @@ -412,7 +410,7 @@ ACMD(mapmove) { clif->message(fd, msg_txt(253)); // You already are at your destination! return false; } - + if ((x || y) && map->getcell(m, x, y, CELL_CHKNOPASS) && pc_get_group_level(sd) < battle_config.gm_ignore_warpable_area) { //This is to prevent the pc->setpos call from printing an error. clif->message(fd, msg_txt(2)); @@ -431,7 +429,7 @@ ACMD(mapmove) { clif->message(fd, msg_txt(1)); // Map not found. return false; } - + clif->message(fd, msg_txt(0)); // Warped. return true; } @@ -441,14 +439,14 @@ ACMD(mapmove) { *------------------------------------------*/ ACMD(where) { struct map_session_data* pl_sd; - + memset(atcmd_player_name, '\0', sizeof atcmd_player_name); - + if (!message || !*message || sscanf(message, "%23[^\n]", atcmd_player_name) < 1) { clif->message(fd, msg_txt(910)); // Please enter a player name (usage: @where ). return false; } - + pl_sd = map->nick2sd(atcmd_player_name); if (pl_sd == NULL || strncmp(pl_sd->status.name, atcmd_player_name, NAME_LENGTH) != 0 || @@ -457,10 +455,10 @@ ACMD(where) { clif->message(fd, msg_txt(3)); // Character not found. return false; } - + snprintf(atcmd_output, sizeof atcmd_output, "%s %s %d %d", pl_sd->status.name, mapindex_id2name(pl_sd->mapindex), pl_sd->bl.x, pl_sd->bl.y); clif->message(fd, atcmd_output); - + return true; } @@ -489,7 +487,7 @@ ACMD(jumpto) { clif->message(fd, msg_txt(3)); // Character not found. return false; } - + if (pl_sd->bl.m >= 0 && map->list[pl_sd->bl.m].flag.nowarpto && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE)) { clif->message(fd, msg_txt(247)); // You are not authorized to warp to this map. return false; @@ -513,21 +511,21 @@ ACMD(jumpto) { ACMD(jump) { short x = 0, y = 0; - + memset(atcmd_output, '\0', sizeof(atcmd_output)); - + sscanf(message, "%hd %hd", &x, &y); - + if (map->list[sd->bl.m].flag.noteleport && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE)) { clif->message(fd, msg_txt(248)); // You are not authorized to warp from your current map. return false; } - + if( pc_isdead(sd) ) { clif->message(fd, msg_txt(864)); // "You cannot use this command when dead." return false; } - + if ((x || y) && map->getcell(sd->bl.m, x, y, CELL_CHKNOPASS)) { //This is to prevent the pc->setpos call from printing an error. clif->message(fd, msg_txt(2)); @@ -539,7 +537,7 @@ ACMD(jump) clif->message(fd, msg_txt(253)); // You already are at your destination! return false; } - + pc->setpos(sd, sd->mapindex, x, y, CLR_TELEPORT); sprintf(atcmd_output, msg_txt(5), sd->bl.x, sd->bl.y); // Jumped to %d %d clif->message(fd, atcmd_output); @@ -565,24 +563,24 @@ ACMD(who) { */ int display_type = 1; int map_id = -1; - + if (stristr(info->command, "map") != NULL) { if (sscanf(message, "%15s %23s", map_name, player_name) < 1 || (map_id = map->mapname2mapid(map_name)) < 0) map_id = sd->bl.m; } else { sscanf(message, "%23s", player_name); } - + if (stristr(info->command, "2") != NULL) display_type = 2; else if (stristr(info->command, "3") != NULL) display_type = 3; - + level = pc_get_group_level(sd); 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) || pc_isinvisible(pl_sd)) && 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)) @@ -598,7 +596,7 @@ ACMD(who) { } case 3: { if (pc_has_permission(sd, PC_PERM_WHO_DISPLAY_AID)) - 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(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 StrBuf->Printf(&buf, msg_txt(344), pcg->get_name(pl_sd->group)); // "(%s) " @@ -608,7 +606,7 @@ ACMD(who) { default: { struct party_data *p = party->search(pl_sd->status.party_id); struct guild *g = pl_sd->guild; - + StrBuf->Printf(&buf, msg_txt(343), pl_sd->status.name); // "Name: %s " if (pc_get_group_id(pl_sd) > 0) // Player title, if exists StrBuf->Printf(&buf, msg_txt(344), pcg->get_name(pl_sd->group)); // "(%s) " @@ -625,7 +623,7 @@ ACMD(who) { } } mapit->free(iter); - + if (map_id < 0) { if (count == 0) StrBuf->Printf(&buf, msg_txt(28)); // No player found. @@ -659,32 +657,32 @@ ACMD(whogm) char player_name[NAME_LENGTH]; struct guild *g; struct party_data *p; - + memset(atcmd_output, '\0', sizeof(atcmd_output)); memset(match_text, '\0', sizeof(match_text)); memset(player_name, '\0', sizeof(player_name)); - + if (sscanf(message, "%199[^\n]", match_text) < 1) strcpy(match_text, ""); for (j = 0; match_text[j]; j++) match_text[j] = TOLOWER(match_text[j]); - + count = 0; 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) ) { pl_level = pc_get_group_level(pl_sd); if (!pl_level) continue; - + if (match_text[0]) { memcpy(player_name, pl_sd->status.name, NAME_LENGTH); for (j = 0; player_name[j]; j++) player_name[j] = TOLOWER(player_name[j]); - // search with no case sensitive + // search with no case sensitive if (strstr(player_name, match_text) == NULL) continue; } @@ -696,28 +694,28 @@ ACMD(whogm) count++; continue; } - + sprintf(atcmd_output, msg_txt(914), // Name: %s (GM:%d) | Location: %s %d %d pl_sd->status.name, pl_level, mapindex_id2name(pl_sd->mapindex), pl_sd->bl.x, pl_sd->bl.y); clif->message(fd, atcmd_output); - + sprintf(atcmd_output, msg_txt(915), // BLvl: %d | Job: %s (Lvl: %d) pl_sd->status.base_level, pc->job_name(pl_sd->status.class_), pl_sd->status.job_level); clif->message(fd, atcmd_output); - + p = party->search(pl_sd->status.party_id); g = pl_sd->guild; - - sprintf(atcmd_output,msg_txt(916), // Party: '%s' | Guild: '%s' - p?p->party.name:msg_txt(917), g?g->name:msg_txt(917)); // None. - + + sprintf(atcmd_output,msg_txt(916), // Party: '%s' | Guild: '%s' + p?p->party.name:msg_txt(917), g?g->name:msg_txt(917)); // None. + clif->message(fd, atcmd_output); count++; } mapit->free(iter); - + if (count == 0) clif->message(fd, msg_txt(150)); // No GM found. else if (count == 1) @@ -726,23 +724,23 @@ ACMD(whogm) sprintf(atcmd_output, msg_txt(152), count); // %d GMs found. clif->message(fd, atcmd_output); } - + return true; } /*========================================== * *------------------------------------------*/ -ACMD(save) { - +ACMD(save) +{ pc->setsavepoint(sd, sd->mapindex, sd->bl.x, sd->bl.y); if (sd->status.pet_id > 0 && sd->pd) intif->save_petdata(sd->status.account_id, &sd->pd->pet); - + chrif->save(sd,0); - + clif->message(fd, msg_txt(6)); // Your save point has been changed. - + return true; } @@ -751,7 +749,7 @@ ACMD(save) { *------------------------------------------*/ ACMD(load) { int16 m; - + m = map->mapindex2mapid(sd->status.save_point.map); if (m >= 0 && map->list[m].flag.nowarpto && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE)) { clif->message(fd, msg_txt(249)); // You are not authorized to warp to your save map. @@ -761,10 +759,10 @@ ACMD(load) { clif->message(fd, msg_txt(248)); // You are not authorized to warp from your current map. return false; } - + pc->setpos(sd, sd->status.save_point.map, sd->status.save_point.x, sd->status.save_point.y, CLR_OUTSIGHT); clif->message(fd, msg_txt(7)); // Warping to save point.. - + return true; } @@ -774,30 +772,30 @@ ACMD(load) { ACMD(speed) { int speed; - + memset(atcmd_output, '\0', sizeof(atcmd_output)); - + if (!message || !*message || sscanf(message, "%d", &speed) < 1) { sprintf(atcmd_output, msg_txt(918), MIN_WALK_SPEED, MAX_WALK_SPEED); // Please enter a speed value (usage: @speed <%d-%d>). clif->message(fd, atcmd_output); return false; } - + sd->state.permanent_speed = 0; - + if (speed < 0) sd->base_status.speed = DEFAULT_WALK_SPEED; else sd->base_status.speed = cap_value(speed, MIN_WALK_SPEED, MAX_WALK_SPEED); - + if( sd->base_status.speed != DEFAULT_WALK_SPEED ) { sd->state.permanent_speed = 1; // Set lock when set to non-default speed. clif->message(fd, msg_txt(8)); // Speed changed. } else clif->message(fd, msg_txt(172)); //Speed returned to normal. - + status_calc_bl(&sd->bl, SCB_SPEED); - + return true; } @@ -808,14 +806,14 @@ ACMD(storage) { if (sd->npc_id || sd->state.vending || sd->state.buyingstore || sd->state.trading || sd->state.storage_flag) return false; - + if (storage->open(sd) == 1) { //Already open. clif->message(fd, msg_txt(250)); return false; } - + clif->message(fd, msg_txt(919)); // Storage opened. - + return true; } @@ -829,20 +827,20 @@ ACMD(guildstorage) clif->message(fd, msg_txt(252)); return false; } - + if (sd->npc_id || sd->state.vending || sd->state.buyingstore || sd->state.trading) return false; - + if (sd->state.storage_flag == 1) { clif->message(fd, msg_txt(250)); return false; } - + if (sd->state.storage_flag == 2) { clif->message(fd, msg_txt(251)); return false; } - + if( gstorage->open(sd) ) { clif->message(fd, msg_txt(1201)); // Your guild's storage has already been opened by another member, try again later. return false; @@ -858,30 +856,30 @@ ACMD(guildstorage) ACMD(option) { int param1 = 0, param2 = 0, param3 = 0; - + if (!message || !*message || sscanf(message, "%d %d %d", ¶m1, ¶m2, ¶m3) < 1 || param1 < 0 || param2 < 0 || param3 < 0) {// failed to match the parameters so inform the user of the options const char* text; - + // attempt to find the setting information for this command text = atcommand_help_string( info ); - + // notify the user of the requirement to enter an option clif->message(fd, msg_txt(921)); // Please enter at least one option. - + if( text ) {// send the help text associated with this command clif->messageln( fd, text ); } - + return false; } - + sd->sc.opt1 = param1; sd->sc.opt2 = param2; pc->setoption(sd, param3); - + clif->message(fd, msg_txt(9)); // Options changed. - + return true; } @@ -896,10 +894,10 @@ ACMD(hide) { else status->set_viewdata(&sd->bl, sd->status.class_); clif->message(fd, msg_txt(10)); // Invisible: Off - + // increment the number of pvp players on the map map->list[sd->bl.m].users_pvp++; - + if( map->list[sd->bl.m].flag.pvp && !map->list[sd->bl.m].flag.pvp_nocalcrank ) { // register the player for ranking calculations sd->pvp_timer = timer->add( timer->gettick() + 200, pc->calc_pvprank_timer, sd->bl.id, 0 ); @@ -910,10 +908,10 @@ ACMD(hide) { sd->sc.option |= OPTION_INVISIBLE; sd->vd.class_ = INVISIBLE_CLASS; clif->message(fd, msg_txt(11)); // Invisible: On - + // decrement the number of pvp players on the map map->list[sd->bl.m].users_pvp--; - + if( map->list[sd->bl.m].flag.pvp && !map->list[sd->bl.m].flag.pvp_nocalcrank && sd->pvp_timer != INVALID_TIMER ) { // unregister the player for ranking timer->delete( sd->pvp_timer, pc->calc_pvprank_timer ); @@ -921,7 +919,7 @@ ACMD(hide) { } } clif->changeoption(&sd->bl); - + return true; } @@ -931,11 +929,11 @@ ACMD(hide) { ACMD(jobchange) { int job = 0, upper = 0; const char* text; - + if (!message || !*message || sscanf(message, "%d %d", &job, &upper) < 1) { upper = 0; - - if( message ) { + + if( message ) { int i; bool found = false; @@ -946,7 +944,7 @@ ACMD(jobchange) { found = true; } } - + // High Jobs, Babies and Third for( i = JOB_NOVICE_HIGH; i < JOB_MAX && !found; i++ ){ if (strncmpi(message, pc->job_name(i), 16) == 0) { @@ -954,7 +952,7 @@ ACMD(jobchange) { found = true; } } - + if (!found) { text = atcommand_help_string(info); if (text) @@ -965,14 +963,14 @@ ACMD(jobchange) { } /* WHY DO WE LIST THEM THEN? */ // Deny direct transformation into dummy jobs - if (job == JOB_KNIGHT2 || job == JOB_CRUSADER2 || job == JOB_WEDDING || job == JOB_XMAS || job == JOB_SUMMER - || job == JOB_LORD_KNIGHT2 || job == JOB_PALADIN2 || job == JOB_BABY_KNIGHT2 || job == JOB_BABY_CRUSADER2 || job == JOB_STAR_GLADIATOR2 - || (job >= JOB_RUNE_KNIGHT2 && job <= JOB_MECHANIC_T2) || (job >= JOB_BABY_RUNE2 && job <= JOB_BABY_MECHANIC2) - ) { + if (job == JOB_KNIGHT2 || job == JOB_CRUSADER2 || job == JOB_WEDDING || job == JOB_XMAS || job == JOB_SUMMER + || job == JOB_LORD_KNIGHT2 || job == JOB_PALADIN2 || job == JOB_BABY_KNIGHT2 || job == JOB_BABY_CRUSADER2 || job == JOB_STAR_GLADIATOR2 + || (job >= JOB_RUNE_KNIGHT2 && job <= JOB_MECHANIC_T2) || (job >= JOB_BABY_RUNE2 && job <= JOB_BABY_MECHANIC2) + ) { clif->message(fd, msg_txt(923)); //"You can not change to this job by command." return true; } - + if (pcdb_checkid(job)) { if (pc->jobchange(sd, job, upper) == 0) clif->message(fd, msg_txt(12)); // Your job has been changed. @@ -982,11 +980,11 @@ ACMD(jobchange) { } } else { text = atcommand_help_string(info); - if (text) - clif->messageln(fd, text); + if (text) + clif->messageln(fd, text); return false; } - + return true; } @@ -1022,15 +1020,15 @@ ACMD(alive) ACMD(kami) { unsigned int color=0; - + memset(atcmd_output, '\0', sizeof(atcmd_output)); - + if(*(info->command + 4) != 'c' && *(info->command + 4) != 'C') { if (!message || !*message) { clif->message(fd, msg_txt(980)); // Please enter a message (usage: @kami ). return false; } - + sscanf(message, "%199[^\n]", atcmd_output); if (stristr(info->command, "l") != NULL) clif->broadcast(&sd->bl, atcmd_output, strlen(atcmd_output) + 1, BC_DEFAULT, ALL_SAMEMAP); @@ -1041,7 +1039,7 @@ ACMD(kami) clif->message(fd, msg_txt(981)); // Please enter color and message (usage: @kamic ). return false; } - + if(color > 0xFFFFFF) { clif->message(fd, msg_txt(982)); // Invalid color. return false; @@ -1057,13 +1055,13 @@ ACMD(kami) ACMD(heal) { int hp = 0, sp = 0; // [Valaris] thanks to fov - + sscanf(message, "%d %d", &hp, &sp); - + // some overflow checks if( hp == INT_MIN ) hp++; if( sp == INT_MIN ) sp++; - + if ( hp == 0 && sp == 0 ) { if (!status_percent_heal(&sd->bl, 100, 100)) clif->message(fd, msg_txt(157)); // HP and SP have already been recovered. @@ -1071,7 +1069,7 @@ ACMD(heal) clif->message(fd, msg_txt(17)); // HP, SP recovered. return true; } - + if ( hp > 0 && sp >= 0 ) { if(!status->heal(&sd->bl, hp, sp, 0)) clif->message(fd, msg_txt(157)); // HP and SP are already with the good value. @@ -1079,14 +1077,14 @@ ACMD(heal) clif->message(fd, msg_txt(17)); // HP, SP recovered. return true; } - + if ( hp < 0 && sp <= 0 ) { status->damage(NULL, &sd->bl, -hp, -sp, 0, 0); clif->damage(&sd->bl,&sd->bl, 0, 0, -hp, 0, 4, 0); clif->message(fd, msg_txt(156)); // HP or/and SP modified. return true; } - + //Opposing signs. if ( hp ) { if (hp > 0) @@ -1096,14 +1094,14 @@ ACMD(heal) clif->damage(&sd->bl,&sd->bl, 0, 0, -hp, 0, 4, 0); } } - + if ( sp ) { if (sp > 0) status->heal(&sd->bl, 0, sp, 0); else status->damage(NULL, &sd->bl, 0, -sp, 0, 0); } - + clif->message(fd, msg_txt(156)); // HP or/and SP modified. return true; } @@ -1119,7 +1117,7 @@ ACMD(item) struct item item_tmp; struct item_data *item_data; int get_count, i; - + memset(item_name, '\0', sizeof(item_name)); if (!strcmpi(info->command,"itembound") && (!message || !*message || ( @@ -1128,24 +1126,24 @@ ACMD(item) ))) { clif->message(fd, msg_txt(295)); // Please enter an item name or ID (usage: @itembound ). return false; - } else if (!message || !*message || ( - sscanf(message, "\"%99[^\"]\" %d", item_name, &number) < 1 && - sscanf(message, "%99s %d", item_name, &number) < 1 )) - { - clif->message(fd, msg_txt(983)); // Please enter an item name or ID (usage: @item ). + } else if (!message || !*message + || ( sscanf(message, "\"%99[^\"]\" %d", item_name, &number) < 1 + && sscanf(message, "%99s %d", item_name, &number) < 1 + )) { + clif->message(fd, msg_txt(983)); // Please enter an item name or ID (usage: @item ). return false; } - + if (number <= 0) number = 1; - + if ((item_data = itemdb->search_name(item_name)) == NULL && (item_data = itemdb->exists(atoi(item_name))) == NULL) { clif->message(fd, msg_txt(19)); // Invalid item ID or name. return false; } - + if(!strcmpi(info->command,"itembound") ) { if( !(bound >= IBT_MIN && bound <= IBT_MAX) ) { clif->message(fd, msg_txt(298)); // Invalid bound type @@ -1178,9 +1176,9 @@ ACMD(item) clif->message(fd, msg_txt(498)); // Cannot create bounded pet eggs or pet armors. return false; } - get_count = 1; + get_count = 1; } - + for (i = 0; i < number; i += get_count) { // if not pet egg if (!pet->create_egg(sd, item_id)) { @@ -1188,12 +1186,12 @@ ACMD(item) item_tmp.nameid = item_id; item_tmp.identify = 1; item_tmp.bound = (unsigned char)bound; - + if ((flag = pc->additem(sd, &item_tmp, get_count, LOG_TYPE_COMMAND))) clif->additem(sd, 0, 0, flag); } } - + if (flag == 0) clif->message(fd, msg_txt(18)); // Item created. return true; @@ -1210,24 +1208,24 @@ ACMD(item2) int item_id, number = 0, bound = 0; int identify = 0, refine = 0, attr = 0; int c1 = 0, c2 = 0, c3 = 0, c4 = 0; - + memset(item_name, '\0', sizeof(item_name)); - + if (!strcmpi(info->command,"itembound2") && (!message || !*message || ( sscanf(message, "\"%99[^\"]\" %d %d %d %d %d %d %d %d %d", item_name, &number, &identify, &refine, &attr, &c1, &c2, &c3, &c4, &bound) < 10 && sscanf(message, "%99s %d %d %d %d %d %d %d %d %d", item_name, &number, &identify, &refine, &attr, &c1, &c2, &c3, &c4, &bound) < 10 ))) { clif->message(fd, msg_txt(296)); // Please enter all parameters (usage: @itembound2 clif->message(fd, msg_txt(297)); // ). return false; - } else if ( !message || !*message || ( - sscanf(message, "\"%99[^\"]\" %d %d %d %d %d %d %d %d", item_name, &number, &identify, &refine, &attr, &c1, &c2, &c3, &c4) < 9 && - sscanf(message, "%99s %d %d %d %d %d %d %d %d", item_name, &number, &identify, &refine, &attr, &c1, &c2, &c3, &c4) < 9 - )) { + } else if ( !message || !*message + || ( sscanf(message, "\"%99[^\"]\" %d %d %d %d %d %d %d %d", item_name, &number, &identify, &refine, &attr, &c1, &c2, &c3, &c4) < 9 + && sscanf(message, "%99s %d %d %d %d %d %d %d %d", item_name, &number, &identify, &refine, &attr, &c1, &c2, &c3, &c4) < 9 + )) { clif->message(fd, msg_txt(984)); // Please enter all parameters (usage: @item2 clif->message(fd, msg_txt(985)); // ). return false; } - + if (number <= 0) number = 1; @@ -1240,7 +1238,7 @@ ACMD(item2) if ((item_data = itemdb->search_name(item_name)) != NULL || (item_data = itemdb->exists(atoi(item_name))) != NULL) item_id = item_data->nameid; - + if (item_id > 500) { int flag = 0; int loop, get_count, i; @@ -1253,7 +1251,7 @@ ACMD(item2) clif->message(fd, msg_txt(498)); // Cannot create bounded pet eggs or pet armors. return false; } - loop = number; + loop = number; get_count = 1; if (item_data->type == IT_PETEGG) { identify = 1; @@ -1278,18 +1276,18 @@ ACMD(item2) item_tmp.card[1] = c2; item_tmp.card[2] = c3; item_tmp.card[3] = c4; - + if ((flag = pc->additem(sd, &item_tmp, get_count, LOG_TYPE_COMMAND))) clif->additem(sd, 0, 0, flag); } - + if (flag == 0) clif->message(fd, msg_txt(18)); // Item created. } else { clif->message(fd, msg_txt(19)); // Invalid item ID or name. return false; } - + return true; } @@ -1299,14 +1297,14 @@ ACMD(item2) ACMD(itemreset) { int i; - + for (i = 0; i < MAX_INVENTORY; i++) { if (sd->status.inventory[i].amount && sd->status.inventory[i].equip == 0) { pc->delitem(sd, i, sd->status.inventory[i].amount, 0, 0, LOG_TYPE_COMMAND); } } clif->message(fd, msg_txt(20)); // All of your items have been removed. - + return true; } @@ -1318,12 +1316,12 @@ ACMD(baselevelup) int level=0, i=0, status_point=0; level = atoi(message); - + if (!message || !*message || !level) { clif->message(fd, msg_txt(986)); // Please enter a level adjustment (usage: @lvup/@blevel/@baselvlup ). return false; } - + if (level > 0) { if (sd->status.base_level >= pc->maxbaselv(sd)) { // check for max level by Valaris clif->message(fd, msg_txt(47)); // Base level can't go any higher. @@ -1333,7 +1331,7 @@ ACMD(baselevelup) level = pc->maxbaselv(sd) - sd->status.base_level; for (i = 0; i < level; i++) status_point += pc->gets_status_point(sd->status.base_level + i); - + sd->status.status_point += status_point; sd->status.base_level += (unsigned int)level; status_calc_pc(sd, SCO_FORCE); @@ -1377,9 +1375,9 @@ ACMD(baselevelup) ACMD(joblevelup) { int level=0; - + level = atoi(message); - + if (!message || !*message || !level) { clif->message(fd, msg_txt(987)); // Please enter a level adjustment (usage: @joblvup/@jlevel/@joblvlup ). return false; @@ -1405,7 +1403,7 @@ ACMD(joblevelup) level = sd->status.job_level-1; sd->status.job_level -= (unsigned int)level; if (sd->status.skill_point < level) - pc->resetskill(sd,0); //Reset skills since we need to subtract more points. + pc->resetskill(sd,0); //Reset skills since we need to subtract more points. if (sd->status.skill_point < level) sd->status.skill_point = 0; else @@ -1418,7 +1416,7 @@ ACMD(joblevelup) clif->updatestatus(sd, SP_NEXTJOBEXP); clif->updatestatus(sd, SP_SKILLPOINT); status_calc_pc(sd, SCO_FORCE); - + return true; } @@ -1429,7 +1427,7 @@ ACMD(help) { const char *command_name = NULL; char *default_command = "help"; AtCommandInfo *tinfo = NULL; - + if (!message || !*message) { command_name = default_command; // If no command_name specified, display help for @help. } else { @@ -1437,33 +1435,33 @@ ACMD(help) { ++message; command_name = atcommand->check_alias(message); } - + if (!atcommand->can_use2(sd, command_name, COMMAND_ATCOMMAND)) { sprintf(atcmd_output, msg_txt(153), message); // "%s is Unknown Command" clif->message(fd, atcmd_output); atcommand->get_suggestions(sd, command_name, true); return false; } - + tinfo = atcommand->get_info_byname(atcommand->check_alias(command_name)); - + if ( !tinfo || tinfo->help == NULL ) { sprintf(atcmd_output, msg_txt(988), atcommand->at_symbol, command_name); // There is no help for %c%s. clif->message(fd, atcmd_output); atcommand->get_suggestions(sd, command_name, true); return false; } - + sprintf(atcmd_output, msg_txt(989), atcommand->at_symbol, command_name); // Help for command %c%s: clif->message(fd, atcmd_output); - + { // Display aliases DBIterator* iter; AtCommandInfo *command_info; AliasInfo *alias_info = NULL; StringBuf buf; bool has_aliases = false; - + StrBuf->Init(&buf); StrBuf->AppendStr(&buf, msg_txt(990)); // Available aliases: command_info = atcommand->get_info_byname(command_name); @@ -1479,7 +1477,7 @@ ACMD(help) { clif->message(fd, StrBuf->Value(&buf)); StrBuf->Destroy(&buf); } - + // Display help contents clif->message(fd, tinfo->help); return true; @@ -1512,16 +1510,16 @@ int atcommand_pvpoff_sub(struct block_list *bl,va_list ap) return 0; } -ACMD(pvpoff) { - +ACMD(pvpoff) +{ if (!map->list[sd->bl.m].flag.pvp) { clif->message(fd, msg_txt(160)); // PvP is already Off. return false; } - + map->zone_change2(sd->bl.m,map->list[sd->bl.m].prev_zone); map->list[sd->bl.m].flag.pvp = 0; - + if (!battle_config.pk_mode) { clif->map_property_mapall(sd->bl.m, MAPPROPERTY_NOTHING); clif->maptypeproperty2(&sd->bl,ALL_SAMEMAP); @@ -1549,24 +1547,24 @@ int atcommand_pvpon_sub(struct block_list *bl,va_list ap) return 0; } -ACMD(pvpon) { - +ACMD(pvpon) +{ if (map->list[sd->bl.m].flag.pvp) { clif->message(fd, msg_txt(161)); // PvP is already On. return false; } - + map->zone_change2(sd->bl.m,strdb_get(map->zone_db, MAP_ZONE_PVP_NAME)); map->list[sd->bl.m].flag.pvp = 1; - + if (!battle_config.pk_mode) {// display pvp circle and rank clif->map_property_mapall(sd->bl.m, MAPPROPERTY_FREEPVPZONE); clif->maptypeproperty2(&sd->bl,ALL_SAMEMAP); map->foreachinmap(atcommand->pvpon_sub,sd->bl.m, BL_PC); } - + clif->message(fd, msg_txt(32)); // PvP: On. - + return true; } @@ -1574,38 +1572,38 @@ ACMD(pvpon) { * *------------------------------------------*/ ACMD(gvgoff) { - + if (!map->list[sd->bl.m].flag.gvg) { clif->message(fd, msg_txt(162)); // GvG is already Off. return false; } - + map->zone_change2(sd->bl.m,map->list[sd->bl.m].prev_zone); map->list[sd->bl.m].flag.gvg = 0; clif->map_property_mapall(sd->bl.m, MAPPROPERTY_NOTHING); clif->maptypeproperty2(&sd->bl,ALL_SAMEMAP); map->foreachinmap(atcommand->stopattack,sd->bl.m, BL_CHAR, 0); clif->message(fd, msg_txt(33)); // GvG: Off. - + return true; } /*========================================== * *------------------------------------------*/ -ACMD(gvgon) { - +ACMD(gvgon) +{ if (map->list[sd->bl.m].flag.gvg) { clif->message(fd, msg_txt(163)); // GvG is already On. return false; } - + map->zone_change2(sd->bl.m,strdb_get(map->zone_db, MAP_ZONE_GVG_NAME)); map->list[sd->bl.m].flag.gvg = 1; clif->map_property_mapall(sd->bl.m, MAPPROPERTY_AGITZONE); clif->maptypeproperty2(&sd->bl,ALL_SAMEMAP); clif->message(fd, msg_txt(34)); // GvG: On. - + return true; } @@ -1615,16 +1613,16 @@ ACMD(gvgon) { ACMD(model) { int hair_style = 0, hair_color = 0, cloth_color = 0; - + memset(atcmd_output, '\0', sizeof(atcmd_output)); - + if (!message || !*message || sscanf(message, "%d %d %d", &hair_style, &hair_color, &cloth_color) < 1) { sprintf(atcmd_output, msg_txt(991), // Please enter at least one value (usage: @model ). MIN_HAIR_STYLE, MAX_HAIR_STYLE, MIN_HAIR_COLOR, MAX_HAIR_COLOR, MIN_CLOTH_COLOR, MAX_CLOTH_COLOR); clif->message(fd, atcmd_output); return false; } - + if (hair_style >= MIN_HAIR_STYLE && hair_style <= MAX_HAIR_STYLE && hair_color >= MIN_HAIR_COLOR && hair_color <= MAX_HAIR_COLOR && cloth_color >= MIN_CLOTH_COLOR && cloth_color <= MAX_CLOTH_COLOR) { @@ -1636,7 +1634,7 @@ ACMD(model) clif->message(fd, msg_txt(37)); // An invalid number was specified. return false; } - + return true; } @@ -1646,15 +1644,15 @@ ACMD(model) ACMD(dye) { int cloth_color = 0; - + memset(atcmd_output, '\0', sizeof(atcmd_output)); - + if (!message || !*message || sscanf(message, "%d", &cloth_color) < 1) { sprintf(atcmd_output, msg_txt(992), MIN_CLOTH_COLOR, MAX_CLOTH_COLOR); // Please enter a clothes color (usage: @dye/@ccolor ). clif->message(fd, atcmd_output); return false; } - + if (cloth_color >= MIN_CLOTH_COLOR && cloth_color <= MAX_CLOTH_COLOR) { pc->changelook(sd, LOOK_CLOTHES_COLOR, cloth_color); clif->message(fd, msg_txt(36)); // Appearance changed. @@ -1662,7 +1660,7 @@ ACMD(dye) clif->message(fd, msg_txt(37)); // An invalid number was specified. return false; } - + return true; } @@ -1672,15 +1670,15 @@ ACMD(dye) ACMD(hair_style) { int hair_style = 0; - + memset(atcmd_output, '\0', sizeof(atcmd_output)); - + if (!message || !*message || sscanf(message, "%d", &hair_style) < 1) { sprintf(atcmd_output, msg_txt(993), MIN_HAIR_STYLE, MAX_HAIR_STYLE); // Please enter a hair style (usage: @hairstyle/@hstyle ). clif->message(fd, atcmd_output); return false; } - + if (hair_style >= MIN_HAIR_STYLE && hair_style <= MAX_HAIR_STYLE) { pc->changelook(sd, LOOK_HAIR, hair_style); clif->message(fd, msg_txt(36)); // Appearance changed. @@ -1688,7 +1686,7 @@ ACMD(hair_style) clif->message(fd, msg_txt(37)); // An invalid number was specified. return false; } - + return true; } @@ -1698,15 +1696,15 @@ ACMD(hair_style) ACMD(hair_color) { int hair_color = 0; - + memset(atcmd_output, '\0', sizeof(atcmd_output)); - + if (!message || !*message || sscanf(message, "%d", &hair_color) < 1) { sprintf(atcmd_output, msg_txt(994), MIN_HAIR_COLOR, MAX_HAIR_COLOR); // Please enter a hair color (usage: @haircolor/@hcolor ). clif->message(fd, atcmd_output); return false; } - + if (hair_color >= MIN_HAIR_COLOR && hair_color <= MAX_HAIR_COLOR) { pc->changelook(sd, LOOK_HAIR_COLOR, hair_color); clif->message(fd, msg_txt(36)); // Appearance changed. @@ -1714,7 +1712,7 @@ ACMD(hair_color) clif->message(fd, msg_txt(37)); // An invalid number was specified. return false; } - + return true; } @@ -1725,7 +1723,7 @@ ACMD(go) { int i; int town = INT_MAX; // Initialized to INT_MAX instead of -1 to avoid conflicts with those who map [-3:-1] to @memo locations. char map_name[MAP_NAME_LENGTH]; - + const struct { char map[MAP_NAME_LENGTH]; int x, y; @@ -1772,23 +1770,23 @@ ACMD(go) { { MAP_MALAYA, 242, 211, 5 }, // 34 = Malaya Port { MAP_ECLAGE, 110, 39, 3 }, // 35 = Eclage }; - + memset(map_name, '\0', sizeof(map_name)); memset(atcmd_output, '\0', sizeof(atcmd_output)); - + if (!message || !*message || sscanf(message, "%11s", map_name) < 1) { // no value matched so send the list of locations const char* text; - + // attempt to find the text help string text = atcommand_help_string( info ); - + clif->message(fd, msg_txt(38)); // Invalid location number, or name. - + if( text ) {// send the text to the client clif->messageln( fd, text ); } - + return false; } @@ -1852,7 +1850,7 @@ ACMD(go) { clif->message(fd, msg_txt(38)); // Invalid location number or name. return false; } - + return true; } @@ -1870,11 +1868,11 @@ ACMD(monster) int i, k, range; short mx, my; unsigned int size; - + memset(name, '\0', sizeof(name)); memset(monster, '\0', sizeof(monster)); memset(atcmd_output, '\0', sizeof(atcmd_output)); - + if (!message || !*message) { clif->message(fd, msg_txt(80)); // Please specify a display name or monster name/id. return false; @@ -1895,35 +1893,35 @@ ACMD(monster) clif->message(fd, msg_txt(80)); // Give a display name and monster name/id please. return false; } - + if ((mob_id = mob->db_searchname(monster)) == 0) // check name first (to avoid possible name beginning by a number) mob_id = mob->db_checkid(atoi(monster)); - + if (mob_id == 0) { clif->message(fd, msg_txt(40)); // Invalid monster ID or name. return false; } - + if (number <= 0) number = 1; - + if( !name[0] ) strcpy(name, "--ja--"); - + // If value of atcommand_spawn_quantity_limit directive is greater than or equal to 1 and quantity of monsters is greater than value of the directive if (battle_config.atc_spawn_quantity_limit && number > battle_config.atc_spawn_quantity_limit) number = battle_config.atc_spawn_quantity_limit; - + if (strcmpi(info->command, "monstersmall") == 0) size = SZ_MEDIUM; else if (strcmpi(info->command, "monsterbig") == 0) size = SZ_BIG; else size = SZ_SMALL; - + if (battle_config.etc_log) ShowInfo("%s monster='%s' name='%s' id=%d count=%d (%d,%d)\n", command, monster, name, mob_id, number, sd->bl.x, sd->bl.y); - + count = 0; range = (int)sqrt((float)number) +2; // calculation of an odd number (+ 4 area around) for (i = 0; i < number; i++) { @@ -1931,7 +1929,7 @@ ACMD(monster) k = mob->once_spawn(sd, sd->bl.m, mx, my, name, mob_id, 1, eventname, size, AI_NONE|(mob_id == MOBID_EMPERIUM?0x200:0x0)); count += (k != 0) ? 1 : 0; } - + if (count != 0) if (number == count) clif->message(fd, msg_txt(39)); // All monster summoned! @@ -1943,7 +1941,7 @@ ACMD(monster) clif->message(fd, msg_txt(40)); // Invalid monster ID or name. return false; } - + return true; } @@ -1954,13 +1952,13 @@ int atkillmonster_sub(struct block_list *bl, va_list ap) { struct mob_data *md; int flag; - + nullpo_ret(md=(struct mob_data *)bl); flag = va_arg(ap, int); - + if (md->guardian_data) return 0; //Do not touch WoE mobs! - + if (flag) status_zap(bl,md->status.hp, 0); else @@ -1971,22 +1969,22 @@ int atkillmonster_sub(struct block_list *bl, va_list ap) ACMD(killmonster) { int map_id, drop_flag; char map_name[MAP_NAME_LENGTH_EXT]; - + memset(map_name, '\0', sizeof(map_name)); - + if (!message || !*message || sscanf(message, "%15s", map_name) < 1) map_id = sd->bl.m; else { if ((map_id = map->mapname2mapid(map_name)) < 0) map_id = sd->bl.m; } - + drop_flag = strcmpi(info->command, "killmonster2"); - + map->foreachinmap(atcommand->atkillmonster_sub, map_id, BL_MOB, -drop_flag); - + clif->message(fd, msg_txt(165)); // All monsters killed! - + return true; } @@ -1997,9 +1995,9 @@ ACMD(refine) { int i,j, position = 0, refine = 0, current_position, final_refine; int count; - + memset(atcmd_output, '\0', sizeof(atcmd_output)); - + if (!message || !*message || sscanf(message, "%d %d", &position, &refine) < 2) { clif->message(fd, msg_txt(996)); // Please enter a position and an amount (usage: @refine <+/- amount>). sprintf(atcmd_output, msg_txt(997), EQP_HEAD_LOW); // %d: Lower Headgear @@ -2024,9 +2022,9 @@ ACMD(refine) clif->message(fd, atcmd_output); return false; } - + refine = cap_value(refine, -MAX_REFINE, MAX_REFINE); - + count = 0; for (j = 0; j < EQI_MAX; j++) { if ((i = sd->equip_index[j]) < 0) @@ -2038,10 +2036,10 @@ ACMD(refine) continue; if(j == EQI_HEAD_TOP && (sd->equip_index[EQI_HEAD_MID] == i || sd->equip_index[EQI_HEAD_LOW] == i)) continue; - + if(position && !(sd->status.inventory[i].equip & position)) continue; - + final_refine = cap_value(sd->status.inventory[i].refine + refine, 0, MAX_REFINE); if (sd->status.inventory[i].refine != final_refine) { sd->status.inventory[i].refine = final_refine; @@ -2055,7 +2053,7 @@ ACMD(refine) count++; } } - + if (count == 0) clif->message(fd, msg_txt(166)); // No item has been refined. else if (count == 1) @@ -2064,7 +2062,7 @@ ACMD(refine) sprintf(atcmd_output, msg_txt(168), count); // %d items have been refined. clif->message(fd, atcmd_output); } - + return true; } @@ -2077,10 +2075,10 @@ ACMD(produce) int item_id, attribute = 0, star = 0; struct item_data *item_data; struct item tmp_item; - + memset(atcmd_output, '\0', sizeof(atcmd_output)); memset(item_name, '\0', sizeof(item_name)); - + if (!message || !*message || ( sscanf(message, "\"%99[^\"]\" %d %d", item_name, &attribute, &star) < 1 && sscanf(message, "%99s %d %d", item_name, &attribute, &star) < 1 @@ -2088,15 +2086,15 @@ ACMD(produce) clif->message(fd, msg_txt(1007)); // Please enter at least one item name/ID (usage: @produce <# of very's>). return false; } - + if ( (item_data = itemdb->search_name(item_name)) == NULL && (item_data = itemdb->exists(atoi(item_name))) == NULL ) { clif->message(fd, msg_txt(170)); //This item is not an equipment. return false; } - + item_id = item_data->nameid; - + if (itemdb->isequip2(item_data)) { int flag = 0; if (attribute < MIN_ATTRIBUTE || attribute > MAX_ATTRIBUTE) @@ -2114,7 +2112,7 @@ ACMD(produce) tmp_item.card[3] = GetWord(sd->status.char_id, 1); clif->produce_effect(sd, 0, item_id); clif->misceffect(&sd->bl, 3); - + if ((flag = pc->additem(sd, &tmp_item, 1, LOG_TYPE_COMMAND))) clif->additem(sd, 0, 0, flag); } else { @@ -2122,7 +2120,7 @@ ACMD(produce) clif->message(fd, atcmd_output); return false; } - + return true; } @@ -2132,9 +2130,9 @@ ACMD(produce) ACMD(memo) { int position = 0; - + memset(atcmd_output, '\0', sizeof(atcmd_output)); - + if( !message || !*message || sscanf(message, "%d", &position) < 1 ) { int i; @@ -2146,17 +2144,17 @@ ACMD(memo) else sprintf(atcmd_output, msg_txt(171), i); // %d - void clif->message(sd->fd, atcmd_output); - } + } return true; - } - + } + if( position < 0 || position >= MAX_MEMOPOINTS ) { sprintf(atcmd_output, msg_txt(1008), 0, MAX_MEMOPOINTS-1); // Please enter a valid position (usage: @memo ). clif->message(fd, atcmd_output); return false; } - + pc->memo(sd, position); return true; } @@ -2166,9 +2164,9 @@ ACMD(memo) *------------------------------------------*/ ACMD(gat) { int y; - + memset(atcmd_output, '\0', sizeof(atcmd_output)); - + for (y = 2; y >= -2; y--) { sprintf(atcmd_output, "%s (x= %d, y= %d) %02X %02X %02X %02X %02X", map->list[sd->bl.m].name, sd->bl.x - 2, sd->bl.y + y, @@ -2177,10 +2175,10 @@ ACMD(gat) { map->getcell(sd->bl.m, sd->bl.x, sd->bl.y + y, CELL_GETTYPE), map->getcell(sd->bl.m, sd->bl.x + 1, sd->bl.y + y, CELL_GETTYPE), map->getcell(sd->bl.m, sd->bl.x + 2, sd->bl.y + y, CELL_GETTYPE)); - + clif->message(fd, atcmd_output); } - + return true; } @@ -2190,19 +2188,19 @@ ACMD(gat) { ACMD(displaystatus) { int i, type, flag, tick, val1 = 0, val2 = 0, val3 = 0; - + if (!message || !*message || (i = sscanf(message, "%d %d %d %d %d %d", &type, &flag, &tick, &val1, &val2, &val3)) < 1) { clif->message(fd, msg_txt(1009)); // Please enter a status type/flag (usage: @displaystatus { { {}}}). return false; } if (i < 2) flag = 1; if (i < 3) tick = 0; - + if( flag == 0 ) clif->sc_end(&sd->bl,sd->bl.id,AREA,type); else clif->status_change(&sd->bl, type, flag, tick, val1, val2, val3); - + return true; } @@ -2213,12 +2211,12 @@ ACMD(statuspoint) { int point; unsigned int new_status_point; - + if (!message || !*message || (point = atoi(message)) == 0) { clif->message(fd, msg_txt(1010)); // Please enter a number (usage: @stpoint ). return false; } - + if(point < 0) { if(sd->status.status_point < (unsigned int)(-point)) @@ -2238,7 +2236,7 @@ ACMD(statuspoint) { new_status_point = sd->status.status_point + point; } - + if (new_status_point != sd->status.status_point) { sd->status.status_point = new_status_point; clif->updatestatus(sd, SP_STATUSPOINT); @@ -2250,7 +2248,7 @@ ACMD(statuspoint) clif->message(fd, msg_txt(149)); // Unable to increase the number/value. return false; } - + return true; } @@ -2261,12 +2259,12 @@ ACMD(skillpoint) { int point; unsigned int new_skill_point; - + if (!message || !*message || (point = atoi(message)) == 0) { clif->message(fd, msg_txt(1011)); // Please enter a number (usage: @skpoint ). return false; } - + if(point < 0) { if(sd->status.skill_point < (unsigned int)(-point)) @@ -2286,7 +2284,7 @@ ACMD(skillpoint) { new_skill_point = sd->status.skill_point + point; } - + if (new_skill_point != sd->status.skill_point) { sd->status.skill_point = new_skill_point; clif->updatestatus(sd, SP_SKILLPOINT); @@ -2298,7 +2296,7 @@ ACMD(skillpoint) clif->message(fd, msg_txt(149)); // Unable to increase the number/value. return false; } - + return true; } @@ -2308,12 +2306,12 @@ ACMD(skillpoint) ACMD(zeny) { int zeny=0, ret=-1; - + if (!message || !*message || (zeny = atoi(message)) == 0) { clif->message(fd, msg_txt(1012)); // Please enter an amount (usage: @zeny ). return false; } - + if(zeny > 0){ if((ret=pc->getzeny(sd,zeny,LOG_TYPE_COMMAND,NULL)) == 1) clif->message(fd, msg_txt(149)); // Unable to increase the number/value. @@ -2338,34 +2336,34 @@ ACMD(param) { int i, value = 0, new_value, max; const char* param[] = { "str", "agi", "vit", "int", "dex", "luk" }; short* stats[6]; - //we don't use direct initialization because it isn't part of the c standard. - + //we don't use direct initialization because it isn't part of the c standard. + memset(atcmd_output, '\0', sizeof(atcmd_output)); - + if (!message || !*message || sscanf(message, "%d", &value) < 1 || value == 0) { clif->message(fd, msg_txt(1013)); // Please enter a valid value (usage: @str/@agi/@vit/@int/@dex/@luk <+/-adjustment>). return false; } - + ARR_FIND( 0, ARRAYLENGTH(param), i, strcmpi(info->command, param[i]) == 0 ); - + if( i == ARRAYLENGTH(param) || i > MAX_STATUS_TYPE) { // normally impossible... clif->message(fd, msg_txt(1013)); // Please enter a valid value (usage: @str/@agi/@vit/@int/@dex/@luk <+/-adjustment>). return false; } - + stats[0] = &sd->status.str; stats[1] = &sd->status.agi; stats[2] = &sd->status.vit; stats[3] = &sd->status.int_; stats[4] = &sd->status.dex; stats[5] = &sd->status.luk; - + if( battle_config.atcommand_max_stat_bypass ) max = SHRT_MAX; else max = pc_maxparameter(sd); - + if(value < 0 && *stats[i] <= -value) { new_value = 1; } else if(max - *stats[i] < value) { @@ -2373,7 +2371,7 @@ ACMD(param) { } else { new_value = *stats[i] + value; } - + if (new_value != *stats[i]) { *stats[i] = new_value; clif->updatestatus(sd, SP_STR + i); @@ -2387,7 +2385,7 @@ ACMD(param) { clif->message(fd, msg_txt(149)); // Unable to increase the number/value. return false; } - + return true; } @@ -2397,15 +2395,15 @@ ACMD(param) { ACMD(stat_all) { int index, count, value, max, new_value; short* stats[6]; - //we don't use direct initialization because it isn't part of the c standard. - + //we don't use direct initialization because it isn't part of the c standard. + stats[0] = &sd->status.str; stats[1] = &sd->status.agi; stats[2] = &sd->status.vit; stats[3] = &sd->status.int_; stats[4] = &sd->status.dex; stats[5] = &sd->status.luk; - + if (!message || !*message || sscanf(message, "%d", &value) < 1 || value == 0) { value = pc_maxparameter(sd); max = pc_maxparameter(sd); @@ -2415,17 +2413,16 @@ ACMD(stat_all) { else max = pc_maxparameter(sd); } - + count = 0; for (index = 0; index < ARRAYLENGTH(stats); index++) { - if (value > 0 && *stats[index] > max - value) new_value = max; else if (value < 0 && *stats[index] <= -value) new_value = 1; else new_value = *stats[index] +value; - + if (new_value != (int)*stats[index]) { *stats[index] = new_value; clif->updatestatus(sd, SP_STR + index); @@ -2433,7 +2430,7 @@ ACMD(stat_all) { count++; } } - + if (count > 0) { // if at least 1 stat modified status_calc_pc(sd, SCO_FORCE); clif->message(fd, msg_txt(84)); // All stats changed! @@ -2444,7 +2441,7 @@ ACMD(stat_all) { clif->message(fd, msg_txt(178)); // You cannot increase that stat anymore. return false; } - + return true; } @@ -2455,12 +2452,12 @@ ACMD(guildlevelup) { int level = 0; int16 added_level; struct guild *guild_info; - + if (!message || !*message || sscanf(message, "%d", &level) < 1 || level == 0) { clif->message(fd, msg_txt(1014)); // Please enter a valid level (usage: @guildlvup/@guildlvlup <# of levels>). return false; } - + if (sd->status.guild_id <= 0 || (guild_info = sd->guild) == NULL) { clif->message(fd, msg_txt(43)); // You're not in a guild. return false; @@ -2471,13 +2468,13 @@ ACMD(guildlevelup) { return false; } #endif // 0 - + if (level > INT16_MAX || (level > 0 && level > MAX_GUILDLEVEL - guild_info->guild_lv)) // fix positive overflow level = MAX_GUILDLEVEL - guild_info->guild_lv; else if (level < INT16_MIN || (level < 0 && level < 1 - guild_info->guild_lv)) // fix negative overflow level = 1 - guild_info->guild_lv; added_level = (int16)level; - + if (added_level != 0) { intif->guild_change_basicinfo(guild_info->guild_id, GBI_GUILDLV, &added_level, sizeof(added_level)); clif->message(fd, msg_txt(179)); // Guild level changed. @@ -2485,7 +2482,7 @@ ACMD(guildlevelup) { clif->message(fd, msg_txt(45)); // Guild level change failed. return false; } - + return true; } @@ -2496,12 +2493,12 @@ ACMD(makeegg) { struct item_data *item_data; int id, pet_id; - + if (!message || !*message) { clif->message(fd, msg_txt(1015)); // Please enter a monster/egg name/ID (usage: @makeegg ). return false; } - + if ((item_data = itemdb->search_name(message)) != NULL) // for egg name id = item_data->nameid; else @@ -2509,7 +2506,7 @@ ACMD(makeegg) ; else id = atoi(message); - + pet_id = pet->search_petDB_index(id, PET_CLASS); if (pet_id < 0) pet_id = pet->search_petDB_index(id, PET_EGG); @@ -2524,7 +2521,7 @@ ACMD(makeegg) clif->message(fd, msg_txt(180)); // The monster/egg name/id doesn't exist. return false; } - + return true; } @@ -2539,7 +2536,7 @@ ACMD(hatch) clif->message(fd, msg_txt(181)); // You already have a pet. return false; } - + return true; } @@ -2550,29 +2547,29 @@ ACMD(petfriendly) { int friendly; struct pet_data *pd; - + if (!message || !*message || (friendly = atoi(message)) < 0) { clif->message(fd, msg_txt(1016)); // Please enter a valid value (usage: @petfriendly <0-1000>). return false; } - + pd = sd->pd; if (!pd) { clif->message(fd, msg_txt(184)); // Sorry, but you have no pet. return false; } - + if (friendly < 0 || friendly > 1000) { clif->message(fd, msg_txt(37)); // An invalid number was specified. return false; } - + if (friendly == pd->pet.intimate) { clif->message(fd, msg_txt(183)); // Pet intimacy is already at maximum. return false; } - + pet->set_intimate(pd, friendly); clif->send_petstatus(sd); clif->message(fd, msg_txt(182)); // Pet intimacy changed. @@ -2586,12 +2583,12 @@ ACMD(pethungry) { int hungry; struct pet_data *pd; - + if (!message || !*message || (hungry = atoi(message)) < 0) { clif->message(fd, msg_txt(1017)); // Please enter a valid number (usage: @pethungry <0-100>). return false; } - + pd = sd->pd; if (!sd->status.pet_id || !pd) { clif->message(fd, msg_txt(184)); // Sorry, but you have no pet. @@ -2605,11 +2602,11 @@ ACMD(pethungry) clif->message(fd, msg_txt(186)); // Pet hunger is already at maximum. return false; } - + pd->pet.hungry = hungry; clif->send_petstatus(sd); clif->message(fd, msg_txt(185)); // Pet hunger changed. - + return true; } @@ -2628,12 +2625,12 @@ ACMD(petrename) clif->message(fd, msg_txt(188)); // You can already rename your pet. return false; } - + pd->pet.rename_flag = 0; intif->save_petdata(sd->status.account_id, &pd->pet); clif->send_petstatus(sd); clif->message(fd, msg_txt(187)); // You can now rename your pet. - + return true; } @@ -2642,24 +2639,23 @@ ACMD(petrename) *------------------------------------------*/ ACMD(recall) { struct map_session_data *pl_sd = NULL; - - + if (!message || !*message) { clif->message(fd, msg_txt(1018)); // Please enter a player name (usage: @recall ). return false; } - + if((pl_sd=map->nick2sd((char *)message)) == NULL && (pl_sd=map->charid2sd(atoi(message))) == NULL) { clif->message(fd, msg_txt(3)); // Character not found. return false; } - + if ( pc_get_group_level(sd) < pc_get_group_level(pl_sd) ) { clif->message(fd, msg_txt(81)); // Your GM level doesn't authorize you to preform this action on the specified player. return false; } - + if (sd->bl.m >= 0 && map->list[sd->bl.m].flag.nowarpto && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE)) { clif->message(fd, msg_txt(1019)); // You are not authorized to warp someone to this map. return false; @@ -2674,7 +2670,7 @@ ACMD(recall) { pc->setpos(pl_sd, sd->mapindex, sd->bl.x, sd->bl.y, CLR_RESPAWN); sprintf(atcmd_output, msg_txt(46), pl_sd->status.name); // %s recalled! clif->message(fd, atcmd_output); - + return true; } @@ -2684,17 +2680,17 @@ ACMD(recall) { *------------------------------------------*/ ACMD(char_block) { - + memset(atcmd_player_name, '\0', sizeof(atcmd_player_name)); - + if (!message || !*message || sscanf(message, "%23[^\n]", atcmd_player_name) < 1) { clif->message(fd, msg_txt(1021)); // Please enter a player name (usage: @block ). return false; } - + chrif->char_ask_name(sd->status.account_id, atcmd_player_name, 1, 0, 0, 0, 0, 0, 0); // type: 1 - block clif->message(fd, msg_txt(88)); // Character name sent to char-server to ask it. - + return true; } @@ -2719,17 +2715,17 @@ ACMD(char_ban) int year, month, day, hour, minute, second, value; time_t timestamp; struct tm *tmtime; - + memset(atcmd_output, '\0', sizeof(atcmd_output)); memset(atcmd_player_name, '\0', sizeof(atcmd_player_name)); - + if (!message || !*message || sscanf(message, "%255s %23[^\n]", atcmd_output, atcmd_player_name) < 2) { clif->message(fd, msg_txt(1022)); // Please enter ban time and a player name (usage: @ban