|
@@ -12420,19 +12420,30 @@ void clif_parse_GuildRequestEmblem(int fd,struct map_session_data *sd)
|
|
|
|
|
|
|
|
|
|
/// Validates data of a guild emblem (compressed bitmap)
|
|
/// 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
|
|
uint8 buf[1800]; // no well-formed emblem bitmap is larger than 1782 (24 bit) / 1654 (8 bit) bytes
|
|
unsigned long buf_len = sizeof(buf);
|
|
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)];
|
|
struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
|
|
unsigned long emblem_len = RFIFOW(fd,info->pos[0])-4;
|
|
unsigned long emblem_len = RFIFOW(fd,info->pos[0])-4;
|
|
const uint8* emblem = RFIFOP(fd,info->pos[1]);
|
|
const uint8* emblem = RFIFOP(fd,info->pos[1]);
|
|
|
|
+ int emb_val=0;
|
|
|
|
|
|
if( !emblem_len || !sd->state.gmaster_flag )
|
|
if( !emblem_len || !sd->state.gmaster_flag )
|
|
return;
|
|
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);
|
|
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;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|