From 1487c7f631721143519cd1664427c0e3d1bcf262 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Thu, 29 Aug 2019 05:23:23 +0200 Subject: [PATCH] Limit book title and text length --- mods/book/init.lua | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/mods/book/init.lua b/mods/book/init.lua index 637298e..c3390d2 100644 --- a/mods/book/init.lua +++ b/mods/book/init.lua @@ -7,6 +7,9 @@ local S = minetest.get_translator("book") local F = minetest.formspec_escape +local BOOK_MAX_TITLE_LENGTH = 64 +local BOOK_MAX_TEXT_LENGTH = 4500 + minetest.register_craftitem( ":default:book", { @@ -43,6 +46,14 @@ minetest.register_on_player_receive_fields( local meta = itemstack:get_meta() + -- Limit title and text length + if string.len(fields.title) > BOOK_MAX_TITLE_LENGTH then + fields.title = string.sub(fields.title, 1, BOOK_MAX_TITLE_LENGTH) + end + if string.len(fields.text) > BOOK_MAX_TEXT_LENGTH then + fields.text= string.sub(fields.text, 1, BOOK_MAX_TEXT_LENGTH) + end + meta:set_string("description", S("Book: “@1”", minetest.colorize("#ffff00", fields.title))) -- Set the item description meta:set_string("book:title", fields.title)