summaryrefslogtreecommitdiff
path: root/src/map
diff options
context:
space:
mode:
Diffstat (limited to 'src/map')
-rw-r--r--src/map/chrif.c4
-rw-r--r--src/map/clif.c229
-rw-r--r--src/map/clif.h4
-rw-r--r--src/map/elemental.c3
-rw-r--r--src/map/elemental.h2
-rw-r--r--src/map/guild.c14
-rw-r--r--src/map/guild.h12
-rw-r--r--src/map/homunculus.c36
-rw-r--r--src/map/homunculus.h8
-rw-r--r--src/map/intif.c24
-rw-r--r--src/map/intif.h6
-rw-r--r--src/map/irc-bot.c17
-rw-r--r--src/map/mercenary.c3
-rw-r--r--src/map/mercenary.h2
-rw-r--r--src/map/party.c11
-rw-r--r--src/map/party.h8
-rw-r--r--src/map/pc.c3
-rw-r--r--src/map/pc.h2
-rw-r--r--src/map/pet.c14
-rw-r--r--src/map/pet.h4
20 files changed, 230 insertions, 176 deletions
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);