3 Commits

Author SHA1 Message Date
df62f2042d skinlist: avoid 'Too many open files' errors
Due to application-specific file descriptor limits,
the garbage collector cannot close the descriptors in time,
resulting in unexpected file open errors.
2024-07-22 18:41:15 +02:00
b7cd514cea API: make skins.register_skin public (#106) 2024-07-07 18:51:48 +02:00
11bb5bad0e Add migration code to player skins using '.' delimiters (#105)
Previously, the players would have their selected skin reset after renaming
the skin textures to the dot separator. This commit implements skin name
migration to ease the transition for server owners.

See 'skins.__fuzzy_match_skin_name' for a detailed explanation.
2024-06-15 15:16:52 +02:00
2 changed files with 27 additions and 0 deletions

25
API.md
View File

@ -27,6 +27,31 @@ Get all allowed skins for player. All public and all player's private skins. If
Get all skins with metadata key is set to value. Example: Get all skins with metadata key is set to value. Example:
skins.get_skinlist_with_meta("playername", playername) - Get all private skins (w.o. public) for playername skins.get_skinlist_with_meta("playername", playername) - Get all private skins (w.o. public) for playername
## skins.register_skin(path, filename)
Registers a new skin based on the texture file path specified by `path` and `filename`.
* `path` (string): points to the parent directory of the texture `filename`.
Generally, this should be in the format `mymod.modpath .. "/textures"`.
* `filename` (string): full file name, without any path specifications.
The file name must adhere to [one of the accepted naming formats](textures/readme.txt).
Note: this function takes the following files into consideration:
1. `<path>/<filename>` (required)
* Main skin texture
2. `<path>/<filenamestem><separator>preview.png` (optional)
* Pre-generated preview image
3. `<path>/../meta/<filenamestem>.txt` (optional)
* Metadata regarding the skin
Return values:
* On failure: `false, reason`
* `reason` (string): human readable reason string (similar to `io.open` errors)
* On success: `true, key`
* `key`: unique skins key for use with e.g. `skins.get(key)` for subsequent
fine-tuning of the skin registration.
## skins.new(key, object) ## skins.new(key, object)
Create and register a new skin object for given key Create and register a new skin object for given key

View File

@ -92,6 +92,7 @@ function skins.register_skin(path, filename)
skin_obj:set_meta("name", data[1]) skin_obj:set_meta("name", data[1])
skin_obj:set_meta("author", data[2]) skin_obj:set_meta("author", data[2])
skin_obj:set_meta("license", data[3]) skin_obj:set_meta("license", data[3])
file:close() -- do not rely on delayed GC
end end
end end
@ -102,6 +103,7 @@ function skins.register_skin(path, filename)
if fh then if fh then
dbgprint("Found preview", preview_name) dbgprint("Found preview", preview_name)
skin_obj:set_preview(preview_name) skin_obj:set_preview(preview_name)
fh:close() -- do not rely on delayed GC
end end
end end