diff options
Diffstat (limited to 'src/char')
-rw-r--r-- | src/char/Makefile.in | 4 | ||||
-rw-r--r-- | src/char/char.c | 358 | ||||
-rw-r--r-- | src/char/char.h | 11 | ||||
-rw-r--r-- | src/char/geoip.c | 2 | ||||
-rw-r--r-- | src/char/int_auction.c | 6 | ||||
-rw-r--r-- | src/char/int_elemental.c | 91 | ||||
-rw-r--r-- | src/char/int_guild.c | 54 | ||||
-rw-r--r-- | src/char/int_guild.h | 2 | ||||
-rw-r--r-- | src/char/int_homun.c | 137 | ||||
-rw-r--r-- | src/char/int_mail.c | 2 | ||||
-rw-r--r-- | src/char/int_mercenary.c | 79 | ||||
-rw-r--r-- | src/char/int_party.c | 27 | ||||
-rw-r--r-- | src/char/int_pet.c | 77 | ||||
-rw-r--r-- | src/char/int_pet.h | 2 | ||||
-rw-r--r-- | src/char/int_quest.c | 9 | ||||
-rw-r--r-- | src/char/int_storage.c | 10 | ||||
-rw-r--r-- | src/char/int_storage.h | 2 | ||||
-rw-r--r-- | src/char/inter.c | 27 | ||||
-rw-r--r-- | src/char/inter.h | 2 | ||||
-rw-r--r-- | src/char/loginif.c | 1 | ||||
-rw-r--r-- | src/char/mapif.c | 64 | ||||
-rw-r--r-- | src/char/mapif.h | 61 | ||||
-rw-r--r-- | src/char/pincode.c | 11 |
23 files changed, 496 insertions, 543 deletions
diff --git a/src/char/Makefile.in b/src/char/Makefile.in index bc2c0e980..8d9094f18 100644 --- a/src/char/Makefile.in +++ b/src/char/Makefile.in @@ -110,13 +110,13 @@ char-server: ../../char-server@EXEEXT@ ../../char-server@EXEEXT@: $(CHAR_SERVER_SQL_DEPENDS) Makefile @echo " LD $(notdir $@)" @$(CC) @STATIC@ @LDFLAGS@ -o ../../char-server@EXEEXT@ $(CHAR_OBJ) $(COMMON_D)/obj_sql/common_sql.a \ - $(COMMON_D)/obj_all/common.a $(MT19937AR_OBJ) $(LIBCONFIG_OBJ) @LIBS@ @PCRE_LIBS@ @MYSQL_LIBS@ + $(COMMON_D)/obj_all/common.a $(MT19937AR_OBJ) $(LIBCONFIG_OBJ) @LIBS@ @MYSQL_LIBS@ # char object files obj_sql/%.o: %.c $(CHAR_H) $(COMMON_H) $(CONFIG_H) $(MT19937AR_H) $(LIBCONFIG_H) | obj_sql @echo " CC $<" - @$(CC) @CFLAGS@ @DEFS@ $(COMMON_INCLUDE) $(THIRDPARTY_INCLUDE) @PCRE_CFLAGS@ @MYSQL_CFLAGS@ @CPPFLAGS@ -c $(OUTPUT_OPTION) $< + @$(CC) @CFLAGS@ @DEFS@ $(COMMON_INCLUDE) $(THIRDPARTY_INCLUDE) @MYSQL_CFLAGS@ @CPPFLAGS@ -c $(OUTPUT_OPTION) $< # missing object files $(COMMON_D)/obj_all/common.a: diff --git a/src/char/char.c b/src/char/char.c index 09f74034c..6cfeb7d1a 100644 --- a/src/char/char.c +++ b/src/char/char.c @@ -61,9 +61,6 @@ #include <stdio.h> #include <stdlib.h> #include <sys/types.h> -#ifndef WIN32 -# include <unistd.h> -#endif // private declarations char char_db[256] = "char"; @@ -419,7 +416,7 @@ int char_mmo_char_tosql(int char_id, struct mmo_charstatus* p) //map inventory data if( memcmp(p->inventory, cp->inventory, sizeof(p->inventory)) ) { - if (!chr->inventory_to_sql(p->inventory, MAX_INVENTORY, p->char_id)) + if (!chr->memitemdata_to_sql(p->inventory, MAX_INVENTORY, p->char_id, TABLE_INVENTORY)) strcat(save_status, " inventory"); else errors++; @@ -469,11 +466,11 @@ int char_mmo_char_tosql(int char_id, struct mmo_charstatus* p) 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'," + if( SQL_ERROR == SQL->Query(inter->sql_handle, "UPDATE `%s` SET `base_level`='%u', `job_level`='%u'," "`base_exp`='%u', `job_exp`='%u', `zeny`='%d'," - "`max_hp`='%d',`hp`='%d',`max_sp`='%d',`sp`='%d',`status_point`='%d',`skill_point`='%d'," + "`max_hp`='%d',`hp`='%d',`max_sp`='%d',`sp`='%d',`status_point`='%u',`skill_point`='%u'," "`str`='%d',`agi`='%d',`vit`='%d',`int`='%d',`dex`='%d',`luk`='%d'," - "`option`='%d',`party_id`='%d',`guild_id`='%d',`pet_id`='%d',`homun_id`='%d',`elemental_id`='%d'," + "`option`='%u',`party_id`='%d',`guild_id`='%d',`pet_id`='%d',`homun_id`='%d',`elemental_id`='%d'," "`weapon`='%d',`shield`='%d',`head_top`='%d',`head_mid`='%d',`head_bottom`='%d'," "`last_map`='%s',`last_x`='%d',`last_y`='%d',`save_map`='%s',`save_x`='%d',`save_y`='%d', `rename`='%d'," "`delete_date`='%lu',`robe`='%d',`slotchange`='%d', `char_opt`='%u', `font`='%u', `uniqueitem_counter` ='%u'," @@ -692,53 +689,63 @@ int char_mmo_char_tosql(int char_id, struct mmo_charstatus* p) return 0; } -/// Saves an array of 'item' entries into the specified table. +/** + * Saves an array of 'item' entries into the specified table. + * + * @param items The items array. + * @param max The array size. + * @param id The character/account/guild ID (depending on tableswitch). + * @param tableswitch The type of table (@see enum inventory_table_type). + * @return Error code. + * @retval 0 in case of success. + */ int char_memitemdata_to_sql(const struct item items[], int max, int id, int tableswitch) { StringBuf buf; - SqlStmt* stmt; - int i; - int j; - const char* tablename; - const char* selectoption; - struct item item; // temp storage variable - bool* flag; // bit array for inventory matching + SqlStmt *stmt = NULL; + int i, j; + const char *tablename = NULL; + const char *selectoption = NULL; + bool has_favorite = false; + struct item item = { 0 }; // temp storage variable + bool *flag = NULL; // bit array for inventory matching bool found; int errors = 0; + nullpo_ret(items); + switch (tableswitch) { - case TABLE_INVENTORY: tablename = inventory_db; selectoption = "char_id"; break; + case TABLE_INVENTORY: tablename = inventory_db; selectoption = "char_id"; has_favorite = true; break; case TABLE_CART: tablename = cart_db; selectoption = "char_id"; break; case TABLE_STORAGE: tablename = storage_db; selectoption = "account_id"; break; case TABLE_GUILD_STORAGE: tablename = guild_storage_db; selectoption = "guild_id"; break; default: ShowError("Invalid table name!\n"); - return 1; + Assert_retr(1, tableswitch); } - // The following code compares inventory with current database values // and performs modification/deletion/insertion only on relevant rows. // This approach is more complicated than a trivial delete&insert, but // it significantly reduces cpu load on the database server. StrBuf->Init(&buf); - StrBuf->AppendStr(&buf, "SELECT `id`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `expire_time`, `bound`"); - for( j = 0; j < MAX_SLOTS; ++j ) + StrBuf->AppendStr(&buf, "SELECT `id`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `expire_time`, `bound`, `unique_id`"); + for (j = 0; j < MAX_SLOTS; ++j) StrBuf->Printf(&buf, ", `card%d`", j); + if (has_favorite) + StrBuf->AppendStr(&buf, ", `favorite`"); StrBuf->Printf(&buf, " FROM `%s` WHERE `%s`='%d'", tablename, selectoption, id); stmt = SQL->StmtMalloc(inter->sql_handle); - if( SQL_ERROR == SQL->StmtPrepareStr(stmt, StrBuf->Value(&buf)) - || SQL_ERROR == SQL->StmtExecute(stmt) ) - { + if (SQL_ERROR == SQL->StmtPrepareStr(stmt, StrBuf->Value(&buf)) + || SQL_ERROR == SQL->StmtExecute(stmt)) { SqlStmt_ShowDebug(stmt); SQL->StmtFree(stmt); StrBuf->Destroy(&buf); return 1; } - memset(&item, 0, sizeof(item)); SQL->StmtBindColumn(stmt, 0, SQLDT_INT, &item.id, 0, NULL, NULL); SQL->StmtBindColumn(stmt, 1, SQLDT_SHORT, &item.nameid, 0, NULL, NULL); SQL->StmtBindColumn(stmt, 2, SQLDT_SHORT, &item.amount, 0, NULL, NULL); @@ -748,30 +755,32 @@ 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 ) - SQL->StmtBindColumn(stmt, 9+j, SQLDT_SHORT, &item.card[j], 0, NULL, NULL); + SQL->StmtBindColumn(stmt, 9, SQLDT_UINT64, &item.unique_id, 0, NULL, NULL); + for (j = 0; j < MAX_SLOTS; ++j) + SQL->StmtBindColumn(stmt, 10+j, SQLDT_SHORT, &item.card[j], 0, NULL, NULL); + if (has_favorite) + SQL->StmtBindColumn(stmt, 10+MAX_SLOTS, SQLDT_UCHAR, &item.favorite, 0, NULL, NULL); // bit array indicating which inventory items have already been matched - flag = (bool*) aCalloc(max, sizeof(bool)); + flag = aCalloc(max, sizeof(bool)); - while( SQL_SUCCESS == SQL->StmtNextRow(stmt) ) - { + while (SQL_SUCCESS == SQL->StmtNextRow(stmt)) { found = false; // search for the presence of the item in the char's inventory - for( i = 0; i < max; ++i ) - { + for (i = 0; i < max; ++i) { // skip empty and already matched entries - if( items[i].nameid == 0 || flag[i] ) + if (items[i].nameid == 0 || flag[i]) continue; - if( items[i].nameid == item.nameid + if (items[i].nameid == item.nameid + && items[i].unique_id == item.unique_id && 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 + // 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 @@ -779,19 +788,21 @@ int char_memitemdata_to_sql(const struct item items[], int max, int id, int tabl && items[i].attribute == item.attribute && items[i].expire_time == item.expire_time && items[i].bound == item.bound + && (!has_favorite || items[i].favorite == item.favorite) ) { ; //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'", + StrBuf->Printf(&buf, "UPDATE `%s` SET `amount`='%d', `equip`='%u', `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) StrBuf->Printf(&buf, ", `card%d`=%d", j, items[i].card[j]); + if (has_favorite) + StrBuf->Printf(&buf, ", `favorite`='%d'", items[i].favorite); StrBuf->Printf(&buf, " WHERE `id`='%d' LIMIT 1", item.id); - if( SQL_ERROR == SQL->QueryStr(inter->sql_handle, StrBuf->Value(&buf)) ) - { + if (SQL_ERROR == SQL->QueryStr(inter->sql_handle, StrBuf->Value(&buf))) { Sql_ShowDebug(inter->sql_handle); errors++; } @@ -801,10 +812,9 @@ int char_memitemdata_to_sql(const struct item items[], int max, int id, int tabl break; //skip to next item in the db. } } - if( !found ) - {// Item not present in inventory, remove it. - if( SQL_ERROR == SQL->Query(inter->sql_handle, "DELETE from `%s` where `id`='%d' LIMIT 1", tablename, item.id) ) - { + if (!found) { + // Item not present in inventory, remove it. + if (SQL_ERROR == SQL->Query(inter->sql_handle, "DELETE from `%s` where `id`='%d' LIMIT 1", tablename, item.id)) { Sql_ShowDebug(inter->sql_handle); errors++; } @@ -814,173 +824,34 @@ 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); + if (has_favorite) + StrBuf->AppendStr(&buf, ", `favorite`"); StrBuf->AppendStr(&buf, ") VALUES "); found = false; // insert non-matched items into the db as new items - for( i = 0; i < max; ++i ) - { + for (i = 0; i < max; ++i) { // skip empty and already matched entries - if( items[i].nameid == 0 || flag[i] ) + if (items[i].nameid == 0 || flag[i]) continue; - if( found ) + if (found) StrBuf->AppendStr(&buf, ","); else found = true; - StrBuf->Printf(&buf, "('%d', '%d', '%d', '%d', '%d', '%d', '%d', '%u', '%d', '%"PRIu64"'", + StrBuf->Printf(&buf, "('%d', '%d', '%d', '%u', '%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]); + if (has_favorite) + StrBuf->Printf(&buf, ", '%d'", items[i].favorite); StrBuf->AppendStr(&buf, ")"); } - if( found && SQL_ERROR == SQL->QueryStr(inter->sql_handle, StrBuf->Value(&buf)) ) - { - Sql_ShowDebug(inter->sql_handle); - errors++; - } - - StrBuf->Destroy(&buf); - aFree(flag); - - return errors; -} -/* pretty much a copy of chr->memitemdata_to_sql except it handles inventory_db exclusively, - * - this is required because inventory db is the only one with the 'favorite' column. */ -int char_inventory_to_sql(const struct item items[], int max, int id) { - StringBuf buf; - SqlStmt* stmt; - int i; - int j; - struct item item; // temp storage variable - bool* flag; // bit array for inventory matching - bool found; - int errors = 0; - - nullpo_ret(items); - - // The following code compares inventory with current database values - // and performs modification/deletion/insertion only on relevant rows. - // This approach is more complicated than a trivial delete&insert, but - // it significantly reduces cpu load on the database server. - - 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 ) - StrBuf->Printf(&buf, ", `card%d`", j); - StrBuf->Printf(&buf, " FROM `%s` WHERE `char_id`='%d'", inventory_db, id); - - stmt = SQL->StmtMalloc(inter->sql_handle); - if( SQL_ERROR == SQL->StmtPrepareStr(stmt, StrBuf->Value(&buf)) - || SQL_ERROR == SQL->StmtExecute(stmt) ) - { - SqlStmt_ShowDebug(stmt); - SQL->StmtFree(stmt); - StrBuf->Destroy(&buf); - return 1; - } - - memset(&item, 0, sizeof(item)); - SQL->StmtBindColumn(stmt, 0, SQLDT_INT, &item.id, 0, NULL, NULL); - SQL->StmtBindColumn(stmt, 1, SQLDT_SHORT, &item.nameid, 0, NULL, NULL); - SQL->StmtBindColumn(stmt, 2, SQLDT_SHORT, &item.amount, 0, NULL, NULL); - SQL->StmtBindColumn(stmt, 3, SQLDT_UINT, &item.equip, 0, NULL, NULL); - SQL->StmtBindColumn(stmt, 4, SQLDT_CHAR, &item.identify, 0, NULL, NULL); - SQL->StmtBindColumn(stmt, 5, SQLDT_CHAR, &item.refine, 0, NULL, NULL); - 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_CHAR, &item.favorite, 0, NULL, NULL); - SQL->StmtBindColumn(stmt, 9, SQLDT_UCHAR, &item.bound, 0, NULL, NULL); - 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 - flag = (bool*) aCalloc(max, sizeof(bool)); - - while( SQL_SUCCESS == SQL->StmtNextRow(stmt) ) { - found = false; - // search for the presence of the item in the char's inventory - for( i = 0; i < max; ++i ) { - // skip empty and already matched entries - if( items[i].nameid == 0 || flag[i] ) - 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. - 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 { - // 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]); - StrBuf->Printf(&buf, " WHERE `id`='%d' LIMIT 1", item.id); - - if( SQL_ERROR == SQL->QueryStr(inter->sql_handle, StrBuf->Value(&buf)) ) { - Sql_ShowDebug(inter->sql_handle); - errors++; - } - } - - found = flag[i] = true; //Item dealt with, - break; //skip to next item in the db. - } - } - if( !found ) {// Item not present in inventory, remove it. - if( SQL_ERROR == SQL->Query(inter->sql_handle, "DELETE from `%s` where `id`='%d' LIMIT 1", inventory_db, item.id) ) { - Sql_ShowDebug(inter->sql_handle); - errors++; - } - } - } - SQL->StmtFree(stmt); - - 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 ) - StrBuf->Printf(&buf, ", `card%d`", j); - StrBuf->AppendStr(&buf, ") VALUES "); - - found = false; - // insert non-matched items into the db as new items - for( i = 0; i < max; ++i ) { - // skip empty and already matched entries - if( items[i].nameid == 0 || flag[i] ) - continue; - - if( found ) - StrBuf->AppendStr(&buf, ","); - else - found = true; - - 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 ) - StrBuf->Printf(&buf, ", '%d'", items[i].card[j]); - StrBuf->AppendStr(&buf, ")"); - } - - if( found && SQL_ERROR == SQL->QueryStr(inter->sql_handle, StrBuf->Value(&buf)) ) { + if (found && SQL_ERROR == SQL->QueryStr(inter->sql_handle, StrBuf->Value(&buf))) { Sql_ShowDebug(inter->sql_handle); errors++; } @@ -1660,7 +1531,8 @@ int char_check_char_name(char * name, char * esc_name) * -5: 'Symbols in Character Names are forbidden' * char_id: Success **/ -int char_make_new_char_sql(struct char_session_data* sd, char* name_, int str, int agi, int vit, int int_, int dex, int luk, int slot, int hair_color, int hair_style) { +int char_make_new_char_sql(struct char_session_data *sd, const char *name_, int str, int agi, int vit, int int_, int dex, int luk, int slot, int hair_color, int hair_style) +{ char name[NAME_LENGTH]; char esc_name[NAME_LENGTH*2+1]; int char_id, flag, k, l; @@ -2033,7 +1905,7 @@ int char_mmo_char_tobuf(uint8* buffer, struct mmo_charstatus* p) { offset += 2; #endif #if (PACKETVER >= 20100720 && PACKETVER <= 20100727) || PACKETVER >= 20100803 - mapindex->getmapname_ext(mapindex_id2name(p->last_point.map), (char*)WBUFP(buf,108)); + mapindex->getmapname_ext(mapindex_id2name(p->last_point.map), WBUFP(buf,108)); offset += MAP_NAME_LENGTH_EXT; #endif #if PACKETVER >= 20100803 @@ -2087,7 +1959,7 @@ void char_mmo_char_send_ban_list(int fd, struct char_session_data *sd) { 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"); + timestamp2string(WFIFOP(fd,8 + (28*c)), 20, sd->unban_time[i], "%Y-%m-%d %H:%M:%S"); if( sd->unban_time[i] > now ) WFIFOL(fd, 4 + (24*c)) = sd->found_char[i]; @@ -2380,8 +2252,8 @@ void char_parse_fromlogin_account_data(int fd) sd->char_slots = MAX_CHARS;/* cap to maximum */ } else if ( sd->char_slots <= 0 )/* no value aka 0 in sql */ sd->char_slots = MAX_CHARS;/* cap to maximum */ - safestrncpy(sd->birthdate, (const char*)RFIFOP(fd,52), sizeof(sd->birthdate)); - safestrncpy(sd->pincode, (const char*)RFIFOP(fd,63), sizeof(sd->pincode)); + safestrncpy(sd->birthdate, RFIFOP(fd,52), sizeof(sd->birthdate)); + safestrncpy(sd->pincode, RFIFOP(fd,63), sizeof(sd->pincode)); sd->pincode_change = RFIFOL(fd,68); // continued from chr->auth_ok... if( (max_connect_user == 0 && sd->group_id != gm_allow_group) || @@ -2608,9 +2480,8 @@ void char_parse_fromlogin_accinfo2_failed(int fd) void char_parse_fromlogin_accinfo2_ok(int fd) { mapif->parse_accinfo2(true, RFIFOL(fd,167), RFIFOL(fd,171), RFIFOL(fd,175), RFIFOL(fd,179), - (char*)RFIFOP(fd,2), (char*)RFIFOP(fd,26), (char*)RFIFOP(fd,59), - (char*)RFIFOP(fd,99), (char*)RFIFOP(fd,119), (char*)RFIFOP(fd,151), - (char*)RFIFOP(fd,156), RFIFOL(fd,115), RFIFOL(fd,143), RFIFOL(fd,147)); + RFIFOP(fd,2), RFIFOP(fd,26), RFIFOP(fd,59), RFIFOP(fd,99), RFIFOP(fd,119), + RFIFOP(fd,151), RFIFOP(fd,156), RFIFOL(fd,115), RFIFOL(fd,143), RFIFOL(fd,147)); RFIFOSKIP(fd,183); } @@ -2637,11 +2508,11 @@ int char_parse_fromlogin(int fd) { } } - while(RFIFOREST(fd) >= 2) { + while (RFIFOREST(fd) >= 2) { uint16 command = RFIFOW(fd,0); if (VECTOR_LENGTH(HPM->packets[hpParse_FromLogin]) > 0) { - int result = HPM->parse_packets(fd,hpParse_FromLogin); + int result = HPM->parse_packets(fd,command,hpParse_FromLogin); if (result == 1) continue; if (result == 2) @@ -2788,7 +2659,7 @@ void char_global_accreg_to_login_add (const char *key, unsigned int index, intpt 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); + safestrncpy(WFIFOP(chr->login_fd,nlen), key, len); nlen += len; WFIFOL(chr->login_fd, nlen) = index; @@ -2805,7 +2676,7 @@ void char_global_accreg_to_login_add (const char *key, unsigned int index, intpt 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); + safestrncpy(WFIFOP(chr->login_fd,nlen), sval, len); nlen += len; } } else { @@ -3096,7 +2967,7 @@ void char_parse_frommap_map_names(int fd, int id) VECTOR_PUSH(chr->server[id].maps, RFIFOW(fd,i)); } - ShowStatus("Map-Server %d connected: %d maps, from IP %d.%d.%d.%d port %d.\n", + ShowStatus("Map-Server %d connected: %d maps, from IP %u.%u.%u.%u port %d.\n", id, (int)VECTOR_LENGTH(chr->server[id].maps), CONVIP(chr->server[id].ip), chr->server[id].port); ShowStatus("Map-server %d loading complete.\n", id); @@ -3292,7 +3163,7 @@ void char_parse_frommap_char_select_req(int fd) } } -void char_change_map_server_ack(int fd, uint8 *data, bool ok) +void char_change_map_server_ack(int fd, const uint8 *data, bool ok) { WFIFOHEAD(fd,30); WFIFOW(fd,0) = 0x2b06; @@ -3371,7 +3242,7 @@ void char_char_name_ack(int fd, int char_id) WFIFOHEAD(fd,30); WFIFOW(fd,0) = 0x2b09; WFIFOL(fd,2) = char_id; - chr->loadName(char_id, (char*)WFIFOP(fd,6)); + chr->loadName(char_id, WFIFOP(fd,6)); WFIFOSET(fd,30); } @@ -3460,7 +3331,7 @@ void char_ask_name_ack(int fd, int acc, const char* name, int type, int result) WFIFOHEAD(fd,34); WFIFOW(fd, 0) = 0x2b0f; WFIFOL(fd, 2) = acc; - safestrncpy((char*)WFIFOP(fd,6), name, NAME_LENGTH); + safestrncpy(WFIFOP(fd,6), name, NAME_LENGTH); WFIFOW(fd,30) = type; WFIFOW(fd,32) = result; WFIFOSET(fd,34); @@ -3515,7 +3386,7 @@ void char_parse_frommap_change_account(int fd) char esc_name[NAME_LENGTH*2+1]; int acc = RFIFOL(fd,2); // account_id of who ask (-1 if server itself made this request) - const char* name = (char*)RFIFOP(fd,6); // name of the target character + const char *name = RFIFOP(fd,6); // name of the target character int type = RFIFOW(fd,30); // type of operation: 1-block, 2-ban, 3-unblock, 4-unban, 5 changesex, 6 charban, 7 charunban short year = 0, month = 0, day = 0, hour = 0, minute = 0, second = 0; int sex = SEX_MALE; @@ -3658,7 +3529,7 @@ void char_parse_frommap_ragsrvinfo(int fd) SQL->EscapeString(inter->sql_handle, esc_server_name, chr->server_name); - if( SQL_ERROR == SQL->Query(inter->sql_handle, "INSERT INTO `%s` SET `index`='%d',`name`='%s',`exp`='%d',`jexp`='%d',`drop`='%d'", + if( SQL_ERROR == SQL->Query(inter->sql_handle, "INSERT INTO `%s` SET `index`='%d',`name`='%s',`exp`='%u',`jexp`='%u',`drop`='%u'", ragsrvinfo_db, fd, esc_server_name, RFIFOL(fd,2), RFIFOL(fd,6), RFIFOL(fd,10)) ) { Sql_ShowDebug(inter->sql_handle); @@ -3834,7 +3705,7 @@ void char_parse_frommap_auth_request(int fd, int id) void char_parse_frommap_update_ip(int fd, int id) { chr->server[id].ip = ntohl(RFIFOL(fd, 2)); - ShowInfo("Updated IP address of map-server #%d to %d.%d.%d.%d.\n", id, CONVIP(chr->server[id].ip)); + ShowInfo("Updated IP address of map-server #%d to %u.%u.%u.%u.\n", id, CONVIP(chr->server[id].ip)); RFIFOSKIP(fd,6); } @@ -3858,17 +3729,13 @@ void char_parse_frommap_request_stats_report(int fd) WFIFOHEAD(sfd, RFIFOW(fd,2) ); - memcpy((char*)WFIFOP(sfd,0), (char*)RFIFOP(fd, 0), RFIFOW(fd,2)); + memcpy(WFIFOP(sfd,0), RFIFOP(fd, 0), RFIFOW(fd,2)); WFIFOSET(sfd, RFIFOW(fd,2) ); do { sockt->flush(sfd); -#ifdef WIN32 - Sleep(1); -#else - sleep(1); -#endif + HSleep(1); } while( !sockt->session[sfd]->flag.eof && sockt->session[sfd]->wdata_size ); sockt->close(sfd); @@ -3887,9 +3754,11 @@ void char_parse_frommap_scdata_update(int fd) int val4 = RFIFOL(fd, 24); short type = RFIFOW(fd, 10); - if( SQL_ERROR == SQL->Query(inter->sql_handle, "REPLACE INTO `%s` (`account_id`,`char_id`,`type`,`tick`,`val1`,`val2`,`val3`,`val4`) VALUES ('%d','%d','%d',-1,'%d','%d','%d','%d')", - scdata_db, account_id, char_id, type, val1, val2, val3, val4) ) - { + if (SQL_ERROR == SQL->Query(inter->sql_handle, "REPLACE INTO `%s`" + " (`account_id`,`char_id`,`type`,`tick`,`val1`,`val2`,`val3`,`val4`)" + " VALUES ('%d','%d','%d','%d','%d','%d','%d','%d')", + scdata_db, account_id, char_id, type, INFINITE_DURATION, val1, val2, val3, val4) + ) { Sql_ShowDebug(inter->sql_handle); } RFIFOSKIP(fd, 28); @@ -3926,16 +3795,17 @@ int char_parse_frommap(int fd) return 0; } - while(RFIFOREST(fd) >= 2) { + while (RFIFOREST(fd) >= 2) { + int packet_id = RFIFOW(fd,0); if (VECTOR_LENGTH(HPM->packets[hpParse_FromMap]) > 0) { - int result = HPM->parse_packets(fd,hpParse_FromMap); + int result = HPM->parse_packets(fd,packet_id,hpParse_FromMap); if (result == 1) continue; if (result == 2) return 0; } - switch(RFIFOW(fd,0)) { + switch (packet_id) { case 0x2b0a: if( RFIFOREST(fd) < RFIFOW(fd, 2) ) return 0; @@ -4456,7 +4326,7 @@ void char_parse_char_connect(int fd, struct char_session_data* sd, uint32 ipl) RFIFOSKIP(fd,17); - ShowInfo("request connect - account_id:%d/login_id1:%d/login_id2:%d\n", account_id, login_id1, login_id2); + ShowInfo("request connect - account_id:%d/login_id1:%u/login_id2:%u\n", account_id, login_id1, login_id2); if (sd) { //Received again auth packet for already authenticated account?? Discard it. @@ -4518,7 +4388,7 @@ void char_send_map_info(int fd, int i, uint32 subnet_map_ip, struct mmo_charstat WFIFOHEAD(fd,28); WFIFOW(fd,0) = 0x71; WFIFOL(fd,2) = cd->char_id; - mapindex->getmapname_ext(mapindex_id2name(cd->last_point.map), (char*)WFIFOP(fd,6)); + mapindex->getmapname_ext(mapindex_id2name(cd->last_point.map), WFIFOP(fd,6)); WFIFOL(fd,22) = htonl((subnet_map_ip) ? subnet_map_ip : chr->server[i].ip); WFIFOW(fd,26) = sockt->ntows(htons(chr->server[i].port)); // [!] LE byte order here [!] WFIFOSET(fd,28); @@ -4529,7 +4399,7 @@ void char_send_wait_char_server(int fd) WFIFOHEAD(fd, 24); WFIFOW(fd, 0) = 0x840; WFIFOW(fd, 2) = 24; - safestrncpy((char*)WFIFOP(fd,4), "0", 20);/* we can't send empty (otherwise the list will pop up) */ + safestrncpy(WFIFOP(fd,4), "0", 20);/* we can't send empty (otherwise the list will pop up) */ WFIFOSET(fd, 24); } @@ -4739,9 +4609,9 @@ void char_parse_char_create_new_char(int fd, struct char_session_data* sd) result = -2; } else { #if PACKETVER >= 20120307 - result = chr->make_new_char_sql(sd, (char*)RFIFOP(fd,2), 1, 1, 1, 1, 1, 1, RFIFOB(fd,26),RFIFOW(fd,27),RFIFOW(fd,29)); + result = chr->make_new_char_sql(sd, RFIFOP(fd,2), 1, 1, 1, 1, 1, 1, RFIFOB(fd,26),RFIFOW(fd,27),RFIFOW(fd,29)); #else - result = chr->make_new_char_sql(sd, (char*)RFIFOP(fd,2),RFIFOB(fd,26),RFIFOB(fd,27),RFIFOB(fd,28),RFIFOB(fd,29),RFIFOB(fd,30),RFIFOB(fd,31),RFIFOB(fd,32),RFIFOW(fd,33),RFIFOW(fd,35)); + result = chr->make_new_char_sql(sd, RFIFOP(fd,2),RFIFOB(fd,26),RFIFOB(fd,27),RFIFOB(fd,28),RFIFOB(fd,29),RFIFOB(fd,30),RFIFOB(fd,31),RFIFOB(fd,32),RFIFOW(fd,33),RFIFOW(fd,35)); #endif } @@ -4855,7 +4725,7 @@ void char_parse_char_rename_char(int fd, struct char_session_data* sd) int i, cid =RFIFOL(fd,2); char name[NAME_LENGTH]; char esc_name[NAME_LENGTH*2+1]; - safestrncpy(name, (char *)RFIFOP(fd,6), NAME_LENGTH); + safestrncpy(name, RFIFOP(fd,6), NAME_LENGTH); RFIFOSKIP(fd,30); ARR_FIND( 0, MAX_CHARS, i, sd->found_char[i] == cid ); @@ -4880,7 +4750,7 @@ void char_parse_char_rename_char2(int fd, struct char_session_data* sd) int i, aid = RFIFOL(fd,2), cid =RFIFOL(fd,6); char name[NAME_LENGTH]; char esc_name[NAME_LENGTH*2+1]; - safestrncpy(name, (char *)RFIFOP(fd,10), NAME_LENGTH); + safestrncpy(name, RFIFOP(fd,10), NAME_LENGTH); RFIFOSKIP(fd,34); if( aid != sd->account_id ) @@ -4977,11 +4847,10 @@ void char_login_map_server_ack(int fd, uint8 flag) void char_parse_char_login_map_server(int fd, uint32 ipl) { - char* l_user = (char*)RFIFOP(fd,2); - char* l_pass = (char*)RFIFOP(fd,26); + char l_user[24], l_pass[24]; int i; - l_user[23] = '\0'; - l_pass[23] = '\0'; + safestrncpy(l_user, RFIFOP(fd,2), 24); + safestrncpy(l_pass, RFIFOP(fd,26), 24); ARR_FIND( 0, ARRAYLENGTH(chr->server), i, chr->server[i].fd <= 0 ); if (core->runflag != CHARSERVER_ST_RUNNING || @@ -5106,21 +4975,21 @@ int char_parse_char(int fd) return 0; } - while( RFIFOREST(fd) >= 2 ) { - //For use in packets that depend on an sd being present [Skotlex] - #define FIFOSD_CHECK(rest) do { if(RFIFOREST(fd) < (rest)) return 0; if (sd==NULL || !sd->auth) { RFIFOSKIP(fd,(rest)); return 0; } } while (0) + while (RFIFOREST(fd) >= 2) { + cmd = RFIFOW(fd,0); + +//For use in packets that depend on an sd being present [Skotlex] +#define FIFOSD_CHECK(rest) do { if(RFIFOREST(fd) < (rest)) return 0; if (sd==NULL || !sd->auth) { RFIFOSKIP(fd,(rest)); return 0; } } while (0) if (VECTOR_LENGTH(HPM->packets[hpParse_Char]) > 0) { - int result = HPM->parse_packets(fd,hpParse_Char); + int result = HPM->parse_packets(fd,cmd,hpParse_Char); if (result == 1) continue; if (result == 2) return 0; } - cmd = RFIFOW(fd,0); - - switch( cmd ) { + switch (cmd) { // request to connect // 0065 <account id>.L <login id1>.L <login id2>.L <???>.W <sex>.B case 0x65: @@ -5292,7 +5161,7 @@ int char_parse_char(int fd) return 0; } -int mapif_sendall(unsigned char *buf, unsigned int len) +int mapif_sendall(const unsigned char *buf, unsigned int len) { int i, c; @@ -6067,7 +5936,6 @@ void char_defaults(void) 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_gender = char_mmo_gender; chr->mmo_chars_fromsql = char_mmo_chars_fromsql; chr->mmo_char_fromsql = char_mmo_char_fromsql; diff --git a/src/char/char.h b/src/char/char.h index 3d25ec465..aedc52fbe 100644 --- a/src/char/char.h +++ b/src/char/char.h @@ -72,7 +72,7 @@ struct mmo_map_server { #define DEFAULT_AUTOSAVE_INTERVAL (300*1000) -enum { +enum inventory_table_type { TABLE_INVENTORY, TABLE_CART, TABLE_STORAGE, @@ -129,7 +129,6 @@ struct char_interface { DBData (*create_charstatus) (DBKey key, va_list args); int (*mmo_char_tosql) (int char_id, struct mmo_charstatus* p); int (*memitemdata_to_sql) (const struct item items[], int max, int id, int tableswitch); - int (*inventory_to_sql) (const struct item items[], int max, int id); int (*mmo_gender) (const struct char_session_data *sd, const struct mmo_charstatus *p, char sex); int (*mmo_chars_fromsql) (struct char_session_data* sd, uint8* buf); int (*mmo_char_fromsql) (int char_id, struct mmo_charstatus* p, bool load_everything); @@ -137,7 +136,7 @@ struct char_interface { bool (*char_slotchange) (struct char_session_data *sd, int fd, unsigned short from, unsigned short to); int (*rename_char_sql) (struct char_session_data *sd, int char_id); int (*check_char_name) (char * name, char * esc_name); - int (*make_new_char_sql) (struct char_session_data* sd, char* name_, int str, int agi, int vit, int int_, int dex, int luk, int slot, int hair_color, int hair_style); + int (*make_new_char_sql) (struct char_session_data *sd, const char *name_, int str, int agi, int vit, int int_, int dex, int luk, int slot, int hair_color, int hair_style); int (*divorce_char_sql) (int partner_id1, int partner_id2); int (*count_users) (void); int (*mmo_char_tobuf) (uint8* buffer, struct mmo_charstatus* p); @@ -189,7 +188,7 @@ struct char_interface { void (*parse_frommap_save_character) (int fd, int id); void (*select_ack) (int fd, int account_id, uint8 flag); void (*parse_frommap_char_select_req) (int fd); - void (*change_map_server_ack) (int fd, uint8 *data, bool ok); + void (*change_map_server_ack) (int fd, const uint8 *data, bool ok); void (*parse_frommap_change_map_server) (int fd); void (*parse_frommap_remove_friend) (int fd); void (*char_name_ack) (int fd, int char_id); @@ -317,8 +316,8 @@ extern char char_reg_num_db[32]; extern int guild_exp_rate; extern int log_inter; -void char_load_defaults(); -void char_defaults(); +void char_load_defaults(void); +void char_defaults(void); #endif // HERCULES_CORE HPShared struct char_interface *chr; diff --git a/src/char/geoip.c b/src/char/geoip.c index 36b908561..433ff0918 100644 --- a/src/char/geoip.c +++ b/src/char/geoip.c @@ -101,7 +101,7 @@ const char* geoip_getcountry(uint32 ipnum) } offset = x; } - ShowError("geoip_getcountry(): Error traversing database for ipnum %d\n", ipnum); + ShowError("geoip_getcountry(): Error traversing database for ipnum %u\n", ipnum); ShowWarning("geoip_getcountry(): Possible database corruption!\n"); return geoip_countryname[0]; diff --git a/src/char/int_auction.c b/src/char/int_auction.c index b402e7f98..464a2092b 100644 --- a/src/char/int_auction.c +++ b/src/char/int_auction.c @@ -73,7 +73,7 @@ void inter_auction_save(struct auction_data *auction) auction_db, auction->seller_id, auction->buyer_id, auction->price, auction->buynow, auction->hours, (unsigned long)auction->timestamp, auction->item.nameid, auction->type, auction->item.refine, auction->item.attribute); for( j = 0; j < MAX_SLOTS; j++ ) StrBuf->Printf(&buf, ", `card%d` = '%d'", j, auction->item.card[j]); - StrBuf->Printf(&buf, " WHERE `auction_id` = '%d'", auction->auction_id); + StrBuf->Printf(&buf, " WHERE `auction_id` = '%u'", auction->auction_id); stmt = SQL->StmtMalloc(inter->sql_handle); if( SQL_SUCCESS != SQL->StmtPrepareStr(stmt, StrBuf->Value(&buf)) @@ -183,7 +183,7 @@ void inter_auction_delete(struct auction_data *auction) auction_id = auction->auction_id; - if( SQL_ERROR == SQL->Query(inter->sql_handle, "DELETE FROM `%s` WHERE `auction_id` = '%d'", auction_db, auction_id) ) + if( SQL_ERROR == SQL->Query(inter->sql_handle, "DELETE FROM `%s` WHERE `auction_id` = '%u'", auction_db, auction_id) ) Sql_ShowDebug(inter->sql_handle); if( auction->auction_end_timer != INVALID_TIMER ) @@ -462,7 +462,7 @@ void mapif_parse_auction_bid(int fd) } auction->buyer_id = char_id; - safestrncpy(auction->buyer_name, (char*)RFIFOP(fd,16), NAME_LENGTH); + safestrncpy(auction->buyer_name, RFIFOP(fd,16), NAME_LENGTH); auction->price = bid; if( bid >= auction->buynow ) diff --git a/src/char/int_elemental.c b/src/char/int_elemental.c index b781654db..c25cfa5c8 100644 --- a/src/char/int_elemental.c +++ b/src/char/int_elemental.c @@ -40,32 +40,54 @@ struct inter_elemental_interface inter_elemental_s; struct inter_elemental_interface *inter_elemental; -bool mapif_elemental_save(struct s_elemental* ele) { - bool flag = true; - +/** + * Creates a new elemental with the given data. + * + * @remark + * The elemental ID is expected to be 0, and will be filled with the newly + * assigned ID. + * + * @param[in,out] ele The new elemental's data. + * @retval false in case of errors. + */ +bool mapif_elemental_create(struct s_elemental *ele) +{ nullpo_retr(false, ele); - if( ele->elemental_id == 0 ) { // Create new DB entry - if( SQL_ERROR == SQL->Query(inter->sql_handle, + Assert_retr(false, ele->elemental_id == 0); + + 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`)" - "VALUES ('%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%u')", - elemental_db, ele->char_id, ele->class_, ele->mode, ele->hp, ele->sp, ele->max_hp, ele->max_sp, ele->atk, ele->atk2, ele->matk, ele->amotion, ele->def, ele->mdef, ele->flee, ele->hit, ele->life_time) ) - { - Sql_ShowDebug(inter->sql_handle); - flag = false; - } - else - ele->elemental_id = (int)SQL->LastInsertId(inter->sql_handle); - } else if( SQL_ERROR == SQL->Query(inter->sql_handle, - "UPDATE `%s` SET `char_id` = '%d', `class` = '%d', `mode` = '%d', `hp` = '%d', `sp` = '%d'," - "`max_hp` = '%d', `max_sp` = '%d', `atk1` = '%d', `atk2` = '%d', `matk` = '%d', `aspd` = '%d', `def` = '%d'," - "`mdef` = '%d', `flee` = '%d', `hit` = '%d', `life_time` = '%u' WHERE `ele_id` = '%d'", - elemental_db, ele->char_id, ele->class_, ele->mode, ele->hp, ele->sp, ele->max_hp, ele->max_sp, ele->atk, ele->atk2, - ele->matk, ele->amotion, ele->def, ele->mdef, ele->flee, ele->hit, ele->life_time, ele->elemental_id) ) - { // Update DB entry + "VALUES ('%d','%d','%u','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d')", + elemental_db, ele->char_id, ele->class_, ele->mode, ele->hp, ele->sp, ele->max_hp, ele->max_sp, ele->atk, + ele->atk2, ele->matk, ele->amotion, ele->def, ele->mdef, ele->flee, ele->hit, ele->life_time)) { Sql_ShowDebug(inter->sql_handle); - flag = false; + return false; } - return flag; + ele->elemental_id = (int)SQL->LastInsertId(inter->sql_handle); + return true; +} + +/** + * Saves an existing elemental. + * + * @param ele The elemental's data. + * @retval false in case of errors. + */ +bool mapif_elemental_save(const struct s_elemental *ele) +{ + nullpo_retr(false, ele); + Assert_retr(false, ele->elemental_id > 0); + + if (SQL_ERROR == SQL->Query(inter->sql_handle, + "UPDATE `%s` SET `char_id` = '%d', `class` = '%d', `mode` = '%u', `hp` = '%d', `sp` = '%d'," + "`max_hp` = '%d', `max_sp` = '%d', `atk1` = '%d', `atk2` = '%d', `matk` = '%d', `aspd` = '%d', `def` = '%d'," + "`mdef` = '%d', `flee` = '%d', `hit` = '%d', `life_time` = '%d' WHERE `ele_id` = '%d'", + elemental_db, ele->char_id, ele->class_, ele->mode, ele->hp, ele->sp, ele->max_hp, ele->max_sp, ele->atk, ele->atk2, + ele->matk, ele->amotion, ele->def, ele->mdef, ele->flee, ele->hit, ele->life_time, ele->elemental_id)) { + Sql_ShowDebug(inter->sql_handle); + return false; + } + return true; } bool mapif_elemental_load(int ele_id, int char_id, struct s_elemental *ele) { @@ -133,9 +155,15 @@ void mapif_elemental_send(int fd, struct s_elemental *ele, unsigned char flag) { WFIFOSET(fd,size); } -void mapif_parse_elemental_create(int fd, struct s_elemental* ele) { - bool result = mapif->elemental_save(ele); - mapif->elemental_send(fd, ele, result); +void mapif_parse_elemental_create(int fd, const struct s_elemental *ele) +{ + struct s_elemental ele_; + bool result; + + memcpy(&ele_, ele, sizeof(ele_)); + + result = mapif->elemental_create(&ele_); + mapif->elemental_send(fd, &ele_, result); } void mapif_parse_elemental_load(int fd, int ele_id, int char_id) { @@ -163,7 +191,8 @@ void mapif_elemental_saved(int fd, unsigned char flag) { WFIFOSET(fd,3); } -void mapif_parse_elemental_save(int fd, struct s_elemental* ele) { +void mapif_parse_elemental_save(int fd, const struct s_elemental *ele) +{ bool result = mapif->elemental_save(ele); mapif->elemental_saved(fd, result); } @@ -182,11 +211,11 @@ 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; - case 0x307e: mapif->parse_elemental_delete(fd, (int)RFIFOL(fd,2)); break; - case 0x307f: mapif->parse_elemental_save(fd, (struct s_elemental*)RFIFOP(fd,4)); break; + switch (cmd) { + case 0x307c: mapif->parse_elemental_create(fd, RFIFOP(fd,4)); break; + case 0x307d: mapif->parse_elemental_load(fd, RFIFOL(fd,2), RFIFOL(fd,6)); break; + case 0x307e: mapif->parse_elemental_delete(fd, RFIFOL(fd,2)); break; + case 0x307f: mapif->parse_elemental_save(fd, RFIFOP(fd,4)); break; default: return 0; } diff --git a/src/char/int_guild.c b/src/char/int_guild.c index 03a1d368d..2ba50d277 100644 --- a/src/char/int_guild.c +++ b/src/char/int_guild.c @@ -767,7 +767,7 @@ void inter_guild_sql_final(void) } // Get guild_id by its name. Returns 0 if not found, -1 on error. -int inter_guild_search_guildname(char *str) +int inter_guild_search_guildname(const char *str) { int guild_id; char esc_name[NAME_LENGTH*2+1]; @@ -1006,7 +1006,7 @@ int mapif_guild_broken(int guild_id, int flag) } // Send guild message -int mapif_guild_message(int guild_id, int account_id, char *mes, int len, int sfd) +int mapif_guild_message(int guild_id, int account_id, const char *mes, int len, int sfd) { unsigned char buf[512]; nullpo_ret(mes); @@ -1139,7 +1139,7 @@ int mapif_guild_master_changed(struct guild *g, int aid, int cid) return 0; } -int mapif_guild_castle_dataload(int fd, int sz, int *castle_ids) +int mapif_guild_castle_dataload(int fd, int sz, const int *castle_ids) { struct guild_castle *gc = NULL; int num = (sz - 4) / sizeof(int); @@ -1163,7 +1163,7 @@ int mapif_guild_castle_dataload(int fd, int sz, int *castle_ids) // Guild creation request -int mapif_parse_CreateGuild(int fd,int account_id,char *name,struct guild_member *master) +int mapif_parse_CreateGuild(int fd, int account_id, const char *name, const struct guild_member *master) { struct guild *g; int i=0; @@ -1201,7 +1201,7 @@ int mapif_parse_CreateGuild(int fd,int account_id,char *name,struct guild_member g->member[0].modified = GS_MEMBER_MODIFIED; // Set default positions - g->position[0].mode = GPERM_BOTH; + g->position[0].mode = GPERM_ALL; strcpy(g->position[0].name,"GuildMaster"); strcpy(g->position[MAX_GUILDPOSITION-1].name,"Newbie"); g->position[0].modified = g->position[MAX_GUILDPOSITION-1].modified = GS_POSITION_MODIFIED; @@ -1259,7 +1259,7 @@ int mapif_parse_GuildInfo(int fd, int guild_id) } // Add member to guild -int mapif_parse_GuildAddMember(int fd, int guild_id, struct guild_member *m) +int mapif_parse_GuildAddMember(int fd, int guild_id, const struct guild_member *m) { struct guild * g; int i; @@ -1455,7 +1455,7 @@ int mapif_parse_BreakGuild(int fd, int guild_id) } // Forward Guild message to others map servers -int mapif_parse_GuildMessage(int fd, int guild_id, int account_id, char *mes, int len) +int mapif_parse_GuildMessage(int fd, int guild_id, int account_id, const char *mes, int len) { return mapif->guild_message(guild_id,account_id,mes,len, fd); } @@ -1548,7 +1548,7 @@ int mapif_parse_GuildMemberInfoChange(int fd, int guild_id, int account_id, int { case GMI_POSITION: { - g->member[i].position=*((short *)data); + g->member[i].position=*((const short *)data); g->member[i].modified = GS_MEMBER_MODIFIED; mapif->guild_memberinfochanged(guild_id,account_id,char_id,type,data,len); g->save_flag |= GS_MEMBER; @@ -1557,7 +1557,7 @@ int mapif_parse_GuildMemberInfoChange(int fd, int guild_id, int account_id, int case GMI_EXP: { uint64 old_exp = g->member[i].exp; - g->member[i].exp=*((uint64 *)data); + g->member[i].exp=*((const uint64 *)data); g->member[i].modified = GS_MEMBER_MODIFIED; if (g->member[i].exp > old_exp) { uint64 exp = g->member[i].exp - old_exp; @@ -1582,7 +1582,7 @@ int mapif_parse_GuildMemberInfoChange(int fd, int guild_id, int account_id, int } case GMI_HAIR: { - g->member[i].hair=*((short *)data); + g->member[i].hair=*((const short *)data); g->member[i].modified = GS_MEMBER_MODIFIED; mapif->guild_memberinfochanged(guild_id,account_id,char_id,type,data,len); g->save_flag |= GS_MEMBER; //Save new data. @@ -1590,7 +1590,7 @@ int mapif_parse_GuildMemberInfoChange(int fd, int guild_id, int account_id, int } case GMI_HAIR_COLOR: { - g->member[i].hair_color=*((short *)data); + g->member[i].hair_color=*((const short *)data); g->member[i].modified = GS_MEMBER_MODIFIED; mapif->guild_memberinfochanged(guild_id,account_id,char_id,type,data,len); g->save_flag |= GS_MEMBER; //Save new data. @@ -1598,7 +1598,7 @@ int mapif_parse_GuildMemberInfoChange(int fd, int guild_id, int account_id, int } case GMI_GENDER: { - g->member[i].gender=*((short *)data); + g->member[i].gender=*((const short *)data); g->member[i].modified = GS_MEMBER_MODIFIED; mapif->guild_memberinfochanged(guild_id,account_id,char_id,type,data,len); g->save_flag |= GS_MEMBER; //Save new data. @@ -1606,7 +1606,7 @@ int mapif_parse_GuildMemberInfoChange(int fd, int guild_id, int account_id, int } case GMI_CLASS: { - g->member[i].class_=*((short *)data); + g->member[i].class_=*((const short *)data); g->member[i].modified = GS_MEMBER_MODIFIED; mapif->guild_memberinfochanged(guild_id,account_id,char_id,type,data,len); g->save_flag |= GS_MEMBER; //Save new data. @@ -1614,7 +1614,7 @@ int mapif_parse_GuildMemberInfoChange(int fd, int guild_id, int account_id, int } case GMI_LEVEL: { - g->member[i].lv=*((short *)data); + g->member[i].lv=*((const short *)data); g->member[i].modified = GS_MEMBER_MODIFIED; mapif->guild_memberinfochanged(guild_id,account_id,char_id,type,data,len); g->save_flag |= GS_MEMBER; //Save new data. @@ -1670,7 +1670,7 @@ int inter_guild_charname_changed(int guild_id, int account_id, int char_id, char } // Change a position desc -int mapif_parse_GuildPosition(int fd, int guild_id, int idx, struct guild_position *p) +int mapif_parse_GuildPosition(int fd, int guild_id, int idx, const struct guild_position *p) { // Could make some improvement in speed, because only change guild_position struct guild * g; @@ -1809,7 +1809,7 @@ int mapif_parse_GuildEmblem(int fd, int len, int guild_id, int dummy, const char return mapif->guild_emblem(g); } -int mapif_parse_GuildCastleDataLoad(int fd, int len, int *castle_ids) +int mapif_parse_GuildCastleDataLoad(int fd, int len, const int *castle_ids) { return mapif->guild_castle_dataload(fd, len, castle_ids); } @@ -1902,22 +1902,22 @@ int inter_guild_parse_frommap(int fd) { RFIFOHEAD(fd); switch(RFIFOW(fd,0)) { - case 0x3030: mapif->parse_CreateGuild(fd,RFIFOL(fd,4),(char*)RFIFOP(fd,8),(struct guild_member *)RFIFOP(fd,32)); break; + case 0x3030: mapif->parse_CreateGuild(fd, RFIFOL(fd,4), RFIFOP(fd,8), RFIFOP(fd,32)); break; case 0x3031: mapif->parse_GuildInfo(fd,RFIFOL(fd,2)); break; - case 0x3032: mapif->parse_GuildAddMember(fd,RFIFOL(fd,4),(struct guild_member *)RFIFOP(fd,8)); break; - case 0x3033: mapif->parse_GuildMasterChange(fd,RFIFOL(fd,4),(const char*)RFIFOP(fd,8),RFIFOW(fd,2)-8); break; - case 0x3034: mapif->parse_GuildLeave(fd,RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),RFIFOB(fd,14),(const char*)RFIFOP(fd,15)); break; + case 0x3032: mapif->parse_GuildAddMember(fd, RFIFOL(fd,4), RFIFOP(fd,8)); break; + case 0x3033: mapif->parse_GuildMasterChange(fd, RFIFOL(fd,4), RFIFOP(fd,8), RFIFOW(fd,2)-8); break; + case 0x3034: mapif->parse_GuildLeave(fd, RFIFOL(fd,2), RFIFOL(fd,6), RFIFOL(fd,10), RFIFOB(fd,14), RFIFOP(fd,15)); break; case 0x3035: mapif->parse_GuildChangeMemberInfoShort(fd,RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),RFIFOB(fd,14),RFIFOW(fd,15),RFIFOW(fd,17)); break; case 0x3036: mapif->parse_BreakGuild(fd,RFIFOL(fd,2)); break; - case 0x3037: mapif->parse_GuildMessage(fd,RFIFOL(fd,4),RFIFOL(fd,8),(char*)RFIFOP(fd,12),RFIFOW(fd,2)-12); break; - case 0x3039: mapif->parse_GuildBasicInfoChange(fd,RFIFOL(fd,4),RFIFOW(fd,8),(const int16 *)RFIFOP(fd,10),RFIFOW(fd,2)-10); break; - case 0x303A: mapif->parse_GuildMemberInfoChange(fd,RFIFOL(fd,4),RFIFOL(fd,8),RFIFOL(fd,12),RFIFOW(fd,16),(const char*)RFIFOP(fd,18),RFIFOW(fd,2)-18); break; - case 0x303B: mapif->parse_GuildPosition(fd,RFIFOL(fd,4),RFIFOL(fd,8),(struct guild_position *)RFIFOP(fd,12)); break; + case 0x3037: mapif->parse_GuildMessage(fd, RFIFOL(fd,4), RFIFOL(fd,8), RFIFOP(fd,12), RFIFOW(fd,2)-12); break; + case 0x3039: mapif->parse_GuildBasicInfoChange(fd, RFIFOL(fd,4), RFIFOW(fd,8), RFIFOP(fd,10), RFIFOW(fd,2)-10); break; + case 0x303A: mapif->parse_GuildMemberInfoChange(fd, RFIFOL(fd,4), RFIFOL(fd,8), RFIFOL(fd,12), RFIFOW(fd,16), RFIFOP(fd,18), RFIFOW(fd,2)-18); break; + case 0x303B: mapif->parse_GuildPosition(fd, RFIFOL(fd,4), RFIFOL(fd,8), RFIFOP(fd,12)); break; case 0x303C: mapif->parse_GuildSkillUp(fd,RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),RFIFOL(fd,14)); break; case 0x303D: mapif->parse_GuildAlliance(fd,RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),RFIFOL(fd,14),RFIFOB(fd,18)); break; - case 0x303E: mapif->parse_GuildNotice(fd,RFIFOL(fd,2),(const char*)RFIFOP(fd,6),(const char*)RFIFOP(fd,66)); break; - case 0x303F: mapif->parse_GuildEmblem(fd,RFIFOW(fd,2)-12,RFIFOL(fd,4),RFIFOL(fd,8),(const char*)RFIFOP(fd,12)); break; - case 0x3040: mapif->parse_GuildCastleDataLoad(fd,RFIFOW(fd,2),(int *)RFIFOP(fd,4)); break; + case 0x303E: mapif->parse_GuildNotice(fd, RFIFOL(fd,2), RFIFOP(fd,6), RFIFOP(fd,66)); break; + case 0x303F: mapif->parse_GuildEmblem(fd, RFIFOW(fd,2)-12, RFIFOL(fd,4), RFIFOL(fd,8), RFIFOP(fd,12)); break; + case 0x3040: mapif->parse_GuildCastleDataLoad(fd, RFIFOW(fd,2), RFIFOP(fd,4)); break; case 0x3041: mapif->parse_GuildCastleDataSave(fd,RFIFOW(fd,2),RFIFOB(fd,4),RFIFOL(fd,5)); break; default: diff --git a/src/char/int_guild.h b/src/char/int_guild.h index 1076b3394..40728c3b2 100644 --- a/src/char/int_guild.h +++ b/src/char/int_guild.h @@ -60,7 +60,7 @@ struct inter_guild_interface { int (*sql_init) (void); int (*db_final) (DBKey key, DBData *data, va_list ap); void (*sql_final) (void); - int (*search_guildname) (char *str); + int (*search_guildname) (const char *str); bool (*check_empty) (struct guild *g); unsigned int (*nextexp) (int level); int (*checkskill) (struct guild *g, int id); diff --git a/src/char/int_homun.c b/src/char/int_homun.c index f60394ee7..e5fde2330 100644 --- a/src/char/int_homun.c +++ b/src/char/int_homun.c @@ -49,7 +49,7 @@ void inter_homunculus_sql_final(void) return; } -void mapif_homunculus_created(int fd, int account_id, struct s_homunculus *sh, unsigned char flag) +void mapif_homunculus_created(int fd, int account_id, const struct s_homunculus *sh, unsigned char flag) { nullpo_retv(sh); WFIFOHEAD(fd, sizeof(struct s_homunculus)+9); @@ -97,7 +97,7 @@ void mapif_homunculus_saved(int fd, int account_id, bool flag) WFIFOSET(fd, 7); } -void mapif_homunculus_renamed(int fd, int account_id, int char_id, unsigned char flag, char* name) +void mapif_homunculus_renamed(int fd, int account_id, int char_id, unsigned char flag, const char *name) { nullpo_retv(name); WFIFOHEAD(fd, NAME_LENGTH+12); @@ -105,68 +105,83 @@ void mapif_homunculus_renamed(int fd, int account_id, int char_id, unsigned char WFIFOL(fd, 2) = account_id; WFIFOL(fd, 6) = char_id; WFIFOB(fd,10) = flag; - safestrncpy((char*)WFIFOP(fd,11), name, NAME_LENGTH); + safestrncpy(WFIFOP(fd,11), name, NAME_LENGTH); WFIFOSET(fd, NAME_LENGTH+12); } -bool mapif_homunculus_save(struct s_homunculus* hd) +/** + * Creates a new homunculus with the given data. + * + * @remark + * The homunculus ID is expected to be 0, and will be filled with the newly + * assigned ID. + * + * @param[in,out] hd The new homunculus' data. + * @retval false in case of errors. + */ +bool mapif_homunculus_create(struct s_homunculus *hd) { - bool flag = true; char esc_name[NAME_LENGTH*2+1]; - nullpo_ret(hd); + nullpo_retr(false, hd); + Assert_retr(false, hd->hom_id == 0); + SQL->EscapeStringLen(inter->sql_handle, esc_name, hd->name, strnlen(hd->name, NAME_LENGTH)); - if( hd->hom_id == 0 ) - {// new homunculus - if( SQL_ERROR == SQL->Query(inter->sql_handle, "INSERT INTO `%s` " + if (SQL_ERROR == SQL->Query(inter->sql_handle, "INSERT INTO `%s` " "(`char_id`, `class`,`prev_class`,`name`,`level`,`exp`,`intimacy`,`hunger`, `str`, `agi`, `vit`, `int`, `dex`, `luk`, `hp`,`max_hp`,`sp`,`max_sp`,`skill_point`, `rename_flag`, `vaporize`) " "VALUES ('%d', '%d', '%d', '%s', '%d', '%u', '%u', '%d', '%d', %d, '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d')", homunculus_db, hd->char_id, hd->class_, hd->prev_class, esc_name, hd->level, hd->exp, hd->intimacy, hd->hunger, hd->str, hd->agi, hd->vit, hd->int_, hd->dex, hd->luk, - hd->hp, hd->max_hp, hd->sp, hd->max_sp, hd->skillpts, hd->rename_flag, hd->vaporize) ) - { - Sql_ShowDebug(inter->sql_handle); - flag = false; - } - else - { - hd->hom_id = (int)SQL->LastInsertId(inter->sql_handle); - } + hd->hp, hd->max_hp, hd->sp, hd->max_sp, hd->skillpts, hd->rename_flag, hd->vaporize)) { + Sql_ShowDebug(inter->sql_handle); + return false; } - else - { - if( SQL_ERROR == SQL->Query(inter->sql_handle, "UPDATE `%s` SET `char_id`='%d', `class`='%d',`prev_class`='%d',`name`='%s',`level`='%d',`exp`='%u',`intimacy`='%u',`hunger`='%d', `str`='%d', `agi`='%d', `vit`='%d', `int`='%d', `dex`='%d', `luk`='%d', `hp`='%d',`max_hp`='%d',`sp`='%d',`max_sp`='%d',`skill_point`='%d', `rename_flag`='%d', `vaporize`='%d' WHERE `homun_id`='%d'", + hd->hom_id = (int)SQL->LastInsertId(inter->sql_handle); + return true; +} + +/** + * Saves an existing homunculus. + * + * @param hd The homunculus' data. + * @retval false in case of errors. + */ +bool mapif_homunculus_save(const struct s_homunculus *hd) +{ + bool flag = true; + char esc_name[NAME_LENGTH*2+1]; + + nullpo_retr(false, hd); + Assert_retr(false, hd->hom_id > 0); + + SQL->EscapeStringLen(inter->sql_handle, esc_name, hd->name, strnlen(hd->name, NAME_LENGTH)); + + if (SQL_ERROR == SQL->Query(inter->sql_handle, "UPDATE `%s` SET `char_id`='%d', `class`='%d',`prev_class`='%d',`name`='%s',`level`='%d',`exp`='%u',`intimacy`='%u',`hunger`='%d', `str`='%d', `agi`='%d', `vit`='%d', `int`='%d', `dex`='%d', `luk`='%d', `hp`='%d',`max_hp`='%d',`sp`='%d',`max_sp`='%d',`skill_point`='%d', `rename_flag`='%d', `vaporize`='%d' WHERE `homun_id`='%d'", homunculus_db, hd->char_id, hd->class_, hd->prev_class, esc_name, hd->level, hd->exp, hd->intimacy, hd->hunger, hd->str, hd->agi, hd->vit, hd->int_, hd->dex, hd->luk, - hd->hp, hd->max_hp, hd->sp, hd->max_sp, hd->skillpts, hd->rename_flag, hd->vaporize, hd->hom_id) ) - { - Sql_ShowDebug(inter->sql_handle); + hd->hp, hd->max_hp, hd->sp, hd->max_sp, hd->skillpts, hd->rename_flag, hd->vaporize, hd->hom_id)) { + Sql_ShowDebug(inter->sql_handle); + flag = false; + } else { + int i; + SqlStmt *stmt = SQL->StmtMalloc(inter->sql_handle); + + if (SQL_ERROR == SQL->StmtPrepare(stmt, "REPLACE INTO `%s` (`homun_id`, `id`, `lv`) VALUES (%d, ?, ?)", skill_homunculus_db, hd->hom_id)) { + SqlStmt_ShowDebug(stmt); flag = false; - } - else - { - SqlStmt* stmt; - int i; - - stmt = SQL->StmtMalloc(inter->sql_handle); - if( SQL_ERROR == SQL->StmtPrepare(stmt, "REPLACE INTO `%s` (`homun_id`, `id`, `lv`) VALUES (%d, ?, ?)", skill_homunculus_db, hd->hom_id) ) - SqlStmt_ShowDebug(stmt); - for( i = 0; i < MAX_HOMUNSKILL; ++i ) - { - if( hd->hskill[i].id > 0 && hd->hskill[i].lv != 0 ) - { - SQL->StmtBindParam(stmt, 0, SQLDT_USHORT, &hd->hskill[i].id, 0); - SQL->StmtBindParam(stmt, 1, SQLDT_USHORT, &hd->hskill[i].lv, 0); - if( SQL_ERROR == SQL->StmtExecute(stmt) ) - { + } else { + for (i = 0; i < MAX_HOMUNSKILL; ++i) { + if (hd->hskill[i].id > 0 && hd->hskill[i].lv != 0) { + SQL->StmtBindParam(stmt, 0, SQLDT_USHORT, (void*)&hd->hskill[i].id, 0); // FIXME: StmtBindParam should take const void + SQL->StmtBindParam(stmt, 1, SQLDT_USHORT, (void*)&hd->hskill[i].lv, 0); // FIXME: StmtBindParam should take const void + if (SQL_ERROR == SQL->StmtExecute(stmt)) { SqlStmt_ShowDebug(stmt); - SQL->StmtFree(stmt); flag = false; break; } } } - SQL->StmtFree(stmt); } + SQL->StmtFree(stmt); } return flag; @@ -181,7 +196,7 @@ bool mapif_homunculus_load(int homun_id, struct s_homunculus* hd) nullpo_ret(hd); memset(hd, 0, sizeof(*hd)); - if( SQL_ERROR == SQL->Query(inter->sql_handle, "SELECT `homun_id`,`char_id`,`class`,`prev_class`,`name`,`level`,`exp`,`intimacy`,`hunger`, `str`, `agi`, `vit`, `int`, `dex`, `luk`, `hp`,`max_hp`,`sp`,`max_sp`,`skill_point`,`rename_flag`, `vaporize` FROM `%s` WHERE `homun_id`='%u'", homunculus_db, homun_id) ) + if( SQL_ERROR == SQL->Query(inter->sql_handle, "SELECT `homun_id`,`char_id`,`class`,`prev_class`,`name`,`level`,`exp`,`intimacy`,`hunger`, `str`, `agi`, `vit`, `int`, `dex`, `luk`, `hp`,`max_hp`,`sp`,`max_sp`,`skill_point`,`rename_flag`, `vaporize` FROM `%s` WHERE `homun_id`='%d'", homunculus_db, homun_id) ) { Sql_ShowDebug(inter->sql_handle); return false; @@ -255,8 +270,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` = '%d'", homunculus_db, homun_id) + || SQL_ERROR == SQL->Query(inter->sql_handle, "DELETE FROM `%s` WHERE `homun_id` = '%d'", skill_homunculus_db, homun_id) ) { Sql_ShowDebug(inter->sql_handle); return false; @@ -264,7 +279,7 @@ bool mapif_homunculus_delete(int homun_id) return true; } -bool mapif_homunculus_rename(char *name) +bool mapif_homunculus_rename(const char *name) { int i; @@ -287,10 +302,15 @@ bool mapif_homunculus_rename(char *name) } -void mapif_parse_homunculus_create(int fd, int len, int account_id, struct s_homunculus* phd) +void mapif_parse_homunculus_create(int fd, int len, int account_id, const struct s_homunculus *phd) { - bool result = mapif->homunculus_save(phd); - mapif->homunculus_created(fd, account_id, phd, result); + struct s_homunculus shd; + bool result; + + memcpy(&shd, phd, sizeof(shd)); + + result = mapif->homunculus_create(&shd); + mapif->homunculus_created(fd, account_id, &shd, result); } void mapif_parse_homunculus_delete(int fd, int homun_id) @@ -306,13 +326,13 @@ void mapif_parse_homunculus_load(int fd, int account_id, int homun_id) mapif->homunculus_loaded(fd, account_id, ( result ? &hd : NULL )); } -void mapif_parse_homunculus_save(int fd, int len, int account_id, struct s_homunculus* phd) +void mapif_parse_homunculus_save(int fd, int len, int account_id, const struct s_homunculus *phd) { bool result = mapif->homunculus_save(phd); mapif->homunculus_saved(fd, account_id, result); } -void mapif_parse_homunculus_rename(int fd, int account_id, int char_id, char* name) +void mapif_parse_homunculus_rename(int fd, int account_id, int char_id, const char *name) { bool result = mapif->homunculus_rename(name); mapif->homunculus_renamed(fd, account_id, char_id, result, name); @@ -325,13 +345,12 @@ int inter_homunculus_parse_frommap(int fd) { unsigned short cmd = RFIFOW(fd,0); - switch( cmd ) - { - case 0x3090: mapif->parse_homunculus_create(fd, (int)RFIFOW(fd,2), (int)RFIFOL(fd,4), (struct s_homunculus*)RFIFOP(fd,8)); break; - case 0x3091: mapif->parse_homunculus_load (fd, (int)RFIFOL(fd,2), (int)RFIFOL(fd,6)); break; - case 0x3092: mapif->parse_homunculus_save (fd, (int)RFIFOW(fd,2), (int)RFIFOL(fd,4), (struct s_homunculus*)RFIFOP(fd,8)); break; - case 0x3093: mapif->parse_homunculus_delete(fd, (int)RFIFOL(fd,2)); break; - case 0x3094: mapif->parse_homunculus_rename(fd, (int)RFIFOL(fd,2), (int)RFIFOL(fd,6), (char*)RFIFOP(fd,10)); break; + switch (cmd) { + case 0x3090: mapif->parse_homunculus_create(fd, RFIFOW(fd,2), RFIFOL(fd,4), RFIFOP(fd,8)); break; + case 0x3091: mapif->parse_homunculus_load (fd, RFIFOL(fd,2), RFIFOL(fd,6)); break; + case 0x3092: mapif->parse_homunculus_save (fd, RFIFOW(fd,2), RFIFOL(fd,4), RFIFOP(fd,8)); break; + case 0x3093: mapif->parse_homunculus_delete(fd, RFIFOL(fd,2)); break; + case 0x3094: mapif->parse_homunculus_rename(fd, RFIFOL(fd,2), RFIFOL(fd,6), RFIFOP(fd,10)); break; default: return 0; } diff --git a/src/char/int_mail.c b/src/char/int_mail.c index c15dc5180..b75a362fb 100644 --- a/src/char/int_mail.c +++ b/src/char/int_mail.c @@ -138,7 +138,7 @@ int inter_mail_savemessage(struct mail_message* msg) StrBuf->Printf(&buf, "INSERT INTO `%s` (`send_name`, `send_id`, `dest_name`, `dest_id`, `title`, `message`, `time`, `status`, `zeny`, `amount`, `nameid`, `refine`, `attribute`, `identify`, `unique_id`", mail_db); for (j = 0; j < MAX_SLOTS; j++) StrBuf->Printf(&buf, ", `card%d`", j); - StrBuf->Printf(&buf, ") VALUES (?, '%d', ?, '%d', ?, ?, '%lu', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%"PRIu64"'", + StrBuf->Printf(&buf, ") VALUES (?, '%d', ?, '%d', ?, ?, '%lu', '%u', '%d', '%d', '%d', '%d', '%d', '%d', '%"PRIu64"'", msg->send_id, msg->dest_id, (unsigned long)msg->timestamp, msg->status, msg->zeny, msg->item.amount, msg->item.nameid, msg->item.refine, msg->item.attribute, msg->item.identify, msg->item.unique_id); for (j = 0; j < MAX_SLOTS; j++) StrBuf->Printf(&buf, ", '%d'", msg->item.card[j]); diff --git a/src/char/int_mercenary.c b/src/char/int_mercenary.c index 2ed45305c..0bc3c0909 100644 --- a/src/char/int_mercenary.c +++ b/src/char/int_mercenary.c @@ -94,32 +94,51 @@ bool inter_mercenary_owner_delete(int char_id) return true; } -bool mapif_mercenary_save(struct s_mercenary* merc) +/** + * Creates a new mercenary with the given data. + * + * @remark + * The mercenary ID is expected to be 0, and will be filled with the newly + * assigned ID. + * + * @param[in,out] merc The new mercenary's data. + * @retval false in case of errors. + */ +bool mapif_mercenary_create(struct s_mercenary *merc) { - bool flag = true; + nullpo_retr(false, merc); + Assert_retr(false, merc->mercenary_id == 0); - nullpo_ret(merc); - if( merc->mercenary_id == 0 ) - { // Create new DB entry - if( SQL_ERROR == SQL->Query(inter->sql_handle, + if (SQL_ERROR == SQL->Query(inter->sql_handle, "INSERT INTO `%s` (`char_id`,`class`,`hp`,`sp`,`kill_counter`,`life_time`) VALUES ('%d','%d','%d','%d','%u','%u')", - mercenary_db, merc->char_id, merc->class_, merc->hp, merc->sp, merc->kill_count, merc->life_time) ) - { - Sql_ShowDebug(inter->sql_handle); - flag = false; - } - else - merc->mercenary_id = (int)SQL->LastInsertId(inter->sql_handle); + mercenary_db, merc->char_id, merc->class_, merc->hp, merc->sp, merc->kill_count, merc->life_time)) { + Sql_ShowDebug(inter->sql_handle); + return false; } - else if( SQL_ERROR == SQL->Query(inter->sql_handle, - "UPDATE `%s` SET `char_id` = '%d', `class` = '%d', `hp` = '%d', `sp` = '%d', `kill_counter` = '%u', `life_time` = '%u' WHERE `mer_id` = '%d'", - mercenary_db, merc->char_id, merc->class_, merc->hp, merc->sp, merc->kill_count, merc->life_time, merc->mercenary_id) ) - { // Update DB entry + merc->mercenary_id = (int)SQL->LastInsertId(inter->sql_handle); + + return true; +} + +/** + * Saves an existing mercenary. + * + * @param merc The mercenary's data. + * @retval false in case of errors. + */ +bool mapif_mercenary_save(const struct s_mercenary *merc) +{ + nullpo_retr(false, merc); + Assert_retr(false, merc->mercenary_id > 0); + + if (SQL_ERROR == SQL->Query(inter->sql_handle, + "UPDATE `%s` SET `char_id` = '%d', `class` = '%d', `hp` = '%d', `sp` = '%d', `kill_counter` = '%u', `life_time` = '%u' WHERE `mer_id` = '%d'", + mercenary_db, merc->char_id, merc->class_, merc->hp, merc->sp, merc->kill_count, merc->life_time, merc->mercenary_id)) { Sql_ShowDebug(inter->sql_handle); - flag = false; + return false; } - return flag; + return true; } bool mapif_mercenary_load(int merc_id, int char_id, struct s_mercenary *merc) @@ -179,10 +198,15 @@ void mapif_mercenary_send(int fd, struct s_mercenary *merc, unsigned char flag) WFIFOSET(fd,size); } -void mapif_parse_mercenary_create(int fd, struct s_mercenary* merc) +void mapif_parse_mercenary_create(int fd, const struct s_mercenary *merc) { - bool result = mapif->mercenary_save(merc); - mapif->mercenary_send(fd, merc, result); + struct s_mercenary merc_; + bool result; + + memcpy(&merc_, merc, sizeof(merc_)); + + result = mapif->mercenary_create(&merc_); + mapif->mercenary_send(fd, &merc_, result); } void mapif_parse_mercenary_load(int fd, int merc_id, int char_id) @@ -236,12 +260,11 @@ int inter_mercenary_parse_frommap(int fd) { unsigned short cmd = RFIFOW(fd,0); - switch( cmd ) - { - case 0x3070: mapif->parse_mercenary_create(fd, (struct s_mercenary*)RFIFOP(fd,4)); break; - case 0x3071: mapif->parse_mercenary_load(fd, (int)RFIFOL(fd,2), (int)RFIFOL(fd,6)); break; - case 0x3072: mapif->parse_mercenary_delete(fd, (int)RFIFOL(fd,2)); break; - case 0x3073: mapif->parse_mercenary_save(fd, (struct s_mercenary*)RFIFOP(fd,4)); break; + switch (cmd) { + case 0x3070: mapif->parse_mercenary_create(fd, RFIFOP(fd,4)); break; + case 0x3071: mapif->parse_mercenary_load(fd, RFIFOL(fd,2), RFIFOL(fd,6)); break; + case 0x3072: mapif->parse_mercenary_delete(fd, RFIFOL(fd,2)); break; + case 0x3073: mapif->parse_mercenary_save(fd, RFIFOP(fd,4)); break; default: return 0; } diff --git a/src/char/int_party.c b/src/char/int_party.c index 71034a17b..684d846d4 100644 --- a/src/char/int_party.c +++ b/src/char/int_party.c @@ -461,7 +461,7 @@ int mapif_party_broken(int party_id, int flag) } //Remarks in the party -int mapif_party_message(int party_id, int account_id, char *mes, int len, int sfd) +int mapif_party_message(int party_id, int account_id, const char *mes, int len, int sfd) { unsigned char buf[512]; nullpo_ret(mes); @@ -479,13 +479,13 @@ int mapif_party_message(int party_id, int account_id, char *mes, int len, int sf // Create Party -int mapif_parse_CreateParty(int fd, char *name, int item, int item2, struct party_member *leader) +int mapif_parse_CreateParty(int fd, const char *name, int item, int item2, const struct party_member *leader) { struct party_data *p; int i; nullpo_ret(name); nullpo_ret(leader); - if( (p=inter_party->search_partyname(name))!=NULL){ + if (!*name || (p = inter_party->search_partyname(name)) != NULL) { mapif->party_created(fd,leader->account_id,leader->char_id,NULL); return 0; } @@ -493,9 +493,12 @@ int mapif_parse_CreateParty(int fd, char *name, int item, int item2, struct part if (char_name_option == 1) { // only letters/symbols in char_name_letters are authorized for (i = 0; i < NAME_LENGTH && name[i]; i++) if (strchr(char_name_letters, name[i]) == NULL) { - if( name[i] == '"' ) { /* client-special-char */ - normalize_name(name,"\""); - mapif->parse_CreateParty(fd,name,item,item2,leader); + if (name[i] == '"') { /* client-special-char */ + char *newname = aStrndup(name, NAME_LENGTH-1); + normalize_name(newname,"\""); + trim(newname); + mapif->parse_CreateParty(fd, newname, item, item2, leader); + aFree(newname); return 0; } mapif->party_created(fd,leader->account_id,leader->char_id,NULL); @@ -511,7 +514,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); + safestrncpy(p->party.name, name, NAME_LENGTH); p->party.exp=0; p->party.item=(item?1:0)|(item2?2:0); @@ -547,7 +550,7 @@ void mapif_parse_PartyInfo(int fd, int party_id, int char_id) } // Add a player to party request -int mapif_parse_PartyAddMember(int fd, int party_id, struct party_member *member) +int mapif_parse_PartyAddMember(int fd, int party_id, const struct party_member *member) { struct party_data *p; int i; @@ -729,7 +732,7 @@ int mapif_parse_BreakParty(int fd, int party_id) } //Party sending the message -int mapif_parse_PartyMessage(int fd, int party_id, int account_id, char *mes, int len) +int mapif_parse_PartyMessage(int fd, int party_id, int account_id, const char *mes, int len) { return mapif->party_message(party_id,account_id,mes,len, fd); } @@ -767,14 +770,14 @@ int inter_party_parse_frommap(int fd) { RFIFOHEAD(fd); switch(RFIFOW(fd,0)) { - case 0x3020: mapif->parse_CreateParty(fd, (char*)RFIFOP(fd,4), RFIFOB(fd,28), RFIFOB(fd,29), (struct party_member*)RFIFOP(fd,30)); break; + case 0x3020: mapif->parse_CreateParty(fd, RFIFOP(fd,4), RFIFOB(fd,28), RFIFOB(fd,29), RFIFOP(fd,30)); break; case 0x3021: mapif->parse_PartyInfo(fd, RFIFOL(fd,2), RFIFOL(fd,6)); break; - case 0x3022: mapif->parse_PartyAddMember(fd, RFIFOL(fd,4), (struct party_member*)RFIFOP(fd,8)); break; + case 0x3022: mapif->parse_PartyAddMember(fd, RFIFOL(fd,4), RFIFOP(fd,8)); break; case 0x3023: mapif->parse_PartyChangeOption(fd, RFIFOL(fd,2), RFIFOL(fd,6), RFIFOW(fd,10), RFIFOW(fd,12)); break; case 0x3024: mapif->parse_PartyLeave(fd, RFIFOL(fd,2), RFIFOL(fd,6), RFIFOL(fd,10)); break; case 0x3025: mapif->parse_PartyChangeMap(fd, RFIFOL(fd,2), RFIFOL(fd,6), RFIFOL(fd,10), RFIFOW(fd,14), RFIFOB(fd,16), RFIFOW(fd,17)); break; case 0x3026: mapif->parse_BreakParty(fd, RFIFOL(fd,2)); break; - case 0x3027: mapif->parse_PartyMessage(fd, RFIFOL(fd,4), RFIFOL(fd,8), (char*)RFIFOP(fd,12), RFIFOW(fd,2)-12); break; + case 0x3027: mapif->parse_PartyMessage(fd, RFIFOL(fd,4), RFIFOL(fd,8), RFIFOP(fd,12), RFIFOW(fd,2)-12); break; case 0x3029: mapif->parse_PartyLeaderChange(fd, RFIFOL(fd,2), RFIFOL(fd,6), RFIFOL(fd,10)); break; default: return 0; diff --git a/src/char/int_pet.c b/src/char/int_pet.c index 6baf832bc..eb9bda8d0 100644 --- a/src/char/int_pet.c +++ b/src/char/int_pet.c @@ -40,44 +40,55 @@ struct inter_pet_interface inter_pet_s; struct inter_pet_interface *inter_pet; -//--------------------------------------------------------- -int inter_pet_tosql(int pet_id, struct s_pet* p) +/** + * Saves a pet to the SQL database. + * + * @remark + * In case of newly created pet, the pet ID is not updated to reflect the + * newly assigned ID. The caller must do so. + * + * @param p The pet data to save. + * @return The ID of the saved pet. + * @retval 0 in case of errors. + */ +int inter_pet_tosql(const struct s_pet *p) { //`pet` (`pet_id`, `class`,`name`,`account_id`,`char_id`,`level`,`egg_id`,`equip`,`intimate`,`hungry`,`rename_flag`,`incubate`) char esc_name[NAME_LENGTH*2+1];// escaped pet name + int pet_id = 0, hungry = 0, intimate = 0; nullpo_ret(p); + SQL->EscapeStringLen(inter->sql_handle, esc_name, p->name, strnlen(p->name, NAME_LENGTH)); - p->hungry = cap_value(p->hungry, 0, 100); - p->intimate = cap_value(p->intimate, 0, 1000); - - if( pet_id == -1 ) - {// New pet. - if( SQL_ERROR == SQL->Query(inter->sql_handle, "INSERT INTO `%s` " - "(`class`,`name`,`account_id`,`char_id`,`level`,`egg_id`,`equip`,`intimate`,`hungry`,`rename_flag`,`incubate`) " - "VALUES ('%d', '%s', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d')", - pet_db, p->class_, esc_name, p->account_id, p->char_id, p->level, p->egg_id, - p->equip, p->intimate, p->hungry, p->rename_flag, p->incubate) ) - { + hungry = cap_value(p->hungry, 0, 100); + intimate = cap_value(p->intimate, 0, 1000); + + if (p->pet_id == 0) { + // New pet. + if (SQL_ERROR == SQL->Query(inter->sql_handle, "INSERT INTO `%s` " + "(`class`,`name`,`account_id`,`char_id`,`level`,`egg_id`,`equip`,`intimate`,`hungry`,`rename_flag`,`incubate`) " + "VALUES ('%d', '%s', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d')", + pet_db, p->class_, esc_name, p->account_id, p->char_id, p->level, p->egg_id, + p->equip, intimate, hungry, p->rename_flag, p->incubate)) { Sql_ShowDebug(inter->sql_handle); return 0; } - p->pet_id = (int)SQL->LastInsertId(inter->sql_handle); - } - else - {// Update pet. - if( SQL_ERROR == SQL->Query(inter->sql_handle, "UPDATE `%s` SET `class`='%d',`name`='%s',`account_id`='%d',`char_id`='%d',`level`='%d',`egg_id`='%d',`equip`='%d',`intimate`='%d',`hungry`='%d',`rename_flag`='%d',`incubate`='%d' WHERE `pet_id`='%d'", - pet_db, p->class_, esc_name, p->account_id, p->char_id, p->level, p->egg_id, - p->equip, p->intimate, p->hungry, p->rename_flag, p->incubate, p->pet_id) ) - { + pet_id = (int)SQL->LastInsertId(inter->sql_handle); + } else { + // Update pet. + if (SQL_ERROR == SQL->Query(inter->sql_handle, "UPDATE `%s` SET `class`='%d',`name`='%s',`account_id`='%d',`char_id`='%d',`level`='%d',`egg_id`='%d',`equip`='%d',`intimate`='%d',`hungry`='%d',`rename_flag`='%d',`incubate`='%d' WHERE `pet_id`='%d'", + pet_db, p->class_, esc_name, p->account_id, p->char_id, p->level, p->egg_id, + p->equip, intimate, hungry, p->rename_flag, p->incubate, p->pet_id)) { Sql_ShowDebug(inter->sql_handle); return 0; } + pet_id = p->pet_id; } if (save_log) ShowInfo("Pet saved %d - %s.\n", pet_id, p->name); - return 1; + + return pet_id; } int inter_pet_fromsql(int pet_id, struct s_pet* p) @@ -211,7 +222,7 @@ int mapif_delete_pet_ack(int fd, int flag) } int mapif_create_pet(int fd, int account_id, int char_id, short pet_class, short pet_lv, short pet_egg_id, - short pet_equip, short intimate, short hungry, char rename_flag, char incubate, char *pet_name) + short pet_equip, short intimate, short hungry, char rename_flag, char incubate, const char *pet_name) { nullpo_ret(pet_name); memset(inter_pet->pt, 0, sizeof(struct s_pet)); @@ -240,8 +251,8 @@ int mapif_create_pet(int fd, int account_id, int char_id, short pet_class, short else if(inter_pet->pt->intimate > 1000) inter_pet->pt->intimate = 1000; - inter_pet->pt->pet_id = -1; //Signal NEW pet. - if (inter_pet->tosql(inter_pet->pt->pet_id,inter_pet->pt)) + inter_pet->pt->pet_id = 0; //Signal NEW pet. + if ((inter_pet->pt->pet_id = inter_pet->tosql(inter_pet->pt)) != 0) mapif->pet_created(fd, account_id, inter_pet->pt); else //Failed... mapif->pet_created(fd, account_id, NULL); @@ -271,7 +282,7 @@ int mapif_load_pet(int fd, int account_id, int char_id, int pet_id) return 0; } -int mapif_save_pet(int fd, int account_id, struct s_pet *data) +int mapif_save_pet(int fd, int account_id, const struct s_pet *data) { //here process pet save request. int len; @@ -283,15 +294,7 @@ int mapif_save_pet(int fd, int account_id, struct s_pet *data) return 0; } - if (data->hungry < 0) - data->hungry = 0; - else if (data->hungry > 100) - data->hungry = 100; - if (data->intimate < 0) - data->intimate = 0; - else if (data->intimate > 1000) - data->intimate = 1000; - inter_pet->tosql(data->pet_id,data); + inter_pet->tosql(data); mapif->save_pet_ack(fd, account_id, 0); return 0; @@ -308,7 +311,7 @@ int mapif_parse_CreatePet(int fd) { RFIFOHEAD(fd); mapif->create_pet(fd, RFIFOL(fd, 2), RFIFOL(fd, 6), RFIFOW(fd, 10), RFIFOW(fd, 12), RFIFOW(fd, 14), RFIFOW(fd, 16), RFIFOW(fd, 18), - RFIFOW(fd, 20), RFIFOB(fd, 22), RFIFOB(fd, 23), (char*)RFIFOP(fd, 24)); + RFIFOW(fd, 20), RFIFOB(fd, 22), RFIFOB(fd, 23), RFIFOP(fd, 24)); return 0; } @@ -322,7 +325,7 @@ int mapif_parse_LoadPet(int fd) int mapif_parse_SavePet(int fd) { RFIFOHEAD(fd); - mapif->save_pet(fd, RFIFOL(fd, 4), (struct s_pet *) RFIFOP(fd, 8)); + mapif->save_pet(fd, RFIFOL(fd, 4), RFIFOP(fd, 8)); return 0; } diff --git a/src/char/int_pet.h b/src/char/int_pet.h index 07a273eac..3eb19d656 100644 --- a/src/char/int_pet.h +++ b/src/char/int_pet.h @@ -30,7 +30,7 @@ struct s_pet; **/ struct inter_pet_interface { struct s_pet *pt; - int (*tosql) (int pet_id, struct s_pet* p); + int (*tosql) (const struct s_pet *p); int (*fromsql) (int pet_id, struct s_pet* p); int (*sql_init) (void); void (*sql_final) (void); diff --git a/src/char/int_quest.c b/src/char/int_quest.c index 946603b0a..b28c81331 100644 --- a/src/char/int_quest.c +++ b/src/char/int_quest.c @@ -154,7 +154,7 @@ bool mapif_quest_add(int char_id, struct quest qd) for (i = 0; i < MAX_QUEST_OBJECTIVES; i++) { StrBuf->Printf(&buf, ", `count%d`", i+1); } - StrBuf->Printf(&buf, ") VALUES ('%d', '%d', '%d', '%d'", qd.quest_id, char_id, qd.state, qd.time); + StrBuf->Printf(&buf, ") VALUES ('%d', '%d', '%u', '%u'", qd.quest_id, char_id, qd.state, qd.time); for (i = 0; i < MAX_QUEST_OBJECTIVES; i++) { StrBuf->Printf(&buf, ", '%d'", qd.count[i]); } @@ -182,7 +182,7 @@ bool mapif_quest_update(int char_id, struct quest qd) int i; StrBuf->Init(&buf); - StrBuf->Printf(&buf, "UPDATE `%s` SET `state`='%d'", quest_db, qd.state); + StrBuf->Printf(&buf, "UPDATE `%s` SET `state`='%u'", quest_db, qd.state); for (i = 0; i < MAX_QUEST_OBJECTIVES; i++) { StrBuf->Printf(&buf, ", `count%d`='%d'", i+1, qd.count[i]); } @@ -218,11 +218,12 @@ int mapif_parse_quest_save(int fd) { int i, j, k, old_n, new_n = (RFIFOW(fd,2)-8)/sizeof(struct quest); int char_id = RFIFOL(fd,4); - struct quest *old_qd = NULL, *new_qd = NULL; + struct quest *old_qd = NULL; + const struct quest *new_qd = NULL; bool success = true; if (new_n > 0) - new_qd = (struct quest*)RFIFOP(fd,8); + new_qd = RFIFOP(fd,8); old_qd = mapif->quests_fromsql(char_id, &old_n); diff --git a/src/char/int_storage.c b/src/char/int_storage.c index 086ef2044..705aa02d2 100644 --- a/src/char/int_storage.c +++ b/src/char/int_storage.c @@ -37,8 +37,6 @@ #include <stdio.h> #include <stdlib.h> -#define STORAGE_MEMINC 16 - struct inter_storage_interface inter_storage_s; struct inter_storage_interface *inter_storage; @@ -99,7 +97,7 @@ int inter_storage_fromsql(int account_id, struct storage_data* p) } /// Save guild_storage data to sql -int inter_storage_guild_storage_tosql(int guild_id, struct guild_storage* p) +int inter_storage_guild_storage_tosql(int guild_id, const struct guild_storage *p) { nullpo_ret(p); chr->memitemdata_to_sql(p->items, MAX_GUILD_STORAGE, guild_id, TABLE_GUILD_STORAGE); @@ -197,7 +195,7 @@ int mapif_load_guild_storage(int fd, int account_id, int guild_id, char flag) WFIFOL(fd,4) = account_id; 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)); + inter_storage->guild_storage_fromsql(guild_id, WFIFOP(fd,13)); WFIFOSET(fd, WFIFOW(fd,2)); return 0; } @@ -249,7 +247,7 @@ int mapif_parse_SaveGuildStorage(int fd) } else if(SQL->NumRows(inter->sql_handle) > 0) { // guild exists SQL->FreeResult(inter->sql_handle); - inter_storage->guild_storage_tosql(guild_id, (struct guild_storage*)RFIFOP(fd,12)); + inter_storage->guild_storage_tosql(guild_id, RFIFOP(fd,12)); mapif->save_guild_storage_ack(fd, RFIFOL(fd,4), guild_id, 0); return 0; } @@ -418,7 +416,7 @@ int mapif_parse_ItemBoundRetrieve_sub(int fd) if( j ) StrBuf->AppendStr(&buf, ","); - StrBuf->Printf(&buf, "('%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%"PRIu64"'", + StrBuf->Printf(&buf, "('%d', '%d', '%d', '%u', '%d', '%d', '%d', '%u', '%d', '%"PRIu64"'", guild_id, items[j].nameid, items[j].amount, items[j].equip, items[j].identify, items[j].refine, items[j].attribute, items[j].expire_time, items[j].bound, items[j].unique_id); for( s = 0; s < MAX_SLOTS; ++s ) diff --git a/src/char/int_storage.h b/src/char/int_storage.h index 9bf5b5fd5..3c48c00ec 100644 --- a/src/char/int_storage.h +++ b/src/char/int_storage.h @@ -32,7 +32,7 @@ struct guild_storage; 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_tosql) (int guild_id, const struct guild_storage *p); int (*guild_storage_fromsql) (int guild_id, struct guild_storage* p); int (*sql_init) (void); void (*sql_final) (void); diff --git a/src/char/inter.c b/src/char/inter.c index 87ecb4e6a..4ef94efdf 100644 --- a/src/char/inter.c +++ b/src/char/inter.c @@ -413,7 +413,7 @@ void inter_vmsg_to_fd(int fd, int u_fd, int aid, char* msg, va_list ap) WFIFOW(fd,2) = 12 + (unsigned short)len; WFIFOL(fd,4) = u_fd; WFIFOL(fd,8) = aid; - safestrncpy((char*)WFIFOP(fd,12), msg_out, len); + safestrncpy(WFIFOP(fd,12), msg_out, len); WFIFOSET(fd,12 + len); @@ -446,7 +446,7 @@ void mapif_parse_accinfo(int fd) int account_id; char *data; - safestrncpy(query, (char*) RFIFOP(fd,14), NAME_LENGTH); + safestrncpy(query, RFIFOP(fd,14), NAME_LENGTH); SQL->EscapeString(inter->sql_handle, query_esq, query); @@ -665,7 +665,7 @@ 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 32 */ plen += 1; - safestrncpy((char*)WFIFOP(fd,plen), data, len); + safestrncpy(WFIFOP(fd,plen), data, len); plen += len; SQL->GetData(inter->sql_handle, 1, &data, NULL); @@ -679,7 +679,7 @@ 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); + safestrncpy(WFIFOP(fd,plen), data, len); plen += len; WFIFOW(fd, 14) += 1; @@ -746,7 +746,7 @@ 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 32 */ plen += 1; - safestrncpy((char*)WFIFOP(fd,plen), data, len); + safestrncpy(WFIFOP(fd,plen), data, len); plen += len; SQL->GetData(inter->sql_handle, 1, &data, NULL); @@ -939,7 +939,7 @@ int inter_mapif_init(int fd) //-------------------------------------------------------- // broadcast sending -int mapif_broadcast(unsigned char *mes, int len, unsigned int fontColor, short fontType, short fontSize, short fontAlign, short fontY, int sfd) +int mapif_broadcast(const unsigned char *mes, int len, unsigned int fontColor, short fontType, short fontSize, short fontAlign, short fontY, int sfd) { unsigned char *buf = (unsigned char*)aMalloc((len)*sizeof(unsigned char)); @@ -981,7 +981,7 @@ int mapif_wis_message(struct WisData *wd) return 0; } -void mapif_wis_response(int fd, unsigned char *src, int flag) +void mapif_wis_response(int fd, const unsigned char *src, int flag) { unsigned char buf[27]; nullpo_retv(src); @@ -1101,7 +1101,7 @@ int mapif_parse_WisRequest(int fd) return 0; } - safestrncpy(name, (char*)RFIFOP(fd,28), NAME_LENGTH); //Received name may be too large and not contain \0! [Skotlex] + safestrncpy(name, RFIFOP(fd,28), NAME_LENGTH); //Received name may be too large and not contain \0! [Skotlex] SQL->EscapeStringLen(inter->sql_handle, esc_name, name, strnlen(name, NAME_LENGTH)); if( SQL_ERROR == SQL->Query(inter->sql_handle, "SELECT `name` FROM `%s` WHERE `name`='%s'", char_db, esc_name) ) @@ -1119,8 +1119,7 @@ int mapif_parse_WisRequest(int fd) memset(name, 0, NAME_LENGTH); memcpy(name, data, min(len, NAME_LENGTH)); // if source is destination, don't ask other servers. - if( strncmp((const char*)RFIFOP(fd,4), name, NAME_LENGTH) == 0 ) - { + if (strncmp(RFIFOP(fd,4), name, NAME_LENGTH) == 0) { mapif->wis_response(fd, RFIFOP(fd, 4), 1); } else @@ -1195,7 +1194,7 @@ int mapif_parse_Registry(int fd) for(i = 0; i < count; i++) { unsigned int index; int len = RFIFOB(fd, cursor); - safestrncpy(key, (char*)RFIFOP(fd, cursor + 1), min((int)sizeof(key), len)); + safestrncpy(key, RFIFOP(fd, cursor + 1), min((int)sizeof(key), len)); cursor += len + 1; index = RFIFOL(fd, cursor); @@ -1213,7 +1212,7 @@ int mapif_parse_Registry(int fd) /* str */ case 2: len = RFIFOB(fd, cursor); - safestrncpy(sval, (char*)RFIFOP(fd, cursor + 1), min((int)sizeof(sval), len)); + safestrncpy(sval, RFIFOP(fd, cursor + 1), min((int)sizeof(sval), len)); cursor += len + 1; inter->savereg(account_id,char_id,key,index,(intptr_t)sval,true); break; @@ -1261,13 +1260,13 @@ void mapif_namechange_ack(int fd, int account_id, int char_id, int type, int fla int mapif_parse_NameChangeRequest(int fd) { int account_id, char_id, type; - char* name; + const char *name; int i; account_id = RFIFOL(fd,2); char_id = RFIFOL(fd,6); type = RFIFOB(fd,10); - name = (char*)RFIFOP(fd,11); + name = RFIFOP(fd,11); // Check Authorized letters/symbols in the name if (char_name_option == 1) { // only letters/symbols in char_name_letters are authorized diff --git a/src/char/inter.h b/src/char/inter.h index 49eca1256..b8bcb2def 100644 --- a/src/char/inter.h +++ b/src/char/inter.h @@ -37,7 +37,7 @@ struct inter_interface { 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 (*msg_to_fd) (int fd, int u_fd, int aid, char *msg, ...) __attribute__((format(printf, 4, 5))); 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); diff --git a/src/char/loginif.c b/src/char/loginif.c index c577ad791..1e457fcca 100644 --- a/src/char/loginif.c +++ b/src/char/loginif.c @@ -39,6 +39,7 @@ struct loginif_interface loginif_s; struct loginif_interface *loginif; /// Resets all the data. +void loginif_reset(void) __attribute__ ((noreturn)); void loginif_reset(void) { int id; diff --git a/src/char/mapif.c b/src/char/mapif.c index 5ba687a77..91bfd884c 100644 --- a/src/char/mapif.c +++ b/src/char/mapif.c @@ -42,7 +42,7 @@ void mapif_server_reset(int id); void mapif_on_disconnect(int id); void mapif_on_parse_accinfo(int account_id, int u_fd, int u_aid, int u_group, int map_fd); void mapif_char_ban(int char_id, time_t timestamp); -int mapif_sendall(unsigned char *buf, unsigned int len); +int mapif_sendall(const unsigned char *buf, unsigned int len); int mapif_sendallwos(int sfd, unsigned char *buf, unsigned int len); int mapif_send(int fd, unsigned char *buf, unsigned int len); void mapif_send_users_count(int users); @@ -57,16 +57,17 @@ void mapif_auction_close(int fd, int char_id, unsigned char result); void mapif_parse_auction_close(int fd); void mapif_auction_bid(int fd, int char_id, int bid, unsigned char result); void mapif_parse_auction_bid(int fd); -bool mapif_elemental_save(struct s_elemental* ele); +bool mapif_elemental_create(struct s_elemental *ele); +bool mapif_elemental_save(const struct s_elemental *ele); bool mapif_elemental_load(int ele_id, int char_id, struct s_elemental *ele); bool mapif_elemental_delete(int ele_id); void mapif_elemental_send(int fd, struct s_elemental *ele, unsigned char flag); -void mapif_parse_elemental_create(int fd, struct s_elemental* ele); +void mapif_parse_elemental_create(int fd, const struct s_elemental *ele); void mapif_parse_elemental_load(int fd, int ele_id, int char_id); void mapif_elemental_deleted(int fd, unsigned char flag); void mapif_parse_elemental_delete(int fd, int ele_id); void mapif_elemental_saved(int fd, unsigned char flag); -void mapif_parse_elemental_save(int fd, struct s_elemental* ele); +void mapif_parse_elemental_save(int fd, const struct s_elemental *ele); int mapif_guild_created(int fd, int account_id, struct guild *g); int mapif_guild_noinfo(int fd, int guild_id); int mapif_guild_info(int fd, struct guild *g); @@ -74,7 +75,7 @@ int mapif_guild_memberadded(int fd, int guild_id, int account_id, int char_id, i int mapif_guild_withdraw(int guild_id, int account_id, int char_id, int flag, const char *name, const char *mes); int mapif_guild_memberinfoshort(struct guild *g, int idx); int mapif_guild_broken(int guild_id, int flag); -int mapif_guild_message(int guild_id,int account_id,char *mes,int len, int sfd); +int mapif_guild_message(int guild_id, int account_id, const char *mes, int len, int sfd); int mapif_guild_basicinfochanged(int guild_id, int type, const void *data, int len); int mapif_guild_memberinfochanged(int guild_id, int account_id, int char_id, int type, const void *data, int len); int mapif_guild_skillupack(int guild_id, uint16 skill_id, int account_id); @@ -83,39 +84,40 @@ int mapif_guild_position(struct guild *g, int idx); int mapif_guild_notice(struct guild *g); int mapif_guild_emblem(struct guild *g); int mapif_guild_master_changed(struct guild *g, int aid, int cid); -int mapif_guild_castle_dataload(int fd, int sz, int *castle_ids); -int mapif_parse_CreateGuild(int fd,int account_id,char *name,struct guild_member *master); +int mapif_guild_castle_dataload(int fd, int sz, const int *castle_ids); +int mapif_parse_CreateGuild(int fd, int account_id, const char *name, const struct guild_member *master); int mapif_parse_GuildInfo(int fd, int guild_id); -int mapif_parse_GuildAddMember(int fd, int guild_id, struct guild_member *m); +int mapif_parse_GuildAddMember(int fd, int guild_id, const struct guild_member *m); int mapif_parse_GuildLeave(int fd, int guild_id, int account_id, int char_id, int flag, const char *mes); int mapif_parse_GuildChangeMemberInfoShort(int fd, int guild_id, int account_id, int char_id, int online, int lv, int class_); int mapif_parse_BreakGuild(int fd, int guild_id); -int mapif_parse_GuildMessage(int fd, int guild_id, int account_id, char *mes, int len); +int mapif_parse_GuildMessage(int fd, int guild_id, int account_id, const char *mes, int len); int mapif_parse_GuildBasicInfoChange(int fd, int guild_id, int type, const void *data, int len); int mapif_parse_GuildMemberInfoChange(int fd, int guild_id, int account_id, int char_id, int type, const char *data, int len); -int mapif_parse_GuildPosition(int fd, int guild_id, int idx, struct guild_position *p); +int mapif_parse_GuildPosition(int fd, int guild_id, int idx, const struct guild_position *p); int mapif_parse_GuildSkillUp(int fd, int guild_id, uint16 skill_id, int account_id, int max); int mapif_parse_GuildDeleteAlliance(struct guild *g, int guild_id, int account_id1, int account_id2, int flag); int mapif_parse_GuildAlliance(int fd, int guild_id1, int guild_id2, int account_id1, int account_id2, int flag); int mapif_parse_GuildNotice(int fd, int guild_id, const char *mes1, const char *mes2); int mapif_parse_GuildEmblem(int fd, int len, int guild_id, int dummy, const char *data); -int mapif_parse_GuildCastleDataLoad(int fd, int len, int *castle_ids); +int mapif_parse_GuildCastleDataLoad(int fd, int len, const int *castle_ids); int mapif_parse_GuildCastleDataSave(int fd, int castle_id, int index, int value); int mapif_parse_GuildMasterChange(int fd, int guild_id, const char* name, int len); -void mapif_homunculus_created(int fd, int account_id, struct s_homunculus *sh, unsigned char flag); +void mapif_homunculus_created(int fd, int account_id, const struct s_homunculus *sh, unsigned char flag); void mapif_homunculus_deleted(int fd, int flag); void mapif_homunculus_loaded(int fd, int account_id, struct s_homunculus *hd); void mapif_homunculus_saved(int fd, int account_id, bool flag); -void mapif_homunculus_renamed(int fd, int account_id, int char_id, unsigned char flag, char* name); -bool mapif_homunculus_save(struct s_homunculus* hd); +void mapif_homunculus_renamed(int fd, int account_id, int char_id, unsigned char flag, const char *name); +bool mapif_homunculus_create(struct s_homunculus *hd); +bool mapif_homunculus_save(const struct s_homunculus *hd); bool mapif_homunculus_load(int homun_id, struct s_homunculus* hd); bool mapif_homunculus_delete(int homun_id); -bool mapif_homunculus_rename(char *name); -void mapif_parse_homunculus_create(int fd, int len, int account_id, struct s_homunculus* phd); +bool mapif_homunculus_rename(const char *name); +void mapif_parse_homunculus_create(int fd, int len, int account_id, const struct s_homunculus *phd); void mapif_parse_homunculus_delete(int fd, int homun_id); void mapif_parse_homunculus_load(int fd, int account_id, int homun_id); -void mapif_parse_homunculus_save(int fd, int len, int account_id, struct s_homunculus* phd); -void mapif_parse_homunculus_rename(int fd, int account_id, int char_id, char* name); +void mapif_parse_homunculus_save(int fd, int len, int account_id, const struct s_homunculus *phd); +void mapif_parse_homunculus_rename(int fd, int account_id, int char_id, const char *name); void mapif_mail_sendinbox(int fd, int char_id, unsigned char flag, struct mail_data *md); void mapif_parse_mail_requestinbox(int fd); void mapif_parse_mail_read(int fd); @@ -129,16 +131,17 @@ void mapif_mail_return(int fd, int char_id, int mail_id, int new_mail); void mapif_parse_mail_return(int fd); void mapif_mail_send(int fd, struct mail_message* msg); void mapif_parse_mail_send(int fd); -bool mapif_mercenary_save(struct s_mercenary* merc); +bool mapif_mercenary_create(struct s_mercenary *merc); +bool mapif_mercenary_save(const struct s_mercenary *merc); bool mapif_mercenary_load(int merc_id, int char_id, struct s_mercenary *merc); bool mapif_mercenary_delete(int merc_id); void mapif_mercenary_send(int fd, struct s_mercenary *merc, unsigned char flag); -void mapif_parse_mercenary_create(int fd, struct s_mercenary* merc); +void mapif_parse_mercenary_create(int fd, const struct s_mercenary *merc); void mapif_parse_mercenary_load(int fd, int merc_id, int char_id); void mapif_mercenary_deleted(int fd, unsigned char flag); void mapif_parse_mercenary_delete(int fd, int merc_id); void mapif_mercenary_saved(int fd, unsigned char flag); -void mapif_parse_mercenary_save(int fd, struct s_mercenary* merc); +void mapif_parse_mercenary_save(int fd, const struct s_mercenary *merc); int mapif_party_created(int fd, int account_id, int char_id, struct party *p); void mapif_party_noinfo(int fd, int party_id, int char_id); void mapif_party_info(int fd, struct party* p, int char_id); @@ -147,15 +150,15 @@ int mapif_party_optionchanged(int fd, struct party *p, int account_id, int flag) int mapif_party_withdraw(int party_id,int account_id, int char_id); int mapif_party_membermoved(struct party *p, int idx); int mapif_party_broken(int party_id, int flag); -int mapif_party_message(int party_id, int account_id, char *mes, int len, int sfd); -int mapif_parse_CreateParty(int fd, char *name, int item, int item2, struct party_member *leader); +int mapif_party_message(int party_id, int account_id, const char *mes, int len, int sfd); +int mapif_parse_CreateParty(int fd, const char *name, int item, int item2, const struct party_member *leader); void mapif_parse_PartyInfo(int fd, int party_id, int char_id); -int mapif_parse_PartyAddMember(int fd, int party_id, struct party_member *member); +int mapif_parse_PartyAddMember(int fd, int party_id, const struct party_member *member); int mapif_parse_PartyChangeOption(int fd,int party_id,int account_id,int exp,int item); int mapif_parse_PartyLeave(int fd, int party_id, int account_id, int char_id); int mapif_parse_PartyChangeMap(int fd, int party_id, int account_id, int char_id, unsigned short map, int online, unsigned int lv); int mapif_parse_BreakParty(int fd, int party_id); -int mapif_parse_PartyMessage(int fd, int party_id, int account_id, char *mes, int len); +int mapif_parse_PartyMessage(int fd, int party_id, int account_id, const char *mes, int len); int mapif_parse_PartyLeaderChange(int fd, int party_id, int account_id, int char_id); int mapif_pet_created(int fd, int account_id, struct s_pet *p); int mapif_pet_info(int fd, int account_id, struct s_pet *p); @@ -163,9 +166,9 @@ int mapif_pet_noinfo(int fd, int account_id); int mapif_save_pet_ack(int fd, int account_id, int flag); int mapif_delete_pet_ack(int fd, int flag); int mapif_create_pet(int fd, int account_id, int char_id, short pet_class, short pet_lv, short pet_egg_id, - short pet_equip, short intimate, short hungry, char rename_flag, char incubate, char *pet_name); + short pet_equip, short intimate, short hungry, char rename_flag, char incubate, const char *pet_name); int mapif_load_pet(int fd, int account_id, int char_id, int pet_id); -int mapif_save_pet(int fd, int account_id, struct s_pet *data); +int mapif_save_pet(int fd, int account_id, const struct s_pet *data); int mapif_delete_pet(int fd, int pet_id); int mapif_parse_CreatePet(int fd); int mapif_parse_LoadPet(int fd); @@ -189,9 +192,9 @@ void mapif_parse_ItemBoundRetrieve(int fd); void mapif_parse_accinfo(int fd); 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); -int mapif_broadcast(unsigned char *mes, int len, unsigned int fontColor, short fontType, short fontSize, short fontAlign, short fontY, int sfd); +int mapif_broadcast(const unsigned char *mes, int len, unsigned int fontColor, short fontType, short fontSize, short fontAlign, short fontY, int sfd); int mapif_wis_message(struct WisData *wd); -void mapif_wis_response(int fd, unsigned char *src, int flag); +void mapif_wis_response(int fd, const unsigned char *src, int flag); int mapif_wis_end(struct WisData *wd, int flag); int mapif_account_reg_reply(int fd,int account_id,int char_id, int type); int mapif_disconnectplayer(int fd, int account_id, int char_id, int reason); @@ -232,6 +235,7 @@ void mapif_defaults(void) { mapif->parse_auction_close = mapif_parse_auction_close; mapif->auction_bid = mapif_auction_bid; mapif->parse_auction_bid = mapif_parse_auction_bid; + mapif->elemental_create = mapif_elemental_create; mapif->elemental_save = mapif_elemental_save; mapif->elemental_load = mapif_elemental_load; mapif->elemental_delete = mapif_elemental_delete; @@ -282,6 +286,7 @@ void mapif_defaults(void) { mapif->homunculus_loaded = mapif_homunculus_loaded; mapif->homunculus_saved = mapif_homunculus_saved; mapif->homunculus_renamed = mapif_homunculus_renamed; + mapif->homunculus_create = mapif_homunculus_create; mapif->homunculus_save = mapif_homunculus_save; mapif->homunculus_load = mapif_homunculus_load; mapif->homunculus_delete = mapif_homunculus_delete; @@ -304,6 +309,7 @@ void mapif_defaults(void) { mapif->parse_mail_return = mapif_parse_mail_return; mapif->mail_send = mapif_mail_send; mapif->parse_mail_send = mapif_parse_mail_send; + mapif->mercenary_create = mapif_mercenary_create; mapif->mercenary_save = mapif_mercenary_save; mapif->mercenary_load = mapif_mercenary_load; mapif->mercenary_delete = mapif_mercenary_delete; diff --git a/src/char/mapif.h b/src/char/mapif.h index eb5d30b2c..37d9444e2 100644 --- a/src/char/mapif.h +++ b/src/char/mapif.h @@ -36,7 +36,7 @@ struct mapif_interface { void (*on_disconnect) (int id); void (*on_parse_accinfo) (int account_id, int u_fd, int u_aid, int u_group, int map_fd); void (*char_ban) (int char_id, time_t timestamp); - int (*sendall) (unsigned char *buf, unsigned int len); + int (*sendall) (const unsigned char *buf, unsigned int len); int (*sendallwos) (int sfd, unsigned char *buf, unsigned int len); int (*send) (int fd, unsigned char *buf, unsigned int len); void (*send_users_count) (int users); @@ -51,16 +51,17 @@ struct mapif_interface { void (*parse_auction_close) (int fd); void (*auction_bid) (int fd, int char_id, int bid, unsigned char result); void (*parse_auction_bid) (int fd); - bool (*elemental_save) (struct s_elemental* ele); + bool (*elemental_create) (struct s_elemental *ele); + bool (*elemental_save) (const struct s_elemental *ele); bool (*elemental_load) (int ele_id, int char_id, struct s_elemental *ele); bool (*elemental_delete) (int ele_id); void (*elemental_send) (int fd, struct s_elemental *ele, unsigned char flag); - void (*parse_elemental_create) (int fd, struct s_elemental* ele); + void (*parse_elemental_create) (int fd, const struct s_elemental *ele); void (*parse_elemental_load) (int fd, int ele_id, int char_id); void (*elemental_deleted) (int fd, unsigned char flag); void (*parse_elemental_delete) (int fd, int ele_id); void (*elemental_saved) (int fd, unsigned char flag); - void (*parse_elemental_save) (int fd, struct s_elemental* ele); + void (*parse_elemental_save) (int fd, const struct s_elemental *ele); int (*guild_created) (int fd, int account_id, struct guild *g); int (*guild_noinfo) (int fd, int guild_id); int (*guild_info) (int fd, struct guild *g); @@ -68,7 +69,7 @@ struct mapif_interface { int (*guild_withdraw) (int guild_id, int account_id, int char_id, int flag, const char *name, const char *mes); int (*guild_memberinfoshort) (struct guild *g, int idx); int (*guild_broken) (int guild_id, int flag); - int (*guild_message) (int guild_id,int account_id,char *mes,int len, int sfd); + int (*guild_message) (int guild_id, int account_id, const char *mes, int len, int sfd); int (*guild_basicinfochanged) (int guild_id, int type, const void *data, int len); int (*guild_memberinfochanged) (int guild_id, int account_id, int char_id, int type, const void *data, int len); int (*guild_skillupack) (int guild_id, uint16 skill_id, int account_id); @@ -77,39 +78,40 @@ struct mapif_interface { int (*guild_notice) (struct guild *g); int (*guild_emblem) (struct guild *g); int (*guild_master_changed) (struct guild *g, int aid, int cid); - int (*guild_castle_dataload) (int fd, int sz, int *castle_ids); - int (*parse_CreateGuild) (int fd,int account_id,char *name,struct guild_member *master); + int (*guild_castle_dataload) (int fd, int sz, const int *castle_ids); + int (*parse_CreateGuild) (int fd, int account_id, const char *name, const struct guild_member *master); int (*parse_GuildInfo) (int fd, int guild_id); - int (*parse_GuildAddMember) (int fd, int guild_id, struct guild_member *m); + int (*parse_GuildAddMember) (int fd, int guild_id, const struct guild_member *m); int (*parse_GuildLeave) (int fd, int guild_id, int account_id, int char_id, int flag, const char *mes); int (*parse_GuildChangeMemberInfoShort) (int fd, int guild_id, int account_id, int char_id, int online, int lv, int class_); int (*parse_BreakGuild) (int fd, int guild_id); - int (*parse_GuildMessage) (int fd, int guild_id, int account_id, char *mes, int len); + int (*parse_GuildMessage) (int fd, int guild_id, int account_id, const char *mes, int len); int (*parse_GuildBasicInfoChange) (int fd, int guild_id, int type, const void *data, int len); int (*parse_GuildMemberInfoChange) (int fd, int guild_id, int account_id, int char_id, int type, const char *data, int len); - int (*parse_GuildPosition) (int fd, int guild_id, int idx, struct guild_position *p); + int (*parse_GuildPosition) (int fd, int guild_id, int idx, const struct guild_position *p); int (*parse_GuildSkillUp) (int fd, int guild_id, uint16 skill_id, int account_id, int max); int (*parse_GuildDeleteAlliance) (struct guild *g, int guild_id, int account_id1, int account_id2, int flag); int (*parse_GuildAlliance) (int fd, int guild_id1, int guild_id2, int account_id1, int account_id2, int flag); int (*parse_GuildNotice) (int fd, int guild_id, const char *mes1, const char *mes2); int (*parse_GuildEmblem) (int fd, int len, int guild_id, int dummy, const char *data); - int (*parse_GuildCastleDataLoad) (int fd, int len, int *castle_ids); + int (*parse_GuildCastleDataLoad) (int fd, int len, const int *castle_ids); int (*parse_GuildCastleDataSave) (int fd, int castle_id, int index, int value); int (*parse_GuildMasterChange) (int fd, int guild_id, const char* name, int len); - void (*homunculus_created) (int fd, int account_id, struct s_homunculus *sh, unsigned char flag); + void (*homunculus_created) (int fd, int account_id, const struct s_homunculus *sh, unsigned char flag); void (*homunculus_deleted) (int fd, int flag); void (*homunculus_loaded) (int fd, int account_id, struct s_homunculus *hd); void (*homunculus_saved) (int fd, int account_id, bool flag); - void (*homunculus_renamed) (int fd, int account_id, int char_id, unsigned char flag, char* name); - bool (*homunculus_save) (struct s_homunculus* hd); + void (*homunculus_renamed) (int fd, int account_id, int char_id, unsigned char flag, const char *name); + bool (*homunculus_create) (struct s_homunculus *hd); + bool (*homunculus_save) (const struct s_homunculus *hd); bool (*homunculus_load) (int homun_id, struct s_homunculus* hd); bool (*homunculus_delete) (int homun_id); - bool (*homunculus_rename) (char *name); - void (*parse_homunculus_create) (int fd, int len, int account_id, struct s_homunculus* phd); + bool (*homunculus_rename) (const char *name); + void (*parse_homunculus_create) (int fd, int len, int account_id, const struct s_homunculus *phd); void (*parse_homunculus_delete) (int fd, int homun_id); void (*parse_homunculus_load) (int fd, int account_id, int homun_id); - void (*parse_homunculus_save) (int fd, int len, int account_id, struct s_homunculus* phd); - void (*parse_homunculus_rename) (int fd, int account_id, int char_id, char* name); + void (*parse_homunculus_save) (int fd, int len, int account_id, const struct s_homunculus *phd); + void (*parse_homunculus_rename) (int fd, int account_id, int char_id, const char *name); void (*mail_sendinbox) (int fd, int char_id, unsigned char flag, struct mail_data *md); void (*parse_mail_requestinbox) (int fd); void (*parse_mail_read) (int fd); @@ -123,16 +125,17 @@ struct mapif_interface { void (*parse_mail_return) (int fd); void (*mail_send) (int fd, struct mail_message* msg); void (*parse_mail_send) (int fd); - bool (*mercenary_save) (struct s_mercenary* merc); + bool (*mercenary_create) (struct s_mercenary *merc); + bool (*mercenary_save) (const struct s_mercenary *merc); bool (*mercenary_load) (int merc_id, int char_id, struct s_mercenary *merc); bool (*mercenary_delete) (int merc_id); void (*mercenary_send) (int fd, struct s_mercenary *merc, unsigned char flag); - void (*parse_mercenary_create) (int fd, struct s_mercenary* merc); + void (*parse_mercenary_create) (int fd, const struct s_mercenary *merc); void (*parse_mercenary_load) (int fd, int merc_id, int char_id); void (*mercenary_deleted) (int fd, unsigned char flag); void (*parse_mercenary_delete) (int fd, int merc_id); void (*mercenary_saved) (int fd, unsigned char flag); - void (*parse_mercenary_save) (int fd, struct s_mercenary* merc); + void (*parse_mercenary_save) (int fd, const struct s_mercenary *merc); int (*party_created) (int fd, int account_id, int char_id, struct party *p); void (*party_noinfo) (int fd, int party_id, int char_id); void (*party_info) (int fd, struct party* p, int char_id); @@ -141,15 +144,15 @@ struct mapif_interface { int (*party_withdraw) (int party_id,int account_id, int char_id); int (*party_membermoved) (struct party *p, int idx); int (*party_broken) (int party_id, int flag); - int (*party_message) (int party_id, int account_id, char *mes, int len, int sfd); - int (*parse_CreateParty) (int fd, char *name, int item, int item2, struct party_member *leader); + int (*party_message) (int party_id, int account_id, const char *mes, int len, int sfd); + int (*parse_CreateParty) (int fd, const char *name, int item, int item2, const struct party_member *leader); void (*parse_PartyInfo) (int fd, int party_id, int char_id); - int (*parse_PartyAddMember) (int fd, int party_id, struct party_member *member); + int (*parse_PartyAddMember) (int fd, int party_id, const struct party_member *member); int (*parse_PartyChangeOption) (int fd,int party_id,int account_id,int exp,int item); int (*parse_PartyLeave) (int fd, int party_id, int account_id, int char_id); int (*parse_PartyChangeMap) (int fd, int party_id, int account_id, int char_id, unsigned short map, int online, unsigned int lv); int (*parse_BreakParty) (int fd, int party_id); - int (*parse_PartyMessage) (int fd, int party_id, int account_id, char *mes, int len); + int (*parse_PartyMessage) (int fd, int party_id, int account_id, const char *mes, int len); int (*parse_PartyLeaderChange) (int fd, int party_id, int account_id, int char_id); int (*pet_created) (int fd, int account_id, struct s_pet *p); int (*pet_info) (int fd, int account_id, struct s_pet *p); @@ -157,9 +160,9 @@ struct mapif_interface { int (*save_pet_ack) (int fd, int account_id, int flag); int (*delete_pet_ack) (int fd, int flag); int (*create_pet) (int fd, int account_id, int char_id, short pet_class, short pet_lv, short pet_egg_id, - short pet_equip, short intimate, short hungry, char rename_flag, char incubate, char *pet_name); + short pet_equip, short intimate, short hungry, char rename_flag, char incubate, const char *pet_name); int (*load_pet) (int fd, int account_id, int char_id, int pet_id); - int (*save_pet) (int fd, int account_id, struct s_pet *data); + int (*save_pet) (int fd, int account_id, const struct s_pet *data); int (*delete_pet) (int fd, int pet_id); int (*parse_CreatePet) (int fd); int (*parse_LoadPet) (int fd); @@ -183,9 +186,9 @@ struct mapif_interface { void (*parse_accinfo) (int fd); void (*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); - int (*broadcast) (unsigned char *mes, int len, unsigned int fontColor, short fontType, short fontSize, short fontAlign, short fontY, int sfd); + int (*broadcast) (const unsigned char *mes, int len, unsigned int fontColor, short fontType, short fontSize, short fontAlign, short fontY, int sfd); int (*wis_message) (struct WisData *wd); - void (*wis_response) (int fd, unsigned char *src, int flag); + void (*wis_response) (int fd, const unsigned char *src, int flag); int (*wis_end) (struct WisData *wd, int flag); int (*account_reg_reply) (int fd,int account_id,int char_id, int type); int (*disconnectplayer) (int fd, int account_id, int char_id, int reason); diff --git a/src/char/pincode.c b/src/char/pincode.c index af79d6f11..6930a7a57 100644 --- a/src/char/pincode.c +++ b/src/char/pincode.c @@ -32,6 +32,7 @@ #include "common/socket.h" #include "common/strlib.h" +#include <stdio.h> #include <stdlib.h> struct pincode_interface pincode_s; @@ -66,7 +67,7 @@ void pincode_check(int fd, struct char_session_data* sd) { char pin[5] = "\0\0\0\0"; nullpo_retv(sd); - safestrncpy(pin, (char*)RFIFOP(fd, 6), sizeof(pin)); + safestrncpy(pin, RFIFOP(fd, 6), sizeof(pin)); pincode->decrypt(sd->pincode_seed, pin); if( pincode->compare( fd, sd, pin ) ){ struct online_char_data* character; @@ -95,12 +96,12 @@ void pincode_change(int fd, struct char_session_data* sd) { char oldpin[5] = "\0\0\0\0", newpin[5] = "\0\0\0\0"; nullpo_retv(sd); - safestrncpy(oldpin, (char*)RFIFOP(fd,6), sizeof(oldpin)); + safestrncpy(oldpin, RFIFOP(fd,6), sizeof(oldpin)); pincode->decrypt(sd->pincode_seed,oldpin); if( !pincode->compare( fd, sd, oldpin ) ) return; - safestrncpy(newpin, (char*)RFIFOP(fd,10), sizeof(newpin)); + safestrncpy(newpin, RFIFOP(fd,10), sizeof(newpin)); pincode->decrypt(sd->pincode_seed,newpin); pincode->update( sd->account_id, newpin ); safestrncpy(sd->pincode, newpin, sizeof(sd->pincode)); @@ -111,7 +112,7 @@ void pincode_setnew(int fd, struct char_session_data* sd) { char newpin[5] = "\0\0\0\0"; nullpo_retv(sd); - safestrncpy(newpin, (char*)RFIFOP(fd,6), sizeof(newpin)); + safestrncpy(newpin, RFIFOP(fd,6), sizeof(newpin)); pincode->decrypt(sd->pincode_seed,newpin); pincode->update( sd->account_id, newpin ); safestrncpy(sd->pincode, newpin, sizeof(sd->pincode)); @@ -143,7 +144,7 @@ void pincode_notifyLoginPinUpdate(int account_id, char* pin) { WFIFOHEAD(chr->login_fd,11); WFIFOW(chr->login_fd,0) = 0x2738; WFIFOL(chr->login_fd,2) = account_id; - safestrncpy( (char*)WFIFOP(chr->login_fd,6), pin, 5 ); + safestrncpy(WFIFOP(chr->login_fd,6), pin, 5); WFIFOSET(chr->login_fd,11); } |