diff options
Diffstat (limited to 'src/map/pet.c')
-rw-r--r-- | src/map/pet.c | 50 |
1 files changed, 37 insertions, 13 deletions
diff --git a/src/map/pet.c b/src/map/pet.c index c6f7e8cca..9ac496659 100644 --- a/src/map/pet.c +++ b/src/map/pet.c @@ -2,7 +2,7 @@ * This file is part of Hercules. * http://herc.ws - http://github.com/HerculesWS/Hercules * - * Copyright (C) 2012-2015 Hercules Dev Team + * Copyright (C) 2012-2016 Hercules Dev Team * Copyright (C) Athena Dev Teams * * Hercules is free software: you can redistribute it and/or modify @@ -91,6 +91,7 @@ void pet_set_intimate(struct pet_data *pd, int value) int pet_create_egg(struct map_session_data *sd, int item_id) { int pet_id = pet->search_petDB_index(item_id, PET_EGG); + nullpo_ret(sd); if (pet_id < 0) return 0; //No pet egg here. if (!pc->inventoryblank(sd)) return 0; // Inventory full sd->catch_target_class = pet->db[pet_id].class_; @@ -117,6 +118,7 @@ int pet_unlocktarget(struct pet_data *pd) * Pet Attack Skill [Skotlex] *------------------------------------------*/ int pet_attackskill(struct pet_data *pd, int target_id) { + nullpo_ret(pd); if (!battle_config.pet_status_support || !pd->a_skill || (battle_config.pet_equip_required && !pd->pet.equip)) return 0; @@ -148,6 +150,7 @@ int pet_target_check(struct map_session_data *sd,struct block_list *bl,int type) struct pet_data *pd; int rate; + nullpo_ret(sd); pd = sd->pd; Assert_ret(pd->msd == 0 || pd->msd->pd == pd); @@ -291,6 +294,7 @@ int pet_performance(struct map_session_data *sd, struct pet_data *pd) { int val; + nullpo_retr(1, pd); if (pd->pet.intimate > 900) val = (pd->petDB->s_perfor > 0)? 4:3; else if(pd->pet.intimate > 750) //TODO: this is way too high @@ -309,6 +313,8 @@ int pet_return_egg(struct map_session_data *sd, struct pet_data *pd) struct item tmp_item; int flag; + nullpo_retr(1, sd); + nullpo_retr(1, pd); pet->lootitem_drop(pd,sd); memset(&tmp_item,0,sizeof(tmp_item)); tmp_item.nameid = pd->petDB->EggID; @@ -317,7 +323,7 @@ int pet_return_egg(struct map_session_data *sd, struct pet_data *pd) tmp_item.card[1] = GetWord(pd->pet.pet_id,0); tmp_item.card[2] = GetWord(pd->pet.pet_id,1); tmp_item.card[3] = pd->pet.rename_flag; - if((flag = pc->additem(sd,&tmp_item,1,LOG_TYPE_OTHER))) { + if((flag = pc->additem(sd,&tmp_item,1,LOG_TYPE_EGG))) { clif->additem(sd,0,0,flag); map->addflooritem(&sd->bl, &tmp_item, 1, sd->bl.m, sd->bl.x, sd->bl.y, 0, 0, 0, 0); } @@ -336,6 +342,7 @@ int pet_data_init(struct map_session_data *sd, struct s_pet *petinfo) int i=0,interval=0; nullpo_retr(1, sd); + nullpo_retr(1, petinfo); Assert_retr(1, sd->status.pet_id == 0 || sd->pd == 0 || sd->pd->msd == sd); if(sd->status.account_id != petinfo->account_id || sd->status.char_id != petinfo->char_id) { @@ -407,6 +414,7 @@ int pet_data_init(struct map_session_data *sd, struct s_pet *petinfo) int pet_birth_process(struct map_session_data *sd, struct s_pet *petinfo) { nullpo_retr(1, sd); + nullpo_retr(1, petinfo); Assert_retr(1, sd->status.pet_id == 0 || sd->pd == 0 || sd->pd->msd == sd); if(sd->status.pet_id && petinfo->incubate == 1) { @@ -443,6 +451,7 @@ int pet_birth_process(struct map_session_data *sd, struct s_pet *petinfo) int pet_recv_petdata(int account_id,struct s_pet *p,int flag) { struct map_session_data *sd; + nullpo_retr(1, p); sd = map->id2sd(account_id); if(sd == NULL) return 1; @@ -464,7 +473,7 @@ int pet_recv_petdata(int account_id,struct s_pet *p,int flag) { return 1; } if (!pet->birth_process(sd,p)) //Pet hatched. Delete egg. - pc->delitem(sd, i, 1, 0, DELITEM_NORMAL, LOG_TYPE_OTHER); + pc->delitem(sd, i, 1, 0, DELITEM_NORMAL, LOG_TYPE_EGG); } else { pet->data_init(sd,p); if(sd->pd && sd->bl.prev != NULL) { @@ -646,11 +655,12 @@ 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; nullpo_retr(1, sd); + nullpo_retr(1, name); pd = sd->pd; if((pd == NULL) || (pd->pet.rename_flag == 1 && !battle_config.pet_rename)) @@ -664,19 +674,26 @@ 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; - if (!pd) return 0; + struct pet_data *pd; + char *newname = NULL; + nullpo_ret(sd); + nullpo_ret(name); + pd = sd->pd; + if (pd == NULL) 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); + safestrncpy(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); @@ -699,7 +716,7 @@ int pet_equipitem(struct map_session_data *sd,int index) { return 1; } - pc->delitem(sd, index, 1, 0, DELITEM_NORMAL, LOG_TYPE_OTHER); + pc->delitem(sd, index, 1, 0, DELITEM_NORMAL, LOG_TYPE_CONSUME); pd->pet.equip = nameid; status->set_viewdata(&pd->bl, pd->pet.class_); //Updates view_data. clif->send_petdata(NULL, sd->pd, 3, sd->pd->vd.head_bottom); @@ -720,6 +737,8 @@ int pet_unequipitem(struct map_session_data *sd, struct pet_data *pd) { struct item tmp_item; int nameid,flag; + nullpo_retr(1, sd); + nullpo_retr(1, pd); if(pd->pet.equip == 0) return 1; @@ -730,7 +749,7 @@ int pet_unequipitem(struct map_session_data *sd, struct pet_data *pd) { memset(&tmp_item,0,sizeof(tmp_item)); tmp_item.nameid = nameid; tmp_item.identify = 1; - if((flag = pc->additem(sd,&tmp_item,1,LOG_TYPE_OTHER))) { + if((flag = pc->additem(sd,&tmp_item,1,LOG_TYPE_CONSUME))) { clif->additem(sd,0,0,flag); map->addflooritem(&sd->bl, &tmp_item, 1, sd->bl.m, sd->bl.x, sd->bl.y, 0, 0, 0, 0); } @@ -758,6 +777,7 @@ int pet_unequipitem(struct map_session_data *sd, struct pet_data *pd) { int pet_food(struct map_session_data *sd, struct pet_data *pd) { int i, food_id; + nullpo_retr(1, pd); food_id = pd->petDB->FoodID; i = pc->search_inventory(sd, food_id); if(i == INDEX_NOT_FOUND) { @@ -843,6 +863,7 @@ int pet_randomwalk(struct pet_data *pd, int64 tick) int pet_ai_sub_hard(struct pet_data *pd, struct map_session_data *sd, int64 tick) { struct block_list *target = NULL; + nullpo_ret(pd); if(pd->bl.prev == NULL || sd == NULL || sd->bl.prev == NULL) return 0; @@ -955,6 +976,7 @@ int pet_ai_sub_hard(struct pet_data *pd, struct map_session_data *sd, int64 tick int pet_ai_sub_foreachclient(struct map_session_data *sd,va_list ap) { int64 tick = va_arg(ap,int64); + nullpo_ret(sd); if(sd->status.pet_id && sd->pd) pet->ai_sub_hard(sd->pd,sd,tick); @@ -1110,7 +1132,8 @@ int pet_recovery_timer(int tid, int64 tick, int id, intptr_t data) { if(sd==NULL || sd->pd == NULL || sd->pd->recovery == NULL) return 1; - pd=sd->pd; + pd = sd->pd; + nullpo_retr(1, pd); if(pd->recovery->timer != tid) { ShowError("pet_recovery_timer %d != %d\n",pd->recovery->timer,tid); @@ -1142,6 +1165,7 @@ int pet_skill_support_timer(int tid, int64 tick, int id, intptr_t data) { return 1; pd=sd->pd; + nullpo_retr(1, pd); if(pd->s_skill->timer != tid) { ShowError("pet_skill_support_timer %d != %d\n",pd->s_skill->timer,tid); |