commit 5c61b1aa936db006beaf6da66b12ad5eee49dfd5 Author: rainer Date: Fri Aug 22 02:35:24 2025 +0200 first commit diff --git a/.github/workflows/luacheck.yml b/.github/workflows/luacheck.yml new file mode 100644 index 0000000..ec553a1 --- /dev/null +++ b/.github/workflows/luacheck.yml @@ -0,0 +1,17 @@ +name: luacheck + +on: [push, pull_request] + +jobs: + build: + + runs-on: ubuntu-20.04 + + steps: + - uses: actions/checkout@v1 + - name: apt + run: sudo apt-get install -y luarocks + - name: luacheck install + run: luarocks install --local luacheck + - name: luacheck run + run: $HOME/.luarocks/bin/luacheck ./ diff --git a/.luacheckrc b/.luacheckrc new file mode 100644 index 0000000..e413e08 --- /dev/null +++ b/.luacheckrc @@ -0,0 +1,22 @@ +unused_args = false +allow_defined_top = true + +globals = { + "minetest", +} + +read_globals = { + string = {fields = {"split"}}, + table = {fields = {"copy", "getn"}}, + + -- Builtin + "vector", "ItemStack", + "dump", "DIR_DELIM", "VoxelArea", "Settings", + "PcgRandom", + + -- MTG + "default", "sfinv", "creative", + + -- Deps + "md2f" +} \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..619a389 --- /dev/null +++ b/README.md @@ -0,0 +1,40 @@ +# minenews + +Localized and simple server news for Minetest servers. Original version by Shara +RedCat, forked and improved by Ronoaldo. + +[![ContentDB](https://content.minetest.net/packages/ronoaldo/minenews/shields/downloads/)](https://content.minetest.net/packages/ronoaldo/minenews/) + +![Localized server news for Minetest](img/open-graph.png) + +This mod displays a formspec when the player joins. To set the news text to +display, make a file named news_*lang_code*.md in your world directory for each +locale you plan to support. The mod will fallback to a news.md file if no +localized version is found. + +The contents of this file will be displayed to the player, interpreted as +Markdown. When changing the contents of the file, there is no need to restart +the server for it to update in game so you can also test quickly the display. + +Players can also type `/news` to display the formspec at any time. + +Players with the `news_bypass` privilege will not see the formspec when they +sign in, but can still use the `/news` command. + + +## Screenshots + +Sample news dialog in English: + +![News in English](screenshot.png) + +And a translated news file shown for the user if the language is set to `pt_BR`: + +![News in Portuguese](screenshot_pt.png) + +# License + +Code for this mod is released under MIT (https://opensource.org/licenses/MIT). + +This mod uses textures from Bootstrap Icons, also licensed under MIT +(https://opensource.org/licenses/MIT). \ No newline at end of file diff --git a/img/chat-text-fill.svg b/img/chat-text-fill.svg new file mode 100644 index 0000000..fff3db3 --- /dev/null +++ b/img/chat-text-fill.svg @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/img/open-graph.png b/img/open-graph.png new file mode 100644 index 0000000..628986b Binary files /dev/null and b/img/open-graph.png differ diff --git a/img/open-graph.xcf b/img/open-graph.xcf new file mode 100644 index 0000000..ff261db Binary files /dev/null and b/img/open-graph.xcf differ diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..abe967f --- /dev/null +++ b/init.lua @@ -0,0 +1,133 @@ +--[[ +Minenews Mod by The-fast-the-curious +https://github.com/The-fast-the-curious/minenews +License: MIT + +This mod displays server news to players on login, configurable via a markdown file. +--]] + +-- Register bypass priv +minetest.register_privilege("news_bypass", { + description = "Skip the news display on login.", + give_to_singleplayer = false +}) + +-- Create formspec from text file +-- Returns the formspec string on success, or nil if news file is not found or empty +local function get_formspec(name) + -- Lookup player language preference + local player_info = minetest.get_player_information(name) + local lang = player_info.lang_code + if lang == "" then + lang = "en" + end + -- Lookup news file to display, trying by language first, with a default news.md + -- fallback. + local news_filename = minetest.get_worldpath().."/news_"..lang..".md" + local news_file = io.open(news_filename, "r") + if not news_file then + news_filename = minetest.get_worldpath().."/news.md" + news_file = io.open(news_filename, "r") + end + + local news = "" + if news_file then + news = news_file:read("*a") + news_file:close() + end + + -- If no news content is found (file doesn't exist or is empty), return nil + -- to prevent showing an empty formspec. + if news == "" then + if news_file then -- Only log if a file existed but was empty + minetest.log("verbose", "News file found for player "..name.." but it is empty. No formspec will be shown.") + end + return nil + end + + minetest.log("verbose", "Displaying news to player "..name.." in "..lang.." from file "..news_filename) + + -- Settings + local fg_color = minetest.settings:get("minenews.fg_color") or "#AFAFAF" + local bg_color = minetest.settings:get("minenews.bg_color") or "#34343400" + local header_color = minetest.settings:get("minenews.header_color") or "#CFCFCF" + local mono_color = minetest.settings:get("minenews.mono_color") or "#6ED2CF" + local discord_link = minetest.settings:get("minenews.discord_invite") or "" + + -- Display the formspec for the server news + local news_fs = "formspec_version[5]".. + "size[24,16]".. + "noprepend[]".. + "bgcolor["..bg_color.."]".. + "button_exit[20.8,14.8;3,1;close;OK]" + + if discord_link ~= "" then + news_fs = news_fs.. + "image[0.2,14.8;1,1;minenews_icon_chat_white.png]".. + "field[1.3,14.8;19.2,1;discord_invite;;"..discord_link.."]" + end + + -- Render the file as markdown + local settings = { + background_color = bg_color, + font_color = fg_color, + heading_1_color = header_color, + heading_2_color = header_color, + heading_3_color = header_color, + heading_4_color = header_color, + heading_5_color = header_color, + heading_6_color = header_color, + heading_1_size = "26", + heading_2_size = "22", + heading_3_size = "18", + heading_4_size = "18", + heading_5_size = "18", + heading_6_size = "18", + code_block_mono_color = mono_color, + code_block_font_size = 14, + mono_color = mono_color, + block_quote_color = mono_color, + } + news_fs = news_fs..md2f.md2f(0.2, 0.5, 23.6, 13.8, news, "news", settings) + minetest.log("verbose", "Formspec => "..news_fs) + return news_fs +end + +-- Show news formspec on player join, unless player has bypass priv +local function on_joinplayer(player) + local name = player:get_player_name() + if player:get_hp() <= 0 or minetest.get_player_privs(name).news_bypass then + return + end + + -- Get the formspec first + local news_fs = get_formspec(name) + + -- Only show the formspec if it's not nil + if news_fs then + minetest.show_formspec(name, "news", news_fs) + end +end +-- Register callback +minetest.register_on_joinplayer(on_joinplayer) + +-- Command to display server news at any time +minetest.register_chatcommand("news", { + description = "Shows server news to the player", + func = function (name) + -- Get the formspec first + local news_fs = get_formspec(name) + + -- Only show the formspec if it's not nil + if news_fs then + minetest.show_formspec(name, "news", news_fs) + else + -- Optional: Give the player feedback that there is no news + minetest.chat_send_player(name, "There is no news to display at the moment.") + end + end +}) + +-- Exported API +minenews = {} +minenews.on_joinplayer = on_joinplayer diff --git a/license.txt b/license.txt new file mode 100644 index 0000000..4bee986 --- /dev/null +++ b/license.txt @@ -0,0 +1,28 @@ + +License: MIT +Mod by: Shara RedCat + +--- + +The MIT License (MIT) + +Copyright (c) 2018 Shara RedCat +Copyright (c) 2021 Ronoaldo JLP + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. \ No newline at end of file diff --git a/mod.conf b/mod.conf new file mode 100644 index 0000000..79eec36 --- /dev/null +++ b/mod.conf @@ -0,0 +1,7 @@ +name = minenews +title = Localized Server News +description = Display localized server news when a player joins +depends = markdown2formspec + +release = 12102 +author = ronoaldo diff --git a/screenshot.png b/screenshot.png new file mode 100644 index 0000000..9222dda Binary files /dev/null and b/screenshot.png differ diff --git a/screenshot_pt.png b/screenshot_pt.png new file mode 100644 index 0000000..84331f6 Binary files /dev/null and b/screenshot_pt.png differ diff --git a/scripts/test.sh b/scripts/test.sh new file mode 100644 index 0000000..717d881 --- /dev/null +++ b/scripts/test.sh @@ -0,0 +1,17 @@ +#!/bin/bash +set -e +set -o pipefail + +export WORLD=$HOME/.minetest/worlds/minenews-dev +export LOGS=$(mktemp "$WORLD/debug.txt") + +rm -rvf $WORLD +mkdir -p $WORLD/worldmods +cp -r scripts/world/* $WORLD/ +cp -r ./ $WORLD/worldmods/minenews + +if [ x"$1" = x"pt" ]; then + echo -e '\nlanguage = pt_BR' >> $WORLD/minetest.conf +fi + +exec minetest --verbose --config $WORLD/minetest.conf --world $WORLD --go \ No newline at end of file diff --git a/scripts/world/minetest.conf b/scripts/world/minetest.conf new file mode 100644 index 0000000..72421c6 --- /dev/null +++ b/scripts/world/minetest.conf @@ -0,0 +1,15 @@ +autosave_screensize = false +clickable_chat_weblinks = true +creative_mode = false +enable_console = false +enable_damage = true +fixed_map_seed = minenews +fog_start = 0.4 +fov = 96 +mg_name = v7 +mgv7_spflags = caverns,floatlands,ridges,mountains +screen_h = 1080 +screen_w = 1920 +server_announce = false +viewing_range = 512 +minenews.discord_invite=https://discord.gg/my-custom-link diff --git a/scripts/world/news.md b/scripts/world/news.md new file mode 100644 index 0000000..109e6f5 --- /dev/null +++ b/scripts/world/news.md @@ -0,0 +1,89 @@ +![0,0](item:///default:furnace) + +# **Welcome to Mercurio Server!** +------------------------------- + +The server is designed to be friendly and enjoyable! Please: + +``` +* Do not destroy other player's properties +* Do not appropriate other player's items. +* No dating allowed. +* No forms of discrimination are tolerated. +``` + +------------------------------- + +![1,1](halo) + + +# **Server Update March 13, 2022** + +![0,0,r](item:///default:pick_diamond) + +Server was updated this week to add two new mods! New vehicles to drive around +and 11 new elements, ores and equipments. Special thanks to player **bramos**, +**farribeiro** and **joseanastacio** who suggeted the mods and helped with testing! + +## Hilights + +### New vhicles +Added APercy's automobiles modpack, adding three new cars for us +to drive: coupe, buggy and roadster. + +### Extra ores! +Added Xtraores (by David), adding 11 new minerals, swords, tools +and armor. More rare minerals are only obtainable bellow the layer -11000, so get +your pickaxle ready! + +![1,1](halo.png) + + +# **Server Update March 07, 2022** + +![0,0,r](item:///default:pick_diamond) + +Sever was updated this week with small fixes for the February update, and with +the notable addition of three new mods: Tubelib, Techpack and Drawers. + +## Hilights + +**New modpack Techpack**: This mod adds several items to the game, allowing for +unmatched automation! Level up your farming! + +**New mod Drawers**: This mod adds a great ammount of new storage items. I mean, +*several* new storage items. Upgrade your wharehouses! + +![1,1](halo.png) + + + +# **Server Update February 12, 2022** + +![0,0,r](item:///default:pick_diamond) + +Server was updated with several mods to their new versions. + +## Highlights + +**New version of APercy planes**: Mods now use *airutils* in common, including +for repairs and base flight logic. + +**New version of Draconis mod**: The Draconis mod has been updated to version 1.2. +One of the main news is that in this new version the furnace can actually be +heated and used to produce the improved ore, tool and armor! We also have new +features in the behavior of wild dragons and a new interface for managing the +tamed dragon. + +![1,1](halo.png) + + +# **Tips and Tricks** + +Follow these tips and suggestions to enhance your gameplay: + +Use `protectors`, `protector blocks` and the `area` delimiters to avoid unwanted +breakage of your builds! Remember some kids play here as well so better be safe +than sorry! + +You can use the `search` dommand to find useful information about the world! diff --git a/scripts/world/news_pt_BR.md b/scripts/world/news_pt_BR.md new file mode 100644 index 0000000..6396f8f --- /dev/null +++ b/scripts/world/news_pt_BR.md @@ -0,0 +1,89 @@ +![0,0](item:///default:furnace) + +# **Bem-vindo ao Servidor Mercurio!** +------------------------------- + +O servidor foi projetado para ser amigável e agradável! Por favor: + +``` +* Não destrua as propriedades de outros jogadores +* Não se aproprie de itens de outros jogadores. +* Nenhum namoro permitido. +* Nenhuma forma de discriminação é tolerada. +``` + +------------------------------- + +![1,1](halo) + + +# **Atualização do servidor em 13 de março de 2022** + +![0,0,r](item:///default:pick_diamond) + +O servidor foi atualizado esta semana para adicionar dois novos mods! Novos veículos para circular +e 11 novos elementos, minérios e equipamentos. Agradecimentos especiais ao jogador **bramos**, +**farribeiro** e **joseanastacio** que sugeriram os mods e ajudaram nos testes! + +## Destaques + +### Novos veículos +Adicionado o modpack de automóveis do APercy, adicionando três novos carros para nós +para dirigir: cupê, buggy e roadster. + +### Minérios extras! +Adicionado Xtraores (por David), adicionando 11 novos minerais, espadas, ferramentas +e armadura. Minerais mais raros só podem ser obtidos abaixo da camada -11000, então pegue +sua picareta pronta! + +![1,1](halo) + + +# **Atualização do servidor em 07 de março de 2022** + +![0,0,r](item:///default:pick_diamond) + +O servidor foi atualizado esta semana com pequenas correções para a atualização de fevereiro e com +a notável adição de três novos mods: Tubelib, Techpack e Drawers. + +## Destaques + +**Novo modpack Techpack**: Este mod adiciona vários itens ao jogo, permitindo +automação incomparável! Aumente o nível da sua agricultura! + +**Novas gavetas de mod**: Este mod adiciona uma grande quantidade de novos itens de armazenamento. Quero dizer, +*vários* novos itens de armazenamento. Atualize seus armazéns! + +![1,1](halo.png) + + + +# **Atualização do servidor em 12 de fevereiro de 2022** + +![0,0,r](item:///default:pick_diamond) + +Servidor foi atualizado com vários mods para suas novas versões. + +## Destaques + +**Nova versão dos aviões APercy**: Mods agora usam *airutils* em comum, incluindo +para reparos e lógica básica de voo. + +**Nova versão do mod Draconis**: O mod Draconis foi atualizado para a versão 1.2. +Uma das principais novidades é que nesta nova versão o forno pode realmente ser +aquecido e usado para produzir minério, ferramenta e armadura melhorados! Também temos novos +recursos no comportamento de dragões selvagens e uma nova interface para gerenciar o +dragão domesticado. + +![1,1](halo.png) + + +# **Dicas e truques** + +Siga estas dicas e sugestões para melhorar sua jogabilidade: + +Use `protectors`, `protector blocks` e os delimitadores `area` para evitar +quebra de suas construções! Lembre-se de que algumas crianças brincam aqui também, então é melhor estar seguro +do que desculpe! + +Você pode usar o comando `search` para encontrar informações úteis sobre o mundo! \ No newline at end of file diff --git a/scripts/world/world.mt b/scripts/world/world.mt new file mode 100644 index 0000000..b3faee8 --- /dev/null +++ b/scripts/world/world.mt @@ -0,0 +1,6 @@ +world_name = MinenewsDev +gameid = minetest +enable_damage = true +creative_mode = true +server_announce = false +load_mod_markdown2formspec = true \ No newline at end of file diff --git a/settingtypes.txt b/settingtypes.txt new file mode 100644 index 0000000..640d330 --- /dev/null +++ b/settingtypes.txt @@ -0,0 +1,13 @@ +# Changes the color of the background container of the rendered form. +minenews.bg_color (Background color for the generated formspec) string #34343400 + +# Changes the color of the rendered text font. +minenews.fg_color (Font color for the generated formspec) string #AFAFAF + +# Changes the color of the Heading elements (h1, h2, ..., h6) when rendered. +minenews.header_color (Header font color) string #CFCFCF + +# Use this to let players more easily copy-paste the invitation link. +# Minetest currently do not support showing clickable links in the GUI, +# so this works as a workaround. +minenews.discord_link (If present, shows a Discord invitation link at the bottom in a text field) string \ No newline at end of file diff --git a/textures/minenews_icon_chat.png b/textures/minenews_icon_chat.png new file mode 100644 index 0000000..55f320b Binary files /dev/null and b/textures/minenews_icon_chat.png differ diff --git a/textures/minenews_icon_chat_white.png b/textures/minenews_icon_chat_white.png new file mode 100644 index 0000000..98e961e Binary files /dev/null and b/textures/minenews_icon_chat_white.png differ