فهرست منبع

* Random accumulated tweaks and fixes.
- Added a error message to npc_enable, to spot disablenpc/enablenpc/hideoffnpc/hideonnpc on non-existing NPCs (related r14750).
- Replaced inlined npc_name2id code with calls to npc_name2id.
- Open Buying Store skill is now exempted from noskill mapflag like Vending as well (bugreport:4815, follow up to r14713).
- Fixed signed constant being returned as unsigned value in get_percentage (bugreport:4765, since r12679).
- Replaced strlen checks, which checked whether or not a string is empty, with first-byte checks.
- Fixed enabling 'fakename' not clearing party and guild name and cleaned up atcommand 'fakename' code.
- Cleaned up party/guild name code in clif_charnameack (follow up to r14737).

git-svn-id: https://svn.code.sf.net/p/rathena/svn/trunk@14751 54d463be-8e91-2dee-dedb-b68131a5f0ec

ai4rei 14 سال پیش
والد
کامیت
6aa18784a3
8فایلهای تغییر یافته به همراه70 افزوده شده و 43 حذف شده
  1. 8 0
      Changelog-Trunk.txt
  2. 1 1
      src/common/utils.c
  3. 25 24
      src/map/atcommand.c
  4. 23 14
      src/map/clif.c
  5. 3 1
      src/map/guild.c
  6. 6 2
      src/map/npc.c
  7. 3 1
      src/map/party.c
  8. 1 0
      src/map/skill.c

+ 8 - 0
Changelog-Trunk.txt

@@ -1,6 +1,14 @@
 Date	Added
 
 2011/03/20
+	* Random accumulated tweaks and fixes. [Ai4rei]
+	- Added a error message to npc_enable, to spot disablenpc/enablenpc/hideoffnpc/hideonnpc on non-existing NPCs (related r14750).
+	- Replaced inlined npc_name2id code with calls to npc_name2id.
+	- Open Buying Store skill is now exempted from noskill mapflag like Vending as well (bugreport:4815, follow up to r14713).
+	- Fixed signed constant being returned as unsigned value in get_percentage (bugreport:4765, since r12679).
+	- Replaced strlen checks, which checked whether or not a string is empty, with first-byte checks.
+	- Fixed enabling 'fakename' not clearing party and guild name and cleaned up atcommand 'fakename' code.
+	- Cleaned up party/guild name code in clif_charnameack (follow up to r14737).
 	* Fixed battleground kvm02 and kvm03 scripts referring to NPCs in the custom battleground kvm (bugreport:4812, since r14369). [Ai4rei]
 	- Fixed kvm02 printing different amount of points, than it actually gives.
 	* Updates the to configure script. [Ai4rei]

+ 1 - 1
src/common/utils.c

@@ -269,7 +269,7 @@ unsigned int get_percentage(const unsigned int A, const unsigned int B)
 	if( B == 0 )
 	{
 		ShowError("get_percentage(): divison by zero! (A=%u,B=%u)\n", A, B);
-		return -1;
+		return ~0U;
 	}
 
 	result = 100 * ((double)A / (double)B);

+ 25 - 24
src/map/atcommand.c

@@ -2377,7 +2377,7 @@ ACMD_FUNC(monster)
 	if (number <= 0)
 		number = 1;
 
-	if (strlen(name) < 1)
+	if( !name[0] )
 		strcpy(name, "--ja--");
 
 	// If value of atcommand_spawn_quantity_limit directive is greater than or equal to 1 and quantity of monsters is greater than value of the directive
@@ -2458,7 +2458,7 @@ ACMD_FUNC(monstersmall)
 	if (number <= 0)
 		number = 1;
 
-	if (strlen(name) < 1)
+	if( !name[0] )
 		strcpy(name, "--ja--");
 
 	// If value of atcommand_spawn_quantity_limit directive is greater than or equal to 1 and quantity of monsters is greater than value of the directive
@@ -2534,7 +2534,7 @@ ACMD_FUNC(monsterbig)
 	if (number <= 0)
 		number = 1;
 
-	if (strlen(name) < 1)
+	if( !name[0] )
 		strcpy(name, "--ja--");
 
 	// If value of atcommand_spawn_quantity_limit directive is greater than or equal to 1 and quantity of monsters is greater than value of the directive
@@ -5983,7 +5983,7 @@ ACMD_FUNC(changegm)
 		return -1;
 	}
 
-	if (strlen(message)==0)
+	if( !message[0] )
 	{
 		clif_displaymessage(fd, "Command usage: @changegm <guildmember name>");
 		return -1;
@@ -6006,7 +6006,7 @@ ACMD_FUNC(changeleader)
 {
 	nullpo_retr(-1, sd);
 	
-	if (strlen(message)==0)
+	if( !message[0] )
 	{
 		clif_displaymessage(fd, "Command usage: @changeleader <party member name>");
 		return -1;
@@ -7744,31 +7744,32 @@ ACMD_FUNC(monsterignore)
  *------------------------------------------*/
 ACMD_FUNC(fakename)
 {
-	char name[NAME_LENGTH];
 	nullpo_retr(-1, sd);
-	
-	if((!message || !*message) && strlen(sd->fakename) > 1) {
-		sd->fakename[0]='\0';
-		clif_charnameack(0, &sd->bl);
-		clif_displaymessage(sd->fd,"Returned to real name.");
-		return 0;
-	}
 
-	if (!message || !*message || sscanf(message, "%23[^\n]", name) < 1) {
-		clif_displaymessage(sd->fd,"You must enter a name.");
+	if( !message || !*message )
+	{
+		if( sd->fakename[0] )
+		{
+			sd->fakename[0] = '\0';
+			clif_charnameack(0, &sd->bl);
+			clif_displaymessage(sd->fd, "Returned to real name.");
+			return 0;
+		}
+
+		clif_displaymessage(sd->fd, "You must enter a name.");
 		return -1;
 	}
 
-	if(strlen(name) < 2) {
-		clif_displaymessage(sd->fd,"Fake name must be at least two characters.");
+	if( strlen(message) < 2 )
+	{
+		clif_displaymessage(sd->fd, "Fake name must be at least two characters.");
 		return -1;
 	}
 	
-	memcpy(sd->fakename,name,NAME_LENGTH);
-	sd->fakename[NAME_LENGTH-1] = '\0';
+	safestrncpy(sd->fakename, message, sizeof(sd->fakename));
 	clif_charnameack(0, &sd->bl);
-	clif_displaymessage(sd->fd,"Fake name enabled.");
-	
+	clif_displaymessage(sd->fd, "Fake name enabled.");
+
 	return 0;
 }
 
@@ -7902,7 +7903,7 @@ ACMD_FUNC(duel)
 		return 0;
 	}
 
-	if(strlen(message) > 0) {
+	if( message[0] ) {
 		if(sscanf(message, "%d", &maxpl) >= 1) {
 			if(maxpl < 2 || maxpl > 65535) {
 				clif_displaymessage(fd, msg_txt(357)); // "Duel: Invalid value."
@@ -8078,7 +8079,7 @@ ACMD_FUNC(clone)
  *-----------------------------------*/
 ACMD_FUNC(main)
 {
-	if(strlen(message) > 0) {
+	if( message[0] ) {
 
 		if(strcmpi(message, "on") == 0) {
 			if(!sd->state.mainchat) {
@@ -9164,7 +9165,7 @@ ACMD_FUNC(commands)
 		if( gm_lvl < atcommand_info[i].level2 && stristr(command,"charcommands") )
 			continue;
 
-		slen = (unsigned int)strlen(atcommand_info[i].command);
+		slen = strlen(atcommand_info[i].command);
 
 		// flush the text buffer if this command won't fit into it
 		if( slen + cur - line_buff >= CHATBOX_SIZE )

+ 23 - 14
src/map/clif.c

@@ -7624,7 +7624,9 @@ int clif_refresh(struct map_session_data *sd)
 	return 0;
 }
 
-// updates the object's (bl) name on client
+/// Updates the object's (bl) name on client (ZC_ACK_REQNAME/ZC_ACK_REQNAMEALL)
+/// 0095 <unit id>.L <char name>.24B
+/// 0195 <unit id>.L <char name>.24B <party name>.24B <guild name>.24B <position name>.24B
 int clif_charnameack (int fd, struct block_list *bl)
 {
 	unsigned char buf[103];
@@ -7647,24 +7649,31 @@ int clif_charnameack (int fd, struct block_list *bl)
 			if (ssd->fd == fd && ssd->disguise)
 				WBUFL(buf,2) = -bl->id;
 
-			if (strlen(ssd->fakename)>1) {
+			if( ssd->fakename[0] )
+			{
+				WBUFW(buf, 0) = cmd = 0x195;
 				memcpy(WBUFP(buf,6), ssd->fakename, NAME_LENGTH);
+				WBUFB(buf,30) = WBUFB(buf,54) = WBUFB(buf,78) = 0;
 				break;
 			}
 			memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH);
-			
-			if (!battle_config.display_party_name) {
-				if (ssd->status.party_id > 0 && ssd->status.guild_id > 0 && (g = guild_search(ssd->status.guild_id)) != NULL)
-					p = party_search(ssd->status.party_id);
-			}else{
-				if (ssd->status.party_id > 0)
-					p = party_search(ssd->status.party_id);
-			}
 
-			if( ssd->status.guild_id > 0 && (g = guild_search(ssd->status.guild_id)) != NULL )
+			if( ssd->status.party_id )
+			{
+				p = party_search(ssd->status.party_id);
+			}
+			if( ssd->status.guild_id )
 			{
-				ARR_FIND(0, g->max_member, i, g->member[i].account_id == ssd->status.account_id && g->member[i].char_id == ssd->status.char_id);
-				if( i < g->max_member ) ps = g->member[i].position;
+				if( ( g = guild_search(ssd->status.guild_id) ) != NULL )
+				{
+					ARR_FIND(0, g->max_member, i, g->member[i].account_id == ssd->status.account_id && g->member[i].char_id == ssd->status.char_id);
+					if( i < g->max_member ) ps = g->member[i].position;
+				}
+			}
+
+			if( !battle_config.display_party_name && g == NULL )
+			{// do not display party unless the player is also in a guild
+				p = NULL;
 			}
 
 			if (p == NULL && g == NULL)
@@ -7766,7 +7775,7 @@ int clif_charnameupdate (struct map_session_data *ssd)
 
 	nullpo_ret(ssd);
 
-	if (strlen(ssd->fakename)>1)
+	if( ssd->fakename[0] )
 		return 0; //No need to update as the party/guild was not displayed anyway.
 
 	WBUFW(buf,0) = cmd;

+ 3 - 1
src/map/guild.c

@@ -357,7 +357,9 @@ int guild_create(struct map_session_data *sd, const char *name)
 	nullpo_ret(sd);
 
 	safestrncpy(tname, name, NAME_LENGTH);
-	if( strlen(trim(tname)) == 0 )
+	trim(tname);
+
+	if( !tname[0] )
 		return 0; // empty name
 
 	if( sd->status.guild_id )

+ 6 - 2
src/map/npc.c

@@ -160,9 +160,13 @@ int npc_enable_sub(struct block_list *bl, va_list ap)
 
 int npc_enable(const char* name, int flag)
 {
-	struct npc_data* nd = (struct npc_data*)strdb_get(npcname_db, name);
+	struct npc_data* nd = npc_name2id(name);
+
 	if (nd==NULL)
+	{
+		ShowError("npc_enable: Attempted to %s a non-existing NPC '%s' (flag=%d).\n", (flag&3) ? "show" : "hide", name, flag);
 		return 0;
+	}
 
 	if (flag&1)
 		nd->sc.option&=~OPTION_INVISIBLE;
@@ -1034,7 +1038,7 @@ struct npc_data* npc_checknear(struct map_session_data* sd, struct block_list* b
  *------------------------------------------*/
 int npc_globalmessage(const char* name, const char* mes)
 {
-	struct npc_data* nd = (struct npc_data *) strdb_get(npcname_db, name);
+	struct npc_data* nd = npc_name2id(name);
 	char temp[100];
 
 	if (!nd)

+ 3 - 1
src/map/party.c

@@ -128,7 +128,9 @@ int party_create(struct map_session_data *sd,char *name,int item,int item2)
 	char tname[NAME_LENGTH];
 
 	safestrncpy(tname, name, NAME_LENGTH);
-	if( strlen(trim(tname)) == 0 )
+	trim(tname);
+
+	if( !tname[0] )
 	{// empty name
 		return 0;
 	}

+ 1 - 0
src/map/skill.c

@@ -398,6 +398,7 @@ int skillnotok (int skillid, struct map_session_data *sd)
 			break;
 		case MC_VENDING:
 		case MC_IDENTIFY:
+		case ALL_BUYING_STORE:
 			return 0; // always allowed
 		case WZ_ICEWALL:
 			// noicewall flag [Valaris]