diff options
author | Haru <haru@dotalux.com> | 2016-01-07 03:41:22 +0100 |
---|---|---|
committer | Haru <haru@dotalux.com> | 2016-02-24 20:57:34 +0100 |
commit | 9aa8a3b09ee2c491b55259ee433af7f39308ca37 (patch) | |
tree | f23571319dc25bdcb7efd56df9fc1eab6be32588 /src | |
parent | 931d716e1000b50a66b012815a412619d16fc957 (diff) | |
download | hercules-9aa8a3b09ee2c491b55259ee433af7f39308ca37.tar.gz hercules-9aa8a3b09ee2c491b55259ee433af7f39308ca37.tar.bz2 hercules-9aa8a3b09ee2c491b55259ee433af7f39308ca37.tar.xz hercules-9aa8a3b09ee2c491b55259ee433af7f39308ca37.zip |
Added const qualifier to several variable/argument pointers
- This is necessary for compatibility with a const RFIFOP.
Signed-off-by: Haru <haru@dotalux.com>
Diffstat (limited to 'src')
36 files changed, 347 insertions, 274 deletions
diff --git a/src/char/char.c b/src/char/char.c index e8709c5b9..1e477ba6e 100644 --- a/src/char/char.c +++ b/src/char/char.c @@ -1657,7 +1657,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; @@ -3289,7 +3290,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; @@ -4971,11 +4972,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, (char *)RFIFOP(fd,2), 24); + safestrncpy(l_pass, (char *)RFIFOP(fd,26), 24); ARR_FIND( 0, ARRAYLENGTH(chr->server), i, chr->server[i].fd <= 0 ); if (core->runflag != CHARSERVER_ST_RUNNING || @@ -5286,7 +5286,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; diff --git a/src/char/char.h b/src/char/char.h index ff46e4353..6d8a9815c 100644 --- a/src/char/char.h +++ b/src/char/char.h @@ -137,7 +137,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 +189,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); diff --git a/src/char/int_elemental.c b/src/char/int_elemental.c index 8d868bc06..70275725d 100644 --- a/src/char/int_elemental.c +++ b/src/char/int_elemental.c @@ -155,10 +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) +void mapif_parse_elemental_create(int fd, const struct s_elemental *ele) { - bool result = mapif->elemental_create(ele); - mapif->elemental_send(fd, ele, result); + 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) { @@ -186,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); } diff --git a/src/char/int_guild.c b/src/char/int_guild.c index c78b6b04f..04de75a20 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; @@ -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); } @@ -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); } 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 95374a978..1377bfbd8 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); @@ -279,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; @@ -302,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_create(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) @@ -321,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); diff --git a/src/char/int_mercenary.c b/src/char/int_mercenary.c index 133dcf565..671c71278 100644 --- a/src/char/int_mercenary.c +++ b/src/char/int_mercenary.c @@ -198,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_create(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) diff --git a/src/char/int_party.c b/src/char/int_party.c index 71034a17b..8ff9ca3a2 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,7 +479,7 @@ 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; @@ -493,9 +493,11 @@ 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,"\""); + if (name[i] == '"') { /* client-special-char */ + char *newname = aStrndup(name, NAME_LENGTH-1); + normalize_name(newname,"\""); mapif->parse_CreateParty(fd,name,item,item2,leader); + aFree(newname); return 0; } mapif->party_created(fd,leader->account_id,leader->char_id,NULL); @@ -547,7 +549,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 +731,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); } diff --git a/src/char/int_pet.c b/src/char/int_pet.c index fcf71b255..676ce6ed6 100644 --- a/src/char/int_pet.c +++ b/src/char/int_pet.c @@ -222,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)); diff --git a/src/char/int_quest.c b/src/char/int_quest.c index de3fbd000..9478b532d 100644 --- a/src/char/int_quest.c +++ b/src/char/int_quest.c @@ -218,7 +218,8 @@ 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) diff --git a/src/char/int_storage.c b/src/char/int_storage.c index 30647233b..e98f538a2 100644 --- a/src/char/int_storage.c +++ b/src/char/int_storage.c @@ -97,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); 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..8dec21a77 100644 --- a/src/char/inter.c +++ b/src/char/inter.c @@ -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); @@ -1261,7 +1261,7 @@ 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); diff --git a/src/char/mapif.c b/src/char/mapif.c index 9e37ff528..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); @@ -62,12 +62,12 @@ 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); @@ -75,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); @@ -84,40 +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); +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); @@ -136,12 +136,12 @@ 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); @@ -150,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); @@ -166,7 +166,7 @@ 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, const struct s_pet *data); int mapif_delete_pet(int fd, int pet_id); @@ -192,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); diff --git a/src/char/mapif.h b/src/char/mapif.h index 6b8afd4b2..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); @@ -56,12 +56,12 @@ struct mapif_interface { 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); @@ -69,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); @@ -78,40 +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); + 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); @@ -130,12 +130,12 @@ struct mapif_interface { 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); @@ -144,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); @@ -160,7 +160,7 @@ 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, const struct s_pet *data); int (*delete_pet) (int fd, int pet_id); @@ -186,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/login/login.c b/src/login/login.c index d724cccfb..8181cdae9 100644 --- a/src/login/login.c +++ b/src/login/login.c @@ -1429,8 +1429,8 @@ bool login_parse_client_login(int fd, struct login_session_data* sd, const char // Shinryo: For the time being, just use token as password. if(command == 0x0825) { - char *accname = (char *)RFIFOP(fd, 9); - char *token = (char *)RFIFOP(fd, 0x5C); + const char *accname = (char *)RFIFOP(fd, 9); + const char *token = (char *)RFIFOP(fd, 0x5C); size_t uAccLen = strlen(accname); size_t uTokenLen = RFIFOREST(fd) - 0x5C; diff --git a/src/map/chrif.c b/src/map/chrif.c index 4de82ef07..e14684e54 100644 --- a/src/map/chrif.c +++ b/src/map/chrif.c @@ -594,7 +594,7 @@ void chrif_authok(int fd) { int account_id, group_id, char_id; uint32 login_id1,login_id2; time_t expiration_time; - struct mmo_charstatus* charstatus; + const struct mmo_charstatus *charstatus; struct auth_node *node; bool changing_mapservers; struct map_session_data *sd = NULL; @@ -1221,7 +1221,7 @@ bool chrif_load_scdata(int fd) { count = RFIFOW(fd,12); //sc_count for (i = 0; i < count; i++) { - struct status_change_data *data = (struct status_change_data*)RFIFOP(fd,14 + i*sizeof(struct status_change_data)); + const struct status_change_data *data = (struct status_change_data*)RFIFOP(fd,14 + i*sizeof(struct status_change_data)); status->change_start(NULL, &sd->bl, (sc_type)data->type, 10000, data->val1, data->val2, data->val3, data->val4, data->tick, SCFLAG_NOAVOID|SCFLAG_FIXEDTICK|SCFLAG_LOADED|SCFLAG_FIXEDRATE); } diff --git a/src/map/clif.c b/src/map/clif.c index a7d7dca97..7152aaa14 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -198,22 +198,6 @@ static inline bool disguised(struct block_list* bl) return true; } -//Guarantees that the given string does not exceeds the allowed size, as well as making sure it's null terminated. [Skotlex] -static inline unsigned int mes_len_check(char* mes, unsigned int len, unsigned int max) { - nullpo_retr(0, mes); - if (len <= 0) - { - mes[0] = '\0'; - Assert_retr(0, len > 0); - } - if( len > max ) - len = max; - - mes[len-1] = '\0'; - - return len; -} - /*========================================== * Ip setting of map-server *------------------------------------------*/ @@ -8884,8 +8868,9 @@ void clif_msgtable_skill(struct map_session_data* sd, uint16 skill_id, int msg_i /// Returns true if the packet was parsed successfully. /// Formats: 0 - <packet id>.w <packet len>.w (<name> : <message>).?B 00 /// 1 - <packet id>.w <packet len>.w <name>.24B <message>.?B 00 -bool clif_process_message(struct map_session_data *sd, int format, char **name_, size_t *namelen_, char **message_, size_t *messagelen_) { - char *text, *name, *message; +bool clif_process_message(struct map_session_data *sd, int format, const char **name_, size_t *namelen_, const char **message_, size_t *messagelen_) +{ + const char *text, *name, *message; unsigned int packetlen, textlen; size_t namelen, messagelen; int fd = sd->fd; @@ -9733,7 +9718,8 @@ void clif_parse_GlobalMessage(int fd, struct map_session_data* sd) const char* text = (char*)RFIFOP(fd,4); size_t textlen = RFIFOW(fd,2) - 4; - char *name, *message, *fakename = NULL; + const char *name = NULL, *message = NULL; + char *fakename = NULL; size_t namelen, messagelen; bool is_fake; @@ -9870,10 +9856,9 @@ void clif_parse_MapMove(int fd, struct map_session_data *sd) __attribute__((nonn void clif_parse_MapMove(int fd, struct map_session_data *sd) { char command[MAP_NAME_LENGTH_EXT+25]; - char* map_name; + char map_name[MAP_NAME_LENGTH_EXT]; - map_name = (char*)RFIFOP(fd,2); - map_name[MAP_NAME_LENGTH_EXT-1]='\0'; + safestrncpy(map_name, (char*)RFIFOP(fd,2), MAP_NAME_LENGTH_EXT); sprintf(command, "%cmapmove %s %d %d", atcommand->at_symbol, map_name, RFIFOW(fd,18), RFIFOW(fd,20)); atcommand->exec(fd, sd, command, true); } @@ -10142,7 +10127,7 @@ void clif_parse_WisMessage(int fd, struct map_session_data* sd) struct map_session_data* dstsd; int i; - char *target, *message; + const char *target, *message; size_t namelen, messagelen; // validate packet and retrieve name and message @@ -10172,7 +10157,7 @@ void clif_parse_WisMessage(int fd, struct map_session_data* sd) // Lordalfa - Paperboy - To whisper NPC commands // //-------------------------------------------------------// if (target[0] && (strncasecmp(target,"NPC:",4) == 0) && (strlen(target) > 4)) { - char* str = target+4; //Skip the NPC: string part. + const char *str = target+4; //Skip the NPC: string part. struct npc_data *nd; if ((nd = npc->name2id(str))) { char split_data[NUM_WHISPER_VAR][CHAT_SIZE_MAX]; @@ -10207,7 +10192,7 @@ void clif_parse_WisMessage(int fd, struct map_session_data* sd) return; } } else if( target[0] == '#' ) { - char *chname = target; + const char *chname = target; struct channel_data *chan = channel->search(chname, sd); if (chan) { @@ -10271,19 +10256,26 @@ void clif_parse_WisMessage(int fd, struct map_session_data* sd) clif->wis_message(dstsd->fd, sd->status.name, message, messagelen); } -void clif_parse_Broadcast(int fd, struct map_session_data* sd) __attribute__((nonnull (2))); +void clif_parse_Broadcast(int fd, struct map_session_data *sd) __attribute__((nonnull (2))); /// /b /nb (CZ_BROADCAST). /// Request to broadcast a message on whole server. /// 0099 <packet len>.W <text>.?B 00 -void clif_parse_Broadcast(int fd, struct map_session_data* sd) { - char command[CHAT_SIZE_MAX+11]; - char* msg = (char*)RFIFOP(fd,4); - unsigned int len = RFIFOW(fd,2)-4; +void clif_parse_Broadcast(int fd, struct map_session_data *sd) +{ + const char commandname[] = "kami"; + char command[sizeof commandname + 2 + CHAT_SIZE_MAX] = ""; // '@' command + ' ' + message + NUL + int len = (int)RFIFOW(fd,2) - 4; + + if (len < 0) + return; + + sprintf(command, "%c%s ", atcommand->at_symbol, commandname); - // as the length varies depending on the command used, just block unreasonably long strings - mes_len_check(msg, len, CHAT_SIZE_MAX); + // as the length varies depending on the command used, truncate unreasonably long strings + if (len >= (int)(sizeof command - strlen(command))) + len = (int)(sizeof command - strlen(command)) - 1; - sprintf(command, "%ckami %s", atcommand->at_symbol, msg); + strncat(command, (char*)RFIFOP(fd,4), len); atcommand->exec(fd, sd, command, true); } @@ -10541,13 +10533,16 @@ void clif_parse_NpcBuyListSend(int fd, struct map_session_data* sd) __attribute_ void clif_parse_NpcBuyListSend(int fd, struct map_session_data* sd) { int n = (RFIFOW(fd,2)-4) /4; - unsigned short* item_list = (unsigned short*)RFIFOP(fd,4); int result; - if( sd->state.trading || !sd->npc_shopid || pc_has_permission(sd,PC_PERM_DISABLE_STORE) ) + if( sd->state.trading || !sd->npc_shopid || pc_has_permission(sd,PC_PERM_DISABLE_STORE) ) { result = 1; - else + } else { + unsigned short *item_list = aMalloc(sizeof(*item_list) * 2 * n); + memcpy(item_list, (unsigned short*)RFIFOP(fd,4), sizeof(*item_list) * 2 * n); result = npc->buylist(sd,n,item_list); + aFree(item_list); + } sd->npc_shopid = 0; //Clear shop data. @@ -10576,15 +10571,17 @@ void clif_parse_NpcSellListSend(int fd,struct map_session_data *sd) __attribute_ void clif_parse_NpcSellListSend(int fd,struct map_session_data *sd) { int fail=0,n; - unsigned short *item_list; n = (RFIFOW(fd,2)-4) /4; - item_list = (unsigned short*)RFIFOP(fd,4); - if (sd->state.trading || !sd->npc_shopid) + if (sd->state.trading || !sd->npc_shopid) { fail = 1; - else + } else { + unsigned short *item_list = aMalloc(sizeof(*item_list) * 2 * n); + memcpy(item_list, (unsigned short*)RFIFOP(fd,4), sizeof(*item_list) * 2 * n); fail = npc->selllist(sd,n,item_list); + aFree(item_list); + } sd->npc_shopid = 0; //Clear shop data. @@ -11595,20 +11592,26 @@ void clif_parse_ResetChar(int fd, struct map_session_data *sd) { atcommand->exec(fd, sd, cmd, true); } -void clif_parse_LocalBroadcast(int fd, struct map_session_data* sd) __attribute__((nonnull (2))); +void clif_parse_LocalBroadcast(int fd, struct map_session_data *sd) __attribute__((nonnull (2))); /// /lb /nlb (CZ_LOCALBROADCAST). /// Request to broadcast a message on current map. /// 019c <packet len>.W <text>.?B -void clif_parse_LocalBroadcast(int fd, struct map_session_data* sd) +void clif_parse_LocalBroadcast(int fd, struct map_session_data *sd) { - char command[CHAT_SIZE_MAX+16]; - char* msg = (char*)RFIFOP(fd,4); - unsigned int len = RFIFOW(fd,2)-4; + const char commandname[] = "lkami"; + char command[sizeof commandname + 2 + CHAT_SIZE_MAX] = ""; // '@' + command + ' ' + message + NUL + int len = (int)RFIFOW(fd,2) - 4; + + if (len < 0) + return; - // as the length varies depending on the command used, just block unreasonably long strings - mes_len_check(msg, len, CHAT_SIZE_MAX); + sprintf(command, "%c%s ", atcommand->at_symbol, commandname); - sprintf(command, "%clkami %s", atcommand->at_symbol, msg); + // as the length varies depending on the command used, truncate unreasonably long strings + if (len >= (int)(sizeof command - strlen(command))) + len = (int)(sizeof command - strlen(command)) - 1; + + strncat(command, (char*)RFIFOP(fd,4), len); atcommand->exec(fd, sd, command, true); } @@ -11755,9 +11758,11 @@ void clif_parse_CreateParty(int fd, struct map_session_data *sd) __attribute__(( /// Party creation request /// 00f9 <party name>.24B (CZ_MAKE_GROUP) /// 01e8 <party name>.24B <item pickup rule>.B <item share rule>.B (CZ_MAKE_GROUP2) -void clif_parse_CreateParty(int fd, struct map_session_data *sd) { - char* name = (char*)RFIFOP(fd,2); - name[NAME_LENGTH-1] = '\0'; +void clif_parse_CreateParty(int fd, struct map_session_data *sd) +{ + char name[NAME_LENGTH]; + + safestrncpy(name, (char*)RFIFOP(fd,2), NAME_LENGTH); if( map->list[sd->bl.m].flag.partylock ) { // Party locked. @@ -11773,11 +11778,13 @@ void clif_parse_CreateParty(int fd, struct map_session_data *sd) { } void clif_parse_CreateParty2(int fd, struct map_session_data *sd) __attribute__((nonnull (2))); -void clif_parse_CreateParty2(int fd, struct map_session_data *sd) { - char* name = (char*)RFIFOP(fd,2); +void clif_parse_CreateParty2(int fd, struct map_session_data *sd) +{ + char name[NAME_LENGTH]; int item1 = RFIFOB(fd,26); int item2 = RFIFOB(fd,27); - name[NAME_LENGTH-1] = '\0'; + + safestrncpy(name, (char*)RFIFOP(fd,2), NAME_LENGTH); if( map->list[sd->bl.m].flag.partylock ) { // Party locked. @@ -11816,10 +11823,12 @@ void clif_parse_PartyInvite(int fd, struct map_session_data *sd) { } void clif_parse_PartyInvite2(int fd, struct map_session_data *sd) __attribute__((nonnull (2))); -void clif_parse_PartyInvite2(int fd, struct map_session_data *sd) { +void clif_parse_PartyInvite2(int fd, struct map_session_data *sd) +{ struct map_session_data *t_sd; - char *name = (char*)RFIFOP(fd,2); - name[NAME_LENGTH-1] = '\0'; + char name[NAME_LENGTH]; + + safestrncpy(name, (char*)RFIFOP(fd,2), NAME_LENGTH); if(map->list[sd->bl.m].flag.partylock) { // Party locked. @@ -11918,7 +11927,7 @@ void clif_parse_PartyMessage(int fd, struct map_session_data* sd) const char* text = (char*)RFIFOP(fd,4); int textlen = RFIFOW(fd,2) - 4; - char *name, *message; + const char *name, *message; size_t namelen, messagelen; // validate packet and retrieve name and message @@ -12660,9 +12669,10 @@ void clif_parse_OpenVending(int fd, struct map_session_data* sd) { void clif_parse_CreateGuild(int fd,struct map_session_data *sd) __attribute__((nonnull (2))); /// Guild creation request (CZ_REQ_MAKE_GUILD). /// 0165 <char id>.L <guild name>.24B -void clif_parse_CreateGuild(int fd,struct map_session_data *sd) { - char* name = (char*)RFIFOP(fd,6); - name[NAME_LENGTH-1] = '\0'; +void clif_parse_CreateGuild(int fd,struct map_session_data *sd) +{ + char name[NAME_LENGTH]; + safestrncpy(name, (char*)RFIFOP(fd,6), NAME_LENGTH); if(map->list[sd->bl.m].flag.guildlock) { //Guild locked. @@ -12915,18 +12925,22 @@ void clif_parse_GuildChangeNotice(int fd, struct map_session_data* sd) __attribu void clif_parse_GuildChangeNotice(int fd, struct map_session_data* sd) { int guild_id = RFIFOL(fd,2); - char* msg1 = (char*)RFIFOP(fd,6); - char* msg2 = (char*)RFIFOP(fd,66); + char *msg1 = NULL, *msg2 = NULL; - if(!sd->state.gmaster_flag) + if (!sd->state.gmaster_flag) return; + msg1 = aStrndup((char*)RFIFOP(fd,6), MAX_GUILDMES1-1); + msg2 = aStrndup((char*)RFIFOP(fd,66), MAX_GUILDMES2-1); + // compensate for some client defects when using multilingual mode if (msg1[0] == '|' && msg1[3] == '|') msg1+= 3; // skip duplicate marker if (msg2[0] == '|' && msg2[3] == '|') msg2+= 3; // skip duplicate marker if (msg2[0] == '|') msg2[strnlen(msg2, MAX_GUILDMES2)-1] = '\0'; // delete extra space at the end of string guild->change_notice(sd, guild_id, msg1, msg2); + aFree(msg1); + aFree(msg2); } // Helper function for guild invite functions @@ -12964,14 +12978,15 @@ void clif_parse_GuildInvite(int fd,struct map_session_data *sd) { void clif_parse_GuildInvite2(int fd, struct map_session_data *sd) __attribute__((nonnull (2))); /// Guild invite request (/guildinvite) (CZ_REQ_JOIN_GUILD2). /// 0916 <char name>.24B -void clif_parse_GuildInvite2(int fd, struct map_session_data *sd) { - char *nick = (char*)RFIFOP(fd, 2); - struct map_session_data *t_sd = map->nick2sd(nick); +void clif_parse_GuildInvite2(int fd, struct map_session_data *sd) +{ + char nick[NAME_LENGTH]; + struct map_session_data *t_sd = NULL; - nick[NAME_LENGTH - 1] = '\0'; + safestrncpy(nick, (char*)RFIFOP(fd, 2), NAME_LENGTH); + t_sd = map->nick2sd(nick); - if (!clif_sub_guild_invite(fd, sd, t_sd)) - return; + clif_sub_guild_invite(fd, sd, t_sd); } void clif_parse_GuildReplyInvite(int fd,struct map_session_data *sd) __attribute__((nonnull (2))); @@ -13022,7 +13037,7 @@ void clif_parse_GuildMessage(int fd, struct map_session_data* sd) const char* text = (char*)RFIFOP(fd,4); int textlen = RFIFOW(fd,2) - 4; - char *name, *message; + const char *name, *message; size_t namelen, messagelen; // validate packet and retrieve name and message @@ -13299,12 +13314,12 @@ void clif_parse_GMShift(int fd, struct map_session_data *sd) __attribute__((nonn /// Request to warp to a character with given name. /// 01bb <char name>.24B void clif_parse_GMShift(int fd, struct map_session_data *sd) -{// FIXME: remove is supposed to receive account name for clients prior 20100803RE - char *player_name; +{ + // FIXME: remove is supposed to receive account name for clients prior 20100803RE + char player_name[NAME_LENGTH]; char command[NAME_LENGTH+8]; - player_name = (char*)RFIFOP(fd,2); - player_name[NAME_LENGTH-1] = '\0'; + safestrncpy(player_name, (char*)RFIFOP(fd,2), NAME_LENGTH); sprintf(command, "%cjumpto %s", atcommand->at_symbol, player_name); atcommand->exec(fd, sd, command, true); @@ -13335,12 +13350,12 @@ void clif_parse_GMRecall(int fd, struct map_session_data *sd) __attribute__((non /// Request to summon a player with given name to own position. /// 01bd <char name>.24B void clif_parse_GMRecall(int fd, struct map_session_data *sd) -{// FIXME: recall is supposed to receive account name for clients prior 20100803RE - char *player_name; - char command [NAME_LENGTH+8]; +{ + // FIXME: recall is supposed to receive account name for clients prior 20100803RE + char player_name[NAME_LENGTH]; + char command[NAME_LENGTH+8]; - player_name = (char*)RFIFOP(fd,2); - player_name[NAME_LENGTH-1] = '\0'; + safestrncpy(player_name, (char*)RFIFOP(fd,2), NAME_LENGTH); sprintf(command, "%crecall %s", atcommand->at_symbol, player_name); atcommand->exec(fd, sd, command, true); @@ -13506,9 +13521,10 @@ void clif_parse_GMRc(int fd, struct map_session_data* sd) __attribute__((nonnull void clif_parse_GMRc(int fd, struct map_session_data* sd) { char command[NAME_LENGTH+15]; - char *name = (char*)RFIFOP(fd,2); + char name[NAME_LENGTH]; + + safestrncpy(name, (char*)RFIFOP(fd,2), NAME_LENGTH); - name[NAME_LENGTH-1] = '\0'; sprintf(command, "%cmute %d %s", atcommand->at_symbol, 60, name); atcommand->exec(fd, sd, command, true); } @@ -13567,13 +13583,14 @@ void clif_parse_PMIgnore(int fd, struct map_session_data* sd) __attribute__((non /// type: /// 0 = (/ex nick) deny speech from nick /// 1 = (/in nick) allow speech from nick -void clif_parse_PMIgnore(int fd, struct map_session_data* sd) { - char* nick; +void clif_parse_PMIgnore(int fd, struct map_session_data* sd) +{ + char nick[NAME_LENGTH]; uint8 type; int i; - nick = (char*)RFIFOP(fd,2); // speed up - nick[NAME_LENGTH-1] = '\0'; // to be sure that the player name has at most 23 characters + safestrncpy(nick, (char*)RFIFOP(fd,2), NAME_LENGTH); + type = RFIFOB(fd,26); if( type == 0 ) { // Add name to ignore list (block) @@ -13831,12 +13848,14 @@ void clif_friendlist_req(struct map_session_data* sd, int account_id, int char_i void clif_parse_FriendsListAdd(int fd, struct map_session_data *sd) __attribute__((nonnull (2))); /// Request to add a player as friend (CZ_ADD_FRIENDS). /// 0202 <name>.24B -void clif_parse_FriendsListAdd(int fd, struct map_session_data *sd) { +void clif_parse_FriendsListAdd(int fd, struct map_session_data *sd) +{ struct map_session_data *f_sd; int i; - char *nick = (char*)RFIFOP(fd,2); + char nick[NAME_LENGTH]; + + safestrncpy(nick, (char*)RFIFOP(fd,2), NAME_LENGTH); - nick[NAME_LENGTH - 1] = '\0'; f_sd = map->nick2sd(nick); // ensure that the request player's friend list is not full @@ -14967,7 +14986,7 @@ void clif_Auction_openwindow(struct map_session_data *sd) /// Returns auction item search results (ZC_AUCTION_ITEM_REQ_SEARCH). /// 0252 <packet len>.W <pages>.L <count>.L { <auction id>.L <seller name>.24B <name id>.W <type>.L <amount>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W <now price>.L <max price>.L <buyer name>.24B <delete time>.L }* -void clif_Auction_results(struct map_session_data *sd, short count, short pages, uint8 *buf) +void clif_Auction_results(struct map_session_data *sd, short count, short pages, const uint8 *buf) { int i, fd, len = sizeof(struct auction_data); struct auction_data auction; @@ -15414,13 +15433,16 @@ void clif_parse_cashshop_buy(int fd, struct map_session_data *sd) int len = RFIFOW(fd,2); int points = RFIFOL(fd,4); int count = RFIFOW(fd,8); - unsigned short* item_list = (unsigned short*)RFIFOP(fd,10); + unsigned short *item_list = NULL; if( len < 10 || len != 10 + count * 4) { ShowWarning("Player %d sent incorrect cash shop buy packet (len %d:%d)!\n", sd->status.char_id, len, 10 + count * 4); return; } + item_list = aMalloc(sizeof(*item_list) * 2 * count); + memcpy(item_list, (unsigned short*)RFIFOP(fd,10), sizeof(*item_list) * 2 * count); fail = npc->cashshop_buylist(sd,points,count,item_list); + aFree(item_list); #endif } @@ -16119,7 +16141,7 @@ void clif_parse_BattleChat(int fd, struct map_session_data* sd) const char* text = (char*)RFIFOP(fd,4); int textlen = RFIFOW(fd,2) - 4; - char *name, *message; + const char *name, *message; size_t namelen, messagelen; if( !clif->process_message(sd, 0, &name, &namelen, &message, &messagelen) ) @@ -16402,27 +16424,33 @@ void clif_parse_LessEffect(int fd, struct map_session_data* sd) sd->state.lesseffect = ( isLess != 0 ); } -void clif_parse_ItemListWindowSelected(int fd, struct map_session_data* sd) __attribute__((nonnull (2))); +void clif_parse_ItemListWindowSelected(int fd, struct map_session_data *sd) __attribute__((nonnull (2))); /// S 07e4 <length>.w <option>.l <val>.l {<index>.w <amount>.w).4b* -void clif_parse_ItemListWindowSelected(int fd, struct map_session_data* sd) { - int n = (RFIFOW(fd,2)-12) / 4; +void clif_parse_ItemListWindowSelected(int fd, struct map_session_data *sd) +{ + int n = ((int)RFIFOW(fd,2) - 12) / 4; int type = RFIFOL(fd,4); int flag = RFIFOL(fd,8); // Button clicked: 0 = Cancel, 1 = OK - unsigned short* item_list = (unsigned short*)RFIFOP(fd,12); + unsigned short *item_list = NULL; if( sd->state.trading || sd->npc_shopid ) return; - if( flag == 0 || n == 0) { + if (flag == 0 || n <= 0) { clif_menuskill_clear(sd); return; // Canceled by player. } - if( sd->menuskill_id != SO_EL_ANALYSIS && sd->menuskill_id != GN_CHANGEMATERIAL ) { + if (n > MAX_INVENTORY) + n = MAX_INVENTORY; // It should be impossible to have more than that. + + if (sd->menuskill_id != SO_EL_ANALYSIS && sd->menuskill_id != GN_CHANGEMATERIAL) { clif_menuskill_clear(sd); return; // Prevent hacking. } + item_list = aMalloc(sizeof *item_list * 2 * n); + memcpy(item_list, (unsigned short*)RFIFOP(fd,12), sizeof *item_list * 2 * n); switch( type ) { case 0: // Change Material skill->changematerial(sd,n,item_list); @@ -16432,6 +16460,7 @@ void clif_parse_ItemListWindowSelected(int fd, struct map_session_data* sd) { skill->elementalanalysis(sd,n,type,item_list); break; } + aFree(item_list); clif_menuskill_clear(sd); return; @@ -16516,7 +16545,7 @@ void clif_parse_ReqOpenBuyingStore(int fd, struct map_session_data* sd) __attrib /// 1 = open void clif_parse_ReqOpenBuyingStore(int fd, struct map_session_data* sd) { const unsigned int blocksize = 8; - uint8* itemlist; + const uint8 *itemlist; char storename[MESSAGE_SIZE]; unsigned char result; int zenylimit; @@ -16698,7 +16727,7 @@ void clif_parse_ReqTradeBuyingStore(int fd, struct map_session_data* sd) __attri /// 0819 <packet len>.W <account id>.L <store id>.L { <index>.W <name id>.W <amount>.W }* void clif_parse_ReqTradeBuyingStore(int fd, struct map_session_data* sd) { const unsigned int blocksize = 6; - uint8* itemlist; + const uint8 *itemlist; int account_id; unsigned int count, packet_len, buyer_id; struct s_packet_db* info = &packet_db[RFIFOW(fd,0)]; diff --git a/src/map/clif.h b/src/map/clif.h index d68a09393..d3be4a971 100644 --- a/src/map/clif.h +++ b/src/map/clif.h @@ -855,7 +855,7 @@ struct clif_interface { void (*messageln) (const int fd, const char* mes); /* message+s(printf) */ void (*messages) (const int fd, const char *mes, ...) __attribute__((format(printf, 2, 3))); - bool (*process_message) (struct map_session_data *sd, int format, char **name_, size_t *namelen_, char **message_, size_t *messagelen_); + bool (*process_message) (struct map_session_data *sd, int format, const char **name_, size_t *namelen_, const char **message_, size_t *messagelen_); void (*wisexin) (struct map_session_data *sd,int type,int flag); void (*wisall) (struct map_session_data *sd,int type,int flag); void (*PMIgnoreList) (struct map_session_data* sd); @@ -997,7 +997,7 @@ struct clif_interface { void (*mail_setattachment) (int fd, int index, uint8 flag); /* auction-related */ void (*auction_openwindow) (struct map_session_data *sd); - void (*auction_results) (struct map_session_data *sd, short count, short pages, uint8 *buf); + void (*auction_results) (struct map_session_data *sd, short count, short pages, const uint8 *buf); void (*auction_message) (int fd, unsigned char flag); void (*auction_close) (int fd, unsigned char flag); void (*auction_setitem) (int fd, int index, bool fail); diff --git a/src/map/elemental.c b/src/map/elemental.c index a87deb7d7..0eed4e799 100644 --- a/src/map/elemental.c +++ b/src/map/elemental.c @@ -254,7 +254,8 @@ void elemental_summon_init(struct elemental_data *ed) { ed->regen.state.block = 0; } -int elemental_data_received(struct s_elemental *ele, bool flag) { +int elemental_data_received(const struct s_elemental *ele, bool flag) +{ struct map_session_data *sd; struct elemental_data *ed; struct s_elemental_db *db; diff --git a/src/map/elemental.h b/src/map/elemental.h index 1a98670e0..8a9bf9414 100644 --- a/src/map/elemental.h +++ b/src/map/elemental.h @@ -122,7 +122,7 @@ struct elemental_interface { struct view_data * (*get_viewdata) (int class_); int (*create) (struct map_session_data *sd, int class_, unsigned int lifetime); - int (*data_received) (struct s_elemental *ele, bool flag); + int (*data_received) (const struct s_elemental *ele, bool flag); int (*save) (struct elemental_data *ed); int (*change_mode_ack) (struct elemental_data *ed, int mode); diff --git a/src/map/guild.c b/src/map/guild.c index f4f0c0528..f14ee4611 100644 --- a/src/map/guild.c +++ b/src/map/guild.c @@ -230,7 +230,7 @@ struct map_session_data* guild_getavailablesd(struct guild* g) } /// lookup: player AID/CID -> member index -int guild_getindex(struct guild *g,int account_id,int char_id) +int guild_getindex(const struct guild *g, int account_id, int char_id) { int i; @@ -433,7 +433,7 @@ int guild_npc_request_info(int guild_id,const char *event) } //Confirmation of the character belongs to guild -int guild_check_member(struct guild *g) +int guild_check_member(const struct guild *g) { int i; struct map_session_data *sd; @@ -475,7 +475,8 @@ int guild_recv_noinfo(int guild_id) } //Get and display information for all member -int guild_recv_info(struct guild *sg) { +int guild_recv_info(const struct guild *sg) +{ struct guild *g,before; int i,bm,m; DBData data; @@ -1126,7 +1127,7 @@ int guild_change_position(int guild_id,int idx,int mode,int exp_mode,const char /*==================================================== * Notification of member has changed his guild title *---------------------------------------------------*/ -int guild_position_changed(int guild_id,int idx,struct guild_position *p) +int guild_position_changed(int guild_id, int idx, const struct guild_position *p) { struct guild *g=guild->search(guild_id); int i; @@ -1883,7 +1884,8 @@ int guild_gm_changed(int guild_id, int account_id, int char_id) /*==================================================== * Guild disbanded *---------------------------------------------------*/ -int guild_break(struct map_session_data *sd,char *name) { +int guild_break(struct map_session_data *sd, const char *name) +{ struct guild *g; struct unit_data *ud; int i; @@ -2064,7 +2066,7 @@ void guild_castle_reconnect(int castle_id, int index, int value) } // Load castle data then invoke OnAgitInit* on last -int guild_castledataloadack(int len, struct guild_castle *gc) +int guild_castledataloadack(int len, const struct guild_castle *gc) { int i; int n = (len-4) / sizeof(struct guild_castle); diff --git a/src/map/guild.h b/src/map/guild.h index 10749f8ad..cd796adb3 100644 --- a/src/map/guild.h +++ b/src/map/guild.h @@ -98,7 +98,7 @@ struct guild_interface { struct guild_castle *(*mapindex2gc) (short map_index); /* */ struct map_session_data *(*getavailablesd) (struct guild *g); - int (*getindex) (struct guild *g,int account_id,int char_id); + int (*getindex) (const struct guild *g, int account_id, int char_id); int (*getposition) (struct guild *g, struct map_session_data *sd); unsigned int (*payexp) (struct map_session_data *sd,unsigned int exp); int (*getexp) (struct map_session_data *sd,int exp); // [Celest] @@ -107,7 +107,7 @@ struct guild_interface { int (*created) (int account_id,int guild_id); int (*request_info) (int guild_id); int (*recv_noinfo) (int guild_id); - int (*recv_info) (struct guild *sg); + int (*recv_info) (const struct guild *sg); int (*npc_request_info) (int guild_id,const char *ev); int (*invite) (struct map_session_data *sd,struct map_session_data *tsd); int (*reply_invite) (struct map_session_data *sd,int guild_id,int flag); @@ -130,7 +130,7 @@ struct guild_interface { int (*change_memberposition) (int guild_id,int account_id,int char_id,short idx); int (*memberposition_changed) (struct guild *g,int idx,int pos); int (*change_position) (int guild_id,int idx,int mode,int exp_mode,const char *name); - int (*position_changed) (int guild_id,int idx,struct guild_position *p); + int (*position_changed) (int guild_id, int idx, const struct guild_position *p); int (*change_notice) (struct map_session_data *sd,int guild_id,const char *mes1,const char *mes2); int (*notice_changed) (int guild_id,const char *mes1,const char *mes2); int (*change_emblem) (struct map_session_data *sd,int len,const char *data); @@ -139,14 +139,14 @@ struct guild_interface { int (*recv_message) (int guild_id,int account_id,const char *mes,int len); int (*send_dot_remove) (struct map_session_data *sd); int (*skillupack) (int guild_id,uint16 skill_id,int account_id); - int (*dobreak) (struct map_session_data *sd,char *name); + int (*dobreak) (struct map_session_data *sd, const char *name); int (*broken) (int guild_id,int flag); int (*gm_change) (int guild_id, struct map_session_data *sd); int (*gm_changed) (int guild_id, int account_id, int char_id); /* */ void (*castle_map_init) (void); int (*castledatasave) (int castle_id,int index,int value); - int (*castledataloadack) (int len, struct guild_castle *gc); + int (*castledataloadack) (int len, const struct guild_castle *gc); void (*castle_reconnect) (int castle_id, int index, int value); /* */ void (*agit_start) (void); @@ -176,7 +176,7 @@ struct guild_interface { int (*broken_sub) (DBKey key, DBData *data, va_list ap); int (*castle_broken_sub) (DBKey key, DBData *data, va_list ap); void (*makemember) (struct guild_member *m,struct map_session_data *sd); - int (*check_member) (struct guild *g); + int (*check_member) (const struct guild *g); int (*get_alliance_count) (struct guild *g,int flag); void (*castle_reconnect_sub) (void *key, void *data, va_list ap); }; diff --git a/src/map/homunculus.c b/src/map/homunculus.c index b642c197f..9924b4aca 100644 --- a/src/map/homunculus.c +++ b/src/map/homunculus.c @@ -705,7 +705,8 @@ void homunculus_hunger_timer_delete(struct homun_data *hd) { } } -int homunculus_change_name(struct map_session_data *sd,char *name) { +int homunculus_change_name(struct map_session_data *sd, const char *name) +{ int i; struct homun_data *hd; nullpo_retr(1, sd); @@ -725,21 +726,26 @@ int homunculus_change_name(struct map_session_data *sd,char *name) { return intif_rename_hom(sd, name); } -bool homunculus_change_name_ack(struct map_session_data *sd, char* name, int flag) { +bool homunculus_change_name_ack(struct map_session_data *sd, const char *name, int flag) +{ struct homun_data *hd; + char *newname = NULL; nullpo_retr(false, sd); nullpo_retr(false, name); hd = sd->hd; nullpo_retr(false, hd); if (!homun_alive(hd)) return false; - normalize_name(name," ");//bugreport:3032 + newname = aStrndup(name, NAME_LENGTH-1); + normalize_name(newname, " ");//bugreport:3032 // FIXME[Haru]: This should be normalized by the inter-server (so that it's const here) - if ( !flag || !strlen(name) ) { + if (flag == 0 || strlen(newname) == 0) { clif->message(sd->fd, msg_sd(sd,280)); // You cannot use this name + aFree(newname); return false; } - safestrncpy(hd->homunculus.name,name,NAME_LENGTH); + safestrncpy(hd->homunculus.name, newname, NAME_LENGTH); + aFree(newname); clif->charnameack (0,&hd->bl); hd->homunculus.rename_flag = 1; clif->hominfo(sd,hd,0); @@ -770,7 +776,8 @@ int homunculus_db_search(int key,int type) { } // Create homunc structure -bool homunculus_create(struct map_session_data *sd, struct s_homunculus *hom) { +bool homunculus_create(struct map_session_data *sd, const struct s_homunculus *hom) +{ struct homun_data *hd; int i = 0; @@ -863,17 +870,20 @@ bool homunculus_call(struct map_session_data *sd) { } // Receive homunculus data from char server -bool homunculus_recv_data(int account_id, struct s_homunculus *sh, int flag) { +bool homunculus_recv_data(int account_id, const struct s_homunculus *sh, int flag) +{ struct map_session_data *sd; struct homun_data *hd; + struct s_homunculus new_sh; nullpo_retr(false, sh); sd = map->id2sd(account_id); if(!sd) return false; - if (sd->status.char_id != sh->char_id) { - if (sd->status.hom_id == sh->hom_id) - sh->char_id = sd->status.char_id; //Correct char id. + memcpy(&new_sh, sh, sizeof(new_sh)); + if (sd->status.char_id != new_sh.char_id) { + if (sd->status.hom_id == new_sh.hom_id) + new_sh.char_id = sd->status.char_id; //Correct char id. else return false; } @@ -883,12 +893,12 @@ bool homunculus_recv_data(int account_id, struct s_homunculus *sh, int flag) { } if (!sd->status.hom_id) //Hom just created. - sd->status.hom_id = sh->hom_id; + sd->status.hom_id = new_sh.hom_id; if (sd->hd) //uh? Overwrite the data. - memcpy(&sd->hd->homunculus, sh, sizeof(struct s_homunculus)); + memcpy(&sd->hd->homunculus, &new_sh, sizeof(struct s_homunculus)); else - homun->create(sd, sh); + homun->create(sd, &new_sh); hd = sd->hd; if(hd && hd->homunculus.hp && hd->homunculus.vaporize == HOM_ST_ACTIVE && hd->bl.prev == NULL && sd->bl.prev != NULL) { diff --git a/src/map/homunculus.h b/src/map/homunculus.h index c2ce042ec..3dd9e4772 100644 --- a/src/map/homunculus.h +++ b/src/map/homunculus.h @@ -186,13 +186,13 @@ struct homunculus_interface { bool (*feed) (struct map_session_data *sd, struct homun_data *hd); int (*hunger_timer) (int tid, int64 tick, int id, intptr_t data); void (*hunger_timer_delete) (struct homun_data *hd); - int (*change_name) (struct map_session_data *sd,char *name); - bool (*change_name_ack) (struct map_session_data *sd, char* name, int flag); + int (*change_name) (struct map_session_data *sd, const char *name); + bool (*change_name_ack) (struct map_session_data *sd, const char *name, int flag); int (*db_search) (int key,int type); - bool (*create) (struct map_session_data *sd, struct s_homunculus *hom); + bool (*create) (struct map_session_data *sd, const struct s_homunculus *hom); void (*init_timers) (struct homun_data * hd); bool (*call) (struct map_session_data *sd); - bool (*recv_data) (int account_id, struct s_homunculus *sh, int flag); + bool (*recv_data) (int account_id, const struct s_homunculus *sh, int flag); bool (*creation_request) (struct map_session_data *sd, int class_); bool (*ressurect) (struct map_session_data* sd, unsigned char per, short x, short y); void (*revive) (struct homun_data *hd, unsigned int hp, unsigned int sp); diff --git a/src/map/intif.c b/src/map/intif.c index 9722b8f9a..e508b7b09 100644 --- a/src/map/intif.c +++ b/src/map/intif.c @@ -132,7 +132,7 @@ int intif_delete_petdata(int pet_id) return 1; } -int intif_rename(struct map_session_data *sd, int type, char *name) +int intif_rename(struct map_session_data *sd, int type, const char *name) { if (intif->CheckForCharServer()) return 1; @@ -231,7 +231,7 @@ int intif_main_message(struct map_session_data* sd, const char* message) } // The transmission of Wisp/Page to inter-server (player not found on this server) -int intif_wis_message(struct map_session_data *sd, char *nick, char *mes, size_t mes_len) +int intif_wis_message(struct map_session_data *sd, const char *nick, const char *mes, size_t mes_len) { if (intif->CheckForCharServer()) return 0; @@ -463,7 +463,7 @@ int intif_send_guild_storage(int account_id,struct guild_storage *gstor) } // Party creation request -int intif_create_party(struct party_member *member,char *name,int item,int item2) +int intif_create_party(struct party_member *member, const char *name, int item, int item2) { if (intif->CheckForCharServer()) return 0; @@ -956,7 +956,7 @@ int intif_homunculus_requestdelete(int homun_id) // Wisp/Page reception // rewritten by [Yor] void intif_parse_WisMessage(int fd) { struct map_session_data* sd; - char *wisp_source; + const char *wisp_source; char name[NAME_LENGTH]; int id, i; @@ -1308,15 +1308,19 @@ void intif_parse_GuildBasicInfoChanged(int fd) { case GBI_SKILLPOINT: g->skill_point = RFIFOL(fd,10); break; case GBI_SKILLLV: { int idx, max; - struct guild_skill *gs = (struct guild_skill *)RFIFOP(fd,10); + const struct guild_skill *p_gs = (struct guild_skill *)RFIFOP(fd,10); + struct guild_skill *gs = NULL; - idx = gs->id - GD_SKILLBASE; + idx = p_gs->id - GD_SKILLBASE; Assert_retv(idx >= 0 && idx < MAX_GUILDSKILL); + + gs = &g->skill[idx]; + memcpy(gs, p_gs, sizeof(*gs)); + max = guild->skill_get_max(gs->id); - if( gs->lv > max ) + if (gs->lv > max) gs->lv = max; - memcpy(&(g->skill[idx]), gs, sizeof(g->skill[idx])); break; } } @@ -1527,7 +1531,7 @@ void intif_parse_QuestLog(int fd) { sd->quest_log = NULL; } } else { - struct quest *received = (struct quest *)RFIFOP(fd, 8); + const struct quest *received = (struct quest *)RFIFOP(fd, 8); int i, k = num_received; if (sd->quest_log) { RECREATE(sd->quest_log, struct quest, num_received); @@ -1876,7 +1880,7 @@ void intif_parse_AuctionResults(int fd) { struct map_session_data *sd = map->charid2sd(RFIFOL(fd,4)); short count = RFIFOW(fd,8); short pages = RFIFOW(fd,10); - uint8* data = RFIFOP(fd,12); + const uint8 *data = RFIFOP(fd,12); if( sd == NULL ) return; diff --git a/src/map/intif.h b/src/map/intif.h index 0bcaae941..dccd31d80 100644 --- a/src/map/intif.h +++ b/src/map/intif.h @@ -62,13 +62,13 @@ struct intif_interface { int (*broadcast) (const char* mes, size_t len, int type); int (*broadcast2) (const char* mes, size_t len, unsigned int fontColor, short fontType, short fontSize, short fontAlign, short fontY); int (*main_message) (struct map_session_data* sd, const char* message); - int (*wis_message) (struct map_session_data *sd,char *nick,char *mes,size_t mes_len); + int (*wis_message) (struct map_session_data *sd, const char *nick, const char *mes, size_t mes_len); int (*wis_message_to_gm) (char *Wisp_name, int permission, char *mes); int (*saveregistry) (struct map_session_data *sd); int (*request_registry) (struct map_session_data *sd, int flag); int (*request_guild_storage) (int account_id, int guild_id); int (*send_guild_storage) (int account_id, struct guild_storage *gstor); - int (*create_party) (struct party_member *member,char *name,int item,int item2); + int (*create_party) (struct party_member *member, const char *name, int item, int item2); int (*request_partyinfo) (int party_id, int char_id); int (*party_addmember) (int party_id,struct party_member *member); int (*party_changeoption) (int party_id, int account_id, int exp, int item); @@ -98,7 +98,7 @@ struct intif_interface { int (*request_petdata) (int account_id, int char_id, int pet_id); int (*save_petdata) (int account_id, struct s_pet *p); int (*delete_petdata) (int pet_id); - int (*rename) (struct map_session_data *sd, int type, char *name); + int (*rename) (struct map_session_data *sd, int type, const char *name); int (*homunculus_create) (int account_id, struct s_homunculus *sh); bool (*homunculus_requestload) (int account_id, int homun_id); int (*homunculus_requestsave) (int account_id, struct s_homunculus* sh); diff --git a/src/map/irc-bot.c b/src/map/irc-bot.c index 3d8ec8b5d..fa4216f18 100644 --- a/src/map/irc-bot.c +++ b/src/map/irc-bot.c @@ -134,7 +134,7 @@ struct irc_func* irc_func_search(char* function_name) { * @see do_sockets */ int irc_parse(int fd) { - char *parse_string = NULL, *str_safe = NULL; + char *parse_string = NULL, *p = NULL, *str_safe = NULL; if (sockt->session[fd]->flag.eof) { sockt->close(fd); @@ -150,18 +150,19 @@ int irc_parse(int fd) { if( !RFIFOREST(fd) ) return 0; - parse_string = (char*)RFIFOP(fd,0); - parse_string[ RFIFOREST(fd) - 1 ] = '\0'; + parse_string = aMalloc(RFIFOREST(fd)); + safestrncpy(parse_string, (char*)RFIFOP(fd,0), RFIFOREST(fd)); + RFIFOSKIP(fd, RFIFOREST(fd)); + RFIFOFLUSH(fd); - parse_string = strtok_r(parse_string,"\r\n",&str_safe); + p = strtok_r(parse_string,"\r\n",&str_safe); - while (parse_string != NULL) { + while (p != NULL) { ircbot->parse_sub(fd,parse_string); - parse_string = strtok_r(NULL,"\r\n",&str_safe); + p = strtok_r(NULL,"\r\n",&str_safe); } + aFree(parse_string); - RFIFOSKIP(fd, RFIFOREST(fd)); - RFIFOFLUSH(fd); return 0; } diff --git a/src/map/mercenary.c b/src/map/mercenary.c index e6c911ef6..ec0b2291f 100644 --- a/src/map/mercenary.c +++ b/src/map/mercenary.c @@ -301,7 +301,8 @@ void merc_contract_init(struct mercenary_data *md) md->regen.state.block = 0; } -int merc_data_received(struct s_mercenary *merc, bool flag) { +int merc_data_received(const struct s_mercenary *merc, bool flag) +{ struct map_session_data *sd; struct mercenary_data *md; struct s_mercenary_db *db; diff --git a/src/map/mercenary.h b/src/map/mercenary.h index 1b3453a84..142460e2a 100644 --- a/src/map/mercenary.h +++ b/src/map/mercenary.h @@ -120,7 +120,7 @@ struct mercenary_interface { struct view_data * (*get_viewdata) (int class_); int (*create) (struct map_session_data *sd, int class_, unsigned int lifetime); - int (*data_received) (struct s_mercenary *merc, bool flag); + int (*data_received) (const struct s_mercenary *merc, bool flag); int (*save) (struct mercenary_data *md); void (*heal) (struct mercenary_data *md, int hp, int sp); diff --git a/src/map/party.c b/src/map/party.c index a3e59c281..39c6e25fb 100644 --- a/src/map/party.c +++ b/src/map/party.c @@ -148,7 +148,7 @@ struct party_data* party_searchname(const char* str) return p; } -int party_create(struct map_session_data *sd,char *name,int item,int item2) +int party_create(struct map_session_data *sd, const char *name,int item,int item2) { struct party_member leader; char tname[NAME_LENGTH]; @@ -175,7 +175,8 @@ int party_create(struct map_session_data *sd,char *name,int item,int item2) return 0; } -void party_created(int account_id,int char_id,int fail,int party_id,char *name) { +void party_created(int account_id, int char_id, int fail, int party_id, const char *name) +{ struct map_session_data *sd; sd=map->id2sd(account_id); @@ -241,10 +242,10 @@ void party_check_state(struct party_data *p) { } } -int party_recv_info(struct party* sp, int char_id) +int party_recv_info(const struct party *sp, int char_id) { struct party_data* p; - struct party_member* member; + const struct party_member *member; struct map_session_data* sd; int removed[MAX_PARTY];// member_id in old data int removed_count = 0; @@ -510,7 +511,7 @@ int party_member_added(int party_id,int account_id,int char_id, int flag) { } /// Party member 'sd' requesting kick of member with <account_id, name>. -int party_removemember(struct map_session_data* sd, int account_id, char* name) +int party_removemember(struct map_session_data* sd, int account_id, const char *name) { struct party_data *p; int i; diff --git a/src/map/party.h b/src/map/party.h index 828916b88..b66a9770c 100644 --- a/src/map/party.h +++ b/src/map/party.h @@ -97,18 +97,18 @@ struct party_interface { int (*getmemberid) (struct party_data* p, struct map_session_data* sd); struct map_session_data* (*getavailablesd) (struct party_data *p); - int (*create) (struct map_session_data *sd,char *name, int item, int item2); - void (*created) (int account_id,int char_id,int fail,int party_id,char *name); + int (*create) (struct map_session_data *sd, const char *name, int item, int item2); + void (*created) (int account_id, int char_id, int fail, int party_id, const char *name); int (*request_info) (int party_id, int char_id); int (*invite) (struct map_session_data *sd,struct map_session_data *tsd); void (*member_joined) (struct map_session_data *sd); int (*member_added) (int party_id,int account_id,int char_id,int flag); int (*leave) (struct map_session_data *sd); - int (*removemember) (struct map_session_data *sd,int account_id,char *name); + int (*removemember) (struct map_session_data *sd, int account_id, const char *name); int (*member_withdraw) (int party_id,int account_id,int char_id); void (*reply_invite) (struct map_session_data *sd,int party_id,int flag); int (*recv_noinfo) (int party_id, int char_id); - int (*recv_info) (struct party* sp, int char_id); + int (*recv_info) (const struct party *sp, int char_id); int (*recv_movemap) (int party_id,int account_id,int char_id, unsigned short mapid,int online,int lv); int (*broken) (int party_id); int (*optionchanged) (int party_id,int account_id,int exp,int item,int flag); diff --git a/src/map/pc.c b/src/map/pc.c index 0eda9ebe3..a79247134 100644 --- a/src/map/pc.c +++ b/src/map/pc.c @@ -1033,7 +1033,8 @@ int pc_isequip(struct map_session_data *sd,int n) * No problem with the session id * set the status that has been sent from char server *------------------------------------------*/ -bool pc_authok(struct map_session_data *sd, int login_id2, time_t expiration_time, int group_id, struct mmo_charstatus *st, bool changing_mapservers) { +bool pc_authok(struct map_session_data *sd, int login_id2, time_t expiration_time, int group_id, const struct mmo_charstatus *st, bool changing_mapservers) +{ int i; int64 tick = timer->gettick(); uint32 ip = sockt->session[sd->fd]->client_addr; diff --git a/src/map/pc.h b/src/map/pc.h index 06bc5e5ae..246209f87 100644 --- a/src/map/pc.h +++ b/src/map/pc.h @@ -834,7 +834,7 @@ END_ZEROED_BLOCK; /* End */ int (*makesavestatus) (struct map_session_data *sd); void (*respawn) (struct map_session_data* sd, clr_type clrtype); int (*setnewpc) (struct map_session_data *sd, int account_id, int char_id, int login_id1, unsigned int client_tick, int sex, int fd); - bool (*authok) (struct map_session_data *sd, int login_id2, time_t expiration_time, int group_id, struct mmo_charstatus *st, bool changing_mapservers); + bool (*authok) (struct map_session_data *sd, int login_id2, time_t expiration_time, int group_id, const struct mmo_charstatus *st, bool changing_mapservers); void (*authfail) (struct map_session_data *sd); int (*reg_received) (struct map_session_data *sd); diff --git a/src/map/pet.c b/src/map/pet.c index c6f7e8cca..71d8d1eb3 100644 --- a/src/map/pet.c +++ b/src/map/pet.c @@ -646,7 +646,7 @@ int pet_menu(struct map_session_data *sd,int menunum) return 0; } -int pet_change_name(struct map_session_data *sd,char *name) +int pet_change_name(struct map_session_data *sd, const char *name) { int i; struct pet_data *pd; @@ -664,19 +664,23 @@ int pet_change_name(struct map_session_data *sd,char *name) return intif_rename_pet(sd, name); } -int pet_change_name_ack(struct map_session_data *sd, char* name, int flag) +int pet_change_name_ack(struct map_session_data *sd, const char *name, int flag) { struct pet_data *pd = sd->pd; + char *newname = NULL; if (!pd) return 0; - normalize_name(name," ");//bugreport:3032 + newname = aStrndup(name, NAME_LENGTH-1); + normalize_name(newname, " ");//bugreport:3032 // FIXME[Haru]: This should be normalized by the inter-server (so that it's const here) - if ( !flag || !strlen(name) ) { + if (flag == 0 || strlen(newname) == 0) { clif->message(sd->fd, msg_sd(sd,280)); // You cannot use this name for your pet. clif->send_petstatus(sd); //Send status so client knows oet name change got rejected. + aFree(newname); return 0; } - memcpy(pd->pet.name, name, NAME_LENGTH); + memcpy(pd->pet.name, newname, NAME_LENGTH); + aFree(newname); clif->charnameack (0,&pd->bl); pd->pet.rename_flag = 1; clif->send_petdata(NULL, sd->pd, 3, sd->pd->vd.head_bottom); diff --git a/src/map/pet.h b/src/map/pet.h index 83e39a887..79cbeddae 100644 --- a/src/map/pet.h +++ b/src/map/pet.h @@ -154,8 +154,8 @@ struct pet_interface { int (*food) (struct map_session_data *sd, struct pet_data *pd); int (*ai_sub_hard_lootsearch) (struct block_list *bl, va_list ap); int (*menu) (struct map_session_data *sd, int menunum); - int (*change_name) (struct map_session_data *sd, char *name); - int (*change_name_ack) (struct map_session_data *sd, char *name, int flag); + int (*change_name) (struct map_session_data *sd, const char *name); + int (*change_name_ack) (struct map_session_data *sd, const char *name, int flag); int (*equipitem) (struct map_session_data *sd, int index); int (*randomwalk) (struct pet_data *pd, int64 tick); int (*ai_sub_hard) (struct pet_data *pd, struct map_session_data *sd, int64 tick); |