From 6ab9fd0eeabd7c269d5f6c96ad0fba24a6c0fc8e Mon Sep 17 00:00:00 2001 From: Lemongrass3110 Date: Sun, 24 Apr 2016 20:32:05 +0200 Subject: [PATCH] Small refactor of pc_setpos pc_setpos now delivers an enum for the error that happened. Additionallly it now returns a different return value when the targeted player is in autotrade state. Added usage of this new return value to all recall commands. --- conf/msg_conf/map_msg.conf | 3 ++- conf/msg_conf/map_msg_chn.conf | 3 --- conf/msg_conf/map_msg_frn.conf | 3 --- conf/msg_conf/map_msg_por.conf | 3 --- conf/msg_conf/map_msg_rus.conf | 3 --- conf/msg_conf/map_msg_spn.conf | 3 --- conf/msg_conf/map_msg_tha.conf | 3 --- src/map/atcommand.c | 29 ++++++++++++++++++++--------- src/map/pc.c | 25 ++++++++++++++----------- src/map/pc.h | 9 ++++++++- 10 files changed, 44 insertions(+), 40 deletions(-) diff --git a/conf/msg_conf/map_msg.conf b/conf/msg_conf/map_msg.conf index 2e50a20434..e9084faed3 100644 --- a/conf/msg_conf/map_msg.conf +++ b/conf/msg_conf/map_msg.conf @@ -949,7 +949,8 @@ // @rates 1024: MVP Drop Rates: Common %.2fx / Healing %.2fx / Usable %.2fx / Equipment %.2fx / Card %.2fx -//1025: free +// @recall +1025: The player cannot be recalled, because he is in autotrading state. // @kick 1026: Please enter a player name (usage: @kick ). diff --git a/conf/msg_conf/map_msg_chn.conf b/conf/msg_conf/map_msg_chn.conf index c73a97c7a2..6b8da573fa 100644 --- a/conf/msg_conf/map_msg_chn.conf +++ b/conf/msg_conf/map_msg_chn.conf @@ -827,9 +827,6 @@ // @charunblock 1024: 請輸入角色名稱 (用法: @charunblock ). -// @charunban -1025: 請輸入角色名稱 (用法: @charunban ). - // @kick 1026: 請輸入角色名稱 (用法: @kick ). diff --git a/conf/msg_conf/map_msg_frn.conf b/conf/msg_conf/map_msg_frn.conf index 3cbc748741..b4a4330f1e 100644 --- a/conf/msg_conf/map_msg_frn.conf +++ b/conf/msg_conf/map_msg_frn.conf @@ -839,9 +839,6 @@ // @charunblock 1024: Entrez un nom de Joueur (usage: @charunblock ). -// @charunban -1025: Entrez un nom de Joueur (usage: @charunban ). - // @kick 1026: Entrez un nom de Joueur (usage: @kick ). diff --git a/conf/msg_conf/map_msg_por.conf b/conf/msg_conf/map_msg_por.conf index 122d207c29..86c522385b 100644 --- a/conf/msg_conf/map_msg_por.conf +++ b/conf/msg_conf/map_msg_por.conf @@ -819,9 +819,6 @@ // @charunblock 1024: Digite o nome de um jogador (uso: @charunblock ). -// @charunban -1025: Digite o nome de um jogador (uso: @charunban ). - // @kick 1026: Digite o nome de um jogador (uso: @kick ). diff --git a/conf/msg_conf/map_msg_rus.conf b/conf/msg_conf/map_msg_rus.conf index 65953679d6..0a06d94328 100644 --- a/conf/msg_conf/map_msg_rus.conf +++ b/conf/msg_conf/map_msg_rus.conf @@ -840,9 +840,6 @@ // @charunblock 1024: (: @charunblock < >). -// @charunban -1025: (: @charunban < >). - // @kick 1026: (: @kick ). diff --git a/conf/msg_conf/map_msg_spn.conf b/conf/msg_conf/map_msg_spn.conf index 5117e1eceb..1103fd236a 100644 --- a/conf/msg_conf/map_msg_spn.conf +++ b/conf/msg_conf/map_msg_spn.conf @@ -826,9 +826,6 @@ // @charunblock 1024: Introduce el nombre de un jugador bloqueado (Instrucciones: @charunblock ). -// @charunban -1025: Introduce el nombre de unjugador bloqueado temporalmente(Instrucciones: @charunban ). - // @kick 1026: Introduce el nombre de un personaje (Instrucciones: @kick ). diff --git a/conf/msg_conf/map_msg_tha.conf b/conf/msg_conf/map_msg_tha.conf index 34a84d53da..2ddd3bdcd5 100644 --- a/conf/msg_conf/map_msg_tha.conf +++ b/conf/msg_conf/map_msg_tha.conf @@ -833,9 +833,6 @@ // @charunblock 1024: ôкت͵Ф (Ը: @charunblock <͵Ф>). -// @charunban -1025: ôкت͵Ф (Ը: @charunban <͵Ф>). - // @kick 1026: ôкت͵Ф (Ը: @kick ). diff --git a/src/map/atcommand.c b/src/map/atcommand.c index 56345f4d73..953af12d1c 100644 --- a/src/map/atcommand.c +++ b/src/map/atcommand.c @@ -483,7 +483,7 @@ ACMD_FUNC(mapmove) clif_displaymessage(fd, msg_txt(sd,248)); return -1; } - if (pc_setpos(sd, mapindex, x, y, CLR_TELEPORT) != 0) { + if (pc_setpos(sd, mapindex, x, y, CLR_TELEPORT) != SETPOS_OK) { clif_displaymessage(fd, msg_txt(sd,1)); // Map not found. return -1; } @@ -2032,7 +2032,7 @@ ACMD_FUNC(go) clif_displaymessage(fd, msg_txt(sd,248)); return -1; } - if (pc_setpos(sd, mapindex_name2id(data[town].map), data[town].x, data[town].y, CLR_TELEPORT) == 0) { + if (pc_setpos(sd, mapindex_name2id(data[town].map), data[town].x, data[town].y, CLR_TELEPORT) == SETPOS_OK) { clif_displaymessage(fd, msg_txt(sd,0)); // Warped. } else { clif_displaymessage(fd, msg_txt(sd,1)); // Map not found. @@ -2901,7 +2901,11 @@ ACMD_FUNC(recall) { if (pl_sd->bl.m == sd->bl.m && pl_sd->bl.x == sd->bl.x && pl_sd->bl.y == sd->bl.y) { return -1; } - pc_setpos(pl_sd, sd->mapindex, sd->bl.x, sd->bl.y, CLR_RESPAWN); + if( pc_setpos(pl_sd, sd->mapindex, sd->bl.x, sd->bl.y, CLR_RESPAWN) == SETPOS_AUTOTRADE ){ + clif_displaymessage(fd, msg_txt(sd,1025)); // The player cannot be recalled, because he is in autotrading state. + return -1; + } + sprintf(atcmd_output, msg_txt(sd,46), pl_sd->status.name); // %s recalled! clif_displaymessage(fd, atcmd_output); @@ -3605,7 +3609,9 @@ ACMD_FUNC(recallall) if (pl_sd->bl.m >= 0 && map[pl_sd->bl.m].flag.nowarp && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE)) count++; else { - pc_setpos(pl_sd, sd->mapindex, sd->bl.x, sd->bl.y, CLR_RESPAWN); + if( pc_setpos(pl_sd, sd->mapindex, sd->bl.x, sd->bl.y, CLR_RESPAWN) == SETPOS_AUTOTRADE ){ + count++; + } } } } @@ -3663,8 +3669,10 @@ ACMD_FUNC(guildrecall) continue; // Skip GMs greater than you... or chars already on the cell if (pl_sd->bl.m >= 0 && map[pl_sd->bl.m].flag.nowarp && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE)) count++; - else - pc_setpos(pl_sd, sd->mapindex, sd->bl.x, sd->bl.y, CLR_RESPAWN); + else{ + if( pc_setpos(pl_sd, sd->mapindex, sd->bl.x, sd->bl.y, CLR_RESPAWN) == SETPOS_AUTOTRADE ){ + count++; + } } } mapit_free(iter); @@ -3722,8 +3730,11 @@ ACMD_FUNC(partyrecall) continue; // Skip GMs greater than you... or chars already on the cell if (pl_sd->bl.m >= 0 && map[pl_sd->bl.m].flag.nowarp && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE)) count++; - else - pc_setpos(pl_sd, sd->mapindex, sd->bl.x, sd->bl.y, CLR_RESPAWN); + else{ + if( pc_setpos(pl_sd, sd->mapindex, sd->bl.x, sd->bl.y, CLR_RESPAWN) == SETPOS_AUTOTRADE ){ + count++; + } + } } } mapit_free(iter); @@ -4442,7 +4453,7 @@ ACMD_FUNC(tonpc) } if ((nd = npc_name2id(npcname)) != NULL) { - if (pc_setpos(sd, map_id2index(nd->bl.m), nd->bl.x, nd->bl.y, CLR_TELEPORT) == 0) + if (pc_setpos(sd, map_id2index(nd->bl.m), nd->bl.x, nd->bl.y, CLR_TELEPORT) == SETPOS_OK) clif_displaymessage(fd, msg_txt(sd,0)); // Warped. else return -1; diff --git a/src/map/pc.c b/src/map/pc.c index d411e35eb7..25c647cf71 100755 --- a/src/map/pc.c +++ b/src/map/pc.c @@ -1195,11 +1195,11 @@ bool pc_authok(struct map_session_data *sd, uint32 login_id2, time_t expiration_ sd->qi_count = 0; //warp player - if ((i=pc_setpos(sd,sd->status.last_point.map, sd->status.last_point.x, sd->status.last_point.y, CLR_OUTSIGHT)) != 0) { + if ((i=pc_setpos(sd,sd->status.last_point.map, sd->status.last_point.x, sd->status.last_point.y, CLR_OUTSIGHT)) != SETPOS_OK) { ShowError ("Last_point_map %s - id %d not found (error code %d)\n", mapindex_id2name(sd->status.last_point.map), sd->status.last_point.map, i); // try warping to a default map instead (church graveyard) - if (pc_setpos(sd, mapindex_name2id(MAP_PRONTERA), 273, 354, CLR_OUTSIGHT) != 0) { + if (pc_setpos(sd, mapindex_name2id(MAP_PRONTERA), 273, 354, CLR_OUTSIGHT) != SETPOS_OK) { // if we fail again clif_authfail_fd(sd->fd, 0); return false; @@ -5238,21 +5238,24 @@ int pc_steal_coin(struct map_session_data *sd,struct block_list *target) * @param x * @param y * @param clrtype - * @return 0 - Success; 1 - Invalid map index; 2 - Map not in this map-server, and failed to locate alternate map-server. + * @return SETPOS_OK Success + * SETPOS_MAPINDEX Invalid map index + * SETPOS_NO_MAPSERVER Map not in this map-server, and failed to locate alternate map-server. + * SETPOS_AUTOTRADE Player is in autotrade state *------------------------------------------*/ -char pc_setpos(struct map_session_data* sd, unsigned short mapindex, int x, int y, clr_type clrtype) +enum e_setpos pc_setpos(struct map_session_data* sd, unsigned short mapindex, int x, int y, clr_type clrtype) { int16 m; - nullpo_ret(sd); + nullpo_retr(SETPOS_OK,sd); if( !mapindex || !mapindex_id2name(mapindex) ) { ShowDebug("pc_setpos: Passed mapindex(%d) is invalid!\n", mapindex); - return 1; + return SETPOS_MAPINDEX; } if ( sd->state.autotrade && (sd->vender_id || sd->buyer_id) ) // Player with autotrade just causes clif glitch! @ FIXME - return 1; + return SETPOS_AUTOTRADE; if( battle_config.revive_onwarp && pc_isdead(sd) ) { //Revive dead people before warping them pc_setstand(sd, true); @@ -5318,7 +5321,7 @@ char pc_setpos(struct map_session_data* sd, unsigned short mapindex, int x, int uint16 port; //if can't find any map-servers, just abort setting position. if(!sd->mapindex || map_mapname2ipport(mapindex,&ip,&port)) - return 2; + return SETPOS_NO_MAPSERVER; if (sd->npc_id) npc_event_dequeue(sd); @@ -5335,7 +5338,7 @@ char pc_setpos(struct map_session_data* sd, unsigned short mapindex, int x, int //Free session data from this map server [Kevin] unit_free_pc(sd); - return 0; + return SETPOS_OK; } if( x < 0 || x >= map[m].xs || y < 0 || y >= map[m].ys ) @@ -5422,7 +5425,7 @@ char pc_setpos(struct map_session_data* sd, unsigned short mapindex, int x, int else sd->count_rewarp = 0; - return 0; + return SETPOS_OK; } /*========================================== @@ -7305,7 +7308,7 @@ void pc_respawn(struct map_session_data* sd, clr_type clrtype) pc_setstand(sd, true); pc_setrestartvalue(sd,3); - if( pc_setpos(sd, sd->status.save_point.map, sd->status.save_point.x, sd->status.save_point.y, clrtype) ) + if( pc_setpos(sd, sd->status.save_point.map, sd->status.save_point.x, sd->status.save_point.y, clrtype) != SETPOS_OK ) clif_resurrection(&sd->bl, 1); //If warping fails, send a normal stand up packet. } diff --git a/src/map/pc.h b/src/map/pc.h index 8bed5a3718..29d17ab30e 100644 --- a/src/map/pc.h +++ b/src/map/pc.h @@ -951,7 +951,14 @@ void pc_clean_skilltree(struct map_session_data *sd); #define pc_checkoverhp(sd) ((sd)->battle_status.hp == (sd)->battle_status.max_hp) #define pc_checkoversp(sd) ((sd)->battle_status.sp == (sd)->battle_status.max_sp) -char pc_setpos(struct map_session_data* sd, unsigned short mapindex, int x, int y, clr_type clrtype); +enum e_setpos{ + SETPOS_OK = 0, + SETPOS_MAPINDEX = 1, + SETPOS_NO_MAPSERVER = 2, + SETPOS_AUTOTRADE = 3 +}; + +enum e_setpos pc_setpos(struct map_session_data* sd, unsigned short mapindex, int x, int y, clr_type clrtype); void pc_setsavepoint(struct map_session_data *sd, short mapindex,int x,int y); char pc_randomwarp(struct map_session_data *sd,clr_type type); bool pc_memo(struct map_session_data* sd, int pos);