Issue information

Issue ID
#3717
Status
Fixed
Severity
None
Started
Hercules Elf Bot
Nov 9, 2009 17:56
Last Post
Hercules Elf Bot
Nov 9, 2009 17:56
Confirmation
N/A

Hercules Elf Bot - Nov 9, 2009 17:56

Originally posted by [b][Leon][/b]
http://www.eathena.ws/board/index.php?autocom=bugtracker&showbug=3717

I was taking a look at the code and something got my attention.

pc_autosave() iterates over all online players, however it saves only one of them. Why does it keep iterating, after it has saved the desired character? Why not break out from the loop?

Let me explain it better. When the for loop starts, save_flag is either 0 (save character after the last one saved) or 1 (save first character found).

If it's 1, both if's will fail and it'll go straight to saving the first character, setting save_flag to 2. All of the remaining iterations will be just continue's (since first if will always fail, as the character whose id is last_save_id was saved already, and second if will always be true, as save_flag will not change inside the for). So it'll iterate over all online characters doing nothing.

If save_flag is 0, it will keep iterating until it finds a character whose id is last_save_id. If it doesn't find, the loop will end and on the next call it'll save the first character and start over again. If it finds the character, it sets save_flag to 1 and continue's. On next iteration both if's will be false and it'll save the character (that comes right after the last one saved). Then it'll set save_flag to 2 and keep iterating over all characters left, doing nothing.

I don't know if there's a reason to iterate over all online characters after saving the desired character, but it seemed pointless at first sight.

Putting a break after chrif_save should save some CPU time. A rewrite of said function would be better, as it's messy at the moment.