summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorskotlex <skotlex@54d463be-8e91-2dee-dedb-b68131a5f0ec>2006-05-31 15:07:37 +0000
committerskotlex <skotlex@54d463be-8e91-2dee-dedb-b68131a5f0ec>2006-05-31 15:07:37 +0000
commit47981612dad9c7d94466e357de003f0ba597efcb (patch)
tree149cca1ddc2fe13a15999585cab3631588b93880
parent8f6123730efe4fb57d9895e032967fefb0a00d40 (diff)
downloadhercules-47981612dad9c7d94466e357de003f0ba597efcb.tar.gz
hercules-47981612dad9c7d94466e357de003f0ba597efcb.tar.bz2
hercules-47981612dad9c7d94466e357de003f0ba597efcb.tar.xz
hercules-47981612dad9c7d94466e357de003f0ba597efcb.zip
- Some cleaning of the fame-update code, fixing a logic bug which made the ranking list fail to display the correct ranker names.
git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@6891 54d463be-8e91-2dee-dedb-b68131a5f0ec
-rw-r--r--Changelog-Trunk.txt2
-rw-r--r--src/char/char.c55
-rw-r--r--src/char_sql/char.c52
-rw-r--r--src/map/chrif.c2
-rw-r--r--src/map/pc.c2
5 files changed, 69 insertions, 44 deletions
diff --git a/Changelog-Trunk.txt b/Changelog-Trunk.txt
index 9325c9ee3..0aa6a5480 100644
--- a/Changelog-Trunk.txt
+++ b/Changelog-Trunk.txt
@@ -4,6 +4,8 @@ AS OF SVN REV. 5091, WE ARE NOW USING TRUNK. ALL UNTESTED BUGFIXES/FEATURES GO
IF YOU HAVE A WORKING AND TESTED BUGFIX PUT IT INTO STABLE AS WELL AS TRUNK.
2006/05/31
+ * Some cleaning of the fame-update code, fixed a logic bug which made the
+ ranking list fail to display the correct ranker names. [Skotlex]
* Removed typedef bool from socket.h and included cbasetypes.c instead.
[Skotlex]
* Cleaned up and corrected the calculation of hit/flee/cri/lucky dodge in
diff --git a/src/char/char.c b/src/char/char.c
index 0617bc3b9..cd2ba683b 100644
--- a/src/char/char.c
+++ b/src/char/char.c
@@ -2849,7 +2849,7 @@ int parse_frommap(int fd) {
// Update and send fame ranking list [DracoRPG]
case 0x2b10:
- if (RFIFOREST(fd) < 10)
+ if (RFIFOREST(fd) < 12)
return 0;
{
int i, j;
@@ -2859,7 +2859,8 @@ int parse_frommap(int fd) {
char pos = RFIFOB(fd, 11);
int size;
struct fame_list *list;
-
+ RFIFOSKIP(fd,12);
+
switch(type) {
case 1:
size = fame_list_size_smith;
@@ -2874,31 +2875,41 @@ int parse_frommap(int fd) {
list = taekwon_fame_list;
break;
default:
- return 0;
- }
-
- if(pos){ // If the player's already in the list, remove the entry and shift the following ones 1 step up
- memmove(list + pos - 1, list + pos, (size - pos) * sizeof(struct fame_list));
- list[size].fame = 0; // At worst, the guy'll end up last (shouldn't happen if fame only goes up)
+ size = 0;
+ break;
}
-
- for(i = 0; i < size; i++) // Find the position where the player has to be inserted
- if(fame >= list[i].fame) { // When found someone with less or as much fame, insert just above
- memmove(list + i + 1, list + i, (size - i - 1) * sizeof(struct fame_list));
- list[i].id = id;
- list[i].fame = fame;
- for(j = 0; j < char_num; j++) // Look for the player's name
- if(char_dat[j].status.char_id == id) {
- strncpy(list[j].name, char_dat[j].status.name, NAME_LENGTH);
- break;
- }
+ if(!size)
+ break;
+ if(pos)
+ {
+ pos--; //Convert from pos to index.
+ if(
+ (pos == 0 || fame < list[pos-1].fame) &&
+ (pos == size-1 || fame > list[pos+1].fame)
+ ) { //No change in order.
+ list[(int)pos].fame = fame;
+ char_send_fame_list(fd);
break;
}
-
+ // If the player's already in the list, remove the entry and shift the following ones 1 step up
+ memmove(list+pos, list+pos+1, (size-pos-1) * sizeof(struct fame_list));
+ list[size].fame = 0; // At worst, the guy'll end up last (shouldn't happen if fame only goes up)
+ }
+ // Find the position where the player has to be inserted
+ for(i = 0; i < size && fame < list[i].fame; i++);
+ // When found someone with less or as much fame, insert just above
+ if(i >= size) break;//Out of ranking.
+ memmove(list+i+1, list+i, (size-i-1) * sizeof(struct fame_list));
+ list[i].id = id;
+ list[i].fame = fame;
+ // Look for the player's name
+ for(j = 0; j < char_num && char_dat[j].status.char_id != id; j++);
+ if(j < char_num)
+ strncpy(list[i].name, char_dat[j].status.name, NAME_LENGTH);
+ else //Not found??
+ strncpy(list[i].name, "Unknown", NAME_LENGTH);
char_send_fame_list(fd);
}
-
- RFIFOSKIP(fd,12);
break;
// Recieve rates [Wizputer]
diff --git a/src/char_sql/char.c b/src/char_sql/char.c
index 614140d85..aecdb80e5 100644
--- a/src/char_sql/char.c
+++ b/src/char_sql/char.c
@@ -2746,7 +2746,7 @@ int parse_frommap(int fd) {
// Update and send fame ranking list [DracoRPG]
case 0x2b10:
- if (RFIFOREST(fd) < 10)
+ if (RFIFOREST(fd) < 12)
return 0;
{
int i, j;
@@ -2756,7 +2756,8 @@ int parse_frommap(int fd) {
char pos = RFIFOB(fd, 11);
int size;
struct fame_list *list;
-
+ RFIFOSKIP(fd,12);
+
switch(type) {
case 1:
size = fame_list_size_smith;
@@ -2771,31 +2772,42 @@ int parse_frommap(int fd) {
list = taekwon_fame_list;
break;
default:
- return 0;
- }
-
- if(pos){ // If the player's already in the list, remove the entry and shift the following ones 1 step up
- memmove(list + pos - 1, list + pos, (size - pos) * sizeof(struct fame_list));
- list[size].fame = 0; // At worst, the guy'll end up last (shouldn't happen if fame only goes up)
+ size = 0;
+ break;
}
-
- for(i = 0; i < size; i++) // Find the position where the player has to be inserted
- if(fame >= list[i].fame) { // When found someone with less or as much fame, insert just above
- memmove(list + i + 1, list + i, (size - i - 1) * sizeof(struct fame_list));
- list[i].id = id;
- list[i].fame = fame;
- for(j = 0; j < char_num; j++) // Look for the player's name
- if(char_dat[j].char_id == id) {
- strncpy(list[j].name, char_dat[j].name, NAME_LENGTH);
- break;
- }
+ if(!size) break; //No list.
+ if(pos)
+ {
+ pos--; //Convert from pos to index.
+ if(
+ (pos == 0 || fame < list[pos-1].fame) &&
+ (pos == size-1 || fame > list[pos+1].fame)
+ ) { //No change in order.
+ list[(int)pos].fame = fame;
+ char_send_fame_list(fd);
break;
}
+ // If the player's already in the list, remove the entry and shift the following ones 1 step up
+ memmove(list+pos, list+pos+1, (size-pos-1) * sizeof(struct fame_list));
+ list[size].fame = 0; // At worst, the guy'll end up last (shouldn't happen if fame only goes up)
+ }
+ // Find the position where the player has to be inserted
+ for(i = 0; i < size && fame < list[i].fame; i++);
+ if(i>=size) break; //Out of ranking.
+ // When found someone with less or as much fame, insert just above
+ memmove(list+i+1, list+i, (size-i-1) * sizeof(struct fame_list));
+ list[i].id = id;
+ list[i].fame = fame;
+ // Look for the player's name
+ for(j = 0; j < char_num && char_dat[j].char_id != id; j++);
+ if(j < char_num)
+ strncpy(list[i].name, char_dat[j].name, NAME_LENGTH);
+ else //Not found??
+ strncpy(list[i].name, "Unknown", NAME_LENGTH);
char_send_fame_list(fd);
}
- RFIFOSKIP(fd,12);
break;
// Recieve rates [Wizputer]
diff --git a/src/map/chrif.c b/src/map/chrif.c
index a5f48dbb8..d3e04a7a1 100644
--- a/src/map/chrif.c
+++ b/src/map/chrif.c
@@ -1127,7 +1127,7 @@ int chrif_updatefamelist(struct map_session_data *sd)
return 0;
}
- WFIFOHEAD(char_fd, 12);
+ WFIFOHEAD(char_fd, 12);
WFIFOW(char_fd, 0) = 0x2b10;
WFIFOL(char_fd, 2) = sd->char_id;
WFIFOL(char_fd, 6) = sd->status.fame;
diff --git a/src/map/pc.c b/src/map/pc.c
index 9049bc52b..fa11d56bd 100644
--- a/src/map/pc.c
+++ b/src/map/pc.c
@@ -226,7 +226,7 @@ int pc_delspiritball(struct map_session_data *sd,int count,int type) {
// Increases a player's fame points and displays a notice to him
void pc_addfame(struct map_session_data *sd,int count) {
- nullpo_retv(sd);
+ nullpo_retv(sd);
sd->status.fame += count;
if(sd->status.fame > MAX_FAME)
sd->status.fame = MAX_FAME;