diff options
author | Haru <haru@dotalux.com> | 2013-09-19 17:12:27 +0200 |
---|---|---|
committer | Haru <haru@dotalux.com> | 2013-09-19 17:12:27 +0200 |
commit | 556834d0508101b70660c5904b24adacacced3e0 (patch) | |
tree | ab9e552032ae4d9bccd8a2d66b6d0a388015098b | |
parent | 257fd1a8f0aa0b26aa8331b390315567344f4e2b (diff) | |
download | hercules-556834d0508101b70660c5904b24adacacced3e0.tar.gz hercules-556834d0508101b70660c5904b24adacacced3e0.tar.bz2 hercules-556834d0508101b70660c5904b24adacacced3e0.tar.xz hercules-556834d0508101b70660c5904b24adacacced3e0.zip |
Cleaned up and de-duplicated ranklist-related code
Follow-up to 6cf032d. Special thanks to Ind.
Signed-off-by: Haru <haru@dotalux.com>
-rw-r--r-- | src/char/char.c | 40 | ||||
-rw-r--r-- | src/common/mmo.h | 7 | ||||
-rw-r--r-- | src/map/chrif.c | 18 | ||||
-rw-r--r-- | src/map/clif.c | 193 | ||||
-rw-r--r-- | src/map/clif.h | 13 | ||||
-rw-r--r-- | src/map/packets.h | 3 |
6 files changed, 96 insertions, 178 deletions
diff --git a/src/char/char.c b/src/char/char.c index 943d1f52e..dc7966e8d 100644 --- a/src/char/char.c +++ b/src/char/char.c @@ -136,7 +136,7 @@ int guild_exp_rate = 100; //Custom limits for the fame lists. [Skotlex] int fame_list_size_chemist = MAX_FAME_LIST; -int fame_list_size_smith = MAX_FAME_LIST; +int fame_list_size_smith = MAX_FAME_LIST; int fame_list_size_taekwon = MAX_FAME_LIST; // Char-server-side stored fame lists [DracoRPG] @@ -2517,8 +2517,7 @@ int save_accreg2(unsigned char* buf, int len) return 0; } -void char_read_fame_list(void) -{ +void char_read_fame_list(void) { int i; char* data; size_t len; @@ -2576,8 +2575,7 @@ void char_read_fame_list(void) } // Send map-servers the fame ranking lists -int char_send_fame_list(int fd) -{ +int char_send_fame_list(int fd) { int i, len = 8; unsigned char buf[32000]; @@ -2612,8 +2610,7 @@ int char_send_fame_list(int fd) return 0; } -void char_update_fame_list(int type, int index, int fame) -{ +void char_update_fame_list(int type, int index, int fame) { unsigned char buf[8]; WBUFW(buf,0) = 0x2b22; WBUFB(buf,2) = type; @@ -3210,12 +3207,11 @@ int parse_frommap(int fd) int player_pos; int fame_pos; - switch(type) - { - case 1: size = fame_list_size_smith; list = smith_fame_list; break; - case 2: size = fame_list_size_chemist; list = chemist_fame_list; break; - case 3: size = fame_list_size_taekwon; list = taekwon_fame_list; break; - default: size = 0; list = NULL; break; + switch(type) { + case RANKTYPE_BLACKSMITH: size = fame_list_size_smith; list = smith_fame_list; break; + case RANKTYPE_ALCHEMIST: size = fame_list_size_chemist; list = chemist_fame_list; break; + case RANKTYPE_TAEKWON: size = fame_list_size_taekwon; list = taekwon_fame_list; break; + default: size = 0; list = NULL; break; } ARR_FIND(0, size, player_pos, list[player_pos].id == cid);// position of the player @@ -3223,22 +3219,20 @@ int parse_frommap(int fd) if( player_pos == size && fame_pos == size ) ;// not on list and not enough fame to get on it - else if( fame_pos == player_pos ) - {// same position + else if( fame_pos == player_pos ) { + // same position list[player_pos].fame = fame; char_update_fame_list(type, player_pos, fame); - } - else - {// move in the list - if( player_pos == size ) - {// new ranker - not in the list + } else { + // move in the list + if( player_pos == size ) { + // new ranker - not in the list ARR_MOVE(size - 1, fame_pos, list, struct fame_list); list[fame_pos].id = cid; list[fame_pos].fame = fame; char_loadName(cid, list[fame_pos].name); - } - else - {// already in the list + } else { + // already in the list if( fame_pos == size ) --fame_pos;// move to the end of the list ARR_MOVE(player_pos, fame_pos, list, struct fame_list); diff --git a/src/common/mmo.h b/src/common/mmo.h index 17a01ff95..b51d0ec4a 100644 --- a/src/common/mmo.h +++ b/src/common/mmo.h @@ -575,6 +575,13 @@ struct fame_list { char name[NAME_LENGTH]; }; +enum fame_list_type { + RANKTYPE_BLACKSMITH = 0, + RANKTYPE_ALCHEMIST = 1, + RANKTYPE_TAEKWON = 2, + RANKTYPE_PK = 3, //Not supported yet +}; + enum { //Change Guild Infos GBI_EXP =1, // Guild Experience (EXP) GBI_GUILDLV, // Guild level diff --git a/src/map/chrif.c b/src/map/chrif.c index 524286da1..c79cf9e4a 100644 --- a/src/map/chrif.c +++ b/src/map/chrif.c @@ -1073,9 +1073,9 @@ int chrif_updatefamelist(struct map_session_data* sd) { chrif_check(-1); switch(sd->class_ & MAPID_UPPERMASK) { - case MAPID_BLACKSMITH: type = 1; break; - case MAPID_ALCHEMIST: type = 2; break; - case MAPID_TAEKWON: type = 3; break; + case MAPID_BLACKSMITH: type = RANKTYPE_BLACKSMITH; break; + case MAPID_ALCHEMIST: type = RANKTYPE_ALCHEMIST; break; + case MAPID_TAEKWON: type = RANKTYPE_TAEKWON; break; default: return 0; } @@ -1104,9 +1104,9 @@ int chrif_recvfamelist(int fd) { int num, size; int total = 0, len = 8; - memset (smith_fame_list, 0, sizeof(smith_fame_list)); - memset (chemist_fame_list, 0, sizeof(chemist_fame_list)); - memset (taekwon_fame_list, 0, sizeof(taekwon_fame_list)); + memset(smith_fame_list, 0, sizeof(smith_fame_list)); + memset(chemist_fame_list, 0, sizeof(chemist_fame_list)); + memset(taekwon_fame_list, 0, sizeof(taekwon_fame_list)); size = RFIFOW(fd, 6); //Blacksmith block size @@ -1147,9 +1147,9 @@ int chrif_updatefamelist_ack(int fd) { uint8 index; switch (RFIFOB(fd,2)) { - case 1: list = smith_fame_list; break; - case 2: list = chemist_fame_list; break; - case 3: list = taekwon_fame_list; break; + case RANKTYPE_BLACKSMITH: list = smith_fame_list; break; + case RANKTYPE_ALCHEMIST: list = chemist_fame_list; break; + case RANKTYPE_TAEKWON: list = taekwon_fame_list; break; default: return 0; } diff --git a/src/map/clif.c b/src/map/clif.c index 342f1d943..bb012c24d 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -14040,143 +14040,115 @@ void clif_parse_PVPInfo(int fd,struct map_session_data *sd) /// Ranking list /// ranking pointlist { <name>.24B <point>.L }*10 -void clif_sub_ranklist(unsigned char *buf,int idx,struct map_session_data* sd, int16 rankingtype){ +void clif_ranklist_sub(unsigned char *buf, enum fame_list_type type) { const char* name; struct fame_list* list; - int i, skip = 0; + int i; - switch(rankingtype+1) { //to keep the same case as char.c - case 1: list = smith_fame_list; break; - case 2: list = chemist_fame_list; break; - case 3: list = taekwon_fame_list; break; - default: skip=1; break; + switch( type ) { + case RANKTYPE_BLACKSMITH: list = smith_fame_list; break; + case RANKTYPE_ALCHEMIST: list = chemist_fame_list; break; + case RANKTYPE_TAEKWON: list = taekwon_fame_list; break; + default: return; // Unsupported } - if(!skip) { - //Packet size limits this list to 10 elements. [Skotlex] - for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) { - if (list[i].id > 0) { - if (strcmp(list[i].name, "-") == 0 && (name = iMap->charid2nick(list[i].id)) != NULL) { - strncpy((char *)(WBUFP(buf,idx + 24 * i)), name, NAME_LENGTH); - } else { - strncpy((char *)(WBUFP(buf,idx + 24 * i)), list[i].name, NAME_LENGTH); - } + // Packet size limits this list to 10 elements. [Skotlex] + for( i = 0; i < 10 && i < MAX_FAME_LIST; i++ ) { + if( list[i].id > 0 ) { + if( strcmp(list[i].name, "-") == 0 && (name = iMap->charid2nick(list[i].id)) != NULL ) { + strncpy((char *)(WBUFP(buf, 24 * i)), name, NAME_LENGTH); } else { - strncpy((char *)(WBUFP(buf, idx + 24 * i)), "None", 5); + strncpy((char *)(WBUFP(buf, 24 * i)), list[i].name, NAME_LENGTH); } - WBUFL(buf, idx + 24 * 10 + i * 4) = list[i].fame; //points - } - for(;i < 10; i++) { //In case the MAX is less than 10. - strncpy((char *)(WBUFP(buf, idx + 24 * i)), "Unavailable", 12); - WBUFL(buf, idx + 24 * 10 + i * 4) = 0; + } else { + strncpy((char *)(WBUFP(buf, 24 * i)), "None", 5); } + WBUFL(buf, 24 * 10 + i * 4) = list[i].fame; //points + } + for( ;i < 10; i++ ) { // In case the MAX is less than 10. + strncpy((char *)(WBUFP(buf, 24 * i)), "Unavailable", 12); + WBUFL(buf, 24 * 10 + i * 4) = 0; } } /// 097d <RankingType>.W {<CharName>.24B <point>L}*10 <mypoint>L (ZC_ACK_RANKING) -void clif_ranklist(struct map_session_data *sd, int16 rankingType){ - unsigned char buf[MAX_FAME_LIST * sizeof(struct fame_list)]; +void clif_ranklist(struct map_session_data *sd, enum fame_list_type type) { + int fd = sd->fd; int mypoint = 0; int upperMask = sd->class_&MAPID_UPPERMASK; - WBUFW(buf, 0) = 0x97d; - WBUFW(buf, 2) = rankingType; - clif_sub_ranklist(buf, 4, sd, rankingType); + WFIFOHEAD(fd, 288); + WFIFOW(fd, 0) = 0x97d; + WFIFOW(fd, 2) = type; + clif_ranklist_sub(WFIFOP(fd,4), type); - - if( - (upperMask == MAPID_BLACKSMITH && rankingType == RANKTYPE_BLACKSMITH) || - (upperMask == MAPID_ALCHEMIST && rankingType == RANKTYPE_ALCHEMIST) || - (upperMask == MAPID_TAEKWON && rankingType == RANKTYPE_TAEKWON) + if( (upperMask == MAPID_BLACKSMITH && type == RANKTYPE_BLACKSMITH) + || (upperMask == MAPID_ALCHEMIST && type == RANKTYPE_ALCHEMIST) + || (upperMask == MAPID_TAEKWON && type == RANKTYPE_TAEKWON) ) { mypoint = sd->status.fame; } else { mypoint = 0; } - WBUFL(buf, 284) = mypoint; //mypoint - clif_send(buf, 288, &sd->bl, SELF); + WFIFOL(fd, 284) = mypoint; //mypoint + WFIFOSET(fd, 288); } /* * 097c <type> (CZ_REQ_RANKING) * */ -void clif_parse_ranklist(int fd,struct map_session_data *sd) { - int16 rankingtype = RFIFOW(fd, 2);//type +void clif_parse_ranklist(int fd, struct map_session_data *sd) { + int16 type = RFIFOW(fd, 2); //type - switch(rankingtype) { + switch( type ) { case RANKTYPE_BLACKSMITH: case RANKTYPE_ALCHEMIST: case RANKTYPE_TAEKWON: - clif_ranklist(sd,rankingtype); // pk_list unsuported atm + clif->ranklist(sd, type); // pk_list unsuported atm break; } } // 097e <RankingType>.W <point>.L <TotalPoint>.L (ZC_UPDATE_RANKING_POINT) -void clif_update_rankingpoint(struct map_session_data *sd, int16 rankingtype, int point){ +void clif_update_rankingpoint(struct map_session_data *sd, enum fame_list_type type, int points) { #if PACKETVER < 20130710 - switch(rankingtype){ - case RANKTYPE_BLACKSMITH: clif->fame_blacksmith(sd,point); break; // Blacksmith - case RANKTYPE_ALCHEMIST: clif->fame_alchemist(sd,point); break; //Alchemist - case RANKTYPE_TAEKWON: clif->fame_taekwon(sd,point); break; // Taekwon + switch( type ) { + case RANKTYPE_BLACKSMITH: clif->fame_blacksmith(sd,points); break; + case RANKTYPE_ALCHEMIST: clif->fame_alchemist(sd,points); break; + case RANKTYPE_TAEKWON: clif->fame_taekwon(sd,points); break; } #else - int fd=sd->fd; - WFIFOHEAD(fd, 14); + int fd = sd->fd; + WFIFOHEAD(fd, 12); WFIFOW(fd, 0) = 0x97e; - WFIFOW(fd, 2) = rankingtype; - WFIFOL(fd, 4) = point; + WFIFOW(fd, 2) = type; + WFIFOL(fd, 4) = points; WFIFOL(fd, 8) = sd->status.fame; WFIFOSET(fd, 12); #endif } - - /// /blacksmith list (ZC_BLACKSMITH_RANK). /// 0219 { <name>.24B }*10 { <point>.L }*10 -void clif_blacksmith(struct map_session_data* sd) -{ - int i, fd = sd->fd; - const char* name; +void clif_blacksmith(struct map_session_data* sd) { + int fd = sd->fd; WFIFOHEAD(fd,packet_len(0x219)); WFIFOW(fd,0) = 0x219; - //Packet size limits this list to 10 elements. [Skotlex] - for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) { - if (smith_fame_list[i].id > 0) { - if (strcmp(smith_fame_list[i].name, "-") == 0 && - (name = iMap->charid2nick(smith_fame_list[i].id)) != NULL) - { - strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), name, NAME_LENGTH); - } else - strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), smith_fame_list[i].name, NAME_LENGTH); - } else - strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), "None", 5); - WFIFOL(fd, 242 + i * 4) = smith_fame_list[i].fame; - } - for(;i < 10; i++) { //In case the MAX is less than 10. - strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), "Unavailable", 12); - WFIFOL(fd, 242 + i * 4) = 0; - } - + clif_ranklist_sub(WFIFOP(fd, 2), RANKTYPE_BLACKSMITH); WFIFOSET(fd, packet_len(0x219)); } - /// /blacksmith (CZ_BLACKSMITH_RANK). /// 0217 -void clif_parse_Blacksmith(int fd,struct map_session_data *sd) -{ +void clif_parse_Blacksmith(int fd,struct map_session_data *sd) { clif->blacksmith(sd); } - /// Notification about backsmith points (ZC_BLACKSMITH_POINT). /// 021b <points>.L <total points>.L -void clif_fame_blacksmith(struct map_session_data *sd, int points) -{ +void clif_fame_blacksmith(struct map_session_data *sd, int points) { int fd = sd->fd; WFIFOHEAD(fd,packet_len(0x21b)); @@ -14186,49 +14158,26 @@ void clif_fame_blacksmith(struct map_session_data *sd, int points) WFIFOSET(fd, packet_len(0x21b)); } - /// /alchemist list (ZC_ALCHEMIST_RANK). /// 021a { <name>.24B }*10 { <point>.L }*10 void clif_alchemist(struct map_session_data* sd) { - int i, fd = sd->fd; - const char* name; + int fd = sd->fd; WFIFOHEAD(fd,packet_len(0x21a)); WFIFOW(fd,0) = 0x21a; - //Packet size limits this list to 10 elements. [Skotlex] - for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) { - if (chemist_fame_list[i].id > 0) { - if (strcmp(chemist_fame_list[i].name, "-") == 0 && - (name = iMap->charid2nick(chemist_fame_list[i].id)) != NULL) - { - memcpy(WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH); - } else - memcpy(WFIFOP(fd, 2 + 24 * i), chemist_fame_list[i].name, NAME_LENGTH); - } else - memcpy(WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH); - WFIFOL(fd, 242 + i * 4) = chemist_fame_list[i].fame; - } - for(;i < 10; i++) { //In case the MAX is less than 10. - memcpy(WFIFOP(fd, 2 + 24 * i), "Unavailable", NAME_LENGTH); - WFIFOL(fd, 242 + i * 4) = 0; - } - + clif_ranklist_sub(WFIFOP(fd,2), RANKTYPE_ALCHEMIST); WFIFOSET(fd, packet_len(0x21a)); } - /// /alchemist (CZ_ALCHEMIST_RANK). /// 0218 -void clif_parse_Alchemist(int fd,struct map_session_data *sd) -{ +void clif_parse_Alchemist(int fd,struct map_session_data *sd) { clif->alchemist(sd); } - /// Notification about alchemist points (ZC_ALCHEMIST_POINT). /// 021c <points>.L <total points>.L -void clif_fame_alchemist(struct map_session_data *sd, int points) -{ +void clif_fame_alchemist(struct map_session_data *sd, int points) { int fd = sd->fd; WFIFOHEAD(fd,packet_len(0x21c)); @@ -14238,48 +14187,26 @@ void clif_fame_alchemist(struct map_session_data *sd, int points) WFIFOSET(fd, packet_len(0x21c)); } - /// /taekwon list (ZC_TAEKWON_RANK). /// 0226 { <name>.24B }*10 { <point>.L }*10 void clif_taekwon(struct map_session_data* sd) { - int i, fd = sd->fd; - const char* name; + int fd = sd->fd; WFIFOHEAD(fd,packet_len(0x226)); WFIFOW(fd,0) = 0x226; - //Packet size limits this list to 10 elements. [Skotlex] - for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) { - if (taekwon_fame_list[i].id > 0) { - if (strcmp(taekwon_fame_list[i].name, "-") == 0 && - (name = iMap->charid2nick(taekwon_fame_list[i].id)) != NULL) - { - memcpy(WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH); - } else - memcpy(WFIFOP(fd, 2 + 24 * i), taekwon_fame_list[i].name, NAME_LENGTH); - } else - memcpy(WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH); - WFIFOL(fd, 242 + i * 4) = taekwon_fame_list[i].fame; - } - for(;i < 10; i++) { //In case the MAX is less than 10. - memcpy(WFIFOP(fd, 2 + 24 * i), "Unavailable", NAME_LENGTH); - WFIFOL(fd, 242 + i * 4) = 0; - } + clif_ranklist_sub(WFIFOP(fd,2), RANKTYPE_TAEKWON); WFIFOSET(fd, packet_len(0x226)); } - /// /taekwon (CZ_TAEKWON_RANK). /// 0225 -void clif_parse_Taekwon(int fd,struct map_session_data *sd) -{ +void clif_parse_Taekwon(int fd,struct map_session_data *sd) { clif->taekwon(sd); } - /// Notification about taekwon points (ZC_TAEKWON_POINT). /// 0224 <points>.L <total points>.L -void clif_fame_taekwon(struct map_session_data *sd, int points) -{ +void clif_fame_taekwon(struct map_session_data *sd, int points) { int fd = sd->fd; WFIFOHEAD(fd,packet_len(0x224)); @@ -14289,7 +14216,6 @@ void clif_fame_taekwon(struct map_session_data *sd, int points) WFIFOSET(fd, packet_len(0x224)); } - /// /pk list (ZC_KILLER_RANK). /// 0238 { <name>.24B }*10 { <point>.L }*10 void clif_ranking_pk(struct map_session_data* sd) { @@ -14307,8 +14233,7 @@ void clif_ranking_pk(struct map_session_data* sd) { /// /pk (CZ_KILLER_RANK). /// 0237 -void clif_parse_RankingPk(int fd,struct map_session_data *sd) -{ +void clif_parse_RankingPk(int fd,struct map_session_data *sd) { clif->ranking_pk(sd); } @@ -18165,7 +18090,7 @@ void clif_defaults(void) { clif->fame_alchemist = clif_fame_alchemist; clif->fame_taekwon = clif_fame_taekwon; clif->ranklist = clif_ranklist; - clif->parse_ranklist = clif_parse_ranklist; + clif->pRanklist = clif_parse_ranklist; clif->update_rankingpoint = clif_update_rankingpoint; clif->hotkeys = clif_hotkeys_send; clif->insight = clif_insight; diff --git a/src/map/clif.h b/src/map/clif.h index b364765e5..4559e4209 100644 --- a/src/map/clif.h +++ b/src/map/clif.h @@ -339,13 +339,6 @@ typedef enum useskill_fail_cause { // clif_skill_fail USESKILL_FAIL_THERE_ARE_NPC_AROUND = 83, }useskill_fail_cause; -enum rank_type { - RANKTYPE_BLACKSMITH = 0, - RANKTYPE_ALCHEMIST = 1, - RANKTYPE_TAEKWON = 2, - RANKTYPE_PK = 3 //Not supported yet -}; - enum clif_messages { SKILL_CANT_USE_AREA = 0x536, ITEM_CANT_USE_AREA = 0x537, @@ -604,9 +597,9 @@ struct clif_interface { void (*fame_blacksmith) (struct map_session_data *sd, int points); void (*fame_alchemist) (struct map_session_data *sd, int points); void (*fame_taekwon) (struct map_session_data *sd, int points); - void (*ranklist) (struct map_session_data *sd, int16 rankingType); - void (*update_rankingpoint) (struct map_session_data *sd, int16 rankingtype, int point); - void (*parse_ranklist) (int fd,struct map_session_data *sd); + void (*ranklist) (struct map_session_data *sd, enum fame_list_type type); + void (*update_rankingpoint) (struct map_session_data *sd, enum fame_list_type type, int points); + void (*pRanklist) (int fd, struct map_session_data *sd); void (*hotkeys) (struct map_session_data *sd); int (*insight) (struct block_list *bl,va_list ap); int (*outsight) (struct block_list *bl,va_list ap); diff --git a/src/map/packets.h b/src/map/packets.h index 86ae3af30..8fcc6c863 100644 --- a/src/map/packets.h +++ b/src/map/packets.h @@ -2366,8 +2366,7 @@ packet(0x020d,-1); packet(0x0360,26,clif->pFriendsListAdd,2); packet(0x094A,5,clif->pHomMenu,2,4); packet(0x0873,36,clif->pStoragePassword,0); - packet(0x097c,4, clif->parse_ranklist); - packet(0x97D,288, clif->update_rankingpoint); //ZC_ACK_RANKING + packet(0x097C,4,clif->pRanklist); #endif |