Illarion-eV / Illarion-Server

Server for the online RPG Illarion
http://illarion.org
GNU Affero General Public License v3.0
27 stars 19 forks source link

world:getTime returns the wrong value #93

Open brightrim opened 1 year ago

brightrim commented 1 year ago

world:getTime() has suddenly started returning negative values

Discovered via this recent report.

I looked into it and found via a log(world:getTime("day") where it returned -4 (which matches the current login message of -4th of Mas) that it is the server function itself that is returning faulty values all of a sudden.

brightrim commented 1 year ago

I tested with "unix" which seems to be working fine, returning 1666721659.

"month" returns 16, as in Mas, even though it should return 2, as in Tanos.

Not sure if this breaks any scripts. Could potentially be urgent, as searches for world:getTime("day") and world:getTime("month") provide a lot of results, though most scripts appear to be using the still working world:getTime("unix") for timestamp purposes.

brightrim commented 1 year ago

So far the following scripts have shown up in the script error log as having been broken due to this: oldSlimeFeeding - seems to affect the text meant to be shown on a sign herbgathering - seems to affect the regrowth of plants as nextregrow itemData is not set as it can not figure out what season it is

estralis commented 1 year ago

Hrm, it isn't even 2038 yet...

A quick fix could be to move the time logics to a script function and see if the error can be reproduced. But of course, a proper fix of the server function is preferred.

Any hint on the root cause?

estralis commented 1 year ago

Root cause is likely in this line:

https://github.com/Illarion-eV/Illarion-Server/blob/e6f943768f7b64e0d9733a5fa661a5bf381988f8/src/WorldIMPLTools.cpp#L610

Using int here results in a variable overflow later on. Illarion time passes 3x as fast, so as Illarion time started in RL year 2000, we accumulated more than seconds of game life than can be stored in an int variable.

A solution would be to change the variable type to long or long long - given this does not break stuff further down the line

estralis commented 1 year ago

This needs to be reverted once the time function works properly again:

https://github.com/Illarion-eV/Illarion-Java/commit/1c13ef4b5c8e2531e931bf4cc05b20e1e37e1931