瀏覽代碼

Emblem checking

Add emblem_check transparency
Add check change during woe time
Thx to Trojal & Aleos for the help and Airei for reminding this
lighta 11 年之前
父節點
當前提交
d07314bcac
共有 5 個文件被更改,包括 49 次插入13 次删除
  1. 7 0
      conf/battle/client.conf
  2. 5 1
      conf/msg_conf/map_msg.conf
  3. 2 0
      src/map/battle.c
  4. 2 1
      src/map/battle.h
  5. 33 11
      src/map/clif.c

+ 7 - 0
conf/battle/client.conf

@@ -154,3 +154,10 @@ client_reshuffle_dice: yes
 // Official servers do not sort storage. (Note 1)
 // NOTE: Enabling this option degrades performance.
 client_sort_storage: no
+
+// Do we allow to change guilde emblem during woe_time ?
+emblem_woe_change: yes
+
+// How many transparent pixel can be found in emblem before detected as invalid ?
+// Note 2
+emblem_transparency_limit: 80

+ 5 - 1
conf/msg_conf/map_msg.conf

@@ -401,7 +401,11 @@
 382: You're too close to a stone or emperium to use this skill.
 383: You cannot create a savepoint in an instance.
 384: You cannot create a memo in an instance.
-//385-389 free
+//emblem chk
+385: You're not allowed to change emblem during woe
+386: The chosen emblem was detected invalid
+387: The chosen emblem was detected invalid as it contain too much transparency (limit=%d)
+//388-389 free
 //NoAsk
 390: Autorejecting is activated.
 391: Autorejecting is deactivated.

+ 2 - 0
src/map/battle.c

@@ -7235,6 +7235,8 @@ static const struct _battle_data {
 	{ "feature.banking",                    &battle_config.feature_banking,                 1,      0,      1,              },
 	{ "mon_trans_disable_in_gvg",           &battle_config.mon_trans_disable_in_gvg,        0,      0,      1,              },
 	{ "homunculus_S_growth_level",          &battle_config.hom_S_growth_level,              99,     0,      MAX_LEVEL,      },
+	{ "emblem_woe_change",                  &battle_config.emblem_woe_change,                0,     0,      1,              },
+	{ "emblem_transparency_limit",          &battle_config.emblem_transparency_limit,       80,     0,    100,              },
 };
 #ifndef STATS_OPT_OUT
 /**

+ 2 - 1
src/map/battle.h

@@ -497,7 +497,8 @@ extern struct Battle_Config
 	int drop_rateincrease;
 	int feature_banking;
 	int mon_trans_disable_in_gvg;
-
+	int emblem_woe_change;
+	int emblem_transparency_limit;
 } battle_config;
 
 void do_init_battle(void);

+ 33 - 11
src/map/clif.c

@@ -12420,19 +12420,30 @@ void clif_parse_GuildRequestEmblem(int fd,struct map_session_data *sd)
 
 
 /// Validates data of a guild emblem (compressed bitmap)
-static bool clif_validate_emblem(const uint8* emblem, unsigned long emblem_len)
-{
-	bool success;
+static bool clif_validate_emblem(const uint8* emblem, unsigned long emblem_len){
 	uint8 buf[1800];  // no well-formed emblem bitmap is larger than 1782 (24 bit) / 1654 (8 bit) bytes
 	unsigned long buf_len = sizeof(buf);
+	int i,j, transcount=1, offset=0, tmp[3];
 
-	success = ( decode_zip(buf, &buf_len, emblem, emblem_len) == 0 && buf_len >= 18 )  // sizeof(BITMAPFILEHEADER) + sizeof(biSize) of the following info header struct
-			&& RBUFW(buf,0) == 0x4d42   // BITMAPFILEHEADER.bfType (signature)
-			&& RBUFL(buf,2) == buf_len  // BITMAPFILEHEADER.bfSize (file size)
-			&& RBUFL(buf,10) < buf_len  // BITMAPFILEHEADER.bfOffBits (offset to bitmap bits)
-			;
+	if(!(( decode_zip(buf, &buf_len, emblem, emblem_len) == 0 && buf_len >= 18 )  // sizeof(BITMAPFILEHEADER) + sizeof(biSize) of the following info header struct
+		&& RBUFW(buf,0) == 0x4d42   // BITMAPFILEHEADER.bfType (signature)
+		&& RBUFL(buf,2) == buf_len  // BITMAPFILEHEADER.bfSize (file size)
+		&& (offset = RBUFL(buf,10)) < buf_len  // BITMAPFILEHEADER.bfOffBits (offset to bitmap bits)
+		))
+		return -1;
 
-	return success;
+	if(battle_config.emblem_transparency_limit != 100){
+		for(i=offset; i<buf_len-1; i++){
+			j = i%3;
+			tmp[j] = RBUFL(buf,i);
+			if(j==2 && (tmp[0] == 0xFFFF00FF) && (tmp[1] == 0xFFFF00) && (tmp[2] == 0xFF00FFFF)) //if pixel is transparent
+				transcount++;
+		}
+		if(((transcount*300)/(buf_len-offset)) > battle_config.emblem_transparency_limit) //convert in % to chk
+			return -2;
+	}
+	
+	return 0;
 }
 
 
@@ -12442,13 +12453,24 @@ void clif_parse_GuildChangeEmblem(int fd,struct map_session_data *sd){
 	struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
 	unsigned long emblem_len = RFIFOW(fd,info->pos[0])-4;
 	const uint8* emblem = RFIFOP(fd,info->pos[1]);
+	int emb_val=0;
 
 	if( !emblem_len || !sd->state.gmaster_flag )
 		return;
 
-	if( !clif_validate_emblem(emblem, emblem_len) )
-	{
+	if(!(battle_config.emblem_woe_change) && (agit_flag || agit2_flag) ){
+		clif_colormes(sd,color_table[COLOR_RED],msg_txt(sd,385)); //"You not allowed to change emblem during woe"
+		return;
+	}
+	emb_val = clif_validate_emblem(emblem, emblem_len);
+	if(emb_val ==-1 ){
 		ShowWarning("clif_parse_GuildChangeEmblem: Rejected malformed guild emblem (size=%lu, accound_id=%d, char_id=%d, guild_id=%d).\n", emblem_len, sd->status.account_id, sd->status.char_id, sd->status.guild_id);
+		clif_colormes(sd,color_table[COLOR_RED],msg_txt(sd,386)); //"The chosen emblem was detected invalid\n"
+		return;
+	} else if(emb_val == -2){
+		char output[128];
+		safesnprintf(output,sizeof(output),msg_txt(sd,387),battle_config.emblem_transparency_limit);
+		clif_colormes(sd,color_table[COLOR_RED],output); //"The chosen emblem was detected invalid as it contain too much transparency (limit=%d)\n"
 		return;
 	}