From d3c7fa71c03258dd2c4c86e54da6ad8c3135f990 Mon Sep 17 00:00:00 2001 From: blaboing <56389853+blaboing@users.noreply.github.com> Date: Wed, 10 May 2023 21:41:35 +0200 Subject: [PATCH] Filename seperator setting to fix #54 (#83) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds a filename split seperator setting that lets you choose between old style `_` and `.` because dot is the only char that isnĀ“t allowed in playername but in texturenames. Default value is `_` to keep it compatible with older versions, while `.` offers a solution to fix #54. --- init.lua | 6 ++++++ settingtypes.txt | 3 +++ skinlist.lua | 2 +- skins_updater.lua | 4 ++-- textures/readme.txt | 12 ++++++++++++ updater/update_skins.py | 8 ++++++-- 6 files changed, 30 insertions(+), 5 deletions(-) create mode 100644 settingtypes.txt diff --git a/init.lua b/init.lua index 34e4540..976c014 100644 --- a/init.lua +++ b/init.lua @@ -8,6 +8,12 @@ skins = {} skins.modpath = minetest.get_modpath(minetest.get_current_modname()) skins.default = "character" +-- see skindsdb/textures/readme.txt to avoid playername with underscore problem +skins.fsep = minetest.settings:get("skinsdb_fsep") or "_" +if skins.fsep == "_" then + minetest.log("warning", "skinsdb filename seperator is set to " .. skins.fsep .. ", see skindsdb/textures/readme.txt to avoid problems with playernames containing underscore") +end + dofile(skins.modpath.."/skin_meta_api.lua") dofile(skins.modpath.."/api.lua") dofile(skins.modpath.."/skinlist.lua") diff --git a/settingtypes.txt b/settingtypes.txt new file mode 100644 index 0000000..e47be76 --- /dev/null +++ b/settingtypes.txt @@ -0,0 +1,3 @@ +# texture filename seperator, default "_" +# see skindsdb/textures/readme.txt to avoid playername with underscore problem +skinsdb_fsep (texture filename seperator) enum _ _,. \ No newline at end of file diff --git a/skinlist.lua b/skinlist.lua index bde0ae5..dc8a155 100644 --- a/skinlist.lua +++ b/skinlist.lua @@ -2,7 +2,7 @@ local skins_dir_list = minetest.get_dir_list(skins.modpath.."/textures") for _, fn in pairs(skins_dir_list) do local name, sort_id, is_preview, playername - local nameparts = string.gsub(fn, "[.]", "_"):split("_") + local nameparts = string.gsub(fn, "[.]", skins.fsep):split(skins.fsep) -- check allowed prefix and file extension if (nameparts[1] == 'player' or nameparts[1] == 'character') and diff --git a/skins_updater.lua b/skins_updater.lua index 1e461ed..1b0f565 100644 --- a/skins_updater.lua +++ b/skins_updater.lua @@ -88,7 +88,7 @@ local function safe_single_skin(skin) skin.license } - local name = "character_" .. skin.id + local name = "character" .. skins.fsep .. skin.id -- core.safe_file_write does not work here unsafe_file_write( @@ -101,7 +101,7 @@ local function safe_single_skin(skin) core.decode_base64(skin.img) ) fetch_url(preview_url:format(skin.id), function(preview) - unsafe_file_write(skins_path .. name .. "_preview.png", preview) + unsafe_file_write(skins_path .. name .. skins.fsep .. "preview.png", preview) end) core.log("action", ("%s: Completed skin %s"):format(_ID_, name)) end diff --git a/textures/readme.txt b/textures/readme.txt index 9d0b450..e53e112 100644 --- a/textures/readme.txt +++ b/textures/readme.txt @@ -1,5 +1,17 @@ In this folder the skin files could be placed according the following file naming convention. +skinsdb uses an underscore as default seperator for filename splitting which can cause problems with playernames containing "_", +see https://github.com/minetest-mods/skinsdb/issues/54. +The config setting skinsdb_fsep (texture filename seperator) was added as a workaround which also offers "."(dot) as seperator, +dot is the only character which is allowed in textures but not in playernames. +To keep compatibility with older versions underscore is the default value. + +fresh install: +you should change the seperator to "." to avoid that problem. +existing install: +- change the filenames according to the naming convention with dot as seperator instead of underscore +- change the texture filename seperator in settings or add "skinsdb_fsep = ." to your minetest.conf before starting your server + Public skin available for all users: character_[number-or-name].png diff --git a/updater/update_skins.py b/updater/update_skins.py index 8b760b7..b5ec889 100644 --- a/updater/update_skins.py +++ b/updater/update_skins.py @@ -1,5 +1,9 @@ import sys, requests, base64 +# filename seperator to use, either default "-" or ".". see skinsdb/textures/readme.txt +#fsep = "_" +fsep = "." + download_preview = ( len (sys.argv) > 1 and sys.argv[1] == "with_preview" ) @@ -24,7 +28,7 @@ for json in data["skins"]: # Texture file raw_data = base64.b64decode(json["img"]) - file = open("../textures/character_" + id + ".png", "wb") + file = open("../textures/character" + fsep + id + ".png", "wb") file.write(bytearray(raw_data)) file.close() @@ -44,7 +48,7 @@ for json in data["skins"]: if r2.status_code == 200: # Preview file preview = r2.content - file = open("../textures/character_" + id + "_preview.png", "wb") + file = open("../textures/character_" + id + fsep + "preview.png", "wb") file.write(bytearray(preview)) file.close() else: