浏览代码

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.
Lemongrass3110 9 年之前
父节点
当前提交
6ab9fd0eea

+ 2 - 1
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 <char name/ID>).

+ 0 - 3
conf/msg_conf/map_msg_chn.conf

@@ -827,9 +827,6 @@
 // @charunblock
 1024: 請輸入角色名稱 (用法: @charunblock <char name>).
 
-// @charunban
-1025: 請輸入角色名稱 (用法: @charunban <char name>).
-
 // @kick
 1026: 請輸入角色名稱 (用法: @kick <char name/ID>).
 

+ 0 - 3
conf/msg_conf/map_msg_frn.conf

@@ -839,9 +839,6 @@
 // @charunblock
 1024: Entrez un nom de Joueur (usage: @charunblock <nom du joueur>).
 
-// @charunban
-1025: Entrez un nom de Joueur (usage: @charunban <nom du joueur>).
-
 // @kick
 1026: Entrez un nom de Joueur (usage: @kick <nom du joueur/ID>).
 

+ 0 - 3
conf/msg_conf/map_msg_por.conf

@@ -819,9 +819,6 @@
 // @charunblock
 1024: Digite o nome de um jogador (uso: @charunblock <nome do personagem>).
 
-// @charunban
-1025: Digite o nome de um jogador (uso: @charunban <nome do personagem>).
-
 // @kick
 1026: Digite o nome de um jogador (uso: @kick <nome do personagem/ID>).
 

+ 0 - 3
conf/msg_conf/map_msg_rus.conf

@@ -840,9 +840,6 @@
 // @charunblock
 1024: Введите ник персонажа (Использование: @charunblock <ник персонажа>).
 
-// @charunban
-1025: Введите ник персонажа (Использование: @charunban <ник персонажа>).
-
 // @kick
 1026: Введите ник персонажа (Использование: @kick <ID/ник персонажа>).
 

+ 0 - 3
conf/msg_conf/map_msg_spn.conf

@@ -826,9 +826,6 @@
 // @charunblock
 1024: Introduce el nombre de un jugador bloqueado (Instrucciones: @charunblock <nombre del personaje>).
 
-// @charunban
-1025: Introduce el nombre de un jugador bloqueado temporalmente (Instrucciones: @charunban <nombre del personaje>).
-
 // @kick
 1026: Introduce el nombre de un personaje (Instrucciones: @kick <nombre del personaje/ID>).
 

+ 0 - 3
conf/msg_conf/map_msg_tha.conf

@@ -833,9 +833,6 @@
 // @charunblock
 1024: âťĂ´Ăкت×čÍľŃÇĹФà (ÇÔ¸ŐăŞé: @charunblock <Ş×čÍľŃÇĹФĂ>).
 
-// @charunban
-1025: âťĂ´Ăкت×čÍľŃÇĹФà (ÇÔ¸ŐăŞé: @charunban <Ş×čÍľŃÇĹФĂ>).
-
 // @kick
 1026: âťĂ´Ăкت×čÍľŃÇĹФà (ÇÔ¸ŐăŞé: @kick <Ş×čÍ/ID ľŃÇĹФĂ>).
 

+ 20 - 9
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;

+ 14 - 11
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.
 }
 

+ 8 - 1
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);