V1.2.1 Interest Fix

It was found that between only running interest on players online or
running interst on all players with a credits account caused issues when
performing interest. (I.E. Server crash)

  This update fixes it.
This commit is contained in:
david 2021-11-03 19:25:33 -04:00
parent 2f004d404e
commit f32319e534
2 changed files with 20 additions and 9 deletions

View File

@ -5,7 +5,7 @@ credits = {}
credits.S = minetest.get_translator("credits")
credits.modpath = minetest.get_modpath("credits")
credits.store = minetest.get_mod_storage()
credits.VERSION = "1.2"
credits.VERSION = "1.2.1"
minetest.log("action", "[credits] Version: "..credits.VERSION)

View File

@ -7,21 +7,32 @@ credits.perform_interest = function()
if last_day < current_day then
local days_off = current_day - last_day
minetest.log("action", "Interest last performed "..tostring(days_off).." days ago")
local my_list = true
local ulist = credits.user_list()
if credits.settings.online_get_interest then -- Instead of every account let's get the current connected players
ulist = minetest.get_connected_players()
my_list = false
end
--minetest.log("action", "There are "..tostring(#ulist).." players to perform interst on")
for i in ipairs(ulist) do
-- Convert user datas into user names
if not my_list then
local new_list = {}
for _, user in ipairs(ulist) do
table.insert(new_list, user:get_player_name())
end
ulist = new_list
end
minetest.log("action", "There are "..tostring(#ulist).." players to perform interst on")
for _, user in ipairs(ulist) do
minetest.log("action", minetest.serialize(user))
-- Only perform 1 days worth of interest. (While this means more online more money it doesn't ruin servers which have been running a long time)
local cur = credits.get_balance_digital(ulist[i])
local cur = credits.get_balance_digital(user)
local earn = math.floor(cur * credits.settings.interest_rate) -- Ensure it's a whole number
--minetest.log("action", "Player '"..ulist[i].."' has "..tostring(cur).." credits")
credits.add_coin(ulist[i], tonumber(earn) ) -- Move the percent interest to settings.lua (interest percent)
minetest.log("action", "Player '"..ulist[i].."' earned "..tostring( tonumber(earn) ).." credits in interest")
local p = minetest.get_player_by_name(ulist[i])
if p ~= nil then
minetest.chat_send_player(ulist[i], "You earned "..tostring(tonumber(earn)).." credits in interest")
credits.add_coin(user, tonumber(earn) ) -- Move the percent interest to settings.lua (interest percent)
minetest.log("action", "Player '"..user.."' earned "..tostring( tonumber(earn) ).." credits in interest")
local p = minetest.get_player_by_name(user)
if p ~= nil then -- Check if they are online, if so let them know now.
minetest.chat_send_player(user, "You earned "..tostring(tonumber(earn)).." credits in interest")
end
end
credits.store:set_string("day_count", tostring(current_day))