From: red-001 Date: Wed, 14 Jun 2017 17:57:05 +0000 (+0100) Subject: Books: Limit the size of books X-Git-Tag: 0.4.17.1~40 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=26606b0520c4d7bbba950561feba74c0f91da92d;p=oweals%2Fminetest_game.git Books: Limit the size of books Really large books just waste hard drive space and the engine is not designed to handle that much data in item metadata, this can cause strange things to happen. --- diff --git a/mods/default/craftitems.lua b/mods/default/craftitems.lua index 1500a346..eda52f51 100644 --- a/mods/default/craftitems.lua +++ b/mods/default/craftitems.lua @@ -75,6 +75,7 @@ local function book_on_use(itemstack, user) return itemstack end +local max_text_size = 10000 minetest.register_on_player_receive_fields(function(player, formname, fields) if formname ~= "default:book" then return end local inv = player:get_inventory() @@ -103,8 +104,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) data.title = fields.title data.owner = player:get_player_name() data.description = "\""..fields.title.."\" by "..data.owner - data.text = fields.text - data.text_len = #data.text + data.text = fields.text:sub(1, max_text_size) data.page = 1 data.page_max = math.ceil((#data.text:gsub("[^\n]", "") + 1) / lpp)